private void Application_Startup(object sender, StartupEventArgs e) { //设置用户名 string userID = "user001"; Application.Current.Properties["userID"] = userID; bus.DataBusServiceClient dataBusServiceClient=null; try { dataBusServiceClient=new bus.DataBusServiceClient(); //初始化设备类型集合 Application.Current.Properties["DeviceTypeArray"]=dataBusServiceClient.QueryAllDeviceTypeInfo(); //初始化设备集合 DataBus dataBus = new DataBus(); dataBus.fillDataBusByRemoteService(dataBusServiceClient,userID); Application.Current.Properties["DataBus"] = dataBus; } catch (Exception e1) { MessageBox.Show(e1.Message); } finally { if (dataBusServiceClient != null) dataBusServiceClient.Close(); dataBusServiceClient=null; } //////////////////////////////////////////////////// try { ThreadScan santhread = new ThreadScan(); Application.Current.Properties["ScanDevice"] = santhread; new InitMonDevice(userID); } catch (Exception e1) { throw e1; } }
/// <summary> /// for debug /// </summary> /// <returns></returns> public static DataBus create_DataBus() { Device dev1 = new Device(); dev1.Name = "dev1"; dev1.DevType = "XBPQ"; Device dev2 = new Device(); dev2.Name = "dev2"; dev2.DevType = "XBPQ"; Device dev3 = new Device(); dev3.Name = "dev3"; dev3.DevType = "XBPQ"; Device dev4 = new Device(); dev4.Name = "dev4"; dev4.DevType = "XBPQ"; MonitorAgent ma1 = new MonitorAgent(); ma1.ID="mon1"; ObservableCollection<Device> devColl = new ObservableCollection<Device>(); devColl.Add(dev1); devColl.Add(dev2); ma1.DeviceList = devColl; MonitorAgent ma2 = new MonitorAgent(); ma2.ID = "mon2"; ObservableCollection<Device> devCol2 = new ObservableCollection<Device>(); devCol2.Add(dev3); devCol2.Add(dev4); ma2.DeviceList = devCol2; ObservableCollection<MonitorAgent> monList = new ObservableCollection<MonitorAgent>(); monList.Add(ma1); monList.Add(ma2); DataBus db = new DataBus(); db.monitorAgentList = monList; return db; }
/// <summary> /// 调用远程服务获取设备集合并绑定到设备树控件 /// </summary> private void refresh_DevTree() { bus.DataBusServiceClient dBSC = new bus.DataBusServiceClient(); bus.MonAgentInfo[] monAgentInfoArray = null; try { //TaskServiceReference.DeviceType[] dt= dBSC.QueryAllDeviceTypeInfo() ; //调用远程服务 monAgentInfoArray = dBSC.QueryMonAgentsDevs(); DataBus db = new DataBus(); db.initFromDataContractObj(monAgentInfoArray); this.DevTreeView.DataContext = db.MonitorAgentList; } catch (Exception exp) { MessageBox.Show("远程获取设备集合出错:"+exp.Message); return; } finally { if (dBSC!=null) dBSC.Close(); } }
/// <summary> /// 从Application刷新成员dataBus和devTypeCollection /// </summary> void refresh_dataBus_deviceTypeArray() { string userID = Application.Current.Properties["userID"] as string; this.deviceTypeArray = Application.Current.Properties["DeviceTypeArray"] as bus.DeviceType[]; this.dataBus = Application.Current.Properties["DataBus"] as DataBus; }
/// <summary> /// 刷新所有数据 /// </summary> public void refreshData() { string userID = Application.Current.Properties["userID"] as string; bus.DataBusServiceClient dataBusServiceClient = new bus.DataBusServiceClient(); try { DataBus dataBus1 = new DataBus(); dataBus1.fillDataBusByRemoteService(dataBusServiceClient,userID); //this.dataBus = dataBus1; Application.Current.Properties["DataBus"] = dataBus1; bus.DeviceType[] deviceTypeArray=dataBusServiceClient.QueryAllDeviceTypeInfo(); Application.Current.Properties["DeviceTypeArray"] = deviceTypeArray; DevTypeCollection devTypeC=new DevTypeCollection(); devTypeC.initFromDataBusDevTypeArray(deviceTypeArray); refreshTreeView(devTypeC); } catch (Exception exp) { MessageBox.Show(exp.Message); return; } finally { if (dataBusServiceClient != null) dataBusServiceClient.Close(); dataBusServiceClient = null; } }