public ByteVar(String varName, int? size, Conversation conversation, int messageId = 0) : base(varName, conversation, messageId) { FixedSize = size; if (FixedSize.HasValue) Bytes = new byte[FixedSize.Value]; else Bytes = new byte[0]; ResizeVariables = new List<ByteVar>(); }
public Message(Conversation conversation, MessageType messageType, String name) { Conversation = conversation; Converse = conversation.Converse; MessageType = messageType; Name = name; Elements = new List<Element>(); if (MessageType == Conversations.MessageType.Extract && Elements.Count > 1 && Elements[0].GetType() == typeof(DynamicByteVar)) MessageType = Conversations.MessageType.ExtractDynamic; }
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 Variable GetSessionVariable(String varName, Conversation conversation = null) { try { String var = varName.ToUpper(); bool conversationScope = var.StartsWith("%PAYLOAD"); foreach (Variable v in Variables) { if (v.Name == var) if (!conversationScope || conversation == v.InitialConversation) return v; } return null; } catch (Exception e) { LogMessage("GetVariable", "varName: " + varName + " - Exception: " + e.Message, LogEntryType.ErrorMessage); throw e; } }
public void LoadConversations(Converse session) { GetNextCommand(); while (!EOF) { String name = ""; // should be conversation label if (CurrentCommand[0] == ':') { if (CurrentCommand.Length < 2) throw new Exception("Conversation Name has zero length"); name = CurrentCommand.Substring(1).Trim(); if (name.Length < 1) throw new Exception("Conversation Name has zero length"); } else throw new Exception("Conversation Name missing"); Conversation conv = new Conversation(session, name, UtilityLog); LoadConversation(session, conv); session.Conversations.Add(conv); } }
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(); } }
public Variable(String varName, Conversation conversation, int messageId) : base(conversation, false) { Name = varName.ToUpper(); MessageId = messageId; IsUnknown = false; }
public UseVariable(Conversation conversation, String varName, String type = null, int? size = null, bool excludeFromChecksum = false, int messageId = 0) : base(conversation, excludeFromChecksum) { Converse session = conversation.Converse; int? variableSize; Variable = conversation.GetVariable(varName); VariableType = type; variableSize = size; Calculations = session.Calculations; IsChecksum16 = (varName.ToUpper() == "CHECKSUM16"); IsChecksum8 = (varName.ToUpper() == "CHECKSUM8"); IsChecksum = IsChecksum16 || IsChecksum8; if (Variable == null) // variable not defined if (type == null) { Variable = new StringVar(varName, conversation); session.Variables.Add(Variable); } else if (type == "BYTE") { Variable = new ByteVar(varName, variableSize, conversation); session.Variables.Add(Variable); } else if (type == "DYNAMICBYTE") { if (variableSize == null || variableSize < 1) variableSize = 10000; Variable = new DynamicByteVar(varName, variableSize.Value, conversation); session.Variables.Add(Variable); } else if (type == "STRING") { Variable = new StringVar(varName, conversation); session.Variables.Add(Variable); } else throw new Exception("Variable " + varName + " type not supported: " + type); }
public TimeVar(String varName, Conversation conversation, int messageId = 0) : base(varName, conversation, messageId) { addressBytes = null; }
public StringVar(String varName, Conversation conversation, int messageId = 0) : base(varName, conversation, messageId) { strValue = ""; }
public Literal(String value, Conversation conversation, bool excludeFromChecksum = false) : base(conversation, excludeFromChecksum) { Value = value; try { bytes = SystemServices.HexToBytes(Value); } catch (Exception) { bytes = SystemServices.StringToBytes(Value); } }
public Element(Conversation conversation, bool excludeFromChecksum = false) { InitialConversation = conversation; Converse = conversation.Converse; ExcludeFromChecksum = excludeFromChecksum; }
public DynamicByteVar(String varName, int maxSize, Conversation conversation, int messageId = 0) : base(varName, conversation, messageId) { MaxBytes = maxSize; Bytes = null; CurrentBytes = 0; }