private async Task StartProcessor(CancellationToken token)
        {
            try
            {
                string hostName = Environment.MachineName;
                string eventHubPath = _configurationProvider.GetConfigurationSettingValue("RulesEventHub.Name");
                string consumerGroup = EventHubConsumerGroup.DefaultGroupName;
                string eventHubConnectionString = _configurationProvider.GetConfigurationSettingValue("RulesEventHub.ConnectionString");
                string storageConnectionString = _configurationProvider.GetConfigurationSettingValue("device.StorageConnectionString");

                _eventProcessorHost = new EventProcessorHost(
                    hostName,
                    eventHubPath,
                    consumerGroup,
                    eventHubConnectionString,
                    storageConnectionString);

                _factory = new ActionProcessorFactory(
                    _actionLogic,
                    _actionMappingLogic,
                    _configurationProvider);

                Trace.TraceInformation("ActionEventProcessor: Registering host...");
                var options = new EventProcessorOptions();
                options.ExceptionReceived += OptionsOnExceptionReceived;
                await _eventProcessorHost.RegisterEventProcessorFactoryAsync(_factory);

                // processing loop
                while (!token.IsCancellationRequested)
                {
                    Trace.TraceInformation("ActionEventProcessor: Processing...");
                    await Task.Delay(TimeSpan.FromMinutes(5), token);
                }

                // cleanup
                await _eventProcessorHost.UnregisterEventProcessorAsync();
            }
            catch (Exception e)
            {
                Trace.TraceError("Error in ActionProcessor.StartProcessor, Exception: {0}", e.ToString());
            }
            _isRunning = false;
        }
Esempio n. 2
0
        private async Task StartProcessor(CancellationToken token)
        {
            try
            {
                string hostName                 = Environment.MachineName;
                string eventHubPath             = _configurationProvider.GetConfigurationSettingValue("RulesEventHub.Name");
                string consumerGroup            = EventHubConsumerGroup.DefaultGroupName;
                string eventHubConnectionString = _configurationProvider.GetConfigurationSettingValue("RulesEventHub.ConnectionString");
                string storageConnectionString  = _configurationProvider.GetConfigurationSettingValue("device.StorageConnectionString");

                _eventProcessorHost = new EventProcessorHost(
                    hostName,
                    eventHubPath,
                    consumerGroup,
                    eventHubConnectionString,
                    storageConnectionString);

                _factory = new ActionProcessorFactory(
                    _actionLogic,
                    _actionMappingLogic,
                    _configurationProvider);

                Trace.TraceInformation("ActionEventProcessor: Registering host...");
                var options = new EventProcessorOptions();
                options.ExceptionReceived += OptionsOnExceptionReceived;
                await _eventProcessorHost.RegisterEventProcessorFactoryAsync(_factory);

                // processing loop
                while (!token.IsCancellationRequested)
                {
                    Trace.TraceInformation("ActionEventProcessor: Processing...");
                    await Task.Delay(TimeSpan.FromMinutes(5), token);
                }

                // cleanup
                await _eventProcessorHost.UnregisterEventProcessorAsync();
            }
            catch (Exception e)
            {
                Trace.TraceError("Error in ActionProcessor.StartProcessor, Exception: {0}", e.ToString());
            }
            _isRunning = false;
        }