示例#1
0
        /// <inheritdoc/>
        public void Start()
        {
            Task.Run(() =>
            {
                while (true)
                {
                    try
                    {
                        var socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
                        socket.Connect(IPAddress.Parse(_configuration.Ip), _configuration.Port);

                        using (var stream = new NetworkStream(socket, FileAccess.Read, true))
                        {
                            _parser.BeginParse(stream, channel =>
                            {
                                var dataPoint = new TagDataPoint <ChannelValue>
                                {
                                    ControlSystem = "Terasaki",
                                    Tag           = channel.Id.ToString(),
                                    Value         = channel.Value,
                                    Timestamp     = Timestamp.UtcNow
                                };
                                _subscribers.ForEach(subscriber => subscriber(channel));
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex, "Error while connecting to TCP stream");
                    }

                    Thread.Sleep(10000);
                }
            });
        }
        /// <summary>
        /// Handles publishing of a single data point
        /// </summary>
        /// <param name="command"><see cref="PublishTagDataPoint"/> command to handle</param>
        public void Handle(PublishTagDataPoint command)
        {
            var dataPoint = new TagDataPoint <double>
            {
                Source    = command.Source,
                Tag       = command.Tag,
                Value     = command.Value,
                Timestamp = Timestamp.UtcNow
            };

            _client.SendAsJson("tags", dataPoint);
        }
示例#3
0
        void DataReceived(IAmAStreamingConnector connector, Tag tag, object data, Timestamp timestamp)
        {
            var dataPoint = new TagDataPoint <object>
            {
                Source    = connector.Name,
                Tag       = tag,
                Value     = data,
                Timestamp = timestamp
            };

            _communicationClient.SendAsJson("output", dataPoint);
        }
示例#4
0
        void ChannelReceived(Channel channel)
        {
            var dataPoint = new TagDataPoint <double>
            {
                Tag           = channel.Id.ToString(),
                ControlSystem = ControlSystemName,
                Timestamp     = Timestamp.UtcNow,
                Value         = channel.Value.Value
            };

            _client.SendAsJson("output", dataPoint);
        }
        /// <summary>
        /// Handles the <see cref="StartTagSimulation"/> command
        /// </summary>
        /// <param name="command">The <see cref="StartTagSimulation">command</see></param>
        public void Handle(StartTagSimulation command)
        {
            var cancellationTokenSource = new CancellationTokenSource();

            Repeat.Interval(TimeSpan.FromSeconds(1), () => {
                var dataPoint = new TagDataPoint <double>
                {
                    Source    = command.Source,
                    Tag       = command.Tag,
                    Value     = _random.NextDouble() * 100,
                    Timestamp = Timestamp.UtcNow
                };

                _logger.Information($"Sending event for system '{command.Source}' - tag '{command.Tag}' with value '{dataPoint.Value}'");

                _client.SendAsJson("tags", dataPoint);
            }, cancellationTokenSource.Token);
        }
        /// <inheritdoc/>
        public async Task Handle(TagDataPoint <object> tagDataPoint)
        {
            if (!_mapper.HasTimeSeriesFor(tagDataPoint.ControlSystem, tagDataPoint.Tag))
            {
                _logger.Warning($"There is no time series for tag '{tagDataPoint.Tag}' on system '{tagDataPoint.ControlSystem}'");
                await Task.CompletedTask;
                return;
            }

            var outputDatapoint = new DataPoint <dynamic>
            {
                Value      = tagDataPoint.Value,
                TimeSeries = _mapper.GetTimeSeriesFor(tagDataPoint.ControlSystem, tagDataPoint.Tag),
                Timestamp  = tagDataPoint.Timestamp
            };

            await _client.SendAsJson(Output, outputDatapoint);

            await Task.CompletedTask;
        }
示例#7
0
 void ChannelReceived(TagDataPoint <double> dataPoint)
 {
     _client.SendAsJson("output", dataPoint);
 }