Example #1
0
        public async Task <HttpResponseMessage> Post([FromUri] string stationId)
        {
            if (!"text/plain".Equals(Request.Content.Headers.ContentType.MediaType))
            {
                return(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType)
                {
                    ReasonPhrase = "Solo text/plain."
                });
            }
            if ((Request.Content.Headers.ContentLength ?? 0L) <= 0)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = "Empty content."
                });
            }
            var fileUri = await fileStore.Store(stationId, await Request.Content.ReadAsStreamAsync());

            await enqueuer.Enqueue(new StationFileToProcess
            {
                RecivedAt = DateTimeOffset.UtcNow,
                FilePath  = fileUri,
                StationId = stationId
            });

            return(new HttpResponseMessage(HttpStatusCode.Accepted));
        }
Example #2
0
        public async Task ProcessMessage([QueueTrigger("stationsensorhourlystatechanged")] StationSensorHourlyStateChanged message)
        {
            if (message == null)
            {
                return;
            }
            var stationId = message.StationId;
            var sensorId  = message.SensorId;
            var day       = message.Day;

            await PersistAverages(stationId, sensorId, day);

            await dailyEnqueuer.Enqueue(new StationSensorDayStateChanged { StationId = stationId, SensorId = sensorId, Day = day });
        }
Example #3
0
        private void NotifyChanges(string stationId, Dictionary <string, List <SensorState> > perSensorState)
        {
            var daysChanged =
                perSensorState.Select(
                    x => new { SensorId = x.Key, Days = x.Value.Select(d => d.At.Date).Distinct().ToArray() });
            var dayschanges = (from sensorDayChanged in daysChanged
                               from day in sensorDayChanged.Days
                               select new StationSensorHourlyStateChanged {
                StationId = stationId, SensorId = sensorDayChanged.SensorId, Day = day
            })
                              .ToArray();
            var tasks = dayschanges.Select(x => hourlyEnqueuer.Enqueue(x)).ToArray();

            Task.WaitAll(tasks);
        }
        public async Task ProcessMessage(StreamSensorAverage message)
        {
            if (string.IsNullOrWhiteSpace(message?.StationId) || string.IsNullOrWhiteSpace(message.SensorId))
            {
                return;
            }
            var stationId = message.StationId;
            var sensorId  = message.SensorId;

            /*
             * NOTE: el stream-analytics usa el 'time' que eventualmente recibe y lo convierte a UTC para su procesamiento y, en output tambien restituye UTC.
             * ya que los sensores están en Argentina cambiamos el Timestamp a la hora local.
             */
            var time = TimeZoneInfo.ConvertTime(message.Time, argentineZoneInfo);
            await statePersister.Persist(stationId, sensorId, time, message.State);

            await hourlyEnqueuer.Enqueue(new StationSensorHourlyStateChanged { StationId = stationId, SensorId = sensorId, Day = time.DateTime });
        }
Example #5
0
        public async Task <HttpResponseMessage> Post([FromUri] int min, [FromUri] int hora, [FromUri] string sensorId, [FromUri] string stationId, [FromUri] int day, [FromUri] int month, [FromUri] int year)
        {
            if (hora < 24 && min < 60)
            {
                string monthMM;
                string dayDD;
                string horaHH;
                string minMM;
                if (month < 10)
                {
                    monthMM = "0" + month.ToString();
                }
                else
                {
                    monthMM = month.ToString();
                }
                if (day < 10)
                {
                    dayDD = "0" + day.ToString();
                }
                else
                {
                    dayDD = day.ToString();
                }
                if (hora < 10)
                {
                    horaHH = "0" + hora.ToString();
                }
                else
                {
                    horaHH = hora.ToString();
                }
                if (min < 10)
                {
                    minMM = "0" + min.ToString();
                }
                else
                {
                    minMM = min.ToString();
                }
                var partition = year.ToString() + monthMM + dayDD;
                var rowkey    = horaHH + minMM;
                await sensorStatesDeleter.Delete(stationId, sensorId, partition, rowkey);

                DateTime dayDate;
                if (!DateTime.TryParseExact($"{year:D4}{month:D2}{day:D2}", "yyyyMMdd", CultureInfo.InvariantCulture,
                                            DateTimeStyles.None, out dayDate))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                await hourlyEnqueuer.Enqueue(new StationSensorHourlyStateChanged {
                    StationId = stationId,
                    SensorId  = sensorId,
                    Day       = dayDate
                });

                return(new HttpResponseMessage(HttpStatusCode.Accepted));
            }
            else
            {
                return(new HttpResponseMessage(HttpStatusCode.Conflict));
            }
        }