コード例 #1
0
        private PrtgUrl(string server, string username, string passhash, string function, Parameters.Parameters parameters)
        {
            StringBuilder urlBuilder = new StringBuilder();

            urlBuilder.Append(AddUrlPrefix(server));

            urlBuilder.Append(function);

            foreach (var p in parameters.GetParameters())
            {
                AddParameter(urlBuilder, p.Key, p.Value);
            }

            if (!usernameFound)
            {
                AddParameter(urlBuilder, Parameter.Username, username);
            }

            if (!passFound)
            {
                if (passhash == null)
                {
                    throw new ArgumentNullException(nameof(passhash), $"A password or passhash must be specified. Please specify a passhash in the {nameof(passhash)} parameter, or a password or passhash in the {nameof(parameters)} parameter");
                }

                AddParameter(urlBuilder, Parameter.PassHash, passhash);
            }

            Url = urlBuilder.ToString();

#if DEBUG
            Debug.WriteLine(Url);
#endif
        }
コード例 #2
0
        private string GetCustomParameter(Parameters.Parameters parameters, string name)
        {
            var customParameters = ((List <CustomParameter>)parameters.GetParameters()[Parameter.Custom]);

            var targetParameter = customParameters.FirstOrDefault(p => p.Name == name);

            return(targetParameter?.Value?.ToString());
        }
コード例 #3
0
        public void Parameters_ReplacesCounterpart()
        {
            var parameters = new Parameters.Parameters
            {
                [Parameter.Password] = "password",
                [Parameter.PassHash] = "passhash"
            };

            Assert.AreEqual(1, parameters.GetParameters().Keys.Count);
            Assert.AreEqual(parameters[Parameter.PassHash], "passhash");
            Assert.AreEqual(null, parameters[Parameter.Password]);
        }