Exemplo n.º 1
0
        /// <inheritdoc/>
        public override async Task <Empty> Open(IAsyncStreamReader <DataPoint> requestStream, ServerCallContext context)
        {
            _logger.Information($"DataPointStream opened");
            while (await requestStream.MoveNext().ConfigureAwait(false))
            {
                _dataPointsState.Set(requestStream.Current.ToMicroservice());
            }

            _logger.Information($"DataPointStream closed");

            return(new Empty());
        }
        /// <inheritdoc/>
        public void Handle(string connectorName, IEnumerable <grpc.TagDataPoint> dataPoints)
        {
            dataPoints.ForEach(tagDataPoint =>
            {
                if (!_timeSeriesMapper.CanIdentify(connectorName, tagDataPoint.Tag))
                {
                    _logger.Information($"Unidentified tag '{tagDataPoint.Tag}' from '{connectorName}'");
                }
                else
                {
                    _logger.Information("DataPoint received");
                    var timeSeriesId = _timeSeriesMapper.Identify(connectorName, tagDataPoint.Tag);

                    var dataPoint = new microserviceDataTypes.DataPoint
                    {
                        TimeSeries = timeSeriesId.ToProtobuf(),
                        Timestamp  = Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow)
                    };

                    switch (tagDataPoint.MeasurementCase)
                    {
                    case grpc.TagDataPoint.MeasurementOneofCase.SingleValue:
                        dataPoint.SingleValue = tagDataPoint.SingleValue.ToMicroservice();
                        break;

                    case grpc.TagDataPoint.MeasurementOneofCase.Vector2Value:
                        dataPoint.Vector2Value = new microserviceDataTypes.Vector2
                        {
                            X = tagDataPoint.Vector2Value.X.ToMicroservice(),
                            Y = tagDataPoint.Vector2Value.Y.ToMicroservice()
                        };
                        break;

                    case grpc.TagDataPoint.MeasurementOneofCase.Vector3Value:
                        dataPoint.Vector3Value = new microserviceDataTypes.Vector3
                        {
                            X = tagDataPoint.Vector3Value.X.ToMicroservice(),
                            Y = tagDataPoint.Vector3Value.Y.ToMicroservice(),
                            Z = tagDataPoint.Vector3Value.Z.ToMicroservice()
                        };
                        break;
                    }

                    _dataPointsState.Set(dataPoint);
                }
            });
        }