Example #1
0
        private void InferConvergedTopology()
        {
            foreach (var device in InfrastructureDevices)
            {
                device.Clients.Clear();
                device.InfrastructureDevices.Clear();
            }

            foreach (var childDevice in InfrastructureDevices)
            {
                var parentDevice = GetParentOf(childDevice);
                if (parentDevice != null)
                {
                    parentDevice.InfrastructureDevices.Add(childDevice);
                }
            }

            foreach (var childClient in Clients)
            {
                var parentDevice = GetParentOf(childClient);
                if (parentDevice != null)
                {
                    parentDevice.Clients.Add(childClient);
                }
            }

            var rootCandidates = InfrastructureDevices.Where(d => d.Uplink == null || string.IsNullOrEmpty(d.Uplink.UplinkMac)).ToList();

            if (rootCandidates.Count == 1)
            {
                TopologicalRoot = rootCandidates[0];
            }
            else
            {
                var nonManagedDevice = new UnknownInfrastructureNetworkedDevice(API, null);
                nonManagedDevice.InfrastructureDevices = rootCandidates;
                TopologicalRoot = nonManagedDevice;
            }
        }