public EventProcessor(EventProcessorFactoryConfiguration configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     this.configuration = configuration;
 }
 public EventProcessor(EventProcessorFactoryConfiguration configuration)
 {
     if (configuration == null)
     {
         throw new ArgumentNullException(nameof(configuration));
     }
     this.configuration = configuration;
 }
        // ReSharper disable once FunctionComplexityOverflow
        private async void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                if (string.Compare(btnStart.Text, Start, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // Validate parameters
                    if (!ValidateParameters())
                    {
                        return;
                    }
                    btnStart.Enabled = false;

                    var eventHubClient = EventHubClient.CreateFromConnectionString(txtServiceBusConnectionString.Text,
                        cboEventHub.Text);

                    // Get the default Consumer Group
                    eventProcessorHost = new EventProcessorHost(Guid.NewGuid().ToString(),
                        eventHubClient.Path.ToLower(),
                        txtConsumerGroup.Text.ToLower(),
                        txtServiceBusConnectionString.Text,
                        txtStorageAccountConnectionString.Text)
                    {
                        PartitionManagerOptions = new PartitionManagerOptions
                        {
                            AcquireInterval = TimeSpan.FromSeconds(10), // Default is 10 seconds
                            RenewInterval = TimeSpan.FromSeconds(10), // Default is 10 seconds
                            LeaseInterval = TimeSpan.FromSeconds(30) // Default value is 30 seconds
                        }
                    };
                    WriteToLog(RegisteringEventProcessor);
                    var eventProcessorOptions = new EventProcessorOptions
                    {
                        InvokeProcessorAfterReceiveTimeout = true,
                        MaxBatchSize = 100,
                        PrefetchCount = 100,
                        ReceiveTimeOut = TimeSpan.FromSeconds(30),
                    };
                    eventProcessorOptions.ExceptionReceived += EventProcessorOptions_ExceptionReceived;
                    var eventProcessorFactoryConfiguration = new EventProcessorFactoryConfiguration
                    {
                        TrackEvent = a => Invoke(new Action<Alert>(i => alertBindingList.Add(i)), a),
                        WriteToLog = m => Invoke(new Action<string>(WriteToLog), m)
                    };
                    await
                        eventProcessorHost.RegisterEventProcessorFactoryAsync(
                            new EventProcessorFactory<EventProcessor>(eventProcessorFactoryConfiguration),
                            eventProcessorOptions);
                    WriteToLog(EventProcessorRegistered);

                    // Change button text
                    btnStart.Text = Stop;
                }
                else
                {
                    // Stop Event Processor
                    if (eventProcessorHost != null)
                    {
                        await eventProcessorHost.UnregisterEventProcessorAsync();
                    }

                    // Change button text
                    btnStart.Text = Start;
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                btnStart.Enabled = true;
            }
        }
        // ReSharper disable once FunctionComplexityOverflow
        private async void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                if (string.Compare(btnStart.Text, Start, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // Validate parameters
                    if (!ValidateParameters())
                    {
                        return;
                    }
                    btnStart.Enabled = false;

                    var eventHubClient = EventHubClient.CreateFromConnectionString(txtServiceBusConnectionString.Text,
                                                                                   cboEventHub.Text);

                    // Get the default Consumer Group
                    eventProcessorHost = new EventProcessorHost(Guid.NewGuid().ToString(),
                                                                eventHubClient.Path.ToLower(),
                                                                txtConsumerGroup.Text.ToLower(),
                                                                txtServiceBusConnectionString.Text,
                                                                txtStorageAccountConnectionString.Text)
                    {
                        PartitionManagerOptions = new PartitionManagerOptions
                        {
                            AcquireInterval = TimeSpan.FromSeconds(10), // Default is 10 seconds
                            RenewInterval   = TimeSpan.FromSeconds(10), // Default is 10 seconds
                            LeaseInterval   = TimeSpan.FromSeconds(30)  // Default value is 30 seconds
                        }
                    };
                    WriteToLog(RegisteringEventProcessor);
                    var eventProcessorOptions = new EventProcessorOptions
                    {
                        InvokeProcessorAfterReceiveTimeout = true,
                        MaxBatchSize   = 100,
                        PrefetchCount  = 100,
                        ReceiveTimeOut = TimeSpan.FromSeconds(30),
                    };
                    eventProcessorOptions.ExceptionReceived += EventProcessorOptions_ExceptionReceived;
                    var eventProcessorFactoryConfiguration = new EventProcessorFactoryConfiguration
                    {
                        TrackEvent = a => Invoke(new Action <Alert>(i => alertBindingList.Add(i)), a),
                        WriteToLog = m => Invoke(new Action <string>(WriteToLog), m)
                    };
                    await
                    eventProcessorHost.RegisterEventProcessorFactoryAsync(
                        new EventProcessorFactory <EventProcessor>(eventProcessorFactoryConfiguration),
                        eventProcessorOptions);

                    WriteToLog(EventProcessorRegistered);

                    // Change button text
                    btnStart.Text = Stop;
                }
                else
                {
                    // Stop Event Processor
                    if (eventProcessorHost != null)
                    {
                        await eventProcessorHost.UnregisterEventProcessorAsync();
                    }

                    // Change button text
                    btnStart.Text = Start;
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                Cursor.Current   = Cursors.Default;
                btnStart.Enabled = true;
            }
        }
 public EventProcessorFactory(EventProcessorFactoryConfiguration configuration)
 {
     this.configuration = configuration;
 }
 public EventProcessorFactory()
 {
     configuration = null;
 }