protected override IWebResponse GetResponse(ref string address, string function)
        {
            switch (function)
            {
            case nameof(XmlFunction.TableData):
                return(GetTableResponse(address));

            case nameof(HtmlFunction.ObjectData):
                return(new SensorSettingsResponse(propertyChanger));

            case nameof(XmlFunction.GetObjectProperty):
                var components = UrlUtilities.CrackUrl(address);

                if (components["name"] == "aggregationchannel")
                {
                    var text = new SensorSettingsResponse(propertyChanger).GetResponseText(ref address);
                    var xml  = ObjectSettings.GetXml(text);

                    var value = xml.Descendants("injected_aggregationchannel").First().Value;

                    return(new RawPropertyResponse(value));
                }

                throw new NotImplementedException($"Don't know how to handle object property '{components["name"]}'");

            case nameof(HtmlFunction.ChannelEdit):
                return(new ChannelResponse(new ChannelItem()));

            default:
                throw GetUnknownFunctionException(function);
            }
        }
Exemplo n.º 2
0
        internal static T GetObjectProperties <T>(string response)
        {
            var xml  = ObjectSettings.GetXml(response);
            var xDoc = new XDocument(xml);

            var items = XmlDeserializer <T> .DeserializeType(xDoc);

            return(items);
        }
Exemplo n.º 3
0
        private string CleanResponse(string response)
        {
            response = Regex.Replace(response, ObjectSettings.basicMatchRegex, string.Empty, RegexOptions.Singleline);
            response = Regex.Replace(response, ObjectSettings.backwardsMatchRegex, string.Empty, RegexOptions.Singleline);
            response = Regex.Replace(response, ObjectSettings.textAreaRegex, string.Empty, RegexOptions.Singleline);
            response = Regex.Replace(response, ObjectSettings.dropDownListRegex, string.Empty, RegexOptions.Singleline);
            response = Regex.Replace(response, ObjectSettings.dependencyDiv, string.Empty, RegexOptions.Singleline);

            var xml = ObjectSettings.GetXml(new Request.PrtgResponse(response, false));

            var descendents = xml.Descendants().ToList();

            Assert.AreEqual(0, descendents.Count, string.Join(", ", descendents.Select(d => d.Name)));

            return(response);
        }
Exemplo n.º 4
0
        internal static T GetObjectProperties <T>(PrtgResponse response, XmlEngine xmlEngine, ObjectProperty mandatoryProperty)
        {
            var xml  = ObjectSettings.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 = ObjectSettings.prefix + ObjectPropertyParser.GetObjectPropertyName(mandatoryProperty).TrimEnd('_');

            if (xDoc.Descendants(name).ToList().Count > 0)
            {
                var items = xmlEngine.DeserializeObject <T>(xDoc.CreateReader());

                return(items);
            }

            return(default(T));
        }