internal void ValidateParameters(NewSensor newSensorCmdlet, NewSensorParameters parameters)
        {
            try
            {
                RequestParser.ValidateObjectParameters(parameters);
            }
            catch (InvalidOperationException ex)
            {
                var property = Regex.Replace(ex.Message, ".*[Pp]roperty '(.+?)'.+", "$1");

                var candidates = new List <string>();

                string singular;

                //Build a list of possible parameter values that could have been invoked
                if (pluralMap.TryGetValue(property, out singular))
                {
                    candidates.Add(singular);
                }

                if (alternateSet != null)
                {
                    candidates.AddRange(alternateSet.Parameters.Where(p => p.OriginalName == property).Select(p => p.Name));
                }

                //Filter the list to the parameter that was actually specified
                candidates = candidates.Where(c => newSensorCmdlet.MyInvocation.BoundParameters.ContainsKey(c)).ToList();

                if (candidates.Count == 1)
                {
                    var newMessage = ex.Message.Replace("Property", "Parameter").Replace($"'{property}'", $"'-{candidates[0]}'");

                    throw new InvalidOperationException(newMessage, ex);
                }
                else
                {
                    throw;
                }
            }
        }
Beispiel #2
0
 public SensorProxy(NewSensorParameters parameters, PrtgClient client) : base(i => client.AddSensor(i, parameters).First())
 {
 }