Пример #1
0
        /// <summary>
        /// Gets the adapter address information.
        /// </summary>
        /// <param name="device">The device to get the adapter address information for.</param>
        /// <returns>The address information for the device.</returns>
        private static string AdapterAddressInformation(Device device)
        {
            StringBuilder lsbDestination = new StringBuilder();
            IPAddress[] lipAddresses = device.AdapterIPAddresses;
            if (lipAddresses != null && lipAddresses.Length > 0)
            {
                string lsIndent = new string(' ', 2);
                lsbDestination.AppendLine("Available on Network Interface IP Addresses: ");
                foreach (IPAddress lipAddress in lipAddresses)
                {
                    lsbDestination.Append(lsIndent);
                    lsbDestination.AppendLine(lipAddress.ToString());
                }
            }

            return lsbDestination.ToString();
        }
Пример #2
0
 /// <summary>
 /// Creates a new device from an already created device.
 /// </summary>
 /// <param name="device">The device to create from.</param>
 public Device(Device device)
     : this(device.COMDevice, device.InterfaceGuid) 
 {
 }
        /// <summary>
        /// Adds a device to the selection tree view.
        /// </summary>
        /// <param name="device">The device to add.</param>
        private void AddDevice(Device device)
        {
            foreach(Service lsService in device.Services)
                tbSelection.AddService(lsService);

            if(device.HasChildren)
                foreach(Device ldDevice in device.Children)
                    AddDevice(ldDevice);
        }
        /// <summary>
        /// Sets the device for the entire operation.
        /// </summary>
        /// <param name="device">The new device.</param>
        /// <remarks>Clears all user settings.</remarks>
        private void SetDevice(Device device)
        {
            tbSelection.Nodes.Clear();
            AddDevice(device);
            DefaultNodes(tbSelection.Nodes);
            tbSelection.ExpandAll();

            tbDeviceNamespace.Text = "UPnP" + device.DefaultCodeGenClassName(CodeGenProvider) + ".Devices";
            tbServiceNamespace.Text = "UPnP" + device.DefaultCodeGenClassName(CodeGenProvider) + ".Services";

            UpdateEnabled();
        }
Пример #5
0
        private void enumAllDevices(Device myDevice, int beforeEnum)
        {
            if (!alreadyHaveDevice.Contains(myDevice.UniqueDeviceName))
            {
                int newServicesAdded = 0;
                Services myServices = myDevice.Services;

                foreach (Service myService in myServices)
                {
                    BlockingCollection<Target> nextTargetsToAdd = new BlockingCollection<Target>();
                    nextTargetsToAdd = getServiceInfo(myService);
                    if (nextTargetsToAdd.Count > 0)
                    {
                        foreach (Target nextTargetToAdd in nextTargetsToAdd)
                        {
                            Targets.Add(nextTargetToAdd);
                            targetFoundCount++;
                        }
                        newServicesAdded++;

                    }
                }
                if ((beforeEnum == deviceDoneCount) && (newServicesAdded > 0))
                {
                    deviceDoneCount++;
                    treeUpdateRequired = true;
                }

                if (beforeEnum == deviceDoneCount)
                {
                    deviceTimedOut++;
                    timedOut = String.Format(" ({0} error)", deviceTimedOut);
                    devicesWithError.Add(myDevice.DocumentURL);
                    treeUpdateRequired = true;
                }



                if (myDevice.HasChildren)
                {
                    foreach (Device childDevice in myDevice.Children)
                    {
                        enumAllDevices(childDevice,beforeEnum);
                    }
                }

            }
            enumTextVar = "Enumeration complete";
            alreadyHaveDevice.Add(myDevice.UniqueDeviceName);
        }
        /// <summary>
        /// Gets a tree node collection for a device.
        /// </summary>
        /// <param name="device">The device to get the collection for.</param>
        /// <returns>The tree node collection for the device, or null if not found.</returns>
        protected TreeNodeCollection GetDeviceNodeFor(Device device)
        {
            List<Device> ldDevices = new List<Device>();

            // Build device heirarchy list
            Device ldParent = device;
            do
            {
                ldDevices.Insert(0, ldParent);
            } while ((ldParent = ldParent.ParentDevice) != null);

            // Find or add each device to the list
            TreeNodeCollection lnCurrentNodes = this.Nodes;
            bool lbAdding = false;
            foreach (Device ldDevice in ldDevices)
            {
                // Have we found it already
                if (!lbAdding)
                {
                    TreeNode[] lnFoundNodes = lnCurrentNodes.Find(UPnPDeviceTreeItem.KeyFor(ldDevice), false);
                    if (lnFoundNodes.Length == 1) lnCurrentNodes = lnFoundNodes[0].Nodes; else lbAdding = true;
                }

                // Are we adding already
                if (lbAdding)
                {
                    lbAdding = true;
                    lnCurrentNodes = AddUPnPItem(lnCurrentNodes, new UPnPDeviceTreeItem(ldDevice)).Nodes;
                }
            }

            // Return the last collection of nodes for the last node added / found
            return lnCurrentNodes;
        }
        /// <summary>
        /// Removes a device from the tree view.
        /// </summary>
        /// <param name="device">The device to remove.</param>
        public void RemoveDevice(Device device)
        {
            TreeNode[] lnFoundNodes = this.Nodes.Find(UPnPDeviceTreeItem.KeyFor(device), true);

            foreach (TreeNode lnNode in lnFoundNodes)
                lnNode.Remove();
        }
 /// <summary>
 /// Creates a new device tree item.
 /// </summary>
 /// <param name="device">The device for the tree item.</param>
 public UPnPDeviceTreeItem(Device device)
 {
     mdDevice = device;
 }
 /// <summary>
 /// Gets the tree item key for a device.
 /// </summary>
 /// <param name="device">The device to get the key for.</param>
 /// <returns>A string.</returns>
 public static string KeyFor(Device device)
 {
     return String.Format("DEVICE:{0}", device.UniqueDeviceName);
 }