public CC_EnviR_Converse(IUtilityLog log)
            : base(log, null)
        {
            // don't bother with ConversationLoader - it is a very simple pattern
            // below creates the conversation definition

            Conversation conv = new Conversation(this, "CC_EnviR_Receive", log);
            Conversations.Add(conv);
            Message message = new Message(conv, MessageType.Find, "");
            Literal literal = new Literal(Element.StringToHex("<msg>", " "), conv);
            message.Elements.Add(literal);
            conv.Messages.Add(message);

            message = new Message(conv, MessageType.ExtractDynamic, "");
            DynamicByteVar variable = new DynamicByteVar("DATA", 10000, conv);
            Variables.Add(variable);
            UseVariable useVar = new UseVariable(conv, "DATA");
            message.Elements.Add(useVar);
            literal = new Literal(Element.StringToHex("</msg>", " "), conv);
            message.Elements.Add(literal);
            conv.Messages.Add(message);
        }
        public void LoadConversation(Converse session, Conversation conv)
        {
            MessageType messageType = MessageType.Read;
            Message curMessage = null;

            String message = GetNextCommand();
            while (message.Length > 0)
            {
                // check for start of new conversation
                if (message[0] == ':')
                    break;
                message = message.ToUpper();
                char msgType = message[0];

                if (msgType == 'R')
                {
                    messageType = MessageType.Read;
                }
                else if (msgType == 'F')
                {
                    messageType = MessageType.Find;
                }
                else if (msgType == 'E')
                {
                    messageType = MessageType.Extract;
                }
                else if (msgType == 'S')
                {
                    messageType = MessageType.Send;
                }

                /*
                if (messageType == MessageType.Extract)
                {
                    if (curMessage == null || curMessage.MessageType == MessageType.Send)
                        throw new Exception("Extract must follow Receive message");
                }
                */

                curMessage = new Message(conv, messageType, "");
                conv.Messages.Add(curMessage);

                curMessage.ParseMessage(message.Substring(1).Trim());

                message = GetNextCommand();
            }
        }
        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;
        }