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

            return false;
        }
Пример #3
0
        private static List<Message> ParseBuffer(bool asEvents)
        {
            List<Message> result = new List<Message>();

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

            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["Body"].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;
        }
Пример #4
0
 internal virtual bool ProcessCommandError(Message msg) // returns true if error is handled
 {
     return false;
 }
Пример #5
0
 internal bool ProcessEvent(Message msg) // returns true if msg is processed;
 {
     if (msg.EventObjectID == ID)
     {
         Process(msg);
         return true;
     }
     return false;
 }
 protected override async void ProcessReply(Message msg)
 {
     if (msg.RequestCommand == Command.QueryObjects(ID, Locomotive.OptionAddress, Locomotive.OptionName, Locomotive.OptionProtocol))
         await 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 bool DelegateReply(Message msg)
        {
            foreach (Locomotive item in Items)
                if (item.ProcessReply(msg))
                    return true;

            return false;
        }
Пример #8
0
 protected virtual void ProcessEvent(Message msg)
 {
 }
Пример #9
0
        internal bool ProcessMessage(Message msg) // returns true if message is processed;
        {
            if (msg != null)
            {
                if (msg.Type == MessageType.Response)
                {
                    var command = sentCommands.FirstOrDefault(cmd => cmd == msg.RequestCommand);
                    if (command != null)
                    {
                        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 // custom 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;
        }
Пример #10
0
 public MessageEventArgs(Message message)
 {
     Message = message;
 }
Пример #11
0
        protected override bool DelegateReply(Message msg)
        {
            foreach (FeedbackModule item in Items)
                if (item.ProcessReply(msg))
                    return true;

            return false;
        }
Пример #12
0
 protected override void ProcessReply(Message msg)
 {
     if (msg.RequestCommand == Command.QueryObjects(ID, FeedbackModule.OptionPorts))
         ProcessQueryObjects(msg.Body);
     //else if (msg.SourceCommand.Contains("create"))
     //    ProcessCreate(msg.Answer);
     //else if (msg.RequestCommand.Contains("delete"))
     //    ProcessDelete(msg.RequestCommand);
 }
Пример #13
0
        protected override bool DelegateEvent(Message msg)
        {
            foreach (Accessory item in Items)
                if (item.ProcessEvent(msg))
                    return true;

            return false;
        }
Пример #14
0
        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);
        }
Пример #15
0
 protected override void ProcessEvent(Message msg)
 {
     Items.Add(new SnifferPacket(msg.Body));
 }
Пример #16
0
 protected void NotifyCommandError(Message message)
 {
     try
     {
         CommandError?.Invoke(this, new MessageEventArgs(message));
     }
     catch { }
 }
Пример #17
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;
        }
Пример #18
0
 protected override void ProcessReply(Message msg)
 {
     Process(msg);
 }
Пример #19
0
 private void Process(Message msg)
 {
     isValueFromMessage = true;
     foreach (string str in msg.Body)
         ProcessData(str);
     isValueFromMessage = false;
 }
Пример #20
0
 protected override void ProcessEvent(Message msg)
 {
     Process(msg);
 }
Пример #21
0
 protected void NotifyCommandError(Message msg)
 {
     CommandError?.Invoke(this, new MessageEventArgs(msg));
 }
Пример #22
0
 protected virtual bool DelegateEvent(Message msg)
 {
     return false;
 }
Пример #23
0
 protected virtual void ProcessReply(Message msg)
 {
 }
Пример #24
0
 protected override void ProcessEvent(Message msg)
 {
     ProcessListChanged(msg.Body);
 }
Пример #25
0
 protected virtual bool DelegateReply(Message msg)
 {
     return false;
 }
 protected override async void ProcessEvent(Message msg)
 {
     await ProcessListChanged(msg.Body);
 }
Пример #27
0
 protected override void ProcessReply(Message msg)
 {
     if (msg.RequestCommand == Command.QueryObjects(ID))
         ProcessQueryObjects(msg.Body);
 }
Пример #28
0
 protected void NotifyCommandError(Message message)
 {
     if (CommandError != null)
         CommandError(this, new MessageEventArgs(message));
 }
Пример #29
0
        internal bool ProcessReply(Message msg) // returns true if msg is processed;
        {
            var command = sentCommands.FirstOrDefault(cmd => cmd == msg.RequestCommand);
            if (command != null)
            {
                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;
        }
Пример #30
0
 protected override void ProcessReply(Message msg)
 {
     if (msg.RequestCommand == Command.Set(ID, OptionGo))
         Status = DeviceStatusType.Go;
     else if (msg.RequestCommand == Command.Set(ID, OptionStop))
         Status = DeviceStatusType.Stop;
     else
         Process(msg.Body);
 }