Azure功能 - 队列触发器将DateTimeOffset返回为null

时间:2017-10-23 10:26:36

标签: c# .net azure azure-functions datetimeoffset

我运行的Azure函数连接到API,获取一些数据并将其保存到Azure中的队列。

然后我有另一个Azure函数作为该队列的触发器运行,我遇到了DateTimeOffset的一些问题?数据中某个对象的属性。所有其他属性按预期工作。

简化示例代码:

run.csx:

using System;
using System.Collections.Generic;
using GoApi;
using GoApi.Reporting.AccountTransactions;

public static void Run(ReverseFactoringTransaction myQueueItem, TraceWriter log)
{
    log.Info(myQueueItem.Transaction.CreatedDate.ToString());
    log.Info(myQueueItem.Transaction.Text.ToString());
    log.Info(myQueueItem.Transaction.Amount.ToString());
    log.Info(myQueueItem.Transaction.Date.ToString());
    log.Info(myQueueItem.Partner.Name.ToString());
    log.Info(myQueueItem.Partner.IsActive.ToString());
    log.Info(myQueueItem.Partner.CreatedDate.ToString());
    log.Info(myQueueItem.LastSynchronizationDate.ToString());
    log.Info(myQueueItem.PostOnCreatedDate.ToString());
}

public class Auditable
{
    public string CreatedBy { get; set; }
    public string UpdatedBy { get; set; }
    public DateTime CreatedDate { get; set; }
    public DateTime UpdatedDate { get; set; }
}

public class Client : Auditable
{
    public Guid Id { get; set; }
    public long? CustomerId { get; set; }
    public string Name { get; set; }
    public string ClientKey { get; set; }
    public bool IsManuallyRecognized { get; set; }
    public bool IsActive { get; set; }
    public Guid PartnerId { get; set; }
    public Partner Partner { get; set; }
}

public class Partner : Auditable
{
    public Guid Id { get; set; }
    public string Name { get; set; }
    public string PartnerKey { get; set; }
    public bool IsActive { get; set; }
    public List<Client> Clients { get; set; }
}

public class ReverseFactoringTransaction
{
    public Partner Partner { get; set; }
    public AccountTransaction Transaction { get; set; }
    public int ReverseAccountCode { get; set; }
    public DateTimeOffset LastSynchronizationDate { get; set; }
    public bool PostOnCreatedDate { get; set; }
}

project.json:

{
    "frameworks":
    {
        "net46":
        {
            "dependencies":
            {
                "PowerOfficeGoSDK": "1.6.3"
            }
        }
    }
}

当我使用此测试输入时:

{
  "Partner": {
    "Id": "da462e01-d999-41d0-a71d-dbcf36ca219b",
    "Name": "Test Acme",
    "PartnerKey": "62504f06-1bee-4665-807c-6c918f2ac454",
    "IsActive": true,
    "CreatedBy": "sth",
    "UpdatedBy": "sth",
    "CreatedDate": "2017-10-18T07:40:16.3244273+00:00",
    "UpdatedDate": "2017-10-18T07:40:16.3244273+00:00"
  },
  "Transaction": {
    "Id": 4889211,
    "AccountCode": 1500,
    "Date": "2017-02-15T00:00:00",
    "VoucherNo": 14,
    "VoucherType": 4,
    "Text": "Invoice 1 for TestCompany Inc",
    "Description": "",
    "VatCode": "0",
    "VatAmount": 0.0,
    "VatRate": 0.0,
    "Amount": 380000.0,
    "CurrencyCode": "GBP",
    "CurrencyAmount": 380000.0,
    "VoucherImagesCount": 0,
    "LastChanged": "2017-10-17T15:31:14+00:00",
    "CreatedDate": "2017-10-17T15:31:14+00:00",
    "CustomerAccountNo": 10013,
    "VoucherDueDate": "2017-10-20T00:00:00",
    "VoucherCID": "141",
    "VoucherId": "95620904-623a-48b6-99a4-6316d893886b",
    "DocumentNo": "14",
    "CreatedFromImportJournalId": "1c9d60cf-9cc0-409e-9b3e-787461a0ae96",
    "IsCreatedFromEhf": false
  },
  "ReverseAccountCode": 1510,
  "LastSynchronizationDate": "2017-01-18T00:00:00+00:00",
  "PostOnCreatedDate": true,
  "$AzureWebJobsParentId": "765c4f56-0cdb-4d08-b9fa-8bc4a94e0499"
}

我将此作为函数的输出:

2017-10-18T08:05:50.391 Function started (Id=bb8f485c-9f33-4976-833f-4a1ac0840e22)
2017-10-18T08:05:50.391 
2017-10-18T08:05:50.391 Invoice 1 for TestCompany Inc
2017-10-18T08:05:50.391 380000.0
2017-10-18T08:05:50.391 2/15/2017 12:00:00 AM
2017-10-18T08:05:50.391 Test Acme
2017-10-18T08:05:50.391 True
2017-10-18T08:05:50.391 10/18/2017 7:40:16 AM
2017-10-18T08:05:50.391 1/18/2017 12:00:00 AM +00:00
2017-10-18T08:05:50.391 True
2017-10-18T08:05:50.391 Function completed (Success, Id=bb8f485c-9f33-4976-833f-4a1ac0840e22, Duration=1ms)

正如您可以看到DateTimeOffset? Transaction对象上的CreatedDate显示为null。但我完全不知道为什么。 有谁知道问题可能是什么?

1 个答案:

答案 0 :(得分:1)

AccountTransaction.CreatedDateinternal个setter,因此在反序列化过程中会被忽略。

有关内部属性反序列化的说明,请参阅this question

如果确实需要它,可以接受队列项作为字符串,然后使用自定义设置/解析器手动反序列化。