From c7ee5800358924f9b044aba2984c80e58401ec33 Mon Sep 17 00:00:00 2001 From: bohdanm-bb Date: Wed, 15 May 2024 03:23:07 +0300 Subject: [PATCH 1/4] DateTime converter --- Apps.BWX/Converters/DateTimeConverter.cs | 29 +++++++++++++++++++ .../Payload/ProjectStatusChangedPayload.cs | 10 ++++--- 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 Apps.BWX/Converters/DateTimeConverter.cs diff --git a/Apps.BWX/Converters/DateTimeConverter.cs b/Apps.BWX/Converters/DateTimeConverter.cs new file mode 100644 index 0000000..1825355 --- /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())); + } + + 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/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")] From 3fe060c60fa106c3e05548ae649d0751736ac6d6 Mon Sep 17 00:00:00 2001 From: bohdanm-bb Date: Wed, 15 May 2024 03:34:19 +0300 Subject: [PATCH 2/4] DateTime converter --- Apps.BWX/Converters/DateTimeConverter.cs | 2 +- Apps.BWX/Webhooks/Payload/NewProjectEvent.cs | 10 +++-- .../Webhooks/Payload/TaskAssignedEvent.cs | 38 +++++++++++-------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Apps.BWX/Converters/DateTimeConverter.cs b/Apps.BWX/Converters/DateTimeConverter.cs index 1825355..bf48d3b 100644 --- a/Apps.BWX/Converters/DateTimeConverter.cs +++ b/Apps.BWX/Converters/DateTimeConverter.cs @@ -15,7 +15,7 @@ public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime e 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())); + return start.AddMilliseconds(long.Parse(reader.Value.ToString())).ToLocalTime(); } throw new JsonException("The JSON value could not be converted to DateTime."); 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/TaskAssignedEvent.cs b/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs index 88694d3..713d9cb 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")] From b0af583e08a7b9113388a186039a8b13d7582384 Mon Sep 17 00:00:00 2001 From: bohdanm-bb Date: Wed, 15 May 2024 03:36:43 +0300 Subject: [PATCH 3/4] Add datetime --- Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs b/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs index 713d9cb..283eaa0 100644 --- a/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs +++ b/Apps.BWX/Webhooks/Payload/TaskAssignedEvent.cs @@ -94,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; } From c72a5de8d728eddb2d69d7821e65bda6636eca63 Mon Sep 17 00:00:00 2001 From: bohdanm-bb Date: Wed, 15 May 2024 16:07:17 +0300 Subject: [PATCH 4/4] New version --- Apps.BWX/Apps.BWX.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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