/// <summary> /// 2. Helper for above GetDevices, which takes selection function for extracting items from DeviceDictHS /// </summary> /// <param name="func"></param> /// <param name="devices">Full DeviceDictHS, can be "null", then will retrieve inside</param> /// <param name="exclude">List<dev_ids> to exclude</param> /// <returns>List of pairs (Name=Value=item) for dropbox</returns> public static MyPairList GetDevicesProps(Func <HSDevice, Int32, string> func, DeviceDictHS devices = null, DeviceIdList exclude = null) { if (devices == null) { devices = Devices(); } if (exclude == null) { exclude = new DeviceIdList(); } // TEMP - TODO: exclude? && Int32.TryParse(item, out int id) && !exclude.Contains(id) IEnumerable <string> sel = devices.Values.Select(func); List <string> sel1 = sel.Distinct().OrderBy(x => x).ToList(); MyPairList items = new MyPairList(); foreach (var item in sel1) { if (item != "") // avoid duplicated "" { items.Add(new MyPair(item, item)); } } return(items); }
/// <summary> /// 2. Helper for above GetDevices - selects devices filtered by Location and/or Location2 /// </summary> /// <param name="Location"></param> /// <param name="Location2"></param> /// <param name="devices">Full DeviceDictHS, can be "null", then will retrieve inside</param> /// <param name="min_vspsCount">Filter devices if their vspsCount exceeds this number</param> /// <param name="exclude">List<dev_ids> to exclude</param> /// <returns>List of pairs (Name=name, Value=deviceID) for dropbox</returns> public static MyPairList GetDevices(string Location, string Location2, DeviceDictHS devices = null, int min_vspsCount = 0, DeviceIdList exclude = null) { IHSApplication _hs = null; //IHSApplication _hs = Hs; if (devices == null) { devices = Devices(); } if (exclude == null) { exclude = new DeviceIdList(); } MyPairList items = new MyPairList(); foreach (int deviceId in devices.Keys) { if (exclude.Contains(deviceId)) { continue; } HSDevice device = devices[deviceId]; string name = device.get_Name(_hs); string dev_loc = device.get_Location(_hs); string dev_loc2 = device.get_Location2(_hs); // Select devices matching Loc/Loc2, or if Loc/Loc2 not specified if ((String.IsNullOrEmpty(Location) || Location == dev_loc) && (String.IsNullOrEmpty(Location2) || Location2 == dev_loc2) ) { // If Loc/Loc2 not specified - prepend them to device name if (String.IsNullOrEmpty(Location)) { name = "[" + dev_loc + "] " + name; } if (String.IsNullOrEmpty(Location2)) { name = "[" + dev_loc2 + "] " + name; } int num_vsps = 0; if (min_vspsCount > 0) { VSVGPairs.VSPair[] vsps = Hs.DeviceVSP_GetAllStatus(deviceId); num_vsps = vsps.Length; } if (num_vsps >= min_vspsCount) { items.Add(new MyPair(name, deviceId)); } } } return(items); }
/// <summary> /// 1. Get list of devices or properties (i.e. Locations) - based on combobox "name" /// </summary> /// <param name="name">Selection for defining what to get</param> /// <param name="devices">Full DeviceDictHS, can be "null", then will retrieve inside</param> /// <param name="exclude">List<dev_ids> to exclude</param> /// <returns>List of pairs (Name=Value=item) for dropbox</returns> // TEMP - TODO: change 'name' to Enum public static MyPairList GetDevicesProps(string name, DeviceDictHS devices = null, DeviceIdList exclude = null, string Location = null, string Location2 = null) { IHSApplication _hs = null; //IHSApplication _hs = Hs; if (devices == null) { devices = Devices(); } switch (name) { //case "StateDeviceId": default: return(GetDevices(Location, Location2, devices, min_vspsCount: 1, exclude: exclude)); case "DropListLocation": Func <HSDevice, Int32, string> func1 = (x, i) => x.get_Location(_hs); return(GetDevicesProps(func1, devices, exclude: exclude)); case "DropListLocation2": Func <HSDevice, Int32, string> func2 = (x, i) => x.get_Location2(_hs); return(GetDevicesProps(func2, devices, exclude: exclude)); } //return null; }