private static void StopClient( CancellationTokenSource cancellationToken, SensorsHub sensorsHub, SensorDataProducer producer, Task processingJob, Channel <SensorDataDto> channel) { cancellationToken.Cancel(); sensorsHub.StopToListen().Wait(); producer.Complete(); Console.WriteLine("Sensor client closing..."); processingJob.Wait(); channel.Reader.Completion.Wait(); Console.WriteLine("Sensor client closed..."); }
static void Main(string[] args) { var configuration = Configuration.Read(); var database = new Database( configuration); var channel = Channel.CreateUnbounded <SensorDataDto>(); var consumers = PrepareConsumers( channel, database, ParallelConsumersCount); var producer = new SensorDataProducer( channel.Writer); var sensorsHub = new SensorsHub( producer); var cancellationToken = new CancellationTokenSource(); var processingJob = StartProcessing( consumers, cancellationToken, sensorsHub); Console.WriteLine("Press any key to to exit."); Console.ReadLine(); StopClient( cancellationToken, sensorsHub, producer, processingJob, channel); }
public SensorsHub(SensorDataProducer sensorDataProducer) { _sensorDataProducer = sensorDataProducer; }