Пример #1
0
        public SchedulerItem AddOrUpdate(string name, string cronExpression)
        {
            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }
            //
            var  eventItem = Get(name);
            bool justAdded = false;

            if (eventItem == null)
            {
                eventItem      = new SchedulerItem();
                eventItem.Name = name;
                events.Add(eventItem);
                justAdded = true;
            }
            eventItem.CronExpression = cronExpression;
            eventItem.LastOccurrence = "-";
            eventItem.NextOccurrence = GetNextEventOccurrence(DateTime.Now, eventItem.CronExpression);
            // by default newly added events are enabled
            if (justAdded)
            {
                eventItem.IsEnabled = true;
            }
            return(eventItem);
        }
Пример #2
0
 public void SetHost(HomeGenieService hg, SchedulerItem item)
 {
     _hgService    = hg;
     _eventItem    = item;
     _scriptEngine = new Engine();
     _hgScriptingHost.SetHost(_hgService, item);
     _scriptEngine.SetValue("hg", _hgScriptingHost);
     _scriptEngine.SetValue("event", _eventItem);
 }
Пример #3
0
 public void SetHost(HomeGenieService hg, SchedulerItem item)
 {
     homegenie    = hg;
     eventItem    = item;
     scriptEngine = new Engine();
     hgScriptingHost.SetHost(homegenie, item);
     scriptEngine.SetValue("hg", hgScriptingHost);
     scriptEngine.SetValue("event", eventItem);
 }
Пример #4
0
        public bool Remove(string name)
        {
            SchedulerItem item = Get(name);

            if (item == null)
            {
                return(false);
            }
            _scheduleditems.Remove(item);
            return(true);
        }
Пример #5
0
        public bool SetProgram(string name, string pid)
        {
            SchedulerItem item = Get(name);

            if (item != null)
            {
                item.ProgramId = pid;
                return(true);
            }
            return(false);
        }
Пример #6
0
        public bool Enable(string name)
        {
            SchedulerItem item = Get(name);

            if (item != null)
            {
                item.IsEnabled      = true;
                item.NextOccurrence = _getnextoccurrence(item.CronExpression);
                return(true);
            }
            return(false);
        }
Пример #7
0
        public bool Disable(string name)
        {
            SchedulerItem item = Get(name);

            if (item != null)
            {
                item.IsEnabled      = false;
                item.LastOccurrence = "-";
                item.NextOccurrence = "-";
                return(true);
            }
            return(false);
        }
Пример #8
0
 public void SetHost(HomeGenieService hg, SchedulerItem item)
 {
     homegenie     = hg;
     schedulerItem = item;
     Reset();
     netHelper        = new NetHelper(homegenie);
     serialPortHelper = new SerialPortHelper();
     tcpClientHelper  = new TcpClientHelper();
     udpClientHelper  = new UdpClientHelper();
     mqttClientHelper = new MqttClientHelper();
     knxClientHelper  = new KnxClientHelper();
     schedulerHelper  = new SchedulerHelper(homegenie);
     programHelper    = new ProgramHelperBase(homegenie);
 }
Пример #9
0
 private bool _matchexpression(string cronexp, List <string> checkedstack = null)
 {
     if (checkedstack == null)
     {
         checkedstack = new List <string>();
     }
     //
     string[] exprs = cronexp.Split(':'); // <-- ':' is OR operator
     for (int e = 0; e < exprs.Length; e++)
     {
         string currentexpr = exprs[e].Trim();
         // avoid loops
         if (checkedstack.Contains(currentexpr))
         {
             continue;
         }
         checkedstack.Add(currentexpr);
         if (currentexpr.StartsWith("@"))
         {
             // Check expresion from scheduled item with a given name
             SchedulerItem itemref = Get(currentexpr.Substring(1));
             if (itemref.IsEnabled && _matchexpression(itemref.CronExpression, checkedstack))
             {
                 return(true);
             }
         }
         else
         {
             // Check current expression
             ValueOrError <CrontabSchedule> cts = NCrontab.CrontabSchedule.TryParse(currentexpr);
             if (!cts.IsError)
             {
                 DateTime occurrence = cts.Value.GetNextOccurrence(DateTime.Now.AddMinutes(-1));
                 string   d1         = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                 string   d2         = occurrence.ToString("yyyy-MM-dd HH:mm");
                 if (d1 == d2)
                 {
                     return(true);
                 }
             }
         }
     }
     //
     return(false);
 }
Пример #10
0
        public SchedulerItem AddOrUpdate(string name, string cronExpression, string data = null,
                                         string description = null, string script = null)
        {
            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }
            //
            var  eventItem = Get(name);
            bool justAdded = false;

            if (eventItem == null)
            {
                eventItem      = new SchedulerItem();
                eventItem.Name = name;
                events.Add(eventItem);
                justAdded = true;
            }
            eventItem.CronExpression = cronExpression;
            if (description != null)
            {
                eventItem.Description = description;
            }
            if (data != null)
            {
                eventItem.Data = data;
            }
            if (script != null)
            {
                if (eventItem.ScriptEngine != null && eventItem.Script != script)
                {
                    eventItem.ScriptEngine.StopScript();
                }
                eventItem.Script = script;
            }
            eventItem.LastOccurrence = "";
            // by default newly added events are enabled
            if (justAdded)
            {
                eventItem.IsEnabled = true;
            }
            return(eventItem);
        }
Пример #11
0
        public SchedulerItem AddOrUpdate(string name, string cronexp)
        {
            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }
            //
            SchedulerItem item = Get(name);

            if (item == null)
            {
                item      = new SchedulerItem();
                item.Name = name;
                _scheduleditems.Add(item);
            }
            item.CronExpression = cronexp;
            item.LastOccurrence = "-";
            item.NextOccurrence = _getnextoccurrence(item.CronExpression);
            return(item);
        }
Пример #12
0
 public SchedulerItem AddOrUpdate(string name, string cronExpression)
 {
     if (String.IsNullOrEmpty(name)) return null;
     //
     var eventItem = Get(name);
     bool justAdded = false;
     if (eventItem == null)
     {
         eventItem = new SchedulerItem();
         eventItem.Name = name;
         events.Add(eventItem);
         justAdded = true;
     }
     eventItem.CronExpression = cronExpression;
     eventItem.LastOccurrence = "-";
     eventItem.NextOccurrence = GetNextEventOccurrence(eventItem.CronExpression);
     // by default newly added events are enabled
     if (justAdded)
     {
         eventItem.IsEnabled = true;
     }
     return eventItem;
 }
Пример #13
0
 private void _checkscheduleditems(object state)
 {
     for (int i = 0; i < _scheduleditems.Count; i++)
     {
         SchedulerItem item = _scheduleditems[i];
         // TODO: execute items only once instead of repeating for the whole minute
         string currentoccurrence = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
         if (item.IsEnabled && item.LastOccurrence != currentoccurrence && IsScheduling(item.CronExpression))
         {
             // update last/next occurrence values
             item.LastOccurrence = currentoccurrence;
             item.NextOccurrence = _getnextoccurrence(item.CronExpression);
             // execute associated task if any
             if (!String.IsNullOrEmpty(item.ProgramId))
             {
                 ProgramBlock pb = _mastercontrolprogram.Programs.Find(p => p.Address.ToString() == item.ProgramId || p.Name == item.ProgramId);
                 if (pb != null)
                 {
                     _mastercontrolprogram.Run(pb, "");
                 }
             }
         }
     }
 }
Пример #14
0
        public SchedulerItem Get(string name)
        {
            SchedulerItem item = _scheduleditems.Find(e => e.Name.ToLower() == name.ToLower());

            return(item);
        }
Пример #15
0
 public void SetHost(HomeGenieService hg, SchedulerItem item)
 {
     homegenie = hg;
     schedulerItem = item;
     Reset();
     netHelper = new NetHelper(homegenie);
     serialPortHelper = new SerialPortHelper();
     tcpClientHelper = new TcpClientHelper();
     udpClientHelper = new UdpClientHelper();
     mqttClientHelper = new MqttClientHelper();
     knxClientHelper = new KnxClientHelper();
     schedulerHelper = new SchedulerHelper(homegenie);
     programHelper = new ProgramHelperBase(homegenie);
 }