private DLDevice FindDeviceInDLThree(WindowsDevice dockRepresentation) { DLDevice result = null; Stack <DLDevice> stack = new Stack <DLDevice>(); DLDevice node = m_PC; while (node != null) { if (node.WindowsDevice == dockRepresentation) { result = node; break; } foreach (var e in node.Children) { stack.Push(e); } node = null; if (stack.Count > 0) { node = stack.Pop(); } } return(result); }
private DLDevice FindParent(DLDevice device) { DLDevice result = null; Stack <DLDevice> stack = new Stack <DLDevice>(); DLDevice node = m_PC; while (node != null) { if (IsInParentChildRelationship(node.WindowsDevice, device.WindowsDevice)) { result = node; } foreach (var e in node.Children) { stack.Push(e); } node = null; if (stack.Count > 0) { node = stack.Pop(); } } return(result); }
public DLDevice Build() { m_PC = new DLDevicePC("PC", null); var displayAdapters = FindDLDisplayAdapters(); foreach (var displayAdapter in displayAdapters) { var dockRepresentation = FindDeviceWhichRepresentingDock(displayAdapter); var existingDock = FindDeviceInDLThree(dockRepresentation); if (existingDock == null) { DLDevice dock = new DLDock(displayAdapter.Name, dockRepresentation); existingDock = dock; DLDevice parent = FindParent(dock); if (parent == null) { parent = m_PC; } parent.Children.Add(dock); dock.Parent = parent; foreach (var sibling in parent.Children) { if (IsInParentChildRelationship(dock.WindowsDevice, sibling.WindowsDevice)) { dock.Children.Add(sibling); sibling.Parent = dock; } } foreach (var siblingForDelete in dock.Children) { parent.Children.Remove(siblingForDelete); } } foreach (var monitorRepresentation in displayAdapter.Children) { DLDevice monitor = new DLMonitor(monitorRepresentation.Name, monitorRepresentation); existingDock.Children.Add(monitor); } } return(m_PC); }
static void Main(string[] args) { Console.WriteLine("Started ..."); // List <WindowsDevice> windowsDeviceList = new List <WindowsDevice>(); WindowsDeviceEnumerator wde = new WindowsDeviceEnumerator(); windowsDeviceList = wde.EnumerateDevices(); //devices is now enumerated, now we should build tree DLDeviceTreeBuilder dlDeviceBuilder = new DLDeviceTreeBuilder(); dlDeviceBuilder.WindowsDevices = windowsDeviceList; DLDevice root = dlDeviceBuilder.Build(); Console.WriteLine(root.ToJson()); // Console.WriteLine("End ..."); Console.ReadLine(); }