Example #1
0
        public LotusView(Context context, IAttributeSet attrs)
            : base(context, attrs)
        {
            Holder.AddCallback(this);

            var screenCenter = new PointVector {
                X = Resources.DisplayMetrics.WidthPixels / 2,
                Y = Resources.DisplayMetrics.HeightPixels / 2
            };

            var controlPadRadius = 225;
            var controlPad = new ControlPad(Resources, new PointVector {
                X = controlPadRadius,
                Y = screenCenter.Y * 2 - controlPadRadius
            }, controlPadRadius);
            var fireButtonRadius = 125;
            var fireButton = new ControlButton(Resources, new PointVector {
                X = screenCenter.X * 2 - fireButtonRadius,
                Y = screenCenter.Y * 2 - fireButtonRadius
            }, fireButtonRadius);

            var player = new Player(controlPad, fireButton);
            mDrawThread = new DrawThread(Holder, screenCenter, player);

            player.RegisterShip(new Ship(Resources, Resource.Drawable.t1, 600, 1200, 720));
            player.RegisterWeapon(new Weapon(Resources, Resource.Drawable.t1, mDrawThread));

            new StaticImage(Resources, Resource.Drawable.background);

            SetOnTouchListener(player);
        }
Example #2
0
        public RecordPageViewModel()
        {
            var controlpads = ControlPad.GetAllControlPads();

            if (controlpads != null && controlpads.Count > 0)
            {
                controlpads.Insert(0, new ControlPad()
                {
                    Id = 0, Name = "==全部=="
                });
                this.ControlPads  = controlpads;
                CurrentControlPad = this.ControlPads[0];
            }
            currentPageSize = this.PageSize;
            this.SelectControlPadCommand = new DelegateCommand <ExCommandParameter>(SelectControlPad);
            this.QueryRecordCommand      = new DelegateCommand(QueryRecord);
            this.FirstPageCommand        = new DelegateCommand(FirstPage);
            this.LastPageCommand         = new DelegateCommand(LastPage);
            this.PrevPageCommand         = new DelegateCommand(PrevPage);
            this.NextPageCommand         = new DelegateCommand(NextPage);
            this.ChangePageSizeCommand   = new DelegateCommand <ExCommandParameter>(ChangePageSize);
            this.ShowAlarmPicCommand     = new DelegateCommand <ExCommandParameter>(ShowAlarmPic);

            XDocument doc  = XDocument.Load("Application.config");
            var       path = doc.Descendants("copyImagePath").Single();

            this.alarmImagePath = path.Attribute("path").Value;
        }
 public ControlPadContentViewModel()
 {
     this.ControlPads             = ControlPad.GetAllControlPads();
     this.BeginningEditCommand    = new DelegateCommand <ExCommandParameter>(BeginningEdit);
     this.RowEditEndingCommand    = new DelegateCommand <ExCommandParameter>(RowEditEnding);
     this.AddNewControlPadCommand = new DelegateCommand(AddNewControlPad);
     this.DeleteControlPadCommand = new DelegateCommand <ExCommandParameter>(DeleteControlPad);
 }
        private void DeleteControlPad(ExCommandParameter param)
        {
            var sender = param.Sender as Button;
            int id     = int.Parse(sender.Tag.ToString());
            //删除
            bool b = ControlPad.DeleteControlPad(id);

            if (b)
            {
                this.ControlPads.Remove(this.ControlPads.Single(p => p.Id == id));
            }
        }
        private void BeginningEdit(ExCommandParameter param)
        {
            var sender = param.Sender as DataGrid;
            var args   = param.EventArgs as DataGridBeginningEditEventArgs;
            int index  = args.Column.DisplayIndex;
            int id     = int.Parse((sender.Columns[0].GetCellContent(args.Row) as TextBlock).Text);
            var pad    = this.ControlPads.SingleOrDefault(p => p.Id == id);

            if (pad != null)
            {
                this.currentControlPad = pad;
            }
        }
        private void RowEditEnding(ExCommandParameter param)
        {
            if (this.currentControlPad == null)
            {
                return;
            }
            var sender = param.Sender as DataGrid;
            var args   = param.EventArgs as DataGridRowEditEndingEventArgs;
            int id     = int.Parse((sender.Columns[0].GetCellContent(args.Row) as TextBlock).Text);
            var pad    = this.ControlPads.SingleOrDefault(p => p.Id == id);

            //保存
            ControlPad.UpdateControlPad(pad);
        }
Example #7
0
        //RoutedPropertyChangedEventArgs<object>
        #region command functions
        private void PageLoaded(ExCommandParameter param)
        {
            var sender         = param.Sender as UserControl;
            var tvControlPads  = sender.FindName("tvControlPads") as TreeView;
            var cboControlPads = sender.FindName("cboControlPads") as ComboBox;

            this.ControlPads = ControlPad.GetAllControlPads();
            this.Cameras     = null;

            XDocument doc  = XDocument.Load("Application.config");
            var       path = doc.Descendants("copyImagePath").Single();

            this.copyImagePath = path.Attribute("path").Value;
        }
Example #8
0
        private void TreeViewSelectChanged(ExCommandParameter param)
        {
            var sender = param.Sender as TreeView;

            if (sender.SelectedItem is ControlPad)
            {
                //屏蔽控制板的右键事件
                if (param.EventArgs is MouseButtonEventArgs)
                {
                    return;
                }
                var pad = sender.SelectedItem as ControlPad;
                this.currentPad = pad;
                pad.Cameras     = pad.GetCameras();
            }
            else if (sender.SelectedItem is Camera)
            {
                if (param.EventArgs is MouseButtonEventArgs)
                {
                    //只有在选中相机并单击右键时,才显示快捷菜单
                    if (sender.SelectedItem == null)
                    {
                        return;
                    }
                    //显示右键菜单
                    var contextMenu = new ContextMenu();
                    //contextMenu.Items.Add(new MenuItem { Header = "连接", Command = this.RemoteDesktopCommand });
                    var menuItem = new MenuItem {
                        Header = "连接"
                    };
                    menuItem.Name    = "menuConnect";
                    menuItem.Tag     = (sender.SelectedItem as Camera).Id;
                    menuItem.Command = this.RemoteDesktopCommand;
                    var parameter = new ExCommandParameter();
                    parameter.Sender          = menuItem;
                    menuItem.CommandParameter = parameter;
                    contextMenu.Items.Add(menuItem);

                    contextMenu.Items.Add(new MenuItem {
                        Header = "开启检测"
                    });
                    contextMenu.IsOpen = true;
                }
            }
        }
Example #9
0
        /// <summary>
        /// 切换相机网口
        /// </summary>
        /// <param name="camera"></param>
        private void SwitchCameraNetPort(Camera camera)
        {
            int no = camera.NetPortNum;

            try
            {
                ControlPad pad = new ControlPad(camera.ControlPadNo, null);
                pad.SwitchNetPort(no);
            }
            catch (Exception ex)
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    camera.IsSwitching = false;
                    ModernDialog.ShowMessage(ex.Message, "提示", MessageBoxButton.OK);
                });
            }
        }
        private void AddNewControlPad()
        {
            int id = 0;

            if (this.ControlPads.Count > 0)
            {
                id = this.ControlPads.Max(p => p.Id);
            }
            ControlPad pad = new ControlPad()
            {
                Id      = id + 1,
                Name    = "控制板" + (id + 1),
                IP      = "0.0.0.0",
                PortNum = 3333
            };

            this.ControlPads.Add(pad);
            //保存到配置文件
            ControlPad.AddControlPad(pad);
        }
        /// <summary>
        /// checks whether the specified button of an Xbox 360 controller
        /// is pressed once for this frame.
        /// </summary>
        /// <param name="pad">Button of the Xbox 360 controller</param>
        public bool IsStrokeControlPad(ControlPad pad)
        {
            switch (pad)
            {
            case ControlPad.LeftThumbStickUp:
                return(IsStrokeThumbStickUp(Trigger.Left));

            case ControlPad.LeftThumbStickDown:
                return(IsStrokeThumbStickDown(Trigger.Left));

            case ControlPad.LeftThumbStickLeft:
                return(IsStrokeThumbStickLeft(Trigger.Left));

            case ControlPad.LeftThumbStickRight:
                return(IsStrokeThumbStickRight(Trigger.Left));

            case ControlPad.RightThumbStickUp:
                return(IsStrokeThumbStickUp(Trigger.Right));

            case ControlPad.RightThumbStickDown:
                return(IsStrokeThumbStickDown(Trigger.Right));

            case ControlPad.RightThumbStickLeft:
                return(IsStrokeThumbStickLeft(Trigger.Right));

            case ControlPad.RightThumbStickRight:
                return(IsStrokeThumbStickRight(Trigger.Right));

            case ControlPad.LeftTrigger:
                return(IsStrokeTriggers(Trigger.Left));

            case ControlPad.RightTrigger:
                return(IsStrokeTriggers(Trigger.Right));
            }
            ;

            //  check stroke GamePad buttons
            return(!IsControlPadState(oldGamePadState, pad, ButtonState.Pressed) &&
                   IsPressControlPad(pad));
        }
Example #12
0
 /// <summary>
 /// configures the Xbox 360 controller setting.
 /// </summary>
 /// <param name="gameKey">game key in the game</param>
 /// <param name="setKey">a key of Xbox 360 controller</param>
 public void SetGameControlPad(GameKey gameKey, ControlPad setKey)
 {
     gameControlPad[(int)gameKey] = setKey;
 }
Example #13
0
 /// <summary>
 /// checks whether the specified button of an Xbox 360 controller is pressed.
 /// </summary>
 /// <param name="pad">Button of the Xbox 360 controller</param>
 public bool IsPressControlPad(ControlPad pad)
 {
     return IsControlPadState(gamePadState, pad, ButtonState.Pressed);
 }
Example #14
0
 /// <summary>
 /// configures the Xbox 360 controller setting.
 /// </summary>
 /// <param name="gameKey">game key in the game</param>
 /// <param name="setKey">a key of Xbox 360 controller</param>
 public void SetGameControlPad(GameKey gameKey, ControlPad setKey)
 {
     gameControlPad[(int)gameKey] = setKey;
 }
        /// <summary>
        /// compares the input state of the Xbox 360 controller.
        /// </summary>
        /// <param name="GamePadState">target input state</param>
        /// <param name="pad">Button of the Xbox 360 Controller</param>
        /// <param name="state">target button state</param>
        /// <returns></returns>
        private bool IsControlPadState(GamePadState targetGamePadState, ControlPad pad,
                                       ButtonState state)
        {
            switch (pad)
            {
            case ControlPad.Start:
                return(targetGamePadState.Buttons.Start == state);

            case ControlPad.Back:
                return(targetGamePadState.Buttons.Back == state);

            case ControlPad.A:
                return(targetGamePadState.Buttons.A == state);

            case ControlPad.B:
                return(targetGamePadState.Buttons.B == state);

            case ControlPad.X:
                return(targetGamePadState.Buttons.X == state);

            case ControlPad.Y:
                return(targetGamePadState.Buttons.Y == state);

            case ControlPad.LeftShoulder:
                return(targetGamePadState.Buttons.LeftShoulder == state);

            case ControlPad.LeftStick:
                return(targetGamePadState.Buttons.LeftStick == state);

            case ControlPad.RightShoulder:
                return(targetGamePadState.Buttons.RightShoulder == state);

            case ControlPad.RightStick:
                return(targetGamePadState.Buttons.RightStick == state);

            case ControlPad.LeftPad:
                return(targetGamePadState.DPad.Left == state);

            case ControlPad.RightPad:
                return(targetGamePadState.DPad.Right == state);

            case ControlPad.UpPad:
                return(targetGamePadState.DPad.Up == state);

            case ControlPad.DownPad:
                return(targetGamePadState.DPad.Down == state);

            case ControlPad.LeftTrigger:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetGamePadTriggers(Trigger.Left) > 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetGamePadTriggers(Trigger.Left) == 0.0f);
                }

                return(false);
            }

            case ControlPad.RightTrigger:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetGamePadTriggers(Trigger.Right) > 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetGamePadTriggers(Trigger.Right) == 0.0f);
                }

                return(false);
            }

            case ControlPad.LeftThumbStickUp:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetThumbStickAmount(Trigger.Left).Y > 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetThumbStickAmount(Trigger.Left).Y == 0.0f);
                }

                return(false);
            }

            case ControlPad.LeftThumbStickDown:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetThumbStickAmount(Trigger.Left).Y < 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetThumbStickAmount(Trigger.Left).Y == 0.0f);
                }

                return(false);
            }

            case ControlPad.LeftThumbStickLeft:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetThumbStickAmount(Trigger.Left).X < 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetThumbStickAmount(Trigger.Left).X == 0.0f);
                }

                return(false);
            }

            case ControlPad.LeftThumbStickRight:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetThumbStickAmount(Trigger.Left).X > 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetThumbStickAmount(Trigger.Left).X == 0.0f);
                }

                return(false);
            }

            case ControlPad.RightThumbStickUp:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetThumbStickAmount(Trigger.Right).Y > 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetThumbStickAmount(Trigger.Right).Y == 0.0f);
                }

                return(false);
            }

            case ControlPad.RightThumbStickDown:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetThumbStickAmount(Trigger.Right).Y < 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetThumbStickAmount(Trigger.Right).Y == 0.0f);
                }

                return(false);
            }

            case ControlPad.RightThumbStickLeft:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetThumbStickAmount(Trigger.Right).X < 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetThumbStickAmount(Trigger.Right).Y == 0.0f);
                }

                return(false);
            }

            case ControlPad.RightThumbStickRight:
            {
                if (state == ButtonState.Pressed)
                {
                    return(GetThumbStickAmount(Trigger.Right).X > 0.0f);
                }
                else if (state == ButtonState.Released)
                {
                    return(GetThumbStickAmount(Trigger.Right).Y == 0.0f);
                }

                return(false);
            }

            default: return(false);
            }
        }
 /// <summary>
 /// checks whether the specified button of an Xbox 360 controller is released.
 /// </summary>
 /// <param name="pad">Button of the Xbox 360 controller</param>
 public bool IsReleaseControlPad(ControlPad pad)
 {
     return(IsControlPadState(gamePadState, pad, ButtonState.Released));
 }
 /// <summary>
 /// checks whether the specified button of an Xbox 360 controller is pressed.
 /// </summary>
 /// <param name="pad">Button of the Xbox 360 controller</param>
 public bool IsPressControlPad(ControlPad pad)
 {
     return(IsControlPadState(gamePadState, pad, ButtonState.Pressed));
 }
 private void PageLoaded(ExCommandParameter param)
 {
     this.ControlPads = ControlPad.GetAllControlPads();
 }
Example #19
0
 /// <summary>
 /// checks whether the specified button of an Xbox 360 controller is released.
 /// </summary>
 /// <param name="pad">Button of the Xbox 360 controller</param>
 public bool IsReleaseControlPad(ControlPad pad)
 {
     return IsControlPadState(gamePadState, pad, ButtonState.Released);
 }
Example #20
0
        /// <summary>
        /// compares the input state of the Xbox 360 controller.
        /// </summary>
        /// <param name="GamePadState">target input state</param>
        /// <param name="pad">Button of the Xbox 360 Controller</param>
        /// <param name="state">target button state</param>
        /// <returns></returns>
        private bool IsControlPadState(GamePadState targetGamePadState, ControlPad pad,
            ButtonState state)
        {
            switch (pad)
            {
                case ControlPad.Start:
                    return (targetGamePadState.Buttons.Start == state);

                case ControlPad.Back:
                    return (targetGamePadState.Buttons.Back == state);

                case ControlPad.A:
                    return (targetGamePadState.Buttons.A == state);

                case ControlPad.B:
                    return (targetGamePadState.Buttons.B == state);

                case ControlPad.X:
                    return (targetGamePadState.Buttons.X == state);

                case ControlPad.Y:
                    return (targetGamePadState.Buttons.Y == state);

                case ControlPad.LeftShoulder:
                    return (targetGamePadState.Buttons.LeftShoulder == state);

                case ControlPad.LeftStick:
                    return (targetGamePadState.Buttons.LeftStick == state);

                case ControlPad.RightShoulder:
                    return (targetGamePadState.Buttons.RightShoulder == state);

                case ControlPad.RightStick:
                    return (targetGamePadState.Buttons.RightStick == state);

                case ControlPad.LeftPad:
                    return (targetGamePadState.DPad.Left == state);

                case ControlPad.RightPad:
                    return (targetGamePadState.DPad.Right == state);

                case ControlPad.UpPad:
                    return (targetGamePadState.DPad.Up == state);

                case ControlPad.DownPad:
                    return (targetGamePadState.DPad.Down == state);

                case ControlPad.LeftTrigger:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetGamePadTriggers(Trigger.Left) > 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetGamePadTriggers(Trigger.Left) == 0.0f);

                        return false;
                    }

                case ControlPad.RightTrigger:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetGamePadTriggers(Trigger.Right) > 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetGamePadTriggers(Trigger.Right) == 0.0f);

                        return false;
                    }

                case ControlPad.LeftThumbStickUp:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetThumbStickAmount(Trigger.Left).Y > 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetThumbStickAmount(Trigger.Left).Y == 0.0f);

                        return false;
                    }

                case ControlPad.LeftThumbStickDown:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetThumbStickAmount(Trigger.Left).Y < 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetThumbStickAmount(Trigger.Left).Y == 0.0f);

                        return false;
                    }

                case ControlPad.LeftThumbStickLeft:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetThumbStickAmount(Trigger.Left).X < 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetThumbStickAmount(Trigger.Left).X == 0.0f);

                        return false;
                    }

                case ControlPad.LeftThumbStickRight:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetThumbStickAmount(Trigger.Left).X > 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetThumbStickAmount(Trigger.Left).X == 0.0f);

                        return false;
                    }

                case ControlPad.RightThumbStickUp:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetThumbStickAmount(Trigger.Right).Y > 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetThumbStickAmount(Trigger.Right).Y == 0.0f);

                        return false;
                    }

                case ControlPad.RightThumbStickDown:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetThumbStickAmount(Trigger.Right).Y < 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetThumbStickAmount(Trigger.Right).Y == 0.0f);

                        return false;
                    }

                case ControlPad.RightThumbStickLeft:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetThumbStickAmount(Trigger.Right).X < 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetThumbStickAmount(Trigger.Right).Y == 0.0f);

                        return false;
                    }

                case ControlPad.RightThumbStickRight:
                    {
                        if (state == ButtonState.Pressed)
                            return (GetThumbStickAmount(Trigger.Right).X > 0.0f);
                        else if (state == ButtonState.Released)
                            return (GetThumbStickAmount(Trigger.Right).Y == 0.0f);

                        return false;
                    }

                default: return false;
            }
        }
Example #21
0
        /// <summary>
        /// checks whether the specified button of an Xbox 360 controller 
        /// is pressed once for this frame.
        /// </summary>
        /// <param name="pad">Button of the Xbox 360 controller</param>
        public bool IsStrokeControlPad(ControlPad pad)
        {
            switch (pad)
            {
                case ControlPad.LeftThumbStickUp:
                    return IsStrokeThumbStickUp(Trigger.Left);

                case ControlPad.LeftThumbStickDown:
                    return IsStrokeThumbStickDown(Trigger.Left);

                case ControlPad.LeftThumbStickLeft:
                    return IsStrokeThumbStickLeft(Trigger.Left);

                case ControlPad.LeftThumbStickRight:
                    return IsStrokeThumbStickRight(Trigger.Left);

                case ControlPad.RightThumbStickUp:
                    return IsStrokeThumbStickUp(Trigger.Right);

                case ControlPad.RightThumbStickDown:
                    return IsStrokeThumbStickDown(Trigger.Right);

                case ControlPad.RightThumbStickLeft:
                    return IsStrokeThumbStickLeft(Trigger.Right);

                case ControlPad.RightThumbStickRight:
                    return IsStrokeThumbStickRight(Trigger.Right);

                case ControlPad.LeftTrigger:
                    return IsStrokeTriggers(Trigger.Left);

                case ControlPad.RightTrigger:
                    return IsStrokeTriggers(Trigger.Right);
            };

            //  check stroke GamePad buttons
            return (!IsControlPadState(oldGamePadState, pad, ButtonState.Pressed) &&
                                    IsPressControlPad(pad));
        }
Example #22
0
 public Player(ControlPad controlPad, ControlButton fireButton)
 {
     mControlPad = controlPad;
     mFireButton = fireButton;
 }
Example #23
0
        public AlarmPageViewModel()
        {
            alarmLamp             = new AlarmLamp();
            ope                   = new AlarmInfoOperator();
            ClearAlarmListCommand = new DelegateCommand(ClearAlamList);
            this.AlarmInfos       = new ObservableCollection <AlarmInfo>();
            if (App.Current == null)
            {
                return;
            }
            if (this.ControlPads == null)
            {
                this.ControlPads = ControlPad.GetAllControlPads();
            }
            //此处需判断是不是服务器
            Task.Run(() =>
            {
                //获取服务器
                XDocument doc   = XDocument.Load("Application.config");
                var server      = doc.Descendants("server").Single();
                string serverIP = server.Attribute("ip").Value;
                int serverPort  = int.Parse(server.Attribute("port").Value);
                //获取客户机
                var clients = doc.Descendants("clients").Descendants("client");
                //获取本机IPv4地址
                string name           = Dns.GetHostName();
                IPAddress[] ipadrlist = Dns.GetHostAddresses(name);
                //判断是否包含服务器的IP地址
                bool b = ipadrlist.Contains(IPAddress.Parse(serverIP));
                if (b)
                {
                    //如果是服务器才向控制板发送数据
                    foreach (var controlpad in this.ControlPads)
                    {
                        CameraList.AddRange(controlpad.GetCameras());
                        try
                        {
                            ControlPad pad = new ControlPad(controlpad.Id, (AlarmInfo[] info, ControlPadState[] states) =>
                            {
                                App.Current.Dispatcher.Invoke(() =>
                                {
                                    //对于5个信息区都进行搜索,不判断标志位
                                    for (int i = 0; i < 5; i++)
                                    {
                                        if (!IsEmpty(info[i]))
                                        {
                                            if (controlpad != null)
                                            {
                                                var camera = CameraList.SingleOrDefault(c => c.Id == info[i].CameraNo &&
                                                                                        c.ControlPadNo == controlpad.Id);
                                                if (camera != null)
                                                {
                                                    info[i].CameraName = camera.Name;
                                                }
                                            }
                                            AlarmInfos.Insert(0, info[i]);
                                            //始终保持界面上的报警记录不得多于50条
                                            if (AlarmInfos.Count == 50 + 1)
                                            {
                                                AlarmInfos.RemoveAt(AlarmInfos.Count - 1);
                                            }
                                            //向报警器串口发送命令
                                            Task.Run(() =>
                                            {
                                                alarmLamp.AlarmMusicAndFlash();
                                                Thread.Sleep(2000);
                                                alarmLamp.StopAllAlarm();
                                            });

                                            CurrentItem = info[i];

                                            //向其他客户机发送报警数据

                                            if (clients.Count() > 0)
                                            {
                                                foreach (var client in clients)
                                                {
                                                    string IP = client.Attribute("ip").Value;
                                                    int port  = int.Parse(client.Attribute("port").Value);
                                                    if (IP != serverIP)
                                                    {
                                                        UdpComm comm     = new UdpComm(IP, port);
                                                        XmlSerializer xs = new XmlSerializer(typeof(AlarmInfo));
                                                        var ms           = new MemoryStream();
                                                        xs.Serialize(ms, CurrentItem);
                                                        comm.SendData(ms.ToArray());
                                                        ms.Close();
                                                        ms.Dispose();
                                                    }
                                                }
                                            }
                                            //写入数据库

                                            ope.Add(ope.AlarmInfoToAlarmInfoForDB(controlpad.Id, controlpad.Name, info[i]));
                                        }
                                    }
                                });
                            });
                        }
                        catch (Exception ex)
                        {
                            App.Current.Dispatcher.Invoke(() =>
                            {
                                ModernDialog.ShowMessage(ex.Message, "提示", MessageBoxButton.OK);
                            });
                        }
                    }
                }
                else
                {
                    //如果不是服务器,开启线程来接受服务器发来的报警信息
                    Task.Run(() =>
                    {
                        //先找到本机的IP和端口

                        foreach (var client in clients)
                        {
                            string IP = client.Attribute("ip").Value;
                            int port  = int.Parse(client.Attribute("port").Value);
                            if (ipadrlist.Contains(IPAddress.Parse(IP)))
                            {
                                //找到本机
                                Task.Run(() =>
                                {
                                    UdpComm comm     = new UdpComm(port);
                                    XmlSerializer xs = new XmlSerializer(typeof(AlarmInfo));
                                    while (true)
                                    {
                                        byte[] data = comm.Receive(serverIP, serverPort);
                                        App.Current.Dispatcher.Invoke(() =>
                                        {
                                            using (var ms = new MemoryStream())
                                            {
                                                ms.Write(data, 0, data.Length);
                                                ms.Position = 0;
                                                AlarmInfos.Add(xs.Deserialize(ms) as AlarmInfo);
                                            }
                                        });
                                    }
                                });
                                break;
                            }
                        }
                    });
                }
            });
        }