1
votes

I have an Azure Function running that connects to an API, gets some data and saves it to a queue in Azure.

Then I have another Azure function running as a trigger on that queue and I am having some problems with the DateTimeOffset? property on one of the objects in the data. All the other properties work as expected.

Simplified example code:

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"
            }
        }
    }
}

When I use this test input:

{
  "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"
}

I get this as the output from the function:

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)

As you can see the DateTimeOffset? CreatedDate on the Transaction object comes out as null. But I have absolutely no idea why. Does anyone know what the problem could be?

1

1 Answers

1
votes

AccountTransaction.CreatedDate has internal setter, so it will be ignored during deserialization.

See this question for description of internal properties deserialization.

If you really need it, you can accept a queue item as string, and then deserialize manually with your custom settings / resolver.