private void PerformSensorEnergyLogBatch(Sensor sensor, SensorLogBatch sensorLogBatch)
        {
            SensorEnergyLog previousLog = GetSensorEnergyLogLast(sensor);

            try
            {
                foreach (var contentLogItem in sensorLogBatch.Content.Split("|"))
                {
                    Func <long, long> getSensorDimTimeId = (unixTime) => this.GetOrCreateSensorDimTime(sensor, unixTime).Id;
                    var newEnergyLog = SensorEnergyLog.Parse(sensor, getSensorDimTimeId, contentLogItem);
                    if (previousLog != null)
                    {
                        newEnergyLog.CalculateDuration(sensor.LogDurationMode, previousLog);
                    }
                    this.SensorEnergyLogs.Add(newEnergyLog);
                    this.SaveOrUpdateSensorEnergyLog(newEnergyLog);
                    previousLog = newEnergyLog;
                }
                this.SensorLogBatchs.Remove(sensorLogBatch);
                this.SaveChanges();
            }
            catch (Exception e)
            {
                sensorLogBatch.Attempts++;
                sensorLogBatch.Exception = $"Message: {e.Message}\nSource: {e.Source}";
                this.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public async Task <int> CreateSensorLogBatch(Sensor sensor, string content)
        {
            var sensorLogBatch = new SensorLogBatch()
            {
                SensorId       = sensor.Id,
                SecretApiToken = sensor.SecretApiToken,
                Content        = content,
                Attempts       = 0
            };

            this.SensorLogBatchs.Add(sensorLogBatch);
            return(await this.SaveChangesAsync());
        }