private void UserControl_Loaded(object sender, RoutedEventArgs e) { if (archorManager == null) { archorManager = new ArchorManager(); archorManager.ArchorListChanged += (list, item) => { if (item != null) { var id = list.IndexOf(item); SetArchorList(archorManager, list, item, id); } else { SetArchorList(archorManager, list); } }; archorManager.LogChanged += ArchorManager_LogChanged; archorManager.PercentChanged += (p) => { ProgressBarEx1.Visibility = Visibility.Visible; ProgressBarEx1.Value = p; }; //archorManager.NewArchorAdded += AddArchor; DataGrid3.archorManager = archorManager; archorManager.arg = GetScanArg(); } Timer = new DispatcherTimer(); Timer.Interval = TimeSpan.FromMilliseconds(200); Timer.Tick += Timer_Tick; Timer.Start(); CbServerIpList.ItemsSource = SetCommands.Cmds; CbServerIpList.DisplayMemberPath = "Name"; CbServerIpList.SelectedIndex = 0; CbLocalIps.ItemsSource = IpHelper.GetLocalList(); }
void InitAreaCanvas() { AreaCanvas1.Init(); AreaCanvas1.udpArchorList = ArchorManager.LoadArchorListResult(); ContextMenu devContextMenu = new ContextMenu(); devContextMenu.AddMenu("设置设备", (tag) => { SetDevInfo(AreaCanvas1.SelectedDev, AreaCanvas1.SelectedDev.Tag as DevEntity); }); devContextMenu.AddMenu("删除设备", (tag) => { var dev = AreaCanvas1.SelectedDev.Tag as DevEntity; RemoveDev(dev); }); devContextMenu.AddMenu("复制设备", (tag) => { var dev = AreaCanvas1.SelectedDev.Tag as DevEntity; dev.Pos.PosX += 5; dev.Pos.PosY += 5; dev.Name += " Copy"; dev.Code = ""; //dev.Ip = ""; var dev2 = devService.Post(dev); var archor = dev.DevDetail as TArchor; if (archor != null) { archor.X += 5; archor.Y += 5; archor.Name += " Copy"; archor.Code = ""; archor.Ip = ""; archor.DevInfoId = dev2.Id; var archorNew = archorService.Post(archor); archorNew.Code = "Code_" + archorNew.Id; archorService.Put(archorNew); } LoadData(); }); AreaCanvas1.DevContextMenu = devContextMenu; ContextMenu areaContextMenu = new ContextMenu(); areaContextMenu.AddMenu("设置区域", (tag) => { var area = AreaCanvas1.SelectedArea; ShowAreaInfo(area); }); areaContextMenu.AddMenu("删除区域", (tag) => { var area = AreaCanvas1.SelectedArea; RemoveArea(area); }); areaContextMenu.AddMenu("删除区域内设备", (tag) => { var area = AreaCanvas1.SelectedArea; RemoveAreaDevs(area); }); areaContextMenu.AddMenu("添加测量点", (tag) => { var area = AreaCanvas1.SelectedArea; TrackPointWindow win = new TrackPointWindow(); if (win.Show(area.Id, AreaCanvas1.SelectedPoint2) == true) { var newDev = win._tp; area.AddLeafNode(newDev.ToTModel()); AreaCanvas1.Refresh(); var newDevRect = AreaCanvas1.GetDev(newDev.Id); Window wnd = SetDevInfo(newDevRect, newDevRect.Tag as DevEntity); if (wnd is RoomArchorSettingWindow) { (wnd as RoomArchorSettingWindow).SaveInfo(false); //wnd.Close(); } } //RoomArchorSettingWindow win = new RoomArchorSettingWindow(); //var dev = topoTree.SelectedObject as DevEntity; //SetDevInfo(null, null); }); AreaCanvas1.AreaContextMenu = areaContextMenu; archorSettings = bll.ArchorSettings.ToList(); AreaCanvas1.GetSettingFunc = (dev) => { object detail = dev.DevDetail; if (detail is TArchor) { var archor = detail as TArchor; return(archorSettings.Find(i => i.Code == archor.Code)); } return(null); }; }
public UDPScanWorker(ArchorManager manager, string[] ips) { this.manager = manager; this.Ips = ips; }
private void InitArchorManager() { if (archorManager == null) { DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(100); timer.Tick += UpdateGridTimer_Tick; timer.Start(); updateGridTimer = timer; archorManager = new ArchorManager(); archorManager.ArchorListChanged += (list, item) => { UDPArchorList = list; //if (item != null) //{ // var id = list.IndexOf(item); // SetArchorList(archorManager, list, item, id); //} //else //{ // SetArchorList(archorManager, list); //} if (item != null) { progressList.Add(item); count++; } IsDirty = true; }; archorManager.LogChanged += ArchorManager_LogChanged; archorManager.PercentChanged += (p) => { ProgressBarEx1.Value = p; //if (p == 100) //{ // SetArchorList(archorManager, UDPArchorList); //} if (p == 100) { ThreadPool.QueueUserWorkItem(a => { Thread.Sleep(3000); //SaveResult(); SetArchorList(archorManager, UDPArchorList); archorManager.SaveArchorListResult(); //scanCount++; //if (scanCount > 1)//第一次启动扫描结果可能是不准的 //{ // Thread.Sleep(2000); // SendAlarm(); //} //IsBusySendAlarm = false; }); } }; //archorManager.NewArchorAdded += AddArchor; DataGrid3.archorManager = archorManager; archorManager.arg = GetScanArg(); } }
private void SetArchorList(ArchorManager archorManager, UDPArchorList list, UDPArchor item1 = null, int id = -1) { this.Dispatcher.Invoke(() => { if (archorManager == null) { TbConsole.Text = ""; DataGrid3.ItemsSource = null; LbCount.Content = ""; LbStatistics.Content = ""; } else { //IsDirty = true; LbTime.Content = archorManager.GetTimeSpan(); TbConsole.Text = archorManager.Log; if (DbArchorListDict != null) { //list.ClearInfo(); foreach (var item in list) { item.DbInfo = ""; item.RealArea = ""; var clientIP = item.GetClientIP(); //var ar = DbArchorList.Find(i => i.Ip == clientIP); if (DbArchorListDict.ContainsKey(clientIP)) { var ar = DbArchorListDict[clientIP]; if (ar != null) { item.RealArea = ar.Parent.Name; if (item.GetClientIP() != ar.Ip) { item.DbInfo = "IP:" + ar.Ip; } else { string code = ar.Code.Trim(); if (!string.IsNullOrEmpty(code)) { item.DbInfo = "有:" + code; } else { item.DbInfo = "有:" + ar.Ip; } } } } } } if (id > 0) { var item2 = list[id]; if (item2 != item1) { } int id2 = list.IndexOf(item1); } DataGrid3.ItemsSource = list; if (id > 0) { var item2 = list[id]; if (item2 != item1) { } int id2 = list.IndexOf(item1); } LbCount.Content = list.GetConnectedCount(); LbStatistics.Content = archorManager.GetStatistics(); LbServerIpList.Content = list.ServerList.GetText(); LbListenCount.Content = archorManager.valueList.Count; LbListenStatistics.Content = archorManager.valueList.GetStatistics(); } }); }
private void SetArchorList(ArchorManager archorManager, UDPArchorList list, UDPArchor item1 = null, int id = -1) { if (DbArchorListDict != null) { //list.ClearInfo(); foreach (var item in list) { item.DbInfo = ""; item.RealArea = ""; var clientIP = item.GetClientIP(); //var ar = DbArchorList.Find(i => i.Ip == clientIP); if (DbArchorListDict.ContainsKey(clientIP)) { var ar = DbArchorListDict[clientIP]; if (ar != null) { item.RealArea = ar.Parent.Name; if (item.GetClientIP() != ar.Ip) { item.DbInfo = "IP:" + ar.Ip; } else { string code = ar.Code.Trim(); if (!string.IsNullOrEmpty(code)) { item.DbInfo = "有:" + code; } else { item.DbInfo = "有:" + ar.Ip; } } } } } if (id > 0) { var item2 = list[id]; if (item2 != item1) { } int id2 = list.IndexOf(item1); } if (UDPArchorList == null) { UDPArchorList = list; } else { //if(UDPArchorList!= list) //{ //} } if (id > 0) { var item2 = list[id]; if (item2 != item1) { } int id2 = list.IndexOf(item1); } } }
private void InitArchorManager() { if (archorManager == null) { //DispatcherTimer timer = new DispatcherTimer(); //timer.Interval = TimeSpan.FromMilliseconds(100); //timer.Tick += UpdateGridTimer_Tick; //timer.Start(); //updateGridTimer = timer; archorManager = new ArchorManager(); archorManager.LocalIp = IPAddress.Parse(EngineClientSetting.LocalIp); archorManager.ArchorListChanged += (list, item) => { //if(UDPArchorList== null) //{ // UDPArchorList = list; //} //else //{ //} //if (UDPArchorList != list) //{ // UDPArchorList = list; //} if (item != null) { var id = list.IndexOf(item); SetArchorList(archorManager, list, item, id); } else { SetArchorList(archorManager, list); } if (item != null) { var maxList = archorManager.GetMaxArchorList(); if (maxList.Count > maxCount) { maxCount = maxList.Count; Log.Info(Name, string.Format("maxCount:{0}", maxCount)); } count++; //Log.Info(Name, "ArchorListChanged:" + count); } //IsDirty = true; }; //archorManager.LogChanged += ArchorManager_LogChanged; archorManager.PercentChanged += (p) => { //ProgressBarEx1.Value = p; //Log.Info(Name, "PercentChanged:" + p); if (p == 100) { int sum = DbArchorList.Count; //Log.Info(Name, string.Format("Completed1:{0}-{1}={2}" ,sum, count,sum-count)); IsBusySendCmd = false; if (IsBusySendAlarm) { return; } IsBusySendAlarm = true; ThreadPool.QueueUserWorkItem(a => { scanCount++; Thread.Sleep(3000); Save(); var listOff = GetOfflineList(); var count2 = listOff.Count; Log.Info(Name, string.Format("Completed2:{0}-{1}={2}", sum, sum - count2, count2)); SendAlarm(); //if (scanCount % 5 == 0) //{ // archorManager.ClearMaxArchorList();//重新开始计算 //} IsBusySendAlarm = false; }); } }; //DataGrid3.archorManager = archorManager; archorManager.arg = GetScanArg(); } }