Ejemplo n.º 1
0
        /*********************************************
         监控信息初始化
        *********************************************/
        public InitMonDevice(string username)
        {
            using (Bus.DataBusServiceClient client = new Bus.DataBusServiceClient())
            {
                Bus.UserMonTask usertask = client.QueryUserTask(username);
                //Bus.DeviceState[] statelist = client.QueryStates("u002");

                /*********************************************
                 需要控制连接失败信息!
                *********************************************/
                GeneratCollection(username);

                GeneratDevice(usertask);
                GenerateSate(usertask,client);

                ThreadScan scanthread = (ThreadScan)Application.Current.Properties["ScanDevice"];
                Collection devcollection = (Collection)Application.Current.Properties["MonitorCollection"];

                int devcount = devcollection.GetDeviceCount();

                if (devcount > 0)
                {
                    scanthread.ScanTime = devcollection.GetScanTime();
                    scanthread.threadStart();
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// "确定"添加监控
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void addMonTask_Button_Click(object sender, RoutedEventArgs e)
 {
     WpfDataBingding.DevTreeData.Device dev_selected = ((WpfDataBingding.DevTreeData.Device)this.DataContext);
     //建立客户服务代理对象
     bus.DataBusServiceClient dBSC = new bus.DataBusServiceClient();
     try
     {
         //获取监控时间间隔
         int timeInterval= getTimeInterval();
         //添加设备监控
         MonTaskConfigration.addMonDevTask(dBSC, dev_selected, timeInterval);
         //隐藏时隙输入模版
         this.MonTimeInputDockPanel.Visibility = System.Windows.Visibility.Hidden;
         this.MonStatus_Label.Content = dev_selected.MonitorStatusLabel;//修改界面
         this.Button_DelAndAddDevMon.Content = dev_selected.MonitorStatusButton;
     }
     catch (Exception exp)
     {
         MessageBox.Show("出错:" + exp.Message);
         return;
     }
     finally
     {
         if (dBSC != null)
             dBSC.Close();
     }
 }
Ejemplo n.º 3
0
        public void ScanState()
        {
            Collection devCollection = (Collection)Application.Current.Properties["MonitorCollection"];
            while (true)
            {
                using (Bus.DataBusServiceClient client = new Bus.DataBusServiceClient())
                {
                    DeviceSign[] devArr = devCollection.GetDeviceIDList();

                    DeviceDynamic device;

                    foreach (var item in devArr)
                    {
                        device = devCollection.GetDevice(item.dev_id,item.mon_id);

                        string []  statelist=device.GetStateName();

                        DynamicState state;
                        Bus.AttributeValue attVal;

                        foreach(var stateitem in statelist)
                        {

                        Bus.DeviceState busquerystate = new Bus.DeviceState();
                        busquerystate.AgentID = device.Monitor_ID;
                        busquerystate.DevType = device.Dev_Type;
                        busquerystate.DevID = device.Device_ID;
                        busquerystate.Name = stateitem;
                        attVal = client.QueryStateTest(busquerystate);

                        if (attVal != null)
                        {
                            AttributeValue stateVal = new AttributeValue(attVal.Type, attVal.Value);

                            state = new DynamicState(stateitem, device.Device_ID,device.Monitor_ID, device.Dev_Type);
                            state.StateValue = stateVal;
                            device.ChangeStateValue(state);
                        }

                        }/////单个设备所以状态扫描

                    }///所有设备集合扫描
                } ///服务端口开

                Thread.Sleep(scantime);
            }////线程循环
        }
Ejemplo n.º 4
0
        public static ChangeStateBackInfo ChangeDeviceDynamicState(DynamicState dyState, string strValue)
        {
            ChangeStateBackInfo backinfo;
            #region////暂用版本
            try
            {
            double val = Double.Parse(strValue);
            Bus.AttributeValue staval = new Bus.AttributeValue();

            staval.Type = "double";
            staval.Value = val;

            Bus.DeviceState deviceState = new Bus.DeviceState();

            deviceState.AgentID = dyState.AgentName;
            deviceState.DevID = dyState.DevID;
            deviceState.DevType = "XBPQ";
            deviceState.Name = dyState.StateName;
            deviceState.Value = staval;

                using (Bus.DataBusServiceClient client = new WpfDataBingding.TaskServiceReference.DataBusServiceClient())
                {
                    bool issucess = client.SetStates(new Bus.DeviceState[] { deviceState });
                    if (issucess == true)
                    {
                        backinfo = new ChangeStateBackInfo { isSucess=true, info=string.Empty};
                    }
                    else
                    {
                        backinfo = new ChangeStateBackInfo {  isSucess=false, info = string.Empty };
                    }
                    client.Close();
                }
            }
            catch(Exception e)
            {
                backinfo = new ChangeStateBackInfo { isSucess=false, info=e.Message.ToString() };
                return backinfo;
            }

            return backinfo;
            #endregion
        }
Ejemplo n.º 5
0
        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;
            }
        }
Ejemplo n.º 6
0
        private void Button_ClickSet(object sender, RoutedEventArgs e)
        {
            Button source = e.Source as Button;
            DockPanel txtblock = source.Parent as DockPanel;
            Label leb = (Label)txtblock.FindName("state_name");
            TextBox txtbox = (TextBox)txtblock.FindName("state_value");
            string state_name =(string)leb.Content;
            string state_value = (string)txtbox.Text;

            /*********************************************
              仅供下变频器设置频率,需要设计逻辑层
             *********************************************/
            double val = Double.Parse(state_value);
            Bus.AttributeValue staval=new Bus.AttributeValue();

            staval.Type="double";
            staval.Value=val;

            Collection devCollection=(Collection)Application.Current.Properties["MonitorCollection"];
            DeviceDynamic device=devCollection.GetDevice(dev_id,mon_id);

               // MessageBox.Show(string.Format("{0} 数据不合法!",state_value));

            Bus.DeviceState deviceState = new Bus.DeviceState();

            deviceState.AgentID = device.Monitor_ID;
            deviceState.DevID = device.Device_ID;
            deviceState.DevType = device.Dev_Type;
            deviceState.Name = state_name;
            deviceState.Value = staval;

            using (Bus.DataBusServiceClient client = new WpfDataBingding.TaskServiceReference.DataBusServiceClient())
            {
              bool issucess=client.SetStates(new Bus.DeviceState[]{deviceState});
              if (issucess == true)
              {
                  MessageBox.Show("属性设置成功!");
              }
              else
              {
                  MessageBox.Show("属性修改失败!");
              }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 添加&删除对某个设备的监控
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_DelAndAddDevMon_Click(object sender, RoutedEventArgs e)
        {
            bool isMonitered;
            WpfDataBingding.DevTreeData.Device dev_selected;
            try
            {
                //获取设备当前的监控状态
                dev_selected = ((WpfDataBingding.DevTreeData.Device)this.DataContext);
                isMonitered=dev_selected.IsMonitered;
            }
            catch (Exception exp)
            {
                MessageBox.Show("内部错误:"+exp.Message);
                return;
            }

            if (!isMonitered)//未监控--添加监控:显示输入时隙模版
            {
                this.MonTimeInputDockPanel.Visibility = System.Windows.Visibility.Visible;
                return;
            }
            else//已被监控--删除监控
            {
                //建立客户服务代理对象
                bus.DataBusServiceClient dBSC = new bus.DataBusServiceClient();
                try
                {
                    //删除监控
                    MonTaskConfigration.deleteMonDevTask(dBSC, dev_selected);
                    this.MonStatus_Label.Content = dev_selected.MonitorStatusLabel;//修改界面
                    this.Button_DelAndAddDevMon.Content = dev_selected.MonitorStatusButton;
                }
                catch (Exception exp)
                {
                    MessageBox.Show("连接远程服务出错:" + exp.Message);
                    return;
                }
                finally
                {
                    if (dBSC != null)
                        dBSC.Close();
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 通过远程调用填充数据总线设备实例,包括是否被监控的信息
        /// </summary>
        public void fillDataBusByRemoteService(string userID)
        {
            //string userID = Application.Current.Properties["userID"] as string;

            bus.DataBusServiceClient dBSC = new bus.DataBusServiceClient();
            TaskServiceReference.MonAgentInfo[] monAgentInfoArray = null;
            try
            {
                //调用远程服务
                monAgentInfoArray = dBSC.QueryMonAgentsDevs();
                //刷新设备实例信息
                initFromDataContractObj(monAgentInfoArray);
                //刷新设备监控信息
                bus.UserMonTask usertask = dBSC.QueryUserTask(userID);
                initDevMonStatusFromDataContractObj(usertask);
            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                if (dBSC != null)
                    dBSC.Close();
            }
        }
Ejemplo n.º 9
0
        /// <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();
            }
        }
Ejemplo n.º 10
0
 /// <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;
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 根据ListView中选项结构添加和删除设备监控
        /// </summary>
        private void MonTaskChange_Button_Click(object sender, RoutedEventArgs e)
        {
            List<Device> devAddList = new List<Device>(4);
            List<Device> devDeleList = new List<Device>(4);
            List<int> timeList = new List<int>(4);
            bus.DataBusServiceClient serviceClient = new bus.DataBusServiceClient();
            try
            {
                foreach (Device dev in ((MonitorAgent)this.DataContext).DeviceList)
                {
                    if (this.MonDeviceRecord_Dictionary.ContainsKey(dev.DevID))//设备需要监控
                    {
                        if (dev.IsMonitered == false)//未被监控
                        {
                            int time = MonDeviceRecord_Dictionary[dev.DevID];
                            if (time <= 0)
                                throw new ApplicationException("设备"+dev.DevID+ "监控时间未正确设置");
                            //添加监控
                            devAddList.Add(dev);
                            timeList.Add(time);
                        }
                    }
                    else//不需要监控
                    {
                        if (dev.IsMonitered)//已经被监控
                        {   //删除监控
                            devDeleList.Add(dev);
                        }
                    }
                }//foreach
                //调用远程服务添加监控任务
                MonTaskConfigration.addMonDevTaskS(serviceClient,devAddList,timeList);
                //调用远程服务删除监控任务
                MonTaskConfigration.deleteMonDevTaskS(serviceClient, devDeleList);
            }
            catch (Exception exp)
            {
                MessageBox.Show("出错:" + exp.Message);
                return;
            }
            finally
            {
                if (serviceClient != null)
                    serviceClient.Close();
            }

            MessageBox.Show("监控任务修改成功");
        }