public async Task <IEnumerable <ChartData> > Get(SignalRFilter filter)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }
            var result = await influxDbClient.QueryAsync(filter.DeviceId, filter.Sensor, filter.From);

            var processed = this.dataParser.ParseMessages(filter.Sensor, result);

            return(processed);
        }
Ejemplo n.º 2
0
        public IActionResult Get([FromQuery(Name = "deviceId")] Guid deviceId,
                                 [FromQuery(Name = "sensor")] string sensor,
                                 [FromQuery(Name = "connId")] string connId)
        {
            if (deviceId == Guid.Empty)
            {
                return(this.BadRequest("DeviceId is missing"));
            }
            if (string.IsNullOrWhiteSpace(sensor))
            {
                return(this.BadRequest("Sensor is missing"));
            }
            if (string.IsNullOrWhiteSpace(connId))
            {
                return(this.BadRequest("Connection ID is missing"));
            }


            var filter = new SignalRFilter()
            {
                DeviceId = deviceId,
                Sensor   = sensor,
                From     = DateTime.Now
            };

            var device = this.deviceService.GetDeviceById(deviceId);
            //var dt = DateTime.Now;
            // refactor using a Timer Factory
            Func <DateTime, Task <DateTime?> > func = async(dt) =>
            {
                filter.From = dt;
                var collection = await dataManager.Get(filter);

                await hub.Clients.All.SendAsync("transferchartdata", collection);

                return(collection.LastOrDefault()?.Date);
            };
            var timerManager = new TimerManager(device.IntervalInSeconds, func);

            Utils.timers[connId] = timerManager;

            return(Ok(new { Message = "Request Completed" }));
        }