Ejemplo n.º 1
0
        public void Start()
        {
            Task.Run(() =>
            {
                foreach (var cmdctxt in IncomingQ.GetConsumingEnumerable())
                {
                    var cmdstr = cmdctxt.CommandMessage;

                    if (AppConfiguration.checkSumCheck)
                    {
                        var checkSum       = cmdstr.Substring(cmdstr.Length - 1 - 2, 2);
                        string strippedCmd = cmdstr.Substring(1, cmdstr.Length - 1 - 3);

                        if (!CheckSum.IsValid(strippedCmd, checkSum))
                        {
                            cmdctxt.ResponseQCallback(ReceptionError.Generate("2000"));
                            continue;
                        }
                    }

                    if (!cmdctxt.CommandMessage.Substring(2, 1).Equals(UnitNumber.ToString()))
                    {
                        cmdctxt.ResponseQCallback(ReceptionError.Generate("5000"));
                        continue;;
                    }

                    var commandBeingCategorized = BaseMessage.Create(UnitNumber, cmdctxt.CommandMessage);

                    if (commandBeingCategorized == null)
                    {
                        cmdctxt.ResponseQCallback(ReceptionError.Generate("6000"));
                        continue;;
                    }

                    commandBeingCategorized.Parse();//Process(cmdctxt);

                    if (commandBeingCategorized.Type == MessageType.Reference)
                    {
                        IncomingReferenceQ.Add(new Tuple <CommandContext, BaseMessage>(cmdctxt, commandBeingCategorized));
                    }
                    else
                    {
                        IncomingOtherQ.Add(new Tuple <CommandContext, BaseMessage>(cmdctxt, commandBeingCategorized));
                    }

                    if (Stop)
                    {
                        break;
                    }
                }
            });

            Task.Run(() =>
            {
                foreach (var tuple in IncomingOtherQ.GetConsumingEnumerable())
                {
                    ProcessOther(tuple.Item1, tuple.Item2);
                    if (Stop)
                    {
                        break;
                    }
                }
            });

            Task.Run(() =>
            {
                foreach (var tuple in IncomingReferenceQ.GetConsumingEnumerable())
                {
                    ProcessReference(tuple.Item1, tuple.Item2);
                    if (Stop)
                    {
                        break;
                    }
                }
            });
        }