//TODO: give this method a little more love public static T GetDevice <T>(this IEnumerable <T> deviceStates, VirtualAddress address) where T : IDeviceState { //TODO: select device by ID var results = (from d in deviceStates let locationMatch = LocationCloseness(d.Location, address.DeviceLocation) where locationMatch != null //TODO: add networkLocation && ((address.NetworkName == null) || d.NetworkState.Name == address.NetworkName) && ((address.NetworkNodeId == null) || d.NetworkState.Address == address.NetworkNodeId) && ((address.DeviceName == null) || (d.Name == address.DeviceName || d.Address == address.DeviceName)) && ((address.DeviceNodeId == null) || d.Address == address.DeviceNodeId) orderby locationMatch ascending select d) .ToList(); if (!results.Any()) { throw new NoMatchingDeviceException(address.Format()); } var firstResult = results.First(); results = results.Where(d => LocationCloseness(d.Location, address.DeviceLocation) == LocationCloseness(firstResult.Location, address.DeviceLocation)).ToList(); if (results.Count() > 1) { throw new MultipleMatchingDevicesException(address.Format(), results.Cast <IDeviceState>()); } return(results.First()); }
public static string BuildVirtualAddress(this IDeviceState state, bool justAddress, bool includeDescription) { string description = null; if (includeDescription) { description = VirtualAddress.FormatNaturalLanguageDescription(state); } return(VirtualAddress.Format(state, justAddress, description)); }
public static string Format(IDeviceState device, bool justAddresses = false, string remarks = null) { var network = device.NetworkState; var virtualAddress = new VirtualAddress { NetworkNodeId = network.Address, NetworkName = (justAddresses) ? (null) : (network.Name), //TODO: fix this NetworkLocation = null, //(justAddresses) ? (null) : network.Location_Hack, DeviceNodeId = device.Address, DeviceName = (justAddresses) ? (null) : (device.Name), DeviceLocation = (justAddresses || device.Location == null) ? (null) : (device.Location.Format()), Remark = remarks }; return(virtualAddress.Format()); }
public static string Format(IDeviceState device, bool justAddresses = false, string remarks = null) { var network = device.NetworkState; var virtualAddress = new VirtualAddress { NetworkNodeId = network.Address, NetworkName = (justAddresses) ? (null) : (network.Name), //TODO: fix this NetworkLocation = null, //(justAddresses) ? (null) : network.Location_Hack, DeviceNodeId = device.Address, DeviceName = (justAddresses) ? (null) : (device.Name), DeviceLocation = (justAddresses || device.Location == null) ? (null) : (device.Location.Format()), Remark = remarks }; return virtualAddress.Format(); }