Beispiel #1
0
 internal void onError(Exception ex, NJobDef def)
 {
     if (Error != null)
     {
         Error(this, new NJobErrorEventArgs(ex, def));
     }
 }
Beispiel #2
0
 internal void onRun(NJobDef def)
 {
     if (Run != null)
     {
         Run(this, def);
     }
 }
Beispiel #3
0
 public NJobErrorEventArgs(Exception exception, NJobDef def)
 {
     _exception = exception;
     _def       = def;
 }
Beispiel #4
0
    public List <NJobDef> LoadDef(string defDoc)
    {
        Dictionary <string, NJobDef> dic = new Dictionary <string, NJobDef>();

        string[] defs = defDoc.Split(new string[] { "\n" }, StringSplitOptions.None);
        int      row  = 1;

        foreach (string def in defs)
        {
            string loc1 = def.Trim().Trim('\r');
            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("NJob配置错误“" + loc1 + "”, 第" + row + "行"));
                continue;
            }
            string      name     = m.Groups[1].Value.Trim('\t', ' ');
            NJobRunMode 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("NJob配置存在重复的名字“" + name + "”, 第" + row + "行"));
                continue;
            }
            if (mode == NJobRunMode.NONE)
            {
                continue;
            }

            NJobDef rd = null;
            if (_dic_jobs.ContainsKey(name))
            {
                rd = _dic_jobs[name];
                rd.Update(mode, param, runParam);
                _dic_jobs.Remove(name);
            }
            else
            {
                rd = new NJobDef(this, name, mode, param, runParam);
            }
            if (rd.Interval < 0)
            {
                onError(new Exception("NJob配置参数错误“" + def + "”, 第" + row + "行"));
                continue;
            }
            dic.Add(rd.Name, rd);
            row++;
        }
        List <NJobDef> rds = new List <NJobDef>();

        foreach (NJobDef rd in dic.Values)
        {
            rds.Add(rd);
        }
        foreach (NJobDef stopBot in _dic_jobs.Values)
        {
            stopBot.Dispose();
        }

        return(rds);
    }