diff options
Diffstat (limited to 'Software/Visual_Studio/Tango.PMR/MessageFactory.cs')
| -rw-r--r-- | Software/Visual_Studio/Tango.PMR/MessageFactory.cs | 43 |
1 files changed, 43 insertions, 0 deletions
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> |
