private void LoadMessages()
 {
     _MessageList = new ObservableCollection<MessageSettings>();
     foreach (XmlNode e in settings.ChildNodes)
     {
         if (e.NodeType == XmlNodeType.Element && e.Name == "message")
         {
             MessageSettings message = new MessageSettings(DeviceManagementSettings, (XmlElement)e);
             _MessageList.Add(message);
         }
     }
 }
Example #2
0
        private Message LoadMessage(Conversation conv, MessageSettings settings)
        {
            MessageType type = settings.Type;
            if (type == MessageType.ValueCount)
                return null;

            Message message = new Message(conv, type, settings.Name);

            foreach (MessageSettings.ElementListValue element in settings.ElementList)
            {
                if (element.Type == "BYTE")
                {
                    if (element.ValueString != null)
                    {
                        message.Elements.Add(new Literal(element.ValueString, conv, element.ExcludeFromChecksum));
                    }
                    else
                    {
                        UseVariable useVar = new UseVariable(conv, element.Name, element.Type, element.Size, element.ExcludeFromChecksum);
                        message.Elements.Add(useVar);
                        if (element.SizeName != null)
                        {
                            try
                            {
                                ByteVar sizeVar = (ByteVar)conv.GetVariable(element.SizeName);
                                sizeVar.AddResizeVariable((ByteVar)useVar.Variable);
                            }
                            catch (Exception) // exceptions are caused by incorrect element types - both must be ByteVar
                            {
                            }
                        }
                    }
                }
                else if (element.Type == "DYNAMICBYTE")
                {
                    UseVariable useVar = new UseVariable(conv, element.Name, element.Type, element.Size, element.ExcludeFromChecksum);
                    message.Elements.Add(useVar);
                    if (element.SizeName != null)
                    {
                        try
                        {
                            ByteVar sizeVar = (ByteVar)conv.GetVariable(element.SizeName);
                            sizeVar.AddResizeVariable((ByteVar)useVar.Variable);
                        }
                        catch (Exception) // exceptions are caused by incorrect element types - both must be ByteVar
                        {
                        }
                    }
                }
                else if (element.Type == "STRING")
                {
                    UseVariable useVar = new UseVariable(conv, element.Name, element.Type, element.Size, element.ExcludeFromChecksum);
                    message.Elements.Add(useVar);
                }
            }

            return message;
        }