Ejemplo n.º 1
0
        public override void Start()
        {
            #region init sending commands Worker

            #region Init  Command Queue client

            Producer = new EQueueClientsProducers.Producer(string.Format("{0}-Reply-Producer", ProducerName), ProducerSetting);
            Producer.Start();
            #endregion

            SendCommandWorkTask = Task.Factory.StartNew(() =>
            {
                try
                {
                    using (var messageStore = IoCFactory.Resolve <IMessageStore>())
                    {
                        messageStore.GetAllUnSentCommands()
                        .ForEach(commandContext => ToBeSentCommandQueue.Add(commandContext as MessageContext));
                    }
                }
                catch (Exception ex)
                {
                    _Logger.Error("Get all unsent commands failed", ex);
                }

                while (!_exit)
                {
                    try
                    {
                        var commandContext = ToBeSentCommandQueue.Take();
                        SendCommand(commandContext);
                    }
                    catch (Exception ex)
                    {
                        _Logger.Debug("send command quit", ex);
                    }
                }
            }, TaskCreationOptions.LongRunning);
            #endregion

            #region init process command reply worker

            base.Start();

            #endregion
        }