Exemplo n.º 1
0
        protected override void OnWorkerStart(CancellationToken token)
        {
            IConfigurationObserver obs = null;

            try
            {
                obs = configurationObserverFactory.Invoke();
                obs.PropertyChanged += (o, ea) =>
                {
                    var cfgDto = new ConfigurationDto
                    {
                        Timeout          = obs.DocumentsJoinerConfiguration.Timeout,
                        BarcodeSeparator = obs.DocumentsJoinerConfiguration.BarcodeSeparatorValue
                    };
                    var cmd = new CommandMessage <ConfigurationDto>
                    {
                        CommandName = CommandMessageName.UPDATE_CONFIGURATION_COMMAND_NAME,
                        Payload     = cfgDto
                    };
                    commandsQueue.SendMessage(cmd.Serialize());
                };
                obs.Start();
                while (!token.IsCancellationRequested)
                {
                    token.WaitHandle.WaitOne(SEND_STATUS_COMMAND_PERIOD_MS);
                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    var statusCmd = new CommandMessage <object>
                    {
                        CommandName = CommandMessageName.SEND_STATUS_COMMAND_NAME
                    };
                    commandsQueue.SendMessage(statusCmd.Serialize());
                }
            }
            finally
            {
                obs?.Dispose();
            }
        }