private static List <GenericSensorTarget> GetTargetFromName(string response, string tableName) { var checkboxes = CreateFromCheckbox(response, tableName, o => new GenericSensorTarget(o)); if (checkboxes.Count > 0) { return(checkboxes); } var options = CreateFromDropDownOptions(response, tableName, o => new GenericSensorTarget(o)); if (options.Count > 0) { return(options); } //todo: we should filter out the common items, and then dont display that item type description entirely if there are none //if there are none of EITHER, fall back and just list all of them (including hidden) var allCheckboxes = ObjectSettings.GetInput(response).Where(i => i.Type == InputType.Checkbox).ToList(); var allDropdowns = ObjectSettings.GetDropDownList(response).ToList(); if (allCheckboxes.FirstOrDefault(c => c.Name == tableName) == null && allDropdowns.FirstOrDefault(d => d.Name == tableName) == null) { throw GetInvalidNameException(allCheckboxes, allDropdowns, tableName); } return(new List <GenericSensorTarget>()); }
/// <summary> /// Retrieves a list of sensor targets from a list of checkboxes in a specified checkbox group. /// </summary> /// <param name="response">The raw HTML response to parse.</param> /// <param name="name">The name of the checkbox group to parse.</param> /// <param name="createObj">A function used to construct a sensor target from the target's raw value.</param> /// <returns>A list of sensor targets of type T</returns> protected static List <T> CreateFromCheckbox(string response, string name, Func <string, T> createObj) { var files = ObjectSettings.GetInput(response) .Where(i => i.Type == Html.InputType.Checkbox && i.Name == name) .Select(i => createObj(i.Value)) .ToList(); return(files); }
/// <summary> /// Retrieves a list of sensor targets from a list of options on a specified dropdown list. /// </summary> /// <param name="response">The raw HTML response to parse.</param> /// <param name="name">The name of the dropdown list to parse.</param> /// <param name="createObj">A function used to construct a sensor target from the target's raw value.</param> /// <returns>A list of sensor targets of type T</returns> protected static List <T> CreateFromDropDownOptions(string response, string name, Func <string, T> createObj) { var files = ObjectSettings.GetDropDownList(response) .Where(d => d.Name == name) .SelectMany(d => d.Options .Select(o => createObj(o.Value))) .ToList(); return(files); }
internal static Dictionary <string, List <GenericSensorTarget> > GetAllTargets(string response) { var checkboxes = ObjectSettings.GetInput(response).Where(i => i.Type == InputType.Checkbox).ToList(); var dropdowns = ObjectSettings.GetDropDownList(response).ToList(); var validCheckboxes = GetValidCheckboxes(checkboxes, false, false); var validDropdowns = GetValidDropdowns(dropdowns, false, false); var checkboxDict = validCheckboxes.ToDictionary(c => c, c => CreateFromCheckbox(response, c, o => new GenericSensorTarget(o))); var boxDict = validDropdowns.ToDictionary(c => c, d => CreateFromDropDownOptions(response, d, o => new GenericSensorTarget(o))); foreach (var d in boxDict) { checkboxDict.Add(d.Key, d.Value); } return(checkboxDict); }
private static List <GenericSensorTarget> GetTargetFromUnknown(string response) { var checkboxes = ObjectSettings.GetInput(response).Where(i => i.Type == InputType.Checkbox).ToList(); var dropdowns = ObjectSettings.GetDropDownList(response).ToList(); var validCheckboxes = GetValidCheckboxes(checkboxes, false, false); var validDropdowns = GetValidDropdowns(dropdowns, false, false); var all = new List <string>(); all.AddRange(validCheckboxes); all.AddRange(validDropdowns); if (all.Count == 0) { throw new ArgumentException("Cannot guess sensor target table. Please specify tableName"); } if (all.Count > 2) { throw new ArgumentException($"Cannot guess sensor target table: multiple tables found. Available tables: {string.Join(", ", all)}"); } var tableName = all.First(); if (validCheckboxes.Count == 1) { return(CreateFromCheckbox(response, tableName, o => new GenericSensorTarget(o))); } else if (validDropdowns.Count == 1) { return(CreateFromDropDownOptions(response, tableName, o => new GenericSensorTarget(o))); } else { throw new NotImplementedException("Table type was unhandled"); } }
private async Task <Dictionary <string, string> > GetObjectPropertiesRawDictionaryAsync(int objectId, object objectType, CancellationToken token) => ObjectSettings.GetDictionary(await GetObjectPropertiesRawInternalAsync(objectId, objectType, token).ConfigureAwait(false));
private Dictionary <string, string> GetObjectPropertiesRawDictionary(int objectId, object objectType) => ObjectSettings.GetDictionary(GetObjectPropertiesRawInternal(objectId, objectType));