diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-08-06 13:03:05 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-08-06 13:03:05 +0300 |
| commit | 88407c1927faeabcec2b9c2699d657eb5723bc81 (patch) | |
| tree | 210f0877e20b401017b5f460e7f2f72dea8e91f8 /Software | |
| parent | f9e3fb301b8b94529f14c8c3291d430cad5d71db (diff) | |
| download | Tango-88407c1927faeabcec2b9c2699d657eb5723bc81.tar.gz Tango-88407c1927faeabcec2b9c2699d657eb5723bc81.zip | |
Refactored data store to use DataStoreMessageType.
Diffstat (limited to 'Software')
15 files changed, 185 insertions, 38 deletions
diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreHelper.cs b/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreHelper.cs index 0409dbf7a..f376afcec 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreHelper.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreHelper.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Tango.Core.ExtensionMethods; using Tango.PMR; using Tango.PMR.Common; +using Tango.PMR.DataStore; namespace Tango.DataStore { @@ -117,7 +118,7 @@ namespace Tango.DataStore /// <returns></returns> /// <exception cref="ArgumentNullException">No PMR message type specified.</exception> /// <exception cref="NotSupportedException">The specified data store type is not supported.</exception> - public static Object ParseDataStoreValue(DataType type, String text, MessageType? protoMessageType = null) + public static Object ParseDataStoreValue(DataType type, String text, DataStoreMessageType? protoMessageType = null) { switch (type) { @@ -133,7 +134,7 @@ namespace Tango.DataStore return bool.Parse(text); case DataType.Proto: if (protoMessageType == null) throw new ArgumentNullException("No PMR message type specified."); - var messageType = MessageFactory.GetPMRTypeFromMessageType(protoMessageType.Value); + var messageType = MessageFactory.GetDataStorePMRTypeFromDataStoreMessageType(protoMessageType.Value); var instance = Activator.CreateInstance(messageType) as IMessage; instance = instance.GetParser().ParseJson(text); return DataStoreProtoObject.FromMessage(instance); diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreProtoObject.cs b/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreProtoObject.cs index 1a9dd324d..5814d6eb4 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreProtoObject.cs +++ b/Software/Visual_Studio/DataStore/Tango.DataStore/DataStoreProtoObject.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core.Bson; using Tango.Core.ExtensionMethods; +using Tango.Logging; using Tango.PMR; using Tango.PMR.Common; using Tango.PMR.DataStore; @@ -19,7 +20,7 @@ namespace Tango.DataStore public class DataStoreProtoObject { [JsonConverter(typeof(StringEnumConverter))] - public MessageType MessageType { get; set; } + public DataStoreMessageType MessageType { get; set; } public Type Type { get; set; } public byte[] Data { get; set; } @@ -47,17 +48,25 @@ namespace Tango.DataStore public static DataStoreProtoObject FromBytes(byte[] data) { - var instance = BsonConvert.Deserialize<DataStoreProtoObject>(data); - instance.Message = MessageFactory.ParseProtoMessage(instance.Data, instance.Type); + try + { + var instance = BsonConvert.Deserialize<DataStoreProtoObject>(data); + instance.Message = MessageFactory.ParseProtoMessage(instance.Data, instance.Type); - return instance; + return instance; + } + catch (Exception ex) + { + LogManager.Default.Log(ex, "Error creating data store proto object."); + return null; + } } public static DataStoreProtoObject FromMessage(IMessage message) { DataStoreProtoObject proto = new DataStoreProtoObject(); proto.Type = message.GetType(); - proto.MessageType = MessageFactory.ParseMessageType(proto.Type.Name); + proto.MessageType = MessageFactory.ParseDataStoreMessageType(proto.Type.Name); proto.Data = message.ToByteArray(); proto.Message = message; return proto; @@ -72,7 +81,7 @@ namespace Tango.DataStore { DataStoreProtoObject proto = new DataStoreProtoObject(); proto.MessageType = item.ProtoType; - proto.Type = MessageFactory.GetPMRTypeFromMessageType(item.ProtoType); + proto.Type = MessageFactory.GetDataStorePMRTypeFromDataStoreMessageType(item.ProtoType); proto.Data = item.BytesValue.ToByteArray(); return proto; } diff --git a/Software/Visual_Studio/DataStore/Tango.DataStore/Tango.DataStore.csproj b/Software/Visual_Studio/DataStore/Tango.DataStore/Tango.DataStore.csproj index d75d39963..fec614168 100644 --- a/Software/Visual_Studio/DataStore/Tango.DataStore/Tango.DataStore.csproj +++ b/Software/Visual_Studio/DataStore/Tango.DataStore/Tango.DataStore.csproj @@ -69,6 +69,10 @@ <Project>{A34EE0F0-649D-41C8-8489-B6F1CC6924EE}</Project> <Name>Tango.Core</Name> </ProjectReference> + <ProjectReference Include="..\..\Tango.Logging\Tango.Logging.csproj"> + <Project>{BC932DBD-7CDB-488C-99E4-F02CF441F55E}</Project> + <Name>Tango.Logging</Name> + </ProjectReference> <ProjectReference Include="..\..\Tango.PMR\Tango.PMR.csproj"> <Project>{e4927038-348d-4295-aaf4-861c58cb3943}</Project> <Name>Tango.PMR</Name> diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Dialogs/DataStoreItemEditDialogView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Dialogs/DataStoreItemEditDialogView.xaml index 2fd3b9cdf..5fcaea2ea 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Dialogs/DataStoreItemEditDialogView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Dialogs/DataStoreItemEditDialogView.xaml @@ -9,6 +9,7 @@ xmlns:sharedControls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:datastore="clr-namespace:Tango.DataStore;assembly=Tango.DataStore" xmlns:pmr="clr-namespace:Tango.PMR.Common;assembly=Tango.PMR" + xmlns:pmrds="clr-namespace:Tango.PMR.DataStore;assembly=Tango.PMR" mc:Ignorable="d" Width="400" Height="500" d:DataContext="{d:DesignInstance Type=local:DataStoreItemEditDialogViewVM, IsDesignTimeCreatable=False}" Background="{StaticResource FSE_PrimaryBackgroundLightBrush}" Foreground="{StaticResource FSE_PrimaryForegroundBrush}"> <Grid Margin="10"> @@ -31,7 +32,7 @@ <StackPanel Margin="0 10 0 0" Visibility="{Binding Type,Converter={StaticResource EnumToVisibilityConverter},ConverterParameter='Proto'}"> <TextBlock Foreground="{StaticResource FSE_GrayBrush}" FontSize="{StaticResource FSE_SmallerFontSize}">Message Type</TextBlock> - <sharedControls:SearchComboBox IsEnabled="{Binding EnableTypeChange}" FontSize="{StaticResource FSE_SmallFontSize}" Margin="0 -5 5 0" ItemsSource="{Binding Source={x:Type pmr:MessageType},Converter={StaticResource EnumToItemsSourceConverter},ConverterParameter='false'}" SelectedItem="{Binding ProtoMessageType,Mode=TwoWay}"></sharedControls:SearchComboBox> + <sharedControls:SearchComboBox IsEnabled="{Binding EnableTypeChange}" FontSize="{StaticResource FSE_SmallFontSize}" Margin="0 -5 5 0" ItemsSource="{Binding Source={x:Type pmrds:DataStoreMessageType},Converter={StaticResource EnumToItemsSourceConverter},ConverterParameter='false'}" SelectedItem="{Binding ProtoMessageType,Mode=TwoWay}"></sharedControls:SearchComboBox> </StackPanel> </StackPanel> diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Dialogs/DataStoreItemEditDialogViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Dialogs/DataStoreItemEditDialogViewVM.cs index 9cde14c6f..e7092c043 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Dialogs/DataStoreItemEditDialogViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Dialogs/DataStoreItemEditDialogViewVM.cs @@ -15,6 +15,8 @@ using Tango.FSE.Common; using Tango.FSE.Common.Storage; using Tango.PMR; using Tango.PMR.Common; +using Tango.PMR.DataStore; +using DataType = Tango.DataStore.DataType; namespace Tango.FSE.MachineConfiguration.Dialogs { @@ -80,8 +82,8 @@ namespace Tango.FSE.MachineConfiguration.Dialogs set { _type = value; RaisePropertyChangedAuto(); OnEditingValueChanged(); } } - private MessageType _protoMessageType; - public MessageType ProtoMessageType + private DataStoreMessageType _protoMessageType; + public DataStoreMessageType ProtoMessageType { get { return _protoMessageType; } set { _protoMessageType = value; RaisePropertyChangedAuto(); OnEditingValueChanged(); } @@ -122,7 +124,7 @@ namespace Tango.FSE.MachineConfiguration.Dialogs { if (Type == DataType.Proto) { - var type = MessageFactory.GetPMRTypeFromMessageType(ProtoMessageType); + var type = MessageFactory.GetDataStorePMRTypeFromDataStoreMessageType(ProtoMessageType); var instance = Activator.CreateInstance(type); EditingValue = instance.ToJsonString(); } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs index 16fe59f61..a90d5aa26 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/DataStoreViewVM.cs @@ -17,6 +17,7 @@ using Tango.FSE.Common.Notifications; using Tango.FSE.MachineConfiguration.Dialogs; using Tango.FSE.MachineConfiguration.Messages; using Tango.FSE.MachineConfiguration.Models; +using Tango.PMR.DataStore; using static Tango.FSE.BL.Services.MachineConfigurationService; using static Tango.SharedUI.Controls.NavigationControl; @@ -209,7 +210,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels Date = DateTime.UtcNow, Guid = Guid.NewGuid().ToString(), Key = result.Input, - Type = DataType.Int32, + Type = Tango.DataStore.DataType.Int32, Value = 10 }); } @@ -332,6 +333,7 @@ namespace Tango.FSE.MachineConfiguration.ViewModels } catch (Exception ex) { + IsFree = true; DataStore = null; LogManager.Log(ex, "Error loading data store."); if (await NotificationProvider.ShowWarningQuestion($"Error occurred while trying to load the data store.\n{ex.FlattenMessage()}", "RETRY", "CANCEL")) @@ -392,14 +394,14 @@ namespace Tango.FSE.MachineConfiguration.ViewModels itemModel.Date = DateTime.Parse(item.Date); itemModel.IsSelected = true; - DataType type = (DataType)Enum.Parse(typeof(DataType), item.Type); + DataStore.DataType type = (DataStore.DataType)Enum.Parse(typeof(DataStore.DataType), item.Type); itemModel.OriginalType = type; itemModel.Type = type; - PMR.Common.MessageType? messageType = null; - if (type == DataType.Proto && item.MessageType.IsNotNullOrEmpty()) + DataStoreMessageType? messageType = null; + if (type == Tango.DataStore.DataType.Proto && item.MessageType.IsNotNullOrEmpty()) { - messageType = (PMR.Common.MessageType)Enum.Parse(typeof(PMR.Common.MessageType), item.MessageType); + messageType = (DataStoreMessageType)Enum.Parse(typeof(DataStoreMessageType), item.MessageType); } itemModel.OriginalValue = DataStoreHelper.ParseDataStoreValue(type, item.Value, messageType); @@ -500,9 +502,9 @@ namespace Tango.FSE.MachineConfiguration.ViewModels { foreach (var item in collection.Items.Where(x => x.IsSelected && !x.IsGlobal && x.Value != null)) { - PMR.Common.MessageType? messageType = null; + DataStoreMessageType? messageType = null; - if (item.Type == DataType.Proto) + if (item.Type == Tango.DataStore.DataType.Proto) { messageType = (item.Value as DataStoreProtoObject).MessageType; } diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/DataStoreView.xaml b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/DataStoreView.xaml index 52a140c81..533414e23 100644 --- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/DataStoreView.xaml +++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/Views/DataStoreView.xaml @@ -51,7 +51,7 @@ <Grid DockPanel.Dock="Left"> <DockPanel VerticalAlignment="Center" Visibility="{Binding CanSync,Converter={StaticResource BooleanToVisibilityConverter}}"> <material:PackIcon Kind="InfoCircleOutline" Foreground="{StaticResource FSE_GreenBrush}" /> - <TextBlock FontSize="{StaticResource FSE_SmallFontSize}" Foreground="{StaticResource FSE_GreenBrush}" VerticalAlignment="Center" Margin="5 2 0 0">Machine is connected, updating the data store will be take effect immediately.</TextBlock> + <TextBlock FontSize="{StaticResource FSE_SmallFontSize}" Foreground="{StaticResource FSE_GreenBrush}" VerticalAlignment="Center" Margin="5 2 0 0">Machine is connected, updating the data store will take effect immediately.</TextBlock> </DockPanel> </Grid> diff --git a/Software/Visual_Studio/FSE/Tango.FSE.UI/DataStore/DefaultDataStoreProvider.cs b/Software/Visual_Studio/FSE/Tango.FSE.UI/DataStore/DefaultDataStoreProvider.cs index f6ea90378..913665877 100644 --- a/Software/Visual_Studio/FSE/Tango.FSE.UI/DataStore/DefaultDataStoreProvider.cs +++ b/Software/Visual_Studio/FSE/Tango.FSE.UI/DataStore/DefaultDataStoreProvider.cs @@ -294,7 +294,11 @@ namespace Tango.FSE.UI.DataStore itemDb.LastUpdated = DateTime.UtcNow; itemDb.IsSynchronized = false; updateRequest.ToDelete.Add(itemDb.Guid); - actionLogDeleted.Add(DataStoreItemDTO.FromObservable(itemDb)); + try + { + actionLogDeleted.Add(DataStoreItemDTO.FromObservable(itemDb)); + } + catch { } } } @@ -370,7 +374,7 @@ namespace Tango.FSE.UI.DataStore foreach (var item in actionLogDeleted) { - ActionLogManager.InsertLog(ActionLogType.DataStoreItemDeleted, AuthenticationProvider.CurrentUser,$"{machine.SerialNumber} => {item.Key}", item, "Data store item deleted via FSE.", true); + ActionLogManager.InsertLog(ActionLogType.DataStoreItemDeleted, AuthenticationProvider.CurrentUser, $"{machine.SerialNumber} => {item.Key}", item, "Data store item deleted via FSE.", true); } foreach (var item in actionLogInserted) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest index d72e75011..efc5f8179 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest @@ -16,7 +16,7 @@ Remove this element if your application requires this virtualization for backwards compatibility. --> - <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> + <!--<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />--> </requestedPrivileges> </security> </trustInfo> diff --git a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs index ab007329f..9d486c8e0 100644 --- a/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs +++ b/Software/Visual_Studio/Tango.Emulations/Emulators/MachineEmulator.cs @@ -2147,7 +2147,7 @@ namespace Tango.Emulations.Emulators { DataType = DataType.Proto, BytesValue = new CalculateRequest() { A = 10, B = 15 }.ToByteString(), - ProtoType = MessageType.CalculateRequest, + ProtoType = DataStoreMessageType.CalculateRequest, } }); @@ -2214,7 +2214,7 @@ namespace Tango.Emulations.Emulators { DataType = DataType.Proto, BytesValue = (new CalculateRequest() { A = 10, B = 15 }).ToByteString(), - ProtoType = MessageType.CalculateRequest, + ProtoType = DataStoreMessageType.CalculateRequest, }, }); @@ -2249,7 +2249,25 @@ namespace Tango.Emulations.Emulators try { var response = await Transporter.SendRequest<GetDataStoreItemRequest, GetDataStoreItemResponse>(request); - LogManager.Log($"Received GetDataStoreItemResponse:\n{response.Message.ToJsonString()}"); + + String protoJson = String.Empty; + + try + { + if (response.Message.Item.DataType == DataType.Proto) + { + var type = MessageFactory.GetDataStorePMRTypeFromDataStoreMessageType(response.Message.Item.ProtoType); + var instance = MessageFactory.ParseProtoMessage(response.Message.Item.BytesValue.ToByteArray(), type); + protoJson = instance.ToJsonString(); + } + } + catch (Exception ex) + { + protoJson = ex.Message; + } + + LogManager.Log($"Received GetDataStoreItemResponse:\n{response.Message.ToJsonString()}\nProtobuf Message:\n{protoJson}"); + } catch (Exception ex) { diff --git a/Software/Visual_Studio/Tango.PMR/DataStore/DataStoreItem.cs b/Software/Visual_Studio/Tango.PMR/DataStore/DataStoreItem.cs index f560237ae..c6b4e6776 100644 --- a/Software/Visual_Studio/Tango.PMR/DataStore/DataStoreItem.cs +++ b/Software/Visual_Studio/Tango.PMR/DataStore/DataStoreItem.cs @@ -23,15 +23,16 @@ namespace Tango.PMR.DataStore { byte[] descriptorData = global::System.Convert.FromBase64String( string.Concat( "ChNEYXRhU3RvcmVJdGVtLnByb3RvEhNUYW5nby5QTVIuRGF0YVN0b3JlGg5E", - "YXRhVHlwZS5wcm90bxoRTWVzc2FnZVR5cGUucHJvdG8i7gEKDURhdGFTdG9y", - "ZUl0ZW0SLwoIRGF0YVR5cGUYASABKA4yHS5UYW5nby5QTVIuRGF0YVN0b3Jl", - "LkRhdGFUeXBlEhIKCkludDMyVmFsdWUYAiABKAUSEgoKRmxvYXRWYWx1ZRgD", - "IAEoAhITCgtEb3VibGVWYWx1ZRgEIAEoARIUCgxCb29sZWFuVmFsdWUYBSAB", - "KAgSEwoLU3RyaW5nVmFsdWUYBiABKAkSEgoKQnl0ZXNWYWx1ZRgHIAEoDBIw", - "CglQcm90b1R5cGUYFCABKA4yHS5UYW5nby5QTVIuQ29tbW9uLk1lc3NhZ2VU", - "eXBlQh8KHWNvbS50d2luZS50YW5nby5wbXIuZGF0YXN0b3JlYgZwcm90bzM=")); + "YXRhVHlwZS5wcm90bxoaRGF0YVN0b3JlTWVzc2FnZVR5cGUucHJvdG8i+gEK", + "DURhdGFTdG9yZUl0ZW0SLwoIRGF0YVR5cGUYASABKA4yHS5UYW5nby5QTVIu", + "RGF0YVN0b3JlLkRhdGFUeXBlEhIKCkludDMyVmFsdWUYAiABKAUSEgoKRmxv", + "YXRWYWx1ZRgDIAEoAhITCgtEb3VibGVWYWx1ZRgEIAEoARIUCgxCb29sZWFu", + "VmFsdWUYBSABKAgSEwoLU3RyaW5nVmFsdWUYBiABKAkSEgoKQnl0ZXNWYWx1", + "ZRgHIAEoDBI8CglQcm90b1R5cGUYFCABKA4yKS5UYW5nby5QTVIuRGF0YVN0", + "b3JlLkRhdGFTdG9yZU1lc3NhZ2VUeXBlQh8KHWNvbS50d2luZS50YW5nby5w", + "bXIuZGF0YXN0b3JlYgZwcm90bzM=")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, - new pbr::FileDescriptor[] { global::Tango.PMR.DataStore.DataTypeReflection.Descriptor, global::Tango.PMR.Common.MessageTypeReflection.Descriptor, }, + new pbr::FileDescriptor[] { global::Tango.PMR.DataStore.DataTypeReflection.Descriptor, global::Tango.PMR.DataStore.DataStoreMessageTypeReflection.Descriptor, }, new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Tango.PMR.DataStore.DataStoreItem), global::Tango.PMR.DataStore.DataStoreItem.Parser, new[]{ "DataType", "Int32Value", "FloatValue", "DoubleValue", "BooleanValue", "StringValue", "BytesValue", "ProtoType" }, null, null, null) })); @@ -158,12 +159,12 @@ namespace Tango.PMR.DataStore { /// <summary>Field number for the "ProtoType" field.</summary> public const int ProtoTypeFieldNumber = 20; - private global::Tango.PMR.Common.MessageType protoType_ = 0; + private global::Tango.PMR.DataStore.DataStoreMessageType protoType_ = 0; /// <summary> ///Use only when DataType = Proto. /// </summary> [global::System.Diagnostics.DebuggerNonUserCodeAttribute] - public global::Tango.PMR.Common.MessageType ProtoType { + public global::Tango.PMR.DataStore.DataStoreMessageType ProtoType { get { return protoType_; } set { protoType_ = value; @@ -347,7 +348,7 @@ namespace Tango.PMR.DataStore { break; } case 160: { - protoType_ = (global::Tango.PMR.Common.MessageType) input.ReadEnum(); + protoType_ = (global::Tango.PMR.DataStore.DataStoreMessageType) input.ReadEnum(); break; } } diff --git a/Software/Visual_Studio/Tango.PMR/DataStore/DataStoreMessageType.cs b/Software/Visual_Studio/Tango.PMR/DataStore/DataStoreMessageType.cs new file mode 100644 index 000000000..9c9f70ef8 --- /dev/null +++ b/Software/Visual_Studio/Tango.PMR/DataStore/DataStoreMessageType.cs @@ -0,0 +1,47 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: DataStoreMessageType.proto +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Tango.PMR.DataStore { + + /// <summary>Holder for reflection information generated from DataStoreMessageType.proto</summary> + public static partial class DataStoreMessageTypeReflection { + + #region Descriptor + /// <summary>File descriptor for DataStoreMessageType.proto</summary> + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static DataStoreMessageTypeReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChpEYXRhU3RvcmVNZXNzYWdlVHlwZS5wcm90bxITVGFuZ28uUE1SLkRhdGFT", + "dG9yZSpSChREYXRhU3RvcmVNZXNzYWdlVHlwZRINCglVbmRlZmluZWQQABIU", + "ChBDYWxjdWxhdGVSZXF1ZXN0EAESFQoRQ2FsY3VsYXRlUmVzcG9uc2UQAkIf", + "Ch1jb20udHdpbmUudGFuZ28ucG1yLmRhdGFzdG9yZWIGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Tango.PMR.DataStore.DataStoreMessageType), }, null)); + } + #endregion + + } + #region Enums + public enum DataStoreMessageType { + [pbr::OriginalName("Undefined")] Undefined = 0, + [pbr::OriginalName("CalculateRequest")] CalculateRequest = 1, + [pbr::OriginalName("CalculateResponse")] CalculateResponse = 2, + } + + #endregion + +} + +#endregion Designer generated code diff --git a/Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs b/Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs index d5475ce7b..be0912220 100644 --- a/Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs +++ b/Software/Visual_Studio/Tango.PMR/ExtensionMethods.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Tango.PMR.Common; +using Tango.PMR.DataStore; using Tango.PMR.Integration; /// <summary> @@ -33,6 +34,19 @@ public static class ExtensionMethods return value.ToString(); } + public static String ToOriginalName(this DataStoreMessageType value) + { + FieldInfo fi = value.GetType().GetField(value.ToString()); + + OriginalNameAttribute[] attributes = (OriginalNameAttribute[])fi.GetCustomAttributes(typeof(OriginalNameAttribute), false); + + if (attributes != null && + attributes.Length > 0) + return attributes[0].Name; + else + return value.ToString(); + } + /// <summary> /// Gets the message parser. /// </summary> diff --git a/Software/Visual_Studio/Tango.PMR/MessageFactory.cs b/Software/Visual_Studio/Tango.PMR/MessageFactory.cs index d23970e88..8aa5283e8 100644 --- a/Software/Visual_Studio/Tango.PMR/MessageFactory.cs +++ b/Software/Visual_Studio/Tango.PMR/MessageFactory.cs @@ -7,6 +7,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Tango.PMR.Common; +using Tango.PMR.DataStore; using Tango.PMR.Integration; namespace Tango.PMR @@ -17,6 +18,7 @@ namespace Tango.PMR public static class MessageFactory { private static Dictionary<MessageType, Type> _pmrTypes; + private static Dictionary<DataStoreMessageType, Type> _pmrDataStoreTypes; private static MethodInfo _parseTangoMessageMethod; static MessageFactory() @@ -35,6 +37,18 @@ namespace Tango.PMR _pmrTypes.Add(value, type); } } + + _pmrDataStoreTypes = new Dictionary<DataStoreMessageType, Type>(); + + foreach (var value in Enum.GetValues(typeof(DataStoreMessageType)).OfType<DataStoreMessageType>()) + { + var type = types.SingleOrDefault(x => x.Name == value.ToOriginalName()); + + if (type != null) + { + _pmrDataStoreTypes.Add(value, type); + } + } } /// <summary> @@ -48,6 +62,16 @@ namespace Tango.PMR } /// <summary> + /// Returns the matching PMR type from the PMR message type. + /// </summary> + /// <param name="messageType">Type of the message.</param> + /// <returns></returns> + public static Type GetDataStorePMRTypeFromDataStoreMessageType(DataStoreMessageType messageType) + { + return _pmrDataStoreTypes[messageType]; + } + + /// <summary> /// Creates a new <see cref="TangoMessage{T}"/>. /// </summary> /// <typeparam name="T"></typeparam> @@ -200,6 +224,25 @@ namespace Tango.PMR } /// <summary> + /// Parses the specified text to a PMR <see cref="MessageType"/>. + /// </summary> + /// <param name="text">The text.</param> + /// <returns></returns> + /// <exception cref="InvalidCastException">Could not parse message type " + text</exception> + public static DataStoreMessageType ParseDataStoreMessageType(String text) + { + DataStoreMessageType t; + if (Enum.TryParse<DataStoreMessageType>(text, true, out t)) + { + return t; + } + else + { + throw new InvalidCastException("Data Store Message type " + text + " was not found on PMR DataStoreMessageType enumeration!"); + } + } + + /// <summary> /// Gets the available request stubs. /// </summary> /// <returns></returns> diff --git a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj index 7e3ec022f..dc2016ae1 100644 --- a/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj +++ b/Software/Visual_Studio/Tango.PMR/Tango.PMR.csproj @@ -88,6 +88,7 @@ <Compile Include="DataStore\DataStoreItem.cs" /> <Compile Include="DataStore\DataStoreItemModifiedRequest.cs" /> <Compile Include="DataStore\DataStoreItemModifiedResponse.cs" /> + <Compile Include="DataStore\DataStoreMessageType.cs" /> <Compile Include="DataStore\DataType.cs" /> <Compile Include="DataStore\GetDataStoreItemRequest.cs" /> <Compile Include="DataStore\GetDataStoreItemResponse.cs" /> @@ -508,7 +509,7 @@ </PropertyGroup> <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> </Project>
\ No newline at end of file |
