Пример #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
        void LoadDevice()
        {
            LedLocalDb db = new LedLocalDb();
            dict_sections = new Dictionary<int, GroupSection>();
            var q = from n in db.tblProjectGroupSection select new GroupSection() { SectionID = n.SectionID, SectionName = n.SectionName };
            foreach (GroupSection sec in q)
            {
                dict_sections.Add(sec.SectionID, sec);
                Console.WriteLine("section:" + sec.SectionName + ",loading!");

                var qq = from n in db.tblDevice where n.SectionID == sec.SectionID select n;

                foreach (tblDevice device in qq)
                {
                    if (device.DevType == "LED")
                    {
                        LedDevice leddev=new LedDevice()
                        {   SectionID=device.SectionID,
                            DeviceType = device.DevType,
                            DeviceID = device.DeviceID,
                            LedType = device.Shape,
                            ZeeBeeID=(int)device.ZeeBeeID
                        };
                        sec.Devices.Add((Device)leddev);
                        leddev.OnConnectChanged += new OnConnectedChangeHandler(Device_OnConnectChanged);
                        devices.Add((ushort)leddev.ZeeBeeID, leddev);
                    }
                    Console.WriteLine("\tDevice ID " + device.DeviceID + ",loading");
                }
            }
        }