/// <summary> /// Create an input group from an enumerable of IUserInputs /// </summary> /// <param name="userInputs"></param> /// <returns></returns> public static InputGroupDto MakeInputGroupDto(IEnumerable <IUserInput> userInputs) { if (userInputs == null) { return(new InputGroupDto()); } var scriptedSelectionInputs = new List <IScriptedSelectionInputDto>(); var selectionInputs = new List <ISelectionInputDto>(); var textInputs = new List <ITextInputDto>(); foreach (var input in userInputs) { if (input is ITextInputDto) { textInputs.Add((ITextInputDto)input); } else if (input is ISelectionInputDto) { selectionInputs.Add((ISelectionInputDto)input); } else if (input is IScriptedSelectionInputDto) { scriptedSelectionInputs.Add((IScriptedSelectionInputDto)input); } } InputGroupDto inputGroup = new InputGroupDto { TextInputs = textInputs, SelectionInputs = selectionInputs, ScriptedSelectionInputs = scriptedSelectionInputs }; return(inputGroup); }
/// <summary> /// Gets the required inputs for all supplied service options /// </summary> /// <param name="performingUserId"></param> /// <param name="serviceOptions">Service Options to get the inputs for</param> /// <returns></returns> public IInputGroupDto GetInputsForServiceOptions(int performingUserId, IEnumerable <IServiceOptionDto> serviceOptions) { if (serviceOptions == null) { base.ThrowArgumentNullError(nameof(serviceOptions)); } var inputGroup = new InputGroupDto(); //Initialize the lists for inputs List <IScriptedSelectionInputDto> scriptedInputs = new List <IScriptedSelectionInputDto>(); List <ISelectionInputDto> selectionInputs = new List <ISelectionInputDto>(); List <ITextInputDto> textInputs = new List <ITextInputDto>(); using (var context = new PrometheusContext()) { var options = serviceOptions.Select(x => context.ServiceOptions.Find(x.Id)); foreach (var option in options) { textInputs.AddRange(from t in option.TextInputs select ManualMapper.MapTextInputToDto(t)); scriptedInputs.AddRange(from t in option.ScriptedSelectionInputs select ManualMapper.MapScriptedSelectionInputToDto(t)); selectionInputs.AddRange(from t in option.SelectionInputs select ManualMapper.MapSelectionInputToDto(t)); } } inputGroup.TextInputs = textInputs; inputGroup.SelectionInputs = selectionInputs; inputGroup.ScriptedSelectionInputs = scriptedInputs; return(inputGroup); }
/// <summary> /// Convert a list of inputs into a DTO group /// </summary> /// <param name="userInputs">strings expected to be in the form type_id</param> /// <returns></returns> public static InputGroupDto MakeInputGroup(ICollection <string> userInputs) { List <ITextInputDto> textInputs = new List <ITextInputDto>(); List <IScriptedSelectionInputDto> scriptedInputs = new List <IScriptedSelectionInputDto>(); List <ISelectionInputDto> selectionInputs = new List <ISelectionInputDto>(); IInputGroupDto group = new InputGroupDto { TextInputs = new List <ITextInputDto>(), SelectionInputs = new List <ISelectionInputDto>(), ScriptedSelectionInputs = new List <IScriptedSelectionInputDto>() }; foreach (string input in userInputs) { string tempString = input.ToLower(); int inputId; // extract the id try { inputId = int.Parse(tempString.Substring(tempString.IndexOf("_") + 1)); } catch (Exception) { continue; } /*just skip this one then */ //extract the type if (tempString.Contains("text")) { textInputs.Add(new TextInputDto { Id = inputId }); } else if (tempString.Contains("script")) //the order here matters - think: scripted selection vs selection { scriptedInputs.Add(new ScriptedSelectionInputDto { Id = inputId }); } else if (tempString.Contains("select")) { selectionInputs.Add(new SelectionInputDto { Id = inputId }); } } group.TextInputs = textInputs; group.SelectionInputs = selectionInputs; group.ScriptedSelectionInputs = scriptedInputs; return((InputGroupDto)group); }