private void doDataLiftWork() { try { _log.Debug("+doDataLiftWork()"); this._registry = new LocalRegistryService(); if (this._registry.isRegistry()) { if (this.isGreaterThanADay(_registry.getLastRunDateFromRegistry()) || this._registry.getRunNowBooleanFromRegistry()) { this._readingDao = new ReadingDao(); this._deviceDao = new DeviceDao(); this._run = new ScheduledRun(this._registry, this._readingDao, this._deviceDao); this._run.getDataAndPostToWebService(); //After use, set date to now and run now to false this._registry.setRegistryValueLastRunDateToNow(); this._registry.setRegistryValueRunNowBoolean(); } } else { this._registry.CreateRegistryPathAndAllValues(); } _log.Debug("-doDataLiftWork()"); } catch (Exception ex) { _log.Error("-doDataLiftWork() Message: " + ex.Message + " InnerException: " + ex.InnerException); } }
public WateringHistoryDto(ScheduledRun run) { this.id = run.Id; this.waterNow = new WaterNowDto { duration = run.Duration, level = run.Level }; this.startTime = run.StartTime; }
private bool HasNotBeenTriggered(WateringScheduleItem item) { // TODO: these operations may be slow when dealing with a lot of schedules. Find a better way to store them int notificationInterval = item.NotifiyBeforeMinutes; DateTime now = DateTime.UtcNow; ScheduledRun lastRun = item.LastRun; if (lastRun != null && (now - lastRun.StartTime).TotalMinutes > notificationInterval || lastRun == null) { return(true); } return(false); }
public void WaterNow([FromBody] WaterNowDto dto) { this._logger.LogInformation("CommandControllerWaterNow"); if (dto == null) { throw new Exception("Could not parse the object"); } User usr = this._context.Users .Include(u => u.DeviceTokens) .Include(u => u.WateringSchedules) .FirstOrDefault(u => u.Id == Misc.GetIdFromClaimsPrincipal(User)); if (usr != null) { string deviceToken = usr.DeviceTokens.Count > 0 ? usr.DeviceTokens[0].Token : null; if (deviceToken == null) { this._logger.LogError("Command_NoToken", "User: {0}", usr.Id); return; // TODO: return some error to the customer so they know it's bad } this._dispatcher.WaterNow(this, new WaterNowArgs { WaterNow = dto, Token = deviceToken }); ScheduledRun newRun = new ScheduledRun { Id = Guid.NewGuid(), Duration = dto.duration, Level = dto.level, StartTime = DateTime.Now }; usr.ScheduledRuns.Add(newRun); WateringScheduleItem wateringSchedule = usr.WateringSchedules.FirstOrDefault(ws => ws.Level == dto.level); if (wateringSchedule != null) { wateringSchedule.LastRun = newRun; } this._context.SaveChanges(); } else { // TODO: the user doesn't exist. There's something wrong with Identity. // tell the user to try again, then log out/log in, then email us if none of this works } }