Example #1
0
        public void SetParameterValue(IParameterInput parameterInput)
        {
            var parameter = FindParameter(parameterInput);
            var slot      = EnsureSlot(parameter);

            try
            {
                slot.SetValue(InputValueConverter.Convert(parameterInput.Value, slot.Parameter.ValueType));
            }
            catch (Exception ex)
            {
                throw new ParameterValueAssignException(parameter, parameterInput, ex);
            }
        }
Example #2
0
        private TParameter FindParameter(IParameterInput parameterInput)
        {
            if (parameterInput.Name == null && _defaultCollectionParameter != null)
            {
                return(_defaultCollectionParameter);
            }

            var prm = _parameters.SingleOrDefault(s => s.Matches(parameterInput));

            if (prm == null)
            {
                throw new ParameterNotFoundException(parameterInput, $"Parameter not found for the following input: {parameterInput}");
            }

            return(prm);
        }
Example #3
0
        public static string BuildMessage(IParameter parameter, IParameterInput input, Exception innerException)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("Failed to set value for a parameter.");
            sb.AppendLine();

            sb.AppendFormat("Parameter: {0}", parameter.Name);
            sb.AppendLine();

            sb.AppendFormat("Input Value: {0}", input.Value);

            if (innerException != null)
            {
                sb.AppendLine();
                sb.AppendFormat("\t{0}", innerException.Message);
            }

            return(sb.ToString());
        }
Example #4
0
        public bool Matches(IParameterInput parameter)
        {
            if (parameter.Name == null)
            {
                if (parameter.PositionIndex != PositionIndex)
                {
                    return(false);
                }

                if (SupportsAssignmentByPositionIndex)
                {
                    return(true);
                }

                throw new NotSupportedException(
                          $"{Name} parameter doesn't support position assignment by index");
            }

            return(Name != null &&
                   (Name.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase) || Synonyms.Contains(parameter.Name)));
        }
Example #5
0
 public ParameterValueAssignException(IParameter parameter, IParameterInput parameterParameterInput, Exception innerException) :
     base(BuildMessage(parameter, parameterParameterInput, innerException), innerException)
 {
     Parameter      = parameter;
     ParameterInput = parameterParameterInput;
 }
 public ParameterNotFoundException(IParameterInput parameterInput, string message) : base(message)
 {
     ParameterInput = parameterInput;
 }