From 88407c1927faeabcec2b9c2699d657eb5723bc81 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Fri, 6 Aug 2021 13:03:05 +0300 Subject: Refactored data store to use DataStoreMessageType. --- Software/Visual_Studio/Tango.PMR/MessageFactory.cs | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'Software/Visual_Studio/Tango.PMR/MessageFactory.cs') 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 _pmrTypes; + private static Dictionary _pmrDataStoreTypes; private static MethodInfo _parseTangoMessageMethod; static MessageFactory() @@ -35,6 +37,18 @@ namespace Tango.PMR _pmrTypes.Add(value, type); } } + + _pmrDataStoreTypes = new Dictionary(); + + foreach (var value in Enum.GetValues(typeof(DataStoreMessageType)).OfType()) + { + var type = types.SingleOrDefault(x => x.Name == value.ToOriginalName()); + + if (type != null) + { + _pmrDataStoreTypes.Add(value, type); + } + } } /// @@ -47,6 +61,16 @@ namespace Tango.PMR return _pmrTypes[messageType]; } + /// + /// Returns the matching PMR type from the PMR message type. + /// + /// Type of the message. + /// + public static Type GetDataStorePMRTypeFromDataStoreMessageType(DataStoreMessageType messageType) + { + return _pmrDataStoreTypes[messageType]; + } + /// /// Creates a new . /// @@ -199,6 +223,25 @@ namespace Tango.PMR } } + /// + /// Parses the specified text to a PMR . + /// + /// The text. + /// + /// Could not parse message type " + text + public static DataStoreMessageType ParseDataStoreMessageType(String text) + { + DataStoreMessageType t; + if (Enum.TryParse(text, true, out t)) + { + return t; + } + else + { + throw new InvalidCastException("Data Store Message type " + text + " was not found on PMR DataStoreMessageType enumeration!"); + } + } + /// /// Gets the available request stubs. /// -- cgit v1.3.1