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); }
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); }
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); }
public bool Remove(string name) { SchedulerItem item = Get(name); if (item == null) { return(false); } _scheduleditems.Remove(item); return(true); }
public bool SetProgram(string name, string pid) { SchedulerItem item = Get(name); if (item != null) { item.ProgramId = pid; return(true); } return(false); }
public bool Enable(string name) { SchedulerItem item = Get(name); if (item != null) { item.IsEnabled = true; item.NextOccurrence = _getnextoccurrence(item.CronExpression); return(true); } return(false); }
public bool Disable(string name) { SchedulerItem item = Get(name); if (item != null) { item.IsEnabled = false; item.LastOccurrence = "-"; item.NextOccurrence = "-"; return(true); } return(false); }
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); }
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); }
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); }
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); }
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; }
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, ""); } } } } }
public SchedulerItem Get(string name) { SchedulerItem item = _scheduleditems.Find(e => e.Name.ToLower() == name.ToLower()); return(item); }