Beispiel #1
0
        /// <summary>
        /// 向监控显示模版添加设备图标
        /// </summary>
        /// <param name="dataCell">设备源数据对象</param>
        public void AddDevIconToDropPanel(Device deviceS)
        {
            //向界面添加图标
            Button button = new Button();
            new CustomDragDropHelper(button);//设置为可拖曳
            button.DataContext = deviceS;//绑定数据源
            button.ToolTip = deviceS.Name;
            button.Click += new RoutedEventHandler(this.DevIconButton_Click);//添加处理函数
            //添加图标上鼠标左键按下事件:用于记录鼠标位置与图标左上角位置的相对距离
            button.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(this.DevIcon_button_PreviewMouseLeftButtonDown);
            button.Height = 40;//设置按钮尺寸
            button.Width = 40;
            Canvas.SetLeft(button,this.curPoint.X);//设置图标按钮位置
            Canvas.SetTop(button, this.curPoint.Y);

            Image image = new Image();
            try
            {
                //for debug---不知如何设置相对Uri来获取图标资源
                this.refresh_dataBus_deviceTypeArray();
                bus.DeviceType deviceType= MonTaskConfigration.getDeviceTypeByName(this.deviceTypeArray, deviceS.DevType);
                string iconFullName = DevType.IconPah + deviceType.DevTypeIconName;
                image.Source = new BitmapImage(new Uri(iconFullName));/////////debug
                image.Margin = new Thickness(0, 0, 0, 0);
                image.Stretch = Stretch.Fill;

                button.Content = image;
            }
            catch (Exception e1)
            {
                MessageBox.Show(e1.Message);
            }

            this.drop_grid.Children.Add(button);
        }
 /// <summary>
 /// 添加设备任务监控,自动创建并调用服务
 /// </summary>
 /// <param name="serviceClient"></param>
 /// <param name="dev"></param>
 /// <param name="time"></param>
 public static void addMonDevTask(Device dev, int time)
 {
     DataBusServiceClient dataBusServiceClient = null;
     try
     {
         dataBusServiceClient = new DataBusServiceClient();
         addMonDevTask(dataBusServiceClient, dev, time);
     }
     catch (Exception e1)
     {
         throw e1;
     }
     finally
     {
         if (dataBusServiceClient != null)
             dataBusServiceClient.Close();
         dataBusServiceClient = null;
     }
 }
Beispiel #3
0
        /// <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>
 /// <param name="serviceClient"></param>
 /// <param name="dev"></param>
 /// <param name="time"></param>
 public static void addMonDevTask(DataBusServiceClient serviceClient, Device dev, int time)
 {
     try
     {
         UserMonTaskSub[] UserMonTaskSubArray = dev.buildMonStructFromDevice_add(time).ToArray();
         if (UserMonTaskSubArray == null)
             return;
         UserMonTask userTask_new = new UserMonTask();
         //////////debug
         userTask_new.UserID = "user001";//设置用户ID
         userTask_new.MonTaskList = UserMonTaskSubArray;
         //调用远程服务,删除dev_selected设备的监控
         bool isSuccess=serviceClient.AddUserMonTasks(userTask_new);
         if (isSuccess == false)
         {
             throw new Exception("远程服务调用返回fasle");
         }
         dev.setMoniterStatus();//修改设备监控状态信息
     }
     catch (Exception e)
     {
         throw new ApplicationException("添加对设备" + dev.DevID + "的监控失败:"+e.Message);
     }
 }
Beispiel #5
0
        /// <summary>
        /// 将从数据总线获取的监控代理列表信息转化为对应的本地类型
        /// </summary>
        /// <param name="monAgentList">从数据总线获取的监控代理列表</param>
        public void initFromDataContractObj(bus.MonAgentInfo[] monAgentArray)
        {
            this.monitorAgentList = new ObservableCollection<MonitorAgent>();

            for (int i = 0; i < monAgentArray.Length; i++)
            {
                bus.MonAgentInfo monAgent = monAgentArray[i];//取出一个MonAgentInfo元素引用

                //新建一个MonitorAgent对象
                MonitorAgent monAgent_new = new MonitorAgent();
                monAgent_new.ID = monAgent.Id;
                monAgent_new.DeviceList = new ObservableCollection<Device>();
                //依次初始化monAgent_new的每个设备
                foreach (bus.MonDeviceInfo devInfo in monAgent.MonDevList)
                {
                    //新建一个Device对象
                    Device device_new = new Device();

                    device_new.MonAgentBelongTo = monAgent_new;//添加设备对其所属监控代理的引用
                    //利用数据契约对应对象初始化
                    device_new.DevID = devInfo.Id;
                    device_new.DevType = devInfo.Type;
                    device_new.Name = devInfo.Name;

                    //初始化静态属性集合
                    device_new.StaticStateList = new ObservableCollection<StaticState>();
                    foreach (bus.StaticAttribute staticAttribute in devInfo.StaticAttrList)
                    {
                        //新建一个StaticState对象
                        StaticState sState_new = new StaticState();
                        sState_new.DeviceBelongTo = device_new;//添加状态对其所属设备的引用
                        sState_new.Name = staticAttribute.AttrName;
                        AttributeValue attrVal_new = new AttributeValue();
                        try
                        {
                            attrVal_new.setDataValue(AttributeValue.mapType(staticAttribute.AttrValueType),
                                                     staticAttribute.AttrValue);
                            sState_new.AttributeValue = attrVal_new;
                        }
                        catch (Exception e)
                        {
                            throw new ApplicationException("数据契约静态属性'" + staticAttribute.AttrName + "'转化为本地类型中,值转化出错:" + e.Message, e);
                        }
                        device_new.StaticStateList.Add(sState_new);//将新静态属性添加到新静态属性列表
                    }

                    //初始化动态属性集合
                    device_new.DynamicStateList = new ObservableCollection<DynamicState>();
                    foreach (bus.State dState in devInfo.StateList)
                    {
                        //新建一个StaticState对象
                        DynamicState dState_new = new DynamicState();
                        dState_new.DeviceBelongTo = device_new;//添加状态对其所属设备的引用
                        dState_new.Name = dState.DsName;
                        dState_new.Title = dState.DsTitle;
                        dState_new.Unit = dState.DsUnit;
                        dState_new.ViewType = dState.DsViewType;
                        dState_new.AttributeValue = new AttributeValue();
                        try
                        {
                            dState_new.AttributeValue.setDataValue(AttributeValue.mapType(dState.DsValueType),
                                                     dState.DsDefaultValue);
                        }
                        catch (Exception e)
                        {
                            throw new ApplicationException("数据契约动态属性'" + dState.DsName + "'转化为本地类型中,值转化出错:" + e.Message, e);
                        }

                        device_new.DynamicStateList.Add(dState_new);//将新静态属性添加到新静态属性列表
                    }

                    monAgent_new.DeviceList.Add(device_new);//将新设备添加到设备列表
                }//devInfo

                this.monitorAgentList.Add(monAgent_new);//将新监控代理添加到代理列表
            }//monAgent
        }
Beispiel #6
0
 /// <summary>
 /// 创建显示设备监控详细信息窗口
 /// </summary>
 private void CreateDevDetailWin(Device devS)
 {
     MessageBox.Show("设备" + devS.DevID + "监控详细信息");
 }