private static List<Message> ParseBuffer(bool asEvents)
        {
            List<Message> result = new List<Message>();

            string pattern = !asEvents ?
                @"<REPLY\s(?<Command>[^>]+)>(?<Answer>[^<]*)<END\s(?<ResultCode>\d+)\s\((?<ResultString>[^>]+)\)>" :
                @"<EVENT\s(?<ID>[\d+,^>]+)>(?<Answer>[^<]*)<END\s(?<ResultCode>\d+)\s\((?<ResultString>[^>]+)\)>";

            Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
            MatchCollection entries = r.Matches(buffer);

            if (entries.Count > 0)
            {
                buffer = r.Replace(buffer, "");

                foreach (Match entry in entries)
                {
                    string[] bodyStrings = entry.Groups["Answer"].Value.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

                    Message msg = new Message()
                    {
                        Type = !asEvents ? MessageType.Response : MessageType.Event,
                        RequestCommand = !asEvents ? entry.Groups["Command"].Value : null,
                        EventObjectID = !asEvents ? -1 : int.Parse(entry.Groups["ID"].Value),
                        Body = new List<string>(bodyStrings),
                        ResultCode = int.Parse(entry.Groups["ResultCode"].Value),
                        ResultString = entry.Groups["ResultString"].Value,
                    };

                    result.Add(msg);
                }
            }

            return result;
        }
 private void Process(Message msg)
 {
     isValueFromMessage = true;
     if (msg.RequestCommand == Command.Get(ID, OptionDelay))
         ProcessDelay(msg.Body[0]);
     isValueFromMessage = false;
 }
        protected override bool DelegateEvent(Message msg)
        {
            //foreach (FeedbackModule item in Items)
            //    if (item.ProcessEvent(msg))
            //        return true;

            return false;
        }
        protected override bool DelegateReply(Message msg)
        {
            foreach (Accessory item in Items)
                if (item.ProcessReply(msg))
                    return true;

            return false;
        }
示例#5
0
 protected void NotifyCommandError(Message message)
 {
     if (CommandError != null)
         CommandError(this, new MessageEventArgs(message));
 }
        protected override bool DelegateReply(Message msg)
        {
            foreach (FeedbackModule item in Items)
                if (item.ProcessReply(msg))
                    return true;

            return false;
        }
        protected override void ProcessReply(Message msg)
        {
            if (msg.RequestCommand == Command.QueryObjects(ID, Accessory.OptionName1, Accessory.OptionName2, Accessory.OptionAddressExt))
                ProcessQueryObjects(msg.Body);

            //else if (msg.RequestCommand == Command.Create(ID, OptionAppend))
            //    ProcessAppendCreated(msg.Body);
            //else if (msg.RequestCommand.Contains("delete"))
            //    ProcessDelete(msg.RequestCommand);
        }
 protected override void ProcessEvent(Message msg)
 {
     ProcessListChanged(msg.Body);
 }
 public MessageEventArgs(Message message)
 {
     Message = message;
 }
示例#10
0
 internal virtual bool ProcessCommandError(Message msg) // returns true if error is handled
 {
     return false;
 }
示例#11
0
 private void Process(Message msg)
 {
     isValueFromMessage = true;
     foreach (string str in msg.Body)
         ProcessData(str);
     isValueFromMessage = false;
 }
示例#12
0
 protected override void ProcessReply(Message msg)
 {
     if (msg.RequestCommand == Command.QueryObjects(ID))
         ProcessQueryObjects(msg.Body);
 }
示例#13
0
        internal bool ProcessReply(Message msg) // returns true if msg is processed;
        {
            foreach (string command in sentCommands)
            {
                if (command == msg.RequestCommand)
                {
                    sentCommands.Remove(command);

                    if (msg.ResultCode != 0)
                        NotifyCommandError(msg);
                    else
                    {
                        // process only GET-commands; SET-command results are processed through their raising events in "ProcessEvent" method

                        if (msg.RequestCommand == Command.Request(ID.ToString(), OptionView))
                            IsRegisteredViewer = true;
                        else if (msg.RequestCommand == Command.Release(ID.ToString(), OptionView))
                            IsRegisteredViewer = false;
                        else if (msg.RequestCommand == Command.Request(ID.ToString(), OptionControl, OptionForce))
                            IsRegisteredControl = true;
                        else if (msg.RequestCommand == Command.Release(ID.ToString(), OptionControl))
                            IsRegisteredControl = false;
                        else if (msg.RequestCommand == Command.QueryObjects(ID.ToString()))
                            ProcessQueryObjects(msg);
                        else
                            Process(msg);
                    }

                    return true;
                }
            }

            return false;
        }
示例#14
0
 protected virtual bool DelegateEvent(Message msg)
 {
     return false;
 }
示例#15
0
 protected virtual bool DelegateReply(Message msg)
 {
     return false;
 }
示例#16
0
 protected virtual void ProcessEvent(Message msg)
 {
 }
示例#17
0
 protected virtual void ProcessReply(Message msg)
 {
 }
示例#18
0
        internal bool ProcessMessage(Message msg) // returns true if message is processed;
        {
            if (msg.Type == MessageType.Response)
            {
                foreach (string command in sentCommands)
                    if (command == msg.RequestCommand)
                    {
                        sentCommands.Remove(command);

                        if (msg.ResultCode != 0)
                            NotifyCommandError(msg);
                        else
                        {
                            if (msg.RequestCommand == Command.Request(ID, OptionView))
                                IsRegisteredViewer = true;
                            else if (msg.RequestCommand == Command.Release(ID, OptionView))
                                IsRegisteredViewer = false;
                            else // specific command
                                ProcessReply(msg);
                        }

                        return true;
                    }

                return DelegateReply(msg); // not my command; bubble down to items (if any)
            }
            else if (msg.Type == MessageType.Event)
            {
                if (msg.EventObjectID.ToString() == ID)
                {
                    ProcessEvent(msg);
                    return true;
                }
                else
                    return DelegateEvent(msg); // not my event; delegate down to items (if any)
            }

            return false;
        }
示例#19
0
 internal bool ProcessEvent(Message msg) // returns true if msg is processed;
 {
     if (msg.EventObjectID == ID)
     {
         Process(msg);
         return true;
     }
     return false;
 }
 protected override void ProcessReply(Message msg)
 {
     Process(msg);
 }
示例#21
0
        private void ProcessQueryObjects(Message msg)
        {
            isValueFromMessage = true;

            var newChildrenIDs = msg.Body.Select((s) => int.Parse(s));

            var deletedItems = ChildrenIDs.Except(newChildrenIDs).ToList();
            foreach (var item in deletedItems)
                ChildrenIDs.Remove(item);

            var addedItems = newChildrenIDs.Except(ChildrenIDs).ToList();
            foreach (var item in addedItems)
                ChildrenIDs.Add(item);

            NotifyPropertyChanged("ChildrenIDs");

            isValueFromMessage = false;
        }
 protected override void ProcessEvent(Message msg)
 {
     Process(msg);
 }
 protected override void ProcessReply(Message msg)
 {
     if (msg.RequestCommand == Command.QueryObjects(ID, Locomotive.OptionAddress, Locomotive.OptionName, Locomotive.OptionProtocol))
         ProcessQueryObjects(msg.Body);
     //else if (msg.SourceCommand.Contains("create"))
     //    ProcessCreate(msg.Answer);
     //else if (msg.RequestCommand == Command.Create(ID, OptionAppend))
     //    ProcessAppendCreated(msg.Body);
     //else if (msg.RequestCommand.Contains("delete"))
     //    ProcessDelete(msg.RequestCommand);
 }
 protected override void ProcessReply(Message msg)
 {
     if (msg.RequestCommand == Command.QueryObjects(ID, FeedbackModule.OptionPorts))
         ProcessIDsPortCounts(msg.Body);
     //else if (msg.SourceCommand.Contains("create"))
     //    ProcessCreate(msg.Answer);
     //else if (msg.RequestCommand.Contains("delete"))
     //    ProcessDelete(msg.RequestCommand);
 }
        protected override bool DelegateEvent(Message msg)
        {
            foreach (Locomotive item in Items)
                if (item.ProcessEvent(msg))
                    return true;

            return false;
        }
 protected override void ProcessEvent(Message msg)
 {
     Items.Add(new SnifferPacket(msg.Body));
 }