minute hour day_month month day_week team
- Day of the week (0 - 7) (Sunday = 0 or = 7)
- Month (1 - 12)
- Day (1 - 31)
- Hour (0 - 23)
- Minute (0 - 59)
0 0 * * 1 - Every Monday at 0:00 minutes
where * means any value
<Minutes> <Hours> <Months_Months> <Months> <Days_Week>> Years> <Time span in minutes>
<?xml version="1.0" encoding="utf-8" ?> <timemode> <device ID="1" > <mode timeperiod="* * * * * * 5" type="" priority="0" /> <mode timeperiod="0 7 * * * * 60" type="*;*80;*80;*21" priority="1" /> </device> </timemode>
“Dir * IMP; PV * 80; BB * 80; Y * 21 "- pulse operation mode, 80% of the speed of the supply fan, 80% of the speed of the exhaust fan, the temperature set point for the room is 21 °
"PV1> STOP"
"PW2> STOP"
“PV3> STOP”
public void XMLread() { arr = new ArrayList(); int prio; XmlDocument xmlDocument = new XmlDocument(); try{ xmlDocument.Load(filepath_local); Massege_str = " " ; } catch { Massege_str = " " ; return; } foreach (XmlNode device in xmlDocument.SelectNodes("/timemode/device")) { prio = -1; string strmode = "???" ; foreach (XmlNode mode in xmlDocument.SelectNodes("/timemode/device[@ID=\"" + device.Attributes["ID"].Value + "\"]/mode")) { int prioNew = Convert.ToInt16(mode.Attributes["priority"].Value) ; if ((innerInterval(mode.Attributes["timeperiod"].Value) > 0 ) && prio < prioNew) { strmode = mode.Attributes["type"].Value; prio = prioNew ; } } string newmes = (device.Attributes["ID"].Value + ">" + strmode); arr.Add(newmes); } ArrayListVentModes_local = arr; CountElement = ">" + ArrayListVentModes.Count.ToString(); Thread.Sleep(5000); clamp = 0; }
int innerInterval(string CronFormatStr){ string[] word = CronFormatStr.Split(' '); DateTime dt = DateTime.Now; if (word.Length == 7) { try { int dayOfWeekArray = 0; if (word[4] != "*") { dayOfWeekArray = Convert.ToInt32(word[4]); } DateTime dt_start = new DateTime( (word[5] == "*") ? dt.Year : Convert.ToInt32(word[5]), (word[3] == "*") ? dt.Month : Convert.ToInt32(word[3]), (word[2] == "*") ? dt.Day: Convert.ToInt32(word[2]), (word[1] == "*") ? dt.Hour : Convert.ToInt32(word[1]), (word[0] == "*") ? 0 : Convert.ToInt32(word[0]), 0 ); DateTime dt_end = dt_start.AddMinutes(Convert.ToInt32(word[6])); if (dt >= dt_start && dt <= dt_end) { if (dayOfWeekArray != Convert.ToInt32(dt.DayOfWeek) && dayOfWeekArray > 0) { return 0; } return 1; } } catch (FormatException) { return -1; } catch { return -10; } } return -1; }
using System; using System.Collections; using System.Collections.Generic; //using System.Linq; using System.Text; using System.Xml; using System.Threading; using System.Xml.Linq; namespace ClassLibrary { public class MyClass { ArrayList ArrayListVentModes_local; public ArrayList ArrayListVentModes{ get{ return ArrayListVentModes_local; } } public string FilePath{ set{ this.filepath_local = value ; } } public string Massege_str{ get; set; } public string CountElement{ get; set; } string filepath_local ; ArrayList arr; int innerInterval(string CronFormatStr){ string[] word = CronFormatStr.Split(' '); DateTime dt = DateTime.Now; if (word.Length == 7) { try { int dayOfWeekArray = 0; if (word[4] != "*") { dayOfWeekArray = Convert.ToInt32(word[4]); } DateTime dt_start = new DateTime( (word[5] == "*") ? dt.Year : Convert.ToInt32(word[5]), (word[3] == "*") ? dt.Month : Convert.ToInt32(word[3]), (word[2] == "*") ? dt.Day: Convert.ToInt32(word[2]), (word[1] == "*") ? dt.Hour : Convert.ToInt32(word[1]), (word[0] == "*") ? 0 : Convert.ToInt32(word[0]), 0 ); DateTime dt_end = dt_start.AddMinutes(Convert.ToInt32(word[6])); if (dt >= dt_start && dt <= dt_end) { if (dayOfWeekArray != Convert.ToInt32(dt.DayOfWeek) && dayOfWeekArray > 0) { return 0; } return 1; } } catch (FormatException) { return -1; } catch { return -10; } } return -1; } int clamp = 0; public void main_metod() { if (this.clamp != 1) { Thread tRec = new Thread(new ThreadStart(XMLread)); tRec.Start(); this.clamp = 1 ; } } public void XMLread() { arr = new ArrayList(); int prio; XmlDocument xmlDocument = new XmlDocument(); try{ xmlDocument.Load(filepath_local); Massege_str = " " ; } catch { Massege_str = " " ; return; } foreach (XmlNode device in xmlDocument.SelectNodes("/timemode/device")) { prio = -1; string strmode = "???" ; foreach (XmlNode mode in xmlDocument.SelectNodes("/timemode/device[@ID=\"" + device.Attributes["ID"].Value + "\"]/mode")) { int prioNew = Convert.ToInt16(mode.Attributes["priority"].Value) ; if ((innerInterval(mode.Attributes["timeperiod"].Value) > 0 ) && prio < prioNew) { strmode = mode.Attributes["type"].Value; prio = prioNew ; } } string newmes = (device.Attributes["ID"].Value + ">" + strmode); arr.Add(newmes); } ArrayListVentModes_local = arr; CountElement = ">" + ArrayListVentModes.Count.ToString(); Thread.Sleep(5000); clamp = 0; } } }
Source: https://habr.com/ru/post/333412/
All Articles