private string GetParameterActionDescription(params ObjectProperty[] additionalParameters) { var items = new List <string>(); foreach (var prop in modifiedSensorParameters .Where(c => !additionalParameters.Any(p => p.ToString() == c.Item1)) //Exclude any additionalParameters; we'll print them specially below .OrderBy(c => c.Item1 != nameof(NewObjectParameters.Name))) //Ensure property "Name" comes first (if applicable) { var val = prop.Item2.IsIEnumerable() ? string.Join(", ", prop.Item2.ToIEnumerable()) : prop.Item2?.ToString(); items.Add($"{prop.Item1} = '{val}'"); } foreach (var param in additionalParameters) { var name = ObjectPropertyParser.GetObjectPropertyName(param); var val = ParametersInternal.GetCustomParameterInternal(name)?.ToString(); if (val?.Contains("\n") == true) { items.Add($"{param} =\n\n{val}\n\n"); } else { items.Add($"{param} = '{val}'"); } } return(MyInvocation.MyCommand.Name + ": " + string.Join(", ", items)); }
private void WarnSuspiciousPropertyName(string name) { if (name.EndsWith("_")) return; var inherited = Enum.GetValues(typeof(ObjectProperty)).Cast<ObjectProperty>().Where(v => v.GetEnumAttribute<LiteralValueAttribute>() != null).ToArray(); var raw = inherited.Select(i => ObjectPropertyParser.GetObjectPropertyName(i)).ToArray(); if (raw.Contains(name)) return; WriteWarning($"Property '{name}' does not look correct. If request does not work try with '{name}_' instead. To suppress this message specify -WarningAction SilentlyContinue."); }
private string GetObjectPropertyName(Enum property, bool forceOriginalName = false) { var name = ObjectPropertyParser.GetObjectPropertyName(property); if (forceOriginalName) { return(name); } string realName; if (property is ObjectProperty && nameOverrideMap.TryGetValue((ObjectProperty)property, out realName)) { name = realName; } return(name); }
internal static T GetObjectProperties <T>(PrtgResponse response, XmlEngine xmlEngine, ObjectProperty mandatoryProperty) { var xml = HtmlParser.Default.GetXml(response); var xDoc = new XDocument(xml); //If the response does not contain the mandatory property, we are executing as a read only user, and //should return null var name = HtmlParser.DefaultPropertyPrefix + ObjectPropertyParser.GetObjectPropertyName(mandatoryProperty).TrimEnd('_'); if (xDoc.Descendants(name).ToList().Count > 0) { var items = xmlEngine.DeserializeObject <T>(xDoc.CreateReader()); return(items); } return(default(T)); }
internal static List <T> CreateFromDropDownOptions(string response, ObjectProperty name, Func <string, T> createObj) { var val = ObjectPropertyParser.GetObjectPropertyName(name).TrimEnd('_'); return(CreateFromDropDownOptions(response, val, createObj)); }
private string GetObjectPropertyName(Enum property) { var name = ObjectPropertyParser.GetObjectPropertyName(property); return(name); }