Пример #1
0
 public NJobDef(NJob onwer, string name, NJobRunMode mode, string param, string runParam)
 {
     _onwer    = onwer;
     _name     = name;
     _mode     = mode;
     _param    = param;
     _runParam = runParam;
 }
Пример #2
0
 public void Update(NJobRunMode mode, string param, string runParam)
 {
     if (_mode != mode || _param != param || _runParam != runParam)
     {
         _mode     = mode;
         _param    = param;
         _runParam = runParam;
         if (_timer != null)
         {
             _timer.Dispose();
             _timer = null;
         }
         RunNow();
     }
 }
Пример #3
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);
    }