public MainWindow() { InitializeComponent(); #if !DEBUG System.Windows.Threading.DispatcherTimer tmr = new System.Windows.Threading.DispatcherTimer(); tmr.Tick += async (s, a) => { try { StreetLightInfo[] infos=null; if (chkStopCycleQuery.IsChecked == false) { infos = await dev.GetVisibleStreetLightListAsync(); this.datagrid1.ItemsSource = infos.OrderBy(n=>n.DevID).ToArray(); CeraDevices.Schedule sch = new CeraDevices.Schedule(); sch.Segnments = Schedules; int repcnt = 0; foreach (StreetLightInfo info in infos) { if (chkIsRepair.IsChecked == true && !sch.IsEqual(info.sch)) { dev.SetDeviceSchedule(info.DevID, sch.GetScheduleSegTimeString(), sch.GetScheduleSegLevelString()); repcnt++; } // grdSchedule.ItemsSource } this.Title = repcnt + "/" + infos.Length.ToString(); } if (cyclecnt++ * cycle % 600 == 0) //10 min if (chkIsLog.IsChecked == true) savelog(infos); } catch { ;} }; tmr.Interval = TimeSpan.FromSeconds(60); tmr.Start(); // dev.SetDeviceRTC("*", DateTime.Now); #endif for (int i = 0; i < Schedules.Length; i++) Schedules[i] = new ScheduleSegnment(); this.grdSchedule.ItemsSource = Schedules; }
public bool IsEqual(Schedule otherSch) { ScheduleSegnment[] thisseg = Segnments.Where(n => n.Level != 255).OrderBy(n => n.Time).ToArray(); ScheduleSegnment[] otherseg = otherSch.Segnments.Where(n => n.Level != 255).OrderBy(n => n.Time).ToArray(); if (thisseg.Length != otherseg.Length) return false; bool iseq = true; try { for (int i = 0; i < thisseg.Length; i++) { if (thisseg[i].Time == 15555) continue; iseq = iseq && thisseg[i].Time == otherseg[i].Time && thisseg[i].Level == otherseg[i].Level; } } catch (Exception ex) { iseq = false; } return iseq; }