コード例 #1
0
        public void LoadSchedule()
        {
            LedClientService.LedLocalDb db = new LedLocalDb();
            Schedule.Scheduler.RemoveAll();
            #region Load Daily
            var q= from n in db.tblProjectGroupSection   select n ;

            foreach (tblProjectGroupSection section in q)
            {
                bool bFirstFlag = false;
                tblSectionLedPlan lastSectionPlan = null;
                var q1 = from n in section.tblSectionLedPlan orderby n.BeginTime descending select n;
                foreach (tblSectionLedPlan plan in q1)
                {
                    DateTime begtime = TodayTime(plan.BeginTime);
                    if (begtime <= DateTime.Now)
                    {
                        begtime = begtime.AddDays(1);
                        if (!bFirstFlag)
                        {
                            if (lastSectionPlan != null)
                            {
                                LedClientService.Schedule.OneTimeSchedule oneSchedule = new Schedule.OneTimeSchedule("tmp_" + plan.PlanID, DateTime.Now,
                                   (int)TodayTime(lastSectionPlan.BeginTime).Subtract(DateTime.Now).TotalMinutes+1,
                                   new Schedule.ScheduleJob[] { new Schedule.ScheduleJob(plan.SectionID, 0,
                                   new Devices.LedOutputData(){ SectionID=plan.SectionID, B=plan.B,R=plan.R,G=plan.G,W=plan.W,Priority= OutputPriority.Scheduled}) },
                                   true);
                                Schedule.Scheduler.AddSchedule(oneSchedule);
                            }
                            else
                            {
                                tblSectionLedPlan[] tmp = q1.ToArray<tblSectionLedPlan>();
                                tblSectionLedPlan refplan = tmp[0];
                                int dueMin = (int)TodayTime(refplan.BeginTime).AddDays(1).Subtract(DateTime.Now).TotalMinutes+1;
                                LedClientService.Schedule.OneTimeSchedule oneSchedule = new Schedule.OneTimeSchedule("tmp_" + plan.PlanID, DateTime.Now, dueMin,
                                new Schedule.ScheduleJob[] { new Schedule.ScheduleJob(plan.SectionID, 0,
                               new Devices.LedOutputData(){SectionID=plan.SectionID, B=refplan.B,W=refplan.W, G=refplan.G, R=refplan.R, Priority= OutputPriority.Scheduled}   ) }
                                , true);
                                Schedule.Scheduler.AddSchedule(oneSchedule);
                            }
                            bFirstFlag = true;
                        }
                    }
                    else
                        lastSectionPlan = plan;

                    Schedule.Schedule schedule = new Schedule.DailySchedule("Daily" + plan.PlanID, begtime,
                       0, new Schedule.ScheduleJob[] { new Schedule.ScheduleJob(plan.SectionID, 0,
                           new Devices.LedOutputData(){ SectionID=plan.SectionID, R=plan.R,G=plan.G,B=plan.B,W=plan.W,Priority= OutputPriority.Scheduled})  }, true); ;

                    Schedule.Scheduler.AddSchedule(schedule);
                    Console.WriteLine("Dialy Schedule" + plan.PlanID + " Loaded!");

                    //for (int i = 0; i < Schedule.Scheduler.Count(); i++)
                    //{
                    //    Schedule.Scheduler.GetScheduleAt(i).ToString();
                    //}
                }
            }

            #endregion
            #region Load OneTime
             var qq = from n in db.tblSectionLedOneTimePlan  where n.BeginTime > DateTime.Now  select n;
            foreach (tblSectionLedOneTimePlan plan in qq)
            {
                DateTime begtime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, plan.BeginTime.Hour, plan.BeginTime.Minute, 0);
                if (begtime <= DateTime.Now)
                    continue;

                Schedule.Schedule schedule = new Schedule.OneTimeSchedule("OneTime" + plan.PlanID, begtime,
                   plan.DurationMin, new Schedule.ScheduleJob[] { new Schedule.ScheduleJob(plan.SectionID, 0,
                   new Devices.LedOutputData(){SectionID=plan.SectionID, W=plan.W,R=plan.R,G=plan.G,B=plan.B,Priority= OutputPriority.OneTime}  ) }, true); ;

                Schedule.Scheduler.AddSchedule(schedule);
                Console.WriteLine("One Time Schedule" + plan.PlanID + " Loaded!");

                //for (int i = 0; i < Schedule.Scheduler.Count(); i++)
                //{
                //  Console.WriteLine(  Schedule.Scheduler.GetScheduleAt(i).ToString());
                //}
            }
            #endregion
        }
コード例 #2
0
ファイル: Schedule.cs プロジェクト: ufjl0683/LedControlPanel
        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);
                        LedClientService.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);
            }
        }