Esempio n. 1
0
        /// <inheritdoc/>
        public override Task Open(grpc.DataPointProcessor request, IServerStreamWriter <grpc.DataPoints> responseStream, ServerCallContext context)
        {
            DataPointProcessor dataPointProcessor = null;
            var id = request.Id.To <DataPointProcessorId>();

            void Received(IEnumerable <DataPoint> dataPoints) => Process(responseStream, dataPoints);

            try
            {
                _logger.Information($"Register processor with identifier '{id}'");
                dataPointProcessor = new DataPointProcessor(id);
                _dataPointProcessors.Register(dataPointProcessor);

                dataPointProcessor.Received += Received;

                context.CancellationToken.ThrowIfCancellationRequested();
                context.CancellationToken.WaitHandle.WaitOne();
            }
            finally
            {
                if (dataPointProcessor != null)
                {
                    dataPointProcessor.Received -= Received;

                    _logger.Information($"Unregister processor with identifier '{id}'");
                    _dataPointProcessors.Unregister(dataPointProcessor);
                }
            }

            return(Task.CompletedTask);
        }
 /// <inheritdoc/>
 public void Unregister(DataPointProcessor dataPointProcessor)
 {
     _logger.Information($"Unregistering '{dataPointProcessor.Id}'");
     lock (_processors) _processors.Remove(dataPointProcessor);
 }
 /// <inheritdoc/>
 public void Register(DataPointProcessor dataPointProcessor)
 {
     _logger.Information($"Registering '{dataPointProcessor.Id}'");
     lock (_processors) _processors.Add(dataPointProcessor);
 }