Exemplo n.º 1
0
        public async Task <bool> RetrieveWateringEvent(string guid)
        {
            WateringEvent result = new WateringEvent();

            try
            {
                result = await App.Database.GetWateringEventAsync(guid);

                if (result != null)
                {
                    this.guid            = result.guid;
                    this.stationFullName = result.stationFullName;
                    this.wateringTime    = result.wateringTime;
                    this.startTime       = result.startTime;
                    this.sunday          = result.sunday;
                    this.monday          = result.monday;
                    this.tuesday         = result.tuesday;
                    this.wednesday       = result.wednesday;
                    this.thursday        = result.thursday;
                    this.friday          = result.friday;
                    this.saturday        = result.saturday;
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
        private void StartSecondaryWatering(object state)
        {
            if (!_cfgCtrl.Configuration.SecondWateringActive)
            {
                return;
            }

            if (!IsSecondWateringNecessary(null))
            {
                StopSecondaryWatering(null);
                return;
            }

            _pumpsActive   = true;
            _wateringEvent = WateringEvent.SecondaryCycle;
            int duration = Convert.ToInt32(_cfgCtrl.Configuration.PumpDurationSecondCycle * 1000);

            if (!_debugMode)
            {
                DigitalIOConnector.Instance.TurnOnPump();
                _logger.Verbose("Pumpe wird eingeschaltet (secondary watering)");
            }

            if (_eveningPumpTimer == null)
            {
                _eveningPumpTimer = new Timer(StopSecondaryWatering, null, duration, Timeout.Infinite);
            }
            else
            {
                _eveningPumpTimer.Change(duration, Timeout.Infinite);
            }
            UpdateInfos(null);
        }
Exemplo n.º 3
0
        public async Task <bool> SaveWateringEvent()
        {
            int           result        = 0;
            WateringEvent wateringEvent = new WateringEvent();

            wateringEvent.guid            = this.guid;
            wateringEvent.stationFullName = this.stationFullName;
            wateringEvent.startTime       = this.startTime;
            wateringEvent.wateringTime    = this.wateringTime;
            wateringEvent.sunday          = this.sunday;
            wateringEvent.monday          = this.monday;
            wateringEvent.tuesday         = this.tuesday;
            wateringEvent.wednesday       = this.wednesday;
            wateringEvent.thursday        = this.thursday;
            wateringEvent.friday          = this.friday;
            wateringEvent.saturday        = this.saturday;
            try
            {
                result = await App.Database.SaveWateringEventAsync(wateringEvent);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        public async Task <int> DeleteWateringEventAsync(WateringEvent wateringEvent)
        {
            int           result        = 0;
            WateringEvent existingEvent = await database.Table <WateringEvent>().Where(i => i.guid == wateringEvent.guid).FirstOrDefaultAsync();

            if (existingEvent != null)
            {
                result = database.DeleteAsync(existingEvent).Result;
            }
            return(result);
        }
        private void StartPrimaryWatering(object state)
        {
            WateringCorrection wateringCorrection = CalcWateringDurationCorrection(null);
            double             correction;

            if (wateringCorrection.CorrFactorHot == 0d)
            {
                correction = 0;
            }
            else if (wateringCorrection.CorrFactorHot > 1)
            {
                correction = wateringCorrection.CorrFactorHot;
            }
            else if (wateringCorrection.CorrFactorCold < 1)
            {
                correction = wateringCorrection.CorrFactorCold;
            }
            else
            {
                correction = 1d;
            }

            int duration = Convert.ToInt32(_cfgCtrl.Configuration.PumpDurationMainCycle * correction * 1000);  //msec

            if (duration == 0)
            {
                StopPrimaryWatering(null);
                _logger.Warning("Primary watering wurde nicht ausgelöst: Korr: 0");
                return;
            }

            _logger.Information("Start primary watering, duration: {Duration}, correction: {Correction}", duration, correction);

            _pumpsActive   = true;
            _wateringEvent = WateringEvent.PrimaryCycle;

            if (!_debugMode)
            {
                DigitalIOConnector.Instance.TurnOnPump();
                _logger.Verbose("Pumpe wird eingeschaltet (primary watering)");
            }

            if (_mainPumpTimer == null)
            {
                _mainPumpTimer = new Timer(StopPrimaryWatering, null, duration, Timeout.Infinite);
            }
            else
            {
                _mainPumpTimer.Change(duration, Timeout.Infinite);
            }
            UpdateInfos(null);
        }
        public EventData(WateringEvent wateringEvent)
        {
            var fi = new DateTimeFormatInfo {
                AMDesignator = "a",
                PMDesignator = "p"
            };

            title = wateringEvent.StartDateTime.ToString("%h:mmtt", fi) + "-" + wateringEvent.EndDateTime.ToString("%h:mmtt", fi);
            start = wateringEvent.StartDateTime.ToString("yyyy-MM-ddTHH:mm:ssK");
            end   = wateringEvent.EndDateTime.ToString("yyyy-MM-ddTHH:mm:ssK");
            id    = wateringEvent.Id;
            valve = string.Format("{0}", wateringEvent.IrrigationValve.ValveNumber + 1);
        }
Exemplo n.º 7
0
        public async Task <int> SaveWateringEventAsync(WateringEvent wateringEvent)
        {
            WateringEvent existingEvent = await database.Table <WateringEvent>().Where(i => i.guid == wateringEvent.guid).FirstOrDefaultAsync();

            if (existingEvent != null)
            {
                return(database.UpdateAsync(wateringEvent).Result);
            }
            else
            {
                return(database.InsertAsync(wateringEvent).Result);
            }
        }
        private void StopSecondaryWatering(object state)
        {
            var delay = CalculateTimeToSecondWatering();

            if (!_debugMode)
            {
                DigitalIOConnector.Instance.TurnOffPump();
            }
            _logger.Verbose("Pumpe wird ausgeschaltet (secondary watering). Next watering: {Delay}", delay);

            _eveningTimer.Change(delay, Timeout.Infinite);
            _pumpsActive   = false;
            _wateringEvent = WateringEvent.None;
            UpdateInfos(null);
        }
 public void Insert(WateringEvent wateringEvent)
 {
     try{
         if (wateringEvent.Id == 0)
         {
             _wateringEventRepository.Insert(wateringEvent);
         }
         else
         {
             _wateringEventRepository.Update(wateringEvent);
         }
     } catch (Exception ex) {
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 10
0
        public async Task <bool> DeleteWateringEvent()
        {
            int           result        = 0;
            WateringEvent wateringEvent = new WateringEvent();

            wateringEvent.guid = this.guid;
            try
            {
                result = await App.Database.DeleteWateringEventAsync(wateringEvent);
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 11
0
        public ActionResult SetWateringEventAction(int valveId, bool status)
        {
            try {
                var valve          = _irrigationValveService.GetIrrigationValveById(valveId);
                var activeWatering = valve.WateringEvents.LastOrDefault(x => x.Watering);
                var user           = _userService.GetUserById(UserId);
                var now            = DateTimeHelper.GetLocalTime();

                if (activeWatering != null && !status)
                {
                    activeWatering.IrrigationValve = null;
                    activeWatering.Watering        = false;
                    activeWatering.EndDateTime     = now;
                    _wateringEventService.Insert(activeWatering);
                    //activeWatering.IrrigationValve = valve;
                    return(Json(new {
                        msg = "Watering for valve " + (valve.ValveNumber + 1) + " has been stopped", watering = user.Unit.IrrigationValves.SelectMany(x => x.WateringEvents).Any(x => x.Watering)
                    }, JsonRequestBehavior.AllowGet));
                }

                if (valve.WateringEvents.Any(x => x.StartDateTime > now && x.StartDateTime < now.AddMinutes(10)))
                {
                    throw new Exception("Cannot start a watering event when a scheduled watering is about to start");
                }

                var newWateringEvent = new WateringEvent {
                    IrrigationValveId = valveId,
                    StartDateTime     = now,
                    EndDateTime       = now.AddMinutes(10),
                    Watering          = true
                };
                _wateringEventService.Insert(newWateringEvent);
                newWateringEvent.IrrigationValve = valve;
                return(Json(new {
                    msg = "Watering event started for 10 minutes", jsonEvent = new EventData(newWateringEvent), watering = user.Unit.IrrigationValves.SelectMany(x => x.WateringEvents).Any(x => x.Watering)
                }, JsonRequestBehavior.AllowGet));
            } catch (Exception ex) {
                return(Json(new { msg = ex.Message, error = true }));
            }
        }
Exemplo n.º 12
0
        public WateringEventViewModel(string guid)
        {
            WateringEvent checkExistingEvent = App.Database.GetWateringEventAsync(guid).Result;

            if (checkExistingEvent == null)
            {
                this.guid = Guid.NewGuid().ToString();
            }
            else
            {
                this.guid            = checkExistingEvent.guid;
                this.stationFullName = checkExistingEvent.stationFullName;
                this.wateringTime    = checkExistingEvent.wateringTime;
                this.startTime       = checkExistingEvent.startTime;
                this.sunday          = checkExistingEvent.sunday;
                this.monday          = checkExistingEvent.monday;
                this.tuesday         = checkExistingEvent.tuesday;
                this.wednesday       = checkExistingEvent.wednesday;
                this.thursday        = checkExistingEvent.thursday;
                this.friday          = checkExistingEvent.friday;
                this.saturday        = checkExistingEvent.saturday;
            }
        }
Exemplo n.º 13
0
        public ActionResult CreateWateringEvent(DateTime selectedDate, DateTime startTime, DateTime endTime, List <int> irrigationValveIds)
        {
            try {
                var events = new List <EventData>();

                foreach (var irrigationValveId in irrigationValveIds)
                {
                    var valve            = _irrigationValveService.GetIrrigationValveById(irrigationValveId);
                    var newWateringEvent = new WateringEvent {
                        StartDateTime     = selectedDate.Date.Add(startTime.TimeOfDay),
                        EndDateTime       = selectedDate.Date.Add(endTime.TimeOfDay),
                        IrrigationValveId = valve.Id
                    };
                    _wateringEventService.Insert(newWateringEvent);

                    newWateringEvent.IrrigationValve = valve;
                    events.Add(new EventData(newWateringEvent));
                }

                return(Json(new { error = false, eventData = events }, JsonRequestBehavior.AllowGet));
            } catch (Exception ex) {
                return(Json(new { error = true, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }