Exemple #1
0
 public Timer(Maticsoft.TimerTask.Model.TaskTimer taskTimer, DateTime executeTime, Action<string[]> action, Action<Maticsoft.TimerTask.Model.TaskTimer> callback, string[] args)
 {
     ElapsedEventHandler handler = null;
     ElapsedEventHandler handler2 = null;
     this._taskTimer = taskTimer;
     TimeSpan span = (TimeSpan) (executeTime - DateTime.Now);
     double totalMilliseconds = span.TotalMilliseconds;
     if (totalMilliseconds >= 2147483647.0)
     {
         throw new ArgumentOutOfRangeException("执行时间超过最大值 24天!");
     }
     if (handler == null)
     {
         handler = delegate (object obj, ElapsedEventArgs e) {
             action(args);
         };
     }
     base.Elapsed += handler;
     if (handler2 == null)
     {
         handler2 = delegate (object obj, ElapsedEventArgs e) {
             callback(this._taskTimer);
         };
     }
     base.Elapsed += handler2;
     base.AutoReset = false;
     base.Interval = ((totalMilliseconds > 0.0) && (totalMilliseconds < 2147483647.0)) ? totalMilliseconds : 100.0;
     base.Enabled = true;
 }
Exemple #2
0
 public static void Add(DateTime executeTime, Action<string[]> action, string[] args)
 {
     DateTime now = DateTime.Now;
     if (executeTime < DateTime.Now)
     {
         executeTime = now.AddSeconds(1.0);
     }
     Maticsoft.TimerTask.Model.TaskTimer timer2 = new Maticsoft.TimerTask.Model.TaskTimer {
         IsSingle = true,
         ExecuteType = action.GetType().FullName,
         ExecuteTime = executeTime
     };
     TimeSpan span = (TimeSpan) (executeTime - now);
     timer2.Interval = (decimal) span.TotalMilliseconds;
     timer2.Params = args;
     Maticsoft.TimerTask.Model.TaskTimer model = timer2;
     model.ID = Maticsoft.TimerTask.BLL.TaskTimer.Add(model);
     Instance().CurrentTasks.Add(new Maticsoft.TimerTask.Timer(model, executeTime, action, new Action<Maticsoft.TimerTask.Model.TaskTimer>(Task.CallBack), args));
 }
Exemple #3
0
 public Maticsoft.TimerTask.Model.TaskTimer DataRowToModel(DataRow row)
 {
     Maticsoft.TimerTask.Model.TaskTimer timer = new Maticsoft.TimerTask.Model.TaskTimer();
     if (row != null)
     {
         if ((row["ID"] != null) && (row["ID"].ToString() != ""))
         {
             timer.ID = int.Parse(row["ID"].ToString());
         }
         if (row["ExecuteType"] != null)
         {
             timer.ExecuteType = row["ExecuteType"].ToString();
         }
         if ((row["IsSingle"] != null) && (row["IsSingle"].ToString() != ""))
         {
             if ((row["IsSingle"].ToString() == "1") || (row["IsSingle"].ToString().ToLower() == "true"))
             {
                 timer.IsSingle = true;
             }
             else
             {
                 timer.IsSingle = false;
             }
         }
         if ((row["Interval"] != null) && (row["Interval"].ToString() != ""))
         {
             timer.Interval = decimal.Parse(row["Interval"].ToString());
         }
         if ((row["ExecuteTime"] != null) && (row["ExecuteTime"].ToString() != ""))
         {
             timer.ExecuteTime = DateTime.Parse(row["ExecuteTime"].ToString());
         }
         if ((row["ExecuteNumber"] != null) && (row["ExecuteNumber"].ToString() != ""))
         {
             timer.ExecuteNumber = int.Parse(row["ExecuteNumber"].ToString());
         }
         if (row["Param1"] != null)
         {
             timer.Param1 = row["Param1"].ToString();
         }
         if (row["Param2"] != null)
         {
             timer.Param2 = row["Param2"].ToString();
         }
         if (row["Param3"] != null)
         {
             timer.Param3 = row["Param3"].ToString();
         }
         if (row["Param4"] != null)
         {
             timer.Param4 = row["Param4"].ToString();
         }
         if (row["Param5"] != null)
         {
             timer.Param5 = row["Param5"].ToString();
         }
         if (row["Param6"] != null)
         {
             timer.Param6 = row["Param6"].ToString();
         }
         if (row["Param7"] != null)
         {
             timer.Param7 = row["Param7"].ToString();
         }
         if (row["Param8"] != null)
         {
             timer.Param8 = row["Param8"].ToString();
         }
         if (row["Param9"] != null)
         {
             timer.Param9 = row["Param9"].ToString();
         }
         if (row["Param10"] != null)
         {
             timer.Param10 = row["Param10"].ToString();
         }
     }
     return timer;
 }