簡體   English   中英

Azure 函數 - 隊列觸發器將 DateTimeOffset 返回為 null

[英]Azure Function - Queue Trigger returns DateTimeOffset as null

我有一個 Azure 函數正在運行,它連接到 API,獲取一些數據並將其保存到 Azure 中的隊列。

然后我有另一個 Azure 函數作為該隊列上的觸發器運行,我在 DateTimeOffset 上遇到了一些問題? 數據中對象之一的屬性。 所有其他屬性都按預期工作。

簡化示例代碼:

運行.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; }
}

項目.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。 但我完全不知道為什么。 有誰知道是什么問題?

AccountTransaction.CreatedDate具有internal設置器,因此在反序列化期間將被忽略。

有關內部屬性反序列化的說明,請參閱此問題

如果你真的需要它,你可以接受一個隊列項目作為字符串,然后使用你的自定義設置/解析器手動反序列化。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM