internal void onError(Exception ex, RobotDef def) { if (Error != null) { Error(this, new RobotErrorEventArgs(ex, def)); } }
internal void onRun(RobotDef def) { if (Run != null) { Run(this, def); } }
public RobotErrorEventArgs(Exception exception, RobotDef def) { _exception = exception; _def = def; }
public List <RobotDef> LoadDef(string defDoc) { Dictionary <string, RobotDef> dic = new Dictionary <string, RobotDef>(); string[] defs = defDoc.Split(new string[] { "\r\n" }, StringSplitOptions.None); int row = 1; foreach (string def in defs) { string loc1 = def.Trim(); if (string.IsNullOrEmpty(loc1) || loc1[0] == 65279 || loc1[0] == ';' || loc1[0] == '#') { continue; } string pattern = @"([^\s]+)\s+(NONE|SEC|MIN|HOUR|DAY|RunOnDay|RunOnWeek|RunOnMonth)\s+([^\s]+)\s+([^\s]+)"; Match m = Regex.Match(loc1, pattern, RegexOptions.IgnoreCase); if (!m.Success) { onError(new Exception("Robot配置错误“" + loc1 + "”, 第" + row + "行")); continue; } string name = m.Groups[1].Value.Trim('\t', ' '); RobotRunMode mode = getMode(m.Groups[2].Value.Trim('\t', ' ')); string param = m.Groups[3].Value.Trim('\t', ' '); string runParam = m.Groups[4].Value.Trim('\t', ' '); if (dic.ContainsKey(name)) { onError(new Exception("Robot配置存在重复的名字“" + name + "”, 第" + row + "行")); continue; } if (mode == RobotRunMode.NONE) { continue; } RobotDef rd = null; if (_dic_robots.ContainsKey(name)) { rd = _dic_robots[name]; rd.Update(mode, param, runParam); _dic_robots.Remove(name); } else { rd = new RobotDef(this, name, mode, param, runParam); } if (rd.Interval < 0) { onError(new Exception("Robot配置参数错误“" + def + "”, 第" + row + "行")); continue; } dic.Add(rd.Name, rd); row++; } List <RobotDef> rds = new List <RobotDef>(); foreach (RobotDef rd in dic.Values) { rds.Add(rd); } foreach (RobotDef stopBot in _dic_robots.Values) { stopBot.Dispose(); } return(rds); }