private async void UnLockAllAlarm(object sender, RoutedEventArgs e)
 {
     UIUnLock.IsEnabled = false;
     UILock.IsEnabled   = false;
     try
     {
         foreach (UIElement uiE in this.UIMapContent.Children)
         {
             if (uiE is UIMapAlarm)
             {
                 UIMapAlarm uiAlarm = uiE as UIMapAlarm;
                 if (!uiAlarm.Alarm.status)
                 {
                     uiAlarm.Alarm.Auto = false;
                     uiAlarm.Enable();
                     await Task.Delay(100);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.GetBaseException().ToString());
     }
     this.DrawMap();
     UIUnLock.IsEnabled = true;
     UILock.IsEnabled   = true;
 }
 public void DrawMap()
 {
     this.UIMapContent.Children.Clear();
     if (App.DataCamera != null && App.DataCamera.Count > 0)
     {
         for (int i = 0; i < App.DataCamera.Count; i++)
         {
             UIMapCamera uiCamera = new UIMapCamera();
             uiCamera.Width   = 34;
             uiCamera.Height  = 170;
             uiCamera.Postion = i;
             uiCamera.PreviewMouseLeftButtonDown += uiCamera_PreviewMouseLeftButtonDown;
             uiCamera.MoveEvent          += uiCamera_MoveEvent;
             uiCamera.ViewCameraEvent    += uiCamera_ViewCameraEvent;
             uiCamera.DeleteCameraEvent  += uiCamera_DeleteCameraEvent;
             uiCamera.AddPresetEvent     += uiCamera_AddPresetEvent;
             uiCamera.ConnectCameraEvent += uiCamera_ConnectCameraEvent;
             this.UIMapContent.Children.Add(uiCamera);
         }
     }
     if (App.DataPreset != null && App.DataPreset.Count > 0)
     {
         for (int i = 0; i < App.DataPreset.Count; i++)
         {
             UIMapPreset uiPreset = new UIMapPreset();
             uiPreset.Width                       = 34;
             uiPreset.Height                      = 170;
             uiPreset.Preset                      = App.DataPreset[i];
             uiPreset.MovePresetEvent            += uiPreset_MovePresetEvent;
             uiPreset.PreviewMouseLeftButtonDown += uiPreset_PreviewMouseDown;
             uiPreset.DeletePresetEvent          += uiPreset_DeletePresetEvent;
             uiPreset.DebugEvent                 += uiPreset_DebugEvent;
             this.UIMapContent.Children.Add(uiPreset);
         }
     }
     if (App.DataAlarm != null && App.DataAlarm.Count > 0)
     {
         for (int i = 0; i < App.DataAlarm.Count; i++)
         {
             UIMapAlarm uiAlarm = new UIMapAlarm();
             uiAlarm.Width      = 34;
             uiAlarm.Height     = 170;
             uiAlarm.Postion    = i;
             uiAlarm.MoveEvent += uiAlarm_MoveEvent;
             uiAlarm.PreviewMouseLeftButtonDown += uiAlarm_PreviewMouseLeftButtonDown;
             uiAlarm.ViewAlarmEvent             += uiAlarm_ViewAlarmEvent;
             uiAlarm.DeleteAlarmEvent           += uiAlarm_DeleteAlarmEvent;
             uiAlarm.ConnectCameraEvent         += uiAlarm_ConnectCameraEvent;
             uiAlarm.DisableAlarmEvent          += uiAlarm_DisableAlarmEvent;
             uiAlarm.AlertEvent       += uiAlarm_AlertEvent;
             uiAlarm.EditConnectEvent += uiAlarm_EditConnectEvent;
             uiAlarm.ScheduleEvent    += uiAlarm_ScheduleEvent;
             this.UIMapContent.Children.Add(uiAlarm);
         }
     }
 }
        void uiAlarm_MoveEvent(object sender, int e)
        {
            UIMapAlarm uiMap = sender as UIMapAlarm;
            Point      p     = Mouse.GetPosition(this.UIMapContent);

            App.DataAlarm[e].Left = p.X - origContentMousePoint.X;
            App.DataAlarm[e].Top  = p.Y - origContentMousePoint.Y;
            uiMap.setLeft(p.X - origContentMousePoint.X);
            uiMap.setTop(p.Y - origContentMousePoint.Y);
        }
 private void RunCmdThreadFunction(object obj)
 {
     while (true)
     {
         if (App.QueueCMD != null && App.QueueCMD.Count > 0)
         {
             string   cmd     = App.QueueCMD.Dequeue();
             string[] element = cmd.Split(' ');
             if (element.Length == 4)
             {
                 if ((element[1] == "A" || element[1] == "B") && (element[3] == "1") && element.Length < 5)
                 {
                     try
                     {
                         int board = Convert.ToInt32(element[0]);
                         int pos   = Convert.ToInt32(element[2]);
                         this.Dispatcher.Invoke(() =>
                         {
                             foreach (UIElement uiE in this.UIMapContent.Children)
                             {
                                 if (uiE is UIMapAlarm)
                                 {
                                     UIMapAlarm uiMap = uiE as UIMapAlarm;
                                     if (uiMap.Alarm.board == board && uiMap.Alarm.pos == pos && !App.DataAlarm[uiMap.Postion].alert)
                                     {
                                         uiMap.RunAlarm();
                                         App.DataAlarm[uiMap.Postion].alert = true;
                                     }
                                 }
                             }
                         });
                     }
                     catch (Exception)
                     {
                     }
                 }
             }
         }
         Thread.Sleep(500);
     }
 }
        void uiAlarm_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            UIMapAlarm uiAlarm = sender as UIMapAlarm;

            origContentMousePoint = Mouse.GetPosition(uiAlarm);
        }
        private void TimeCheckFunctionThread()
        {
            while (true)
            {
                this.Dispatcher.Invoke(() =>
                {
                    this.UIUnLock.IsEnabled = false;
                    this.UILock.IsEnabled   = false;
                    try
                    {
                        bool isChange = false;
                        foreach (UIElement uiE in this.UIMapContent.Children)
                        {
                            if (uiE is UIMapAlarm)
                            {
                                UIMapAlarm uiAlarm = uiE as UIMapAlarm;
                                if (uiAlarm.Alarm != null && uiAlarm.Alarm.TimeOffs.Count > 0 && uiAlarm.Alarm.Auto)
                                {
                                    if (DateTime.Now.TimeOfDay >= uiAlarm.Alarm.TimeOffs[0].beginTime.TimeOfDay && DateTime.Now.TimeOfDay < uiAlarm.Alarm.TimeOffs[0].EndTime.TimeOfDay)
                                    {
                                        if (uiAlarm.Alarm.status)
                                        {
                                            uiAlarm.Disable();
                                        }
                                    }
                                    else if ((DateTime.Now.TimeOfDay < uiAlarm.Alarm.TimeOffs[0].beginTime.TimeOfDay || DateTime.Now.TimeOfDay > uiAlarm.Alarm.TimeOffs[0].EndTime.TimeOfDay))
                                    {
                                        if (!uiAlarm.Alarm.status)
                                        {
                                            uiAlarm.Enable();
                                        }
                                    }
                                }
                            }
                        }
                        if (isChange)
                        {
                            this.DrawMap();
                        }
                    }
                    catch (Exception)
                    {
                    }
                    this.UIUnLock.IsEnabled = true;
                    this.UILock.IsEnabled   = true;

                    if (App.curFolder != this.curFolder)
                    {
                        this.curFolder = App.curFolder;

                        if (this.isRecord)
                        {
                            foreach (UIElement uiE in this.UICCTVContent.Children)
                            {
                                if (uiE is CameraCCTV)
                                {
                                    CameraCCTV uiCamera = uiE as CameraCCTV;
                                    uiCamera.StopRecord();
                                }
                            }
                            Thread.Sleep(1500);
                            if (App.DataAlarm != null)
                            {
                                for (int i = 0; i < App.DataAlarm.Count; i++)
                                {
                                    App.DataAlarm[i].isDisable = false;
                                    App.DataAlarm[i].isEnable  = false;
                                }
                            }

                            foreach (UIElement uiE in this.UICCTVContent.Children)
                            {
                                if (uiE is CameraCCTV)
                                {
                                    CameraCCTV uiCamera = uiE as CameraCCTV;
                                    uiCamera.RecordFile();
                                }
                            }
                            UIRecordBtn.Foreground = Brushes.Red;
                        }
                    }
                });

                Thread.Sleep(2000);
            }
        }