diff --git a/Apps.BWX/Apps.BWX.csproj b/Apps.BWX/Apps.BWX.csproj index a6e4496..99bd28b 100644 --- a/Apps.BWX/Apps.BWX.csproj +++ b/Apps.BWX/Apps.BWX.csproj @@ -5,7 +5,7 @@ enable enable Bureau Works - 1.0.9 + 1.0.10 Bureau Works is cutting edge translation software that helps its users translate at greater speeds and with an increased sense of authorship. Apps.BWX diff --git a/Apps.BWX/Converters/DateTimeConverter.cs b/Apps.BWX/Converters/DateTimeConverter.cs new file mode 100644 index 0000000..bf48d3b --- /dev/null +++ b/Apps.BWX/Converters/DateTimeConverter.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Apps.BWX.Converters +{ + public class DateTimeConverter : JsonConverter + { + public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.Integer) + { + DateTime start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + return start.AddMilliseconds(long.Parse(reader.Value.ToString())).ToLocalTime(); + } + + throw new JsonException("The JSON value could not be converted to DateTime."); + } + + public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer) + { + writer.WriteValue(value.ToString()); + } + } +} diff --git a/Apps.BWX/Webhooks/Payload/NewProjectEvent.cs b/Apps.BWX/Webhooks/Payload/NewProjectEvent.cs index 7cca2bd..ce97a3e 100644 --- a/Apps.BWX/Webhooks/Payload/NewProjectEvent.cs +++ b/Apps.BWX/Webhooks/Payload/NewProjectEvent.cs @@ -1,4 +1,5 @@ -using Blackbird.Applications.Sdk.Common; +using Apps.BWX.Converters; +using Blackbird.Applications.Sdk.Common; using Newtonsoft.Json; namespace Apps.BWX.Webhooks.Payload; @@ -9,9 +10,10 @@ public class NewProjectEvent [JsonProperty("uuid")] public string Uuid { get; set; } - //[Display("Creation timestamp")] - //[JsonProperty("creation_timestamp")] - //public long CreationTimestamp { get; set; } + [Display("Creation date")] + [JsonProperty("creation_timestamp")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime CreationTimestamp { get; set; } [JsonProperty("creator")] public string Creator { get; set; } diff --git a/Apps.BWX/Webhooks/Payload/ProjectStatusChangedPayload.cs b/Apps.BWX/Webhooks/Payload/ProjectStatusChangedPayload.cs index 7d6c338..aa14df6 100644 --- a/Apps.BWX/Webhooks/Payload/ProjectStatusChangedPayload.cs +++ b/Apps.BWX/Webhooks/Payload/ProjectStatusChangedPayload.cs @@ -1,4 +1,5 @@ -using Blackbird.Applications.Sdk.Common; +using Apps.BWX.Converters; +using Blackbird.Applications.Sdk.Common; using Newtonsoft.Json; namespace Apps.BWX.Webhooks.Payload; @@ -9,9 +10,10 @@ public class ProjectStatusChangedPayload [JsonProperty("uuid")] public string Uuid { get; set; } - //[Display("Creation timestamp")] - //[JsonProperty("creation_timestamp")] - //public long CreationTimestamp { get; set; } + [Display("Creation date")] + [JsonProperty("creation_timestamp")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime CreationTimestamp { get; set; } public string Creator { get; set; } [Display("Creator email")] diff --git a/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs b/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs index 88694d3..283eaa0 100644 --- a/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs +++ b/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs @@ -1,4 +1,5 @@ -using Blackbird.Applications.Sdk.Common; +using Apps.BWX.Converters; +using Blackbird.Applications.Sdk.Common; using Newtonsoft.Json; namespace Apps.BWX.Webhooks.Payload; @@ -9,13 +10,15 @@ public class TaskAssignedEvent [JsonProperty("uuid")] public string Uuid { get; set; } - //[Display("Acceptance date")] - //[JsonProperty("acceptance_date")] - //public long AcceptanceDate { get; set; } + [Display("Acceptance date")] + [JsonProperty("acceptance_date")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime AcceptanceDate { get; set; } - //[Display("Assign date")] - //[JsonProperty("assign_date")] - //public long AssignDate { get; set; } + [Display("Assign date")] + [JsonProperty("assign_date")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime AssignDate { get; set; } [Display("Assigned by email")] [JsonProperty("assigned_by_email")] @@ -40,9 +43,10 @@ public class TaskAssignedEvent [JsonProperty("begin_index", NullValueHandling = NullValueHandling.Ignore)] public long BeginIndex { get; set; } - //[Display("Creation timestamp")] - //[JsonProperty("creation_timestamp")] - //public long CreationTimestamp { get; set; } + [Display("Creation date")] + [JsonProperty("creation_timestamp")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime CreationTimestamp { get; set; } [JsonProperty("creator")] public string Creator { get; set; } @@ -51,13 +55,15 @@ public class TaskAssignedEvent [JsonProperty("creator_email")] public string CreatorEmail { get; set; } - //[Display("Delivery date")] - //[JsonProperty("delivery_date")] - //public long DeliveryDate { get; set; } + [Display("Delivery date")] + [JsonProperty("delivery_date")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime DeliveryDate { get; set; } - //[Display("Due date")] - //[JsonProperty("due_date")] - //public long DueDate { get; set; } + [Display("Due date")] + [JsonProperty("due_date")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime DueDate { get; set; } //[Display("End index")] //[JsonProperty("end_index")] @@ -88,13 +94,15 @@ public class TaskAssignedEvent [JsonProperty("reference_files")] public List ReferenceFiles { get; set; } - //[Display("Scheduled date")] - //[JsonProperty("scheduled_date")] - //public long ScheduledDate { get; set; } + [Display("Scheduled date")] + [JsonProperty("scheduled_date")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime ScheduledDate { get; set; } - //[Display("Skip date")] - //[JsonProperty("skip_date")] - //public long SkipDate { get; set; } + [Display("Skip date")] + [JsonProperty("skip_date")] + [JsonConverter(typeof(DateTimeConverter))] + public DateTime SkipDate { get; set; } [JsonProperty("status")] public string Status { get; set; }