コード例 #1
0
        async Task StartProcessor(CancellationToken token)
        {
            try
            {
                // Initialize
                _eventProcessorHost = new EventProcessorHost(
                    Environment.MachineName,
                    _configurationProvider.GetConfigurationSettingValue("eventHub.HubName").ToLowerInvariant(),
                    EventHubConsumerGroup.DefaultGroupName,
                    _configurationProvider.GetConfigurationSettingValue("eventHub.ConnectionString"),
                    _configurationProvider.GetConfigurationSettingValue("eventHub.StorageConnectionString"));

                _factory = new DeviceAdministrationProcessorFactory(_deviceLogic, _configurationProvider);
                Trace.TraceInformation("DeviceEventProcessor: Registering host...");
                var options = new EventProcessorOptions();
                options.ExceptionReceived += OptionsOnExceptionReceived;
                await _eventProcessorHost.RegisterEventProcessorFactoryAsync(_factory);

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

                    // Any additional incremental processing can be done here (like checking states, etc).
                }

                // cleanup
                await _eventProcessorHost.UnregisterEventProcessorAsync();
            }
            catch (Exception e)
            {
                Trace.TraceInformation("Error in DeviceEventProcessor.StartProcessor, Exception: {0}", e.Message);
            }
            _running = false;
        }
コード例 #2
0
        async Task StartProcessor(CancellationToken token)
        {
            try
            {
                // Initialize
                _eventProcessorHost = new EventProcessorHost(
                    Environment.MachineName,
                    _configurationProvider.GetConfigurationSettingValue("eventHub.HubName").ToLowerInvariant(),
                    EventHubConsumerGroup.DefaultGroupName,
                    _configurationProvider.GetConfigurationSettingValue("eventHub.ConnectionString"),
                    _configurationProvider.GetConfigurationSettingValue("eventHub.StorageConnectionString"));

                _factory = new DeviceAdministrationProcessorFactory(_deviceLogic, _configurationProvider);
                Trace.TraceInformation("DeviceEventProcessor: Registering host...");
                var options = new EventProcessorOptions();
                options.ExceptionReceived += OptionsOnExceptionReceived;
                await _eventProcessorHost.RegisterEventProcessorFactoryAsync(_factory);

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

                    // Any additional incremental processing can be done here (like checking states, etc).
                }

                // cleanup
                await _eventProcessorHost.UnregisterEventProcessorAsync();
            }
            catch (Exception e)
            {
                Trace.TraceInformation("Error in DeviceEventProcessor.StartProcessor, Exception: {0}", e.Message);
            }
            _running = false;
        }