Exemplo n.º 1
0
        public void DoScheduleTask()
        {
            //  ScheduleJob[] BB=;
            try
            {
                if (this.IsPrimary)
                {
                         Console.WriteLine(this.schid+",Invoked");

                         OneTimeSchedule jobsch = new OneTimeSchedule(this.schid + "@",
                                System.DateTime.Now,
                                this.m_durationMin, this.jobs, false);
                        Host.Schedule.Scheduler.AddSchedule(jobsch);

                        jobsch.outputMode = this.outputMode;

                   // Host.Schedule.Scheduler.AddSchedule(new OneTimeSchedule(schid + "@", System.DateTime.Now, this.m_durationMin, jobs, false));
                }
                else  //sub schedule
                {
                    Console.WriteLine(this.schid + " invoked");
                    foreach (ScheduleJob job in jobs)
                    {
                        try
                        {
                          //  job.DoJob(System.Convert.ToInt32(this.schid.TrimEnd(new char[] { '@' })));
                            System.Threading.Thread th = new Thread(JobTask);
                            th.Start(job);
                        }
                        catch (Exception ex)
                        {
                            RemoteInterface.Util.SysLog("schd.log", ex.Message + ex.StackTrace);

                        }

                    }

                }
            }
            catch (Exception ex)
            {
                RemoteInterface.ConsoleServer.WriteLine(ex.Message);
            }
        }
Exemplo n.º 2
0
        public static Schedule CreateSchedule(int schid,string schname,int schtype,int isDuration,int durationMin,DateTime dt,int[] weekdays)
        {
            System.DateTime starttime=DateTime.MinValue;
            #if DEBUG
              //  dt = System.DateTime.Now.AddMinutes(1);

            #endif
            Schedule schedule=null;

            if (schtype == 0)  //repeat
            {
                for (int i = 0; i <= 7; i++)
                {
                    DateTime invokeTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, dt.Hour, dt.Minute, dt.Second).AddDays(i);
                    if (weekdays[(int)invokeTime.DayOfWeek] == 1 && invokeTime > DateTime.Now)
                    {
                        starttime = invokeTime;
                        break;
                    }

                }
            }
            else  //one time
                if (DateTime.Now < dt)
                    starttime = dt;
                else
                    throw new Exception(schid + " 過期");

             if (starttime == DateTime.MinValue)
                 throw new Exception("Schedule Err:can not find invoke time!");

             OdbcConnection cn = new OdbcConnection(Global.Db2ConnectionString);
             OdbcCommand cmd = new OdbcCommand("select schid,subschid,devicename,command from tblschdetail where schid=" + schid);
             cmd.Connection = cn;
             System.Collections.ArrayList ary = new System.Collections.ArrayList();
             try
             {

                 cn.Open();
                 OdbcDataReader rd = cmd.ExecuteReader();

               //  int inx = 0;
                 while (rd.Read())
                 {
                    // int schid = System.Convert.ToInt32(rd[Global.getFiledInx(rd, "schid")]);
                     int subschid = System.Convert.ToInt32(rd[Global.getFiledInx(rd, "subschid")]);
                     string devName = rd[Global.getFiledInx(rd, "devicename")].ToString();
                     string command ="";
                     if (!rd.IsDBNull(Global.getFiledInx(rd, "command")))
                         command = rd[Global.getFiledInx(rd, "command")].ToString();
                     else
                         command = "";
                     if(command=="")
                      ary.Add(  new ScheduleJob(schid,devName, subschid, null));
                     else
                      ary.Add(new ScheduleJob(schid,devName,subschid,RemoteInterface.Utils.Util.StringToObj(command)));

                 }

                  ScheduleJob[] schjobs= new ScheduleJob[ary.Count];
                  for (int i = 0; i < ary.Count; i++)
                      schjobs[i] = (ScheduleJob)ary[i];

                 switch (schtype)
                 {
                     case 0: //repeat
                         schedule = new DailySchedule(schid.ToString(), starttime, (isDuration == 0) ? 0 : durationMin, schjobs, true);
                         break;
                     case 1: //one time
                         schedule = new OneTimeSchedule(schid.ToString(), starttime, (isDuration == 0) ? 0 : durationMin, schjobs, true);
                         break;
                 }

                 for(int i=0;i<7;i++)
                     schedule.SetWeekDay((DayOfWeek)i,(weekdays[i]==1)?true:false);

                 return schedule;

             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message + "," + ex.StackTrace);
             }
             finally
             {
                 cn.Close();
             }
        }