aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Core
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-23 08:44:31 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-08-23 08:44:31 +0300
commit02ae577faa0bd4938507061d603e4f9447e2b64f (patch)
tree7daf0e275338ec92e93bfca39f2d529d93858162 /Software/Visual_Studio/Tango.Core
parent67770063ff1a1c5c522e3bc29f442c42eb6dc521 (diff)
downloadTango-02ae577faa0bd4938507061d603e4f9447e2b64f.tar.gz
Tango-02ae577faa0bd4938507061d603e4f9447e2b64f.zip
Fixed issue with insights file datetime utc.
added insights application exception/crash. added remote actions service. fixed issue with LiteDB hang on application start/exit. reduced insights listener empty frames.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core')
-rw-r--r--Software/Visual_Studio/Tango.Core/Bson/BsonUtcSerializer.cs68
-rw-r--r--Software/Visual_Studio/Tango.Core/Tango.Core.csproj3
2 files changed, 70 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Bson/BsonUtcSerializer.cs b/Software/Visual_Studio/Tango.Core/Bson/BsonUtcSerializer.cs
new file mode 100644
index 000000000..6f5cb7700
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Core/Bson/BsonUtcSerializer.cs
@@ -0,0 +1,68 @@
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Core.Bson
+{
+ public class BsonUtcSerializer : JsonSerializer
+ {
+ private class DateTimeConverter : JsonConverter
+ {
+ public override bool CanConvert(Type objectType)
+ {
+ return typeof(DateTime) == objectType
+ || typeof(DateTime?) == objectType;
+ }
+
+ public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+ {
+ var dateTimeOffset = (DateTime)value;
+ // Serialize DateTimeOffset as round-trip formatted string
+ serializer.Serialize(writer, dateTimeOffset.ToString("O"));
+ }
+
+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ {
+ if (reader.TokenType != JsonToken.String && reader.TokenType != JsonToken.Date)
+ return null;
+
+ DateTime dt;
+
+ var dateWithOffset = (String)reader.Value;
+
+ if (String.IsNullOrEmpty(dateWithOffset))
+ return null;
+
+ if (DateTime.TryParseExact(dateWithOffset, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out dt))
+ return dt;
+
+ return null;
+ }
+
+ }
+
+ private class DateTimeContractResolver : DefaultContractResolver
+ {
+ protected override JsonContract CreateContract(Type objectType)
+ {
+ var contract = base.CreateContract(objectType);
+
+ if (objectType == typeof(DateTime) || objectType == typeof(DateTime?))
+ contract.Converter = new DateTimeConverter();
+
+ return contract;
+ }
+ }
+
+ public BsonUtcSerializer()
+ {
+ ContractResolver = new DateTimeContractResolver();
+ DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
+ }
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj
index 2db9c8643..2ecd441f2 100644
--- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj
+++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj
@@ -95,6 +95,7 @@
<Compile Include="..\Versioning\GlobalVersionInfo.cs">
<Link>GlobalVersionInfo.cs</Link>
</Compile>
+ <Compile Include="Bson\BsonUtcSerializer.cs" />
<Compile Include="Components\CmdCommand.cs" />
<Compile Include="CustomAttributes\PropertyIndexAttribute.cs" />
<Compile Include="CustomAttributes\StringFormatAttribute.cs" />
@@ -216,7 +217,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
+ <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
</VisualStudio>
</ProjectExtensions>
<Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" />