From adaddad79352c156303e9178a6f172a18af50cd2 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 24 Oct 2020 06:40:07 +0300 Subject: Refactored DataStore Proto. --- .../Tango.DataStore/DataStoreHelper.cs | 70 ++++++++++++++-------- 1 file changed, 45 insertions(+), 25 deletions(-) (limited to 'Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs') diff --git a/Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs b/Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs index 53745990e..3cf24bdd0 100644 --- a/Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs +++ b/Software/Visual_Studio/Tango.DataStore/DataStoreHelper.cs @@ -1,8 +1,14 @@ -using System; +using Google.Protobuf; +using Newtonsoft.Json.Linq; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Tango.Core.ExtensionMethods; +using Tango.PMR; +using Tango.PMR.Common; namespace Tango.DataStore { @@ -53,6 +59,14 @@ namespace Tango.DataStore { return DataType.Bytes; } + else if (type == typeof(DataStoreProtoObject)) + { + return DataType.Proto; + } + else if (typeof(IMessage).IsAssignableFrom(type)) + { + return DataType.Proto; + } throw new NotSupportedException($"The specified type '{type.Name}' is not supported by the data store."); } @@ -63,26 +77,28 @@ namespace Tango.DataStore /// The type. /// /// The specified data type is not supported. - public static Type GetType(DataType type) - { - switch (type) - { - case DataType.Boolean: - return typeof(bool); - case DataType.Bytes: - return typeof(byte[]); - case DataType.Double: - return typeof(double); - case DataType.Float: - return typeof(float); - case DataType.Int32: - return typeof(Int32); - case DataType.String: - return typeof(String); - } + //public static Type GetType(DataType type) + //{ + // switch (type) + // { + // case DataType.Boolean: + // return typeof(bool); + // case DataType.Bytes: + // return typeof(byte[]); + // case DataType.Double: + // return typeof(double); + // case DataType.Float: + // return typeof(float); + // case DataType.Int32: + // return typeof(Int32); + // case DataType.String: + // return typeof(String); + // case DataType.Proto: + // return typeof(DataStoreProtoObject); + // } - throw new NotSupportedException("The specified data type is not supported."); - } + // throw new NotSupportedException("The specified data type is not supported."); + //} /// /// Formats the data store item as a string. @@ -91,11 +107,7 @@ namespace Tango.DataStore /// public static String FormatDataStoreItem(IDataStoreItem item) { - if (item.Type != DataType.Bytes) - { - return $"{item.Key}: {item.Value}"; - } - else + if (item.Type == DataType.Bytes) { byte[] bytes = (byte[])item.Value; @@ -106,6 +118,14 @@ namespace Tango.DataStore } return hex.ToString(); } + else if (item.Type == DataType.Proto) + { + return (item.Value as DataStoreProtoObject).Message.ToJsonString(); + } + else + { + return $"{item.Key}: {item.Value}"; + } } } } -- cgit v1.3.1