Beispiel #1
0
        public static VirtualAddress Parse(string format)
        {
            if (String.IsNullOrWhiteSpace(format))
            {
                return(null);
            }

            var match = addressRegex.Match(format);

            if (!match.Success)
            {
                return(null);
            }

            var result = new VirtualAddress
            {
                NetworkNodeId   = getValue(match, "network_id"),
                NetworkName     = getValue(match, "network_name"),
                NetworkLocation = getValue(match, "network_location"),

                DeviceNodeId   = getValue(match, "device_id"),
                DeviceName     = getValue(match, "device_name"),
                DeviceLocation = getValue(match, "location_name"),

                //TODO: unit test remarks
                Remark = getValue(match, "remarks")
            };

            return(result);
        }
        //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());
        }
Beispiel #3
0
        public static VirtualAddress ToVirtualAddress(this string value)
        {
            var result = VirtualAddress.Parse(value);

            if (result == null)
            {
                throw new ArgumentException("The input does not represent a valid VirtualAddress", "value");
            }

            return(result);
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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());
        }
Beispiel #6
0
        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();
        }
Beispiel #7
0
        public static VirtualAddress Parse(string format)
        {
            if (String.IsNullOrWhiteSpace(format))
            {
                return null;
            }

            var match = addressRegex.Match(format);

            if (!match.Success)
            {
                return null;
            }

            var result = new VirtualAddress
            {
                NetworkNodeId = getValue(match, "network_id"),
                NetworkName = getValue(match, "network_name"),
                NetworkLocation = getValue(match, "network_location"),

                DeviceNodeId = getValue(match, "device_id"),
                DeviceName = getValue(match, "device_name"),
                DeviceLocation = getValue(match, "location_name"),

                //TODO: unit test remarks
                Remark = getValue(match, "remarks")
            };

            return result;
        }