Exemplo n.º 1
0
        /// <summary>
        /// Continually monitors the RepositoryReaderWorker's TriggerUpdateNotification buffer. When a new
        /// notification arrives, the worker retrives the correct trigger(s) from the DTS repository and updates
        /// its controller's list of active triggers.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token used to stop the worker.</param>
        public void Run(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            // Get initial list of triggers
            Log.Info("Getting initial trigger list from the repostiory...");
            var triggerList = _repository.GetAllTriggers();

            _controller.UpdateTriggers(triggerList);
            Log.Info("Triggers were successfully retrieved.");

            while (true)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return;
                }

                try
                {
                    var nextNotification = _updateBuffer.Take(cancellationToken);
                    HandleTriggerNotification(nextNotification);
                }
                catch (OperationCanceledException)
                {
                    return;
                }
            }
        }