Example #1
0
        private static void AddGroup(Node topNode, DeviceGroup deviceGroup, List<Node> processedNodes, Device[] devices)
        {
            string[] paths = deviceGroup.Path.Split(new[] {@"\", @"\\"}, StringSplitOptions.RemoveEmptyEntries);

            Node groupNode = null;

            if (paths.Length == 1)
            {
                groupNode = new Node(topNode, deviceGroup.Path, deviceGroup.Name, deviceGroup.Icon);

                groupNode.SetDevices(devices.Where(d => d.Path == deviceGroup.Path).Select(d => new DeviceInfo
                {
                    DeviceId = d.DeviceId
                }));

                topNode.Nodes.Add(groupNode);
                processedNodes.Add(groupNode);

                return;
            }

            int indexOfName = deviceGroup.Path.LastIndexOf(@"\", StringComparison.Ordinal);

            string parentPath = deviceGroup.Path.Remove(indexOfName);

            Node parentNode = processedNodes.Single(n => n.Path == parentPath);

            groupNode = new Node(parentNode, deviceGroup.Path, deviceGroup.Name, deviceGroup.Icon);

            groupNode.SetDevices(devices.Where(d => d.Path == deviceGroup.Path).Select(d => new DeviceInfo
            {
                DeviceId = d.DeviceId
            }));

            parentNode.Nodes.Add(groupNode);
            processedNodes.Add(groupNode);
        }
        private static void AddGroup(Node topNode, DeviceGroup deviceGroup, List <Node> processedNodes, Device[] devices)
        {
            string[] paths = deviceGroup.Path.Split(new[] { @"\", @"\\" }, StringSplitOptions.RemoveEmptyEntries);

            Node groupNode = null;

            if (paths.Length == 1)
            {
                groupNode = new Node(topNode, deviceGroup.Path, deviceGroup.Name, deviceGroup.Icon);

                groupNode.SetDevices(devices.Where(d => d.Path == deviceGroup.Path).Select(d => new DeviceInfo
                {
                    DeviceId = d.DeviceId
                }));

                topNode.Nodes.Add(groupNode);
                processedNodes.Add(groupNode);

                return;
            }

            int indexOfName = deviceGroup.Path.LastIndexOf(@"\", StringComparison.Ordinal);

            string parentPath = deviceGroup.Path.Remove(indexOfName);

            Node parentNode = processedNodes.Single(n => n.Path == parentPath);

            groupNode = new Node(parentNode, deviceGroup.Path, deviceGroup.Name, deviceGroup.Icon);

            groupNode.SetDevices(devices.Where(d => d.Path == deviceGroup.Path).Select(d => new DeviceInfo
            {
                DeviceId = d.DeviceId
            }));

            parentNode.Nodes.Add(groupNode);
            processedNodes.Add(groupNode);
        }