private void EnumerateChildren()
        {
            IntPtr ptrFirstChild = IntPtr.Zero;

            if (Win32.CM_Get_Child_Ex(
                    ref ptrFirstChild,
                    _deviceHandle,
                    0,
                    _machineHandle) != 0)
            {
                return;
            }

            var ptrChild   = ptrFirstChild;
            var ptrSibling = IntPtr.Zero;

            do
            {
                var childDevice = new DeviceNode(ptrChild, this);
                _children.Add(childDevice);

                if (Win32.CM_Get_Sibling_Ex(
                        ref ptrSibling,
                        ptrChild,
                        0,
                        _machineHandle) != 0)
                {
                    break;
                }

                ptrChild = ptrSibling;
            }while (true);
        }
 public DeviceNode(IntPtr deviceHandle, DeviceNode parentDevice)
     : this(
         deviceHandle,
         parentDevice,
         parentDevice._machineHandle)
 {
 }
Ejemplo n.º 3
0
        /// <summary>
        ///		Update a DeviceNode in the database
        /// </summary>
        /// <param name="Node">
        ///		DeviceNode that should be updated
        /// </param>
        /// <returns>
        ///		true, if the node is updated
        ///		false, if no node is updated
        /// </returns>
        public Boolean UpdateNode(DeviceNode Node)
        {
            // Command that will be send to the databse
            MySqlCommand Command = this.Connection.CreateCommand();

            // Update a row in the databse with the given node id
            // UPDATE						> Update rows of a table
            // SET	[colum name] = [value],	> Set a column to the given value
            //		[colum name] = [value]	> Set a column to the given value
            // WHERE object_id = {0}		> Update all rows where the column object_id matches the given id
            Command.CommandText = String.Format(
                "UPDATE object_tree SET object_parent_id={0}, object_name='{1}', object_description='{2}', object_last_updated='{3}', sensor_ip_address='{4}', sensor_port={5} WHERE object_id={6}",
                Node.GetParentID(), Node.GetName(), Node.GetDescription(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Node.GetIPAddress().ToString(), Node.GetPort(), Node.GetID()
                );
            Command.Connection = this.Connection;

            // Execute the command and get the number of rows that are affected by the command
            Int32 AffectedRows = Command.ExecuteNonQuery();

            // If no rows where affected return false
            if (AffectedRows == 0)
            {
                return(false);
            }

            // Row successfully updated
            return(true);
        }
Ejemplo n.º 4
0
        private void BtnImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlgFile = new OpenFileDialog
            {
                Filter   = "XML files (*.xml)|*.xml|All files (*.*)|*.*",
                FileName = "cardlist.xml"
            };

            if (dlgFile.ShowDialog() == DialogResult.OK)
            {
                //加载XML文件
                XDocument doc = XDocument.Load(dlgFile.FileName);
                //获得根节点下dev子节点
                var DeviceNodes = doc.Root.Elements("dev");
                foreach (var DeviceNode in DeviceNodes)
                {
                    //int DeviceType = int.Parse(DeviceNode.Attribute("ty").Value);
                    string DeviceId   = DeviceNode.Attribute("ro").Value;
                    var    DeviceInDB = (from d in db.Devices
                                         where d.roomid == DeviceId
                                         select d).FirstOrDefault();
                    //if (DeviceInDB != null)
                    {
                        var cards = (from card in DeviceNode.Elements("card")
                                     select new Iccard {
                            C_icno = card.Value, C_roomid = "00-00-00-00-00"
                        }).ToList();
                        //using (var db = new ICMDBContext())
                        {
                            foreach (var card in cards)
                            {
                                if (DeviceInDB != null)
                                {
                                    var mapInDB = (from m in db.Icmaps
                                                   where m.C_icno == card.C_icno &&
                                                   m.C_entrancedoor == DeviceId
                                                   select m).FirstOrDefault();
                                    if (mapInDB == null)
                                    {
                                        db.Icmaps.Add(new icmap {
                                            C_icno = card.C_icno, C_entrancedoor = DeviceId
                                        });
                                    }
                                }

                                var cardInDB = (from c in db.Iccards
                                                where c.C_icno == card.C_icno
                                                select c).FirstOrDefault();
                                if (cardInDB == null)
                                {
                                    db.Iccards.Add(card);
                                }
                            }
                        }
                        db.SaveChanges();
                    }
                }
                BtnRefresh_Click(null, null);
            }
        }
Ejemplo n.º 5
0
 public void updateQueryForm(DeviceNode deviceNode)
 {
     this.deviceNode = deviceNode;
     this.dateTimePickerStartDT.Value = DateTime.Now;
     this.dateTimePickerEndDT.Value   = DateTime.Now;
     this.textBoxDeviceInfo.Text      = this.deviceNode.name;
 }
Ejemplo n.º 6
0
        /// <summary>
        ///		Insert a DeviceNode into the database
        /// </summary>
        /// <param name="Node">
        ///		DeviceNode that should be insert
        /// </param>
        /// <returns>
        ///		true, if a row was inserted
        ///		false, if no row was inserted
        /// </returns>
        public Boolean InsertNode(DeviceNode Node)
        {
            // Command that will be send to the databse
            MySqlCommand Command = this.Connection.CreateCommand();

            // Update a row in the databse with the given node id
            // UPDATE						> Update rows of a table
            // SET	[colum name] = [value],	> Set a column to the given value
            //		[colum name] = [value]	> Set a column to the given value
            // WHERE object_id = {0}		> Update all rows where the column object_id matches the given id
            Command.CommandText = String.Format(
                "INSERT INTO object_tree ( object_parent_id , object_type , object_name , object_description , object_last_updated , sensor_ip_address , sensor_port , sensor_threshold_co2 , sensor_threshold_loudness ) Values( {0} , {1} , '{2}' , '{3}' , '{4}' , '{5}' , '{6}' , {7} , {8} )",
                Node.GetParentID(), DeviceNode.NODE_TYPE, Node.GetName(), Node.GetDescription(), Node.GetLastUpdated().ToString("yyyy-MM-dd HH:mm:ss"), Node.GetIPAddress().ToString(), Node.GetPort(), Node.GetCO2Threshold(), Node.GetLoudnessThreshold()
                );
            Command.Connection = this.Connection;

            // Execute the command and get the number of rows that are affected by the command
            Int32 AffectedRows = Command.ExecuteNonQuery();

            // Set the ID of the node to the ID that was provided by the database
            Node.SetID(Command.LastInsertedId);

            // If no rows where affected return false
            if (AffectedRows == 0)
            {
                return(false);
            }

            // Row successfully insert
            return(true);
        }
Ejemplo n.º 7
0
 static Int64 InsertExampleDeviceNode(Int64 ParentID)
 {
     try {
         Console.Write("> Insert device node...");
         Random     random     = new Random();
         String     Name       = "Sensor " + random.Next(1, 500).ToString();
         DeviceNode deviceNode = new DeviceNode();
         deviceNode.SetName(Name);
         deviceNode.SetParentID(ParentID);
         deviceNode.SetDescription(Name);
         deviceNode.SetLastUpdated(DateTime.Now);
         deviceNode.SetIPAddress(new IPAddress(new Byte[] { 192, 168, 2, 116 }));
         deviceNode.SetPort(10001);
         deviceNode.SetCO2Threshold(1000);
         deviceNode.SetLoudnessThreshold(80);
         Boolean inserted = Database.InsertNode(deviceNode);
         if (inserted)
         {
             ConsoleWriteSuccess(deviceNode.ToString());
         }
         else
         {
             ConsoleWriteError("Could not device node");
         }
         return(deviceNode.GetID());
     } catch (Exception ex) {
         ConsoleWriteError(ex.Message);
         return(0);
     }
 }
Ejemplo n.º 8
0
        public static UsbDevice GetUsbDevice(DeviceNode node)
        {
            if (node == null)
            {
                return(null);
            }
            //UsbController controller = UsbController.GetControllerForDeviceNode(node);
            //if (controller != null) return controller;
            UsbHub hub = UsbHub.GetHubForDeviceNode(node);

            if (hub != null)
            {
                return(hub);
            }
            DeviceNode parent = node.GetParent();

            if (parent == null)
            {
                return(null);
            }
            if (parent.Service == "usbccgp")
            {
                return(GetUsbDevice(parent));
            }
            hub = UsbHub.GetHubForDeviceNode(parent);
            if (hub == null)
            {
                return(null);
            }
            return(hub.FindChildForDeviceNode(node));
        }
Ejemplo n.º 9
0
 internal void deviceAdded(Device device)
 {
     try {
         DeviceNode node = new DeviceNode(form, device);
         devices.Add(device, node);
         if (!form.Visible)
         {
             Nodes.Add(node);
         }
         else
         {
             form.BeginInvoke(new MethodInvoker(() => {
                 form.tree.BeginUpdate();
                 Nodes.Add(node);
                 form.tree.EndUpdate();
             }));
         }
         foreach (Property property in device.Properties)
         {
             node.propertyAdded(property);
         }
     } catch (Exception exception) {
         Console.WriteLine(exception);
     }
 }
Ejemplo n.º 10
0
        private void okClick(object sender, EventArgs e)
        {
            DeviceNode node = (DeviceNode)tree.SelectedNode;

            driver.deviceName = node.Text;
            driver.device     = node.device;
            removeEventHandlers();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 添加Opc Ua 业务数据
        /// </summary>
        /// <param name="inputDtos">要添加的Opc Ua 业务数据DTO信息</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> AddCommOpcUaBusinesss(params CommOpcUaBusinessInputDto[] inputDtos)
        {
            inputDtos.CheckNotNull("inputDtos");
            foreach (var dtoData in inputDtos)
            {
                if (CommOpcUaBusinessRepository.CheckExists(x => x.BusinessName.Equals(dtoData.BusinessName)))
                {
                    return(new OperationResult(OperationResultType.Error, $"业务名称为{dtoData.BusinessName}的信息已存在,数据不合法,改组数据不被存储"));
                }
            }

            CommOpcUaBusinessRepository.UnitOfWork.BeginTransaction();

            CommOpcUaBusinessNodeMapInputDto commOpcUaBusinessNodeMapInputDto = new CommOpcUaBusinessNodeMapInputDto();

            foreach (var dtoData in inputDtos)
            {
                DeviceNode commOpcUaNode = CommOpcUaNodeRepository.TrackEntities.Where(x => x.Id.Equals(dtoData.NodeId)).FirstOrDefault();

                if (commOpcUaNode != null)
                {
                    //var result = await CommOpcUaBusinessContract.AddCommOpcUaBusinesss(dtoData);
                    var result = await CommOpcUaBusinessRepository.InsertAsync(dtoData.MapTo <CommOpcUaBusiness>());

                    if (result > 0)
                    {
                        CommOpcUaBusiness commOpcUaBusiness = CommOpcUaBusinessRepository.TrackEntities.Where(x => x.BusinessName.Equals(dtoData.BusinessName)).FirstOrDefault();
                        commOpcUaBusinessNodeMapInputDto.OpcUaNode     = commOpcUaNode;
                        commOpcUaBusinessNodeMapInputDto.OpcUaBusiness = commOpcUaBusiness;

                        commOpcUaBusinessNodeMapInputDto.Id                = CombHelper.NewComb();
                        commOpcUaBusinessNodeMapInputDto.CreatorUserId     = dtoData.CreatorUserId;
                        commOpcUaBusinessNodeMapInputDto.CreatedTime       = DateTime.Now;
                        commOpcUaBusinessNodeMapInputDto.LastUpdatedTime   = commOpcUaBusinessNodeMapInputDto.CreatedTime;
                        commOpcUaBusinessNodeMapInputDto.LastUpdatorUserId = commOpcUaBusinessNodeMapInputDto.CreatorUserId;

                        var saveResult = await CommOpcUaBusinessNodeMapContract.AddCommOpcUaBusinessNodeMaps(commOpcUaBusinessNodeMapInputDto);

                        if (saveResult.ResultType == OperationResultType.Error)
                        {
                            return(new OperationResult(OperationResultType.Error, $"存储通讯业务点表与通讯点表关联数据失败,取消数据点\"{dtoData.BusinessName}\"存储!"));
                        }
                    }
                    else
                    {
                        return(new OperationResult(OperationResultType.Error, "存储通讯业务点表数据失败!"));
                    }
                }
                else
                {
                    return(new OperationResult(OperationResultType.Error, "查询通讯点表数据失败!"));
                }
            }

            CommOpcUaBusinessRepository.UnitOfWork.Commit();
            return(new OperationResult(OperationResultType.Success, "存储业务点数据成功!"));
        }
Ejemplo n.º 12
0
 public static USBIORegistry GetDeviceForDeviceNode(DeviceNode device, Guid classGuid)
 {
     String[] iLibUsb = device.GetInterfaces(classGuid);
     if (iLibUsb == null || iLibUsb.Length == 0)
     {
         return(null);
     }
     return(new USBIORegistry(device, iLibUsb[0]));
 }
Ejemplo n.º 13
0
        public static IDictionary <String, Object> GetSPDRPProperties(DeviceNode device)
        {
            Dictionary <string, object> deviceProperties = new Dictionary <string, object>();

            foreach (SPDRP prop in Enum.GetValues(typeof(SPDRP)))
            {
                Byte[] propBuffer = device.GetProperty(prop);
                if (propBuffer == null)
                {
                    continue;
                }
                int    iReturnBytes = propBuffer.Length;
                object oValue       = null;
                switch (prop)
                {
                case SPDRP.PhysicalDeviceObjectName:
                case SPDRP.LocationInformation:
                case SPDRP.Class:
                case SPDRP.Mfg:
                case SPDRP.DeviceDesc:
                case SPDRP.Driver:
                case SPDRP.EnumeratorName:
                case SPDRP.FriendlyName:
                case SPDRP.ClassGuid:
                case SPDRP.Service:
                    oValue = GetAsString(propBuffer, iReturnBytes);
                    break;

                case SPDRP.HardwareId:
                case SPDRP.CompatibleIds:
                case SPDRP.LocationPaths:
                    oValue = GetAsStringArray(propBuffer, iReturnBytes);
                    break;

                case SPDRP.BusNumber:
                case SPDRP.InstallState:
                case SPDRP.LegacyBusType:
                case SPDRP.RemovalPolicy:
                case SPDRP.UiNumber:
                case SPDRP.Address:
                    oValue = GetAsInt32(propBuffer, iReturnBytes);
                    break;

                case SPDRP.BusTypeGuid:
                    oValue = GetAsGuid(propBuffer, iReturnBytes);
                    break;

                default:
                    oValue = propBuffer;
                    break;
                }
                deviceProperties.Add(prop.ToString(), oValue);
            }
            return(deviceProperties);
        }
Ejemplo n.º 14
0
            private void deviceAdded(Device device)
            {
                DeviceNode node = new DeviceNode(tree, device);

                devices.Add(device, node);
                tree.BeginInvoke(new MethodInvoker(() => {
                    tree.BeginUpdate();
                    Nodes.Add(node);
                    tree.EndUpdate();
                }));
            }
Ejemplo n.º 15
0
 public void AddDeviceNode(DeviceNode deviceNode)
 {
     if (!(DeviceNodes.Contains(deviceNode)))
     {
         DeviceNodes.Add(deviceNode);
     }
     else
     {
         Debug.LogWarning("Add an existed Device Node -> Device Nodes (List)");
     }
 }
Ejemplo n.º 16
0
 private void listViewDeviceNodes_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
 {
     if (listViewDeviceNodes.SelectedItems.Count == 1)
     {
         DeviceNode node = (DeviceNode)listViewDeviceNodes.SelectedItems[0].Tag;
         if (node != null)
         {
             this.textBoxName.Text = node.name;
         }
     }
 }
Ejemplo n.º 17
0
 private void tree_AfterSelect(object sender, TreeViewEventArgs e)
 {
     okButton.Enabled = false;
     if (((TreeView)sender).SelectedNode is DeviceNode)
     {
         DeviceNode node = (DeviceNode)((TreeView)sender).SelectedNode;
         if (node.ForeColor == DefaultForeColor)
         {
             okButton.Enabled = true;
         }
     }
 }
Ejemplo n.º 18
0
 private void ShowDeviceSerialCodeDetail()
 {
     if (listViewDeviceNodes.SelectedItems.Count == 1)
     {
         DeviceNode node = (DeviceNode)listViewDeviceNodes.SelectedItems[0].Tag;
         if (node != null)
         {
             this.formDeviceSNDetail.updateQueryForm(node);
             this.formDeviceSNDetail.ShowDialog();
         }
     }
 }
Ejemplo n.º 19
0
 public Device(DeviceNode deviceNode)
 {
     if (deviceNode.devicename != null && deviceNode.devicename.Length != 0)
     {
         this.DeviceName = deviceNode.devicename;
     }
     else
     {
         this.DeviceName = "Unknown Device";
     }
     this.Index     = deviceNode.index;
     this.isChecked = false;
 }
Ejemplo n.º 20
0
 public static UsbController GetControllerForDeviceNode(DeviceNode node)
 {
     if (node == null)
     {
         return(null);
     }
     String[] interfaces = node.GetInterfaces(IID_DEVINTERFACE_USB_HOST_CONTROLLER);
     if (interfaces == null || interfaces.Length == 0)
     {
         return(null);
     }
     return(new UsbController(node, interfaces[0]));
 }
Ejemplo n.º 21
0
        private void DeviceNodeHandler(SubscriptionMessage message)
        {
            var nodeRootTopic = message.Topic.Replace("/$type", "");
            var nodeID        = nodeRootTopic.Replace(MQTTRootTopicLevel + "/", "");

            if (Nodes.Find(node => node.MQTTRootTopicLevel == nodeRootTopic) == null)
            {
                var node = new DeviceNode(nodeRootTopic, nodeID, MQTTManager);
                node.ChangeEvent         += OnNodeChange;
                node.PropertyChangeEvent += OnNodePropertyChange;
                Nodes.Add(node);
            }
        }
Ejemplo n.º 22
0
        public static IList <UsbController> GetControllers()
        {
            IList <UsbController> devices = new List <UsbController>();

            foreach (DeviceNode dev in DeviceNode.GetDevices(IID_DEVINTERFACE_USB_HOST_CONTROLLER))
            {
                UsbController controller = GetControllerForDeviceNode(dev);
                if (controller != null)
                {
                    devices.Add(controller);
                }
            }
            return(devices);
        }
        public DeviceNode(
            IntPtr deviceHandle,
            DeviceNode parentDevice,
            IntPtr machineHandle)
        {
            _deviceProperties = new Dictionary <int, string>();
            _children         = new List <DeviceNode>();

            _deviceHandle  = deviceHandle;
            _machineHandle = machineHandle;
            _parentDevice  = parentDevice;

            EnumerateDeviceProperties();
            EnumerateChildren();
        }