コード例 #1
0
        // GET: Dashboard
        public ActionResult Index(string environment = null)
        {
            var node = MvcApplication.Configuration.GetNodeForEnviroment(environment);

            var restClient = new JsonClient(useISODates: true);
            var dashboard  = new Models.Dashboard
            {
                Info         = restClient.Get <DashboardInfo>($"http://{node.ClusterHost}/api/Status/GetDashboardInfo", useDefaultCredentials: true),
                Environment  = node.Name,
                Environments = MvcApplication.Configuration.Nodes.Select(c => c.Name).ToList()
            };

            ViewBag.EnvironmentApiRoot = new Uri($"http://{node.ClusterHost}");
            ViewBag.OndemandRoot       =
                string.IsNullOrEmpty(node.OndemandHost) ? null : new Uri($"http://{node.OndemandHost}");
            return(View(dashboard));
        }
コード例 #2
0
        private async Task <bool> ValidateRecaptcha(string?recaptchaResponse)
        {
            // skip validation if we don't enable recaptcha
            if ((_options.Recaptcha != null) && string.IsNullOrWhiteSpace(_options.Recaptcha.PrivateKey))
            {
                return(true);
            }
            else if ((_options.Recaptcha != null) && (string.IsNullOrEmpty(recaptchaResponse) != false))
            {
                var requestUrl = new Uri(
                    $"https://www.google.com/recaptcha/api/siteverify?secret={_options.Recaptcha.PrivateKey}&response={recaptchaResponse}");
                var validationResponse = await JsonClient.Get <Dictionary <string, object> >(requestUrl)
                                         .ConfigureAwait(false);

                return(Convert.ToBoolean(validationResponse["success"], System.Globalization.CultureInfo.InvariantCulture));
            }
            return(false);
        }
コード例 #3
0
        public async Task ThrowGetErrorTest()
        {
            await Task.Delay(10);

            Assert.ThrowsAsync <HttpRequestException>(async() =>
            {
                await JsonClient.GetString(_defaultHttp);
            });

            Assert.ThrowsAsync <HttpRequestException>(async() =>
            {
                await JsonClient.Get <BasicJson>(_defaultHttp);
            });

            Assert.ThrowsAsync <HttpRequestException>(async() =>
            {
                await JsonClient.GetBinary(_defaultHttp);
            });
        }
コード例 #4
0
        private List <TimeSeriesPoint> GetObservations40(TimeSeriesDescription timeSeriesDescription, DateTimeOffset startTime, DateTimeOffset endTime)
        {
            var request = new GetObservationRequest40
            {
                ObservedProperty =
                    CreateObservedPropertyName(timeSeriesDescription.Parameter, timeSeriesDescription.Label),
                FeatureOfInterest = CreateFeatureOfInterestId(timeSeriesDescription.LocationIdentifier),
                TemporalFilter    = CreateTemporalFilter(startTime, endTime)
            };

            var response = JsonClient.Get(request);

            ThrowIfSosException(response);
            if (response == null)
            {
                return(new List <TimeSeriesPoint>());
            }

            var observation = response
                              .Observations
                              ?.FirstOrDefault();

            if (observation?.Result?.Values == null)
            {
                return(new List <TimeSeriesPoint>());
            }

            return(observation
                   .Result
                   .Values
                   .Select(p => new TimeSeriesPoint
            {
                Timestamp = new StatisticalDateTimeOffset
                {
                    DateTimeOffset = DateTimeOffset.Parse(p[0])
                },
                Value = new DoubleWithDisplay
                {
                    Numeric = double.Parse(p[1])
                }
            })
                   .ToList());
        }
コード例 #5
0
        private async Task <bool> ValidateRecaptcha(string recaptchaResponse)
        {
            _logger.Information("START PasswordController.ValidateRecaptcha: ");
            // skip validation if we don't enable recaptcha
            if (string.IsNullOrWhiteSpace(_options.ReCaptcha.PrivateKey))
            {
                return(true);
            }

            // immediately return false because we don't
            if (string.IsNullOrEmpty(recaptchaResponse))
            {
                return(false);
            }

            var requestUrl = new Uri(
                $"https://www.google.com/recaptcha/api/siteverify?secret={_options.ReCaptcha.PrivateKey}&response={recaptchaResponse}");

            var validationResponse = await JsonClient.Get <Dictionary <string, object> >(requestUrl)
                                     .ConfigureAwait(false);

            return(Convert.ToBoolean(validationResponse["success"], System.Globalization.CultureInfo.InvariantCulture));
        }
コード例 #6
0
        public static string Get()
        {
            try
            {
                var apiUrl = "https://baconipsum.com/api?type=all-meat&paras=1&start-with-lorem=0&format=text";
                var ipsum  = JsonClient.Get(apiUrl);

                if (ipsum == null)
                {
                    throw new InvalidOperationException("Unable to get bacon ipsum!");
                }

                return(ipsum.ToString());
            }
            catch (Exception ex) // [TODO] improve console logging
            {
                Console.BackgroundColor = ConsoleColor.DarkRed;
                Console.WriteLine($"Error occurred: {ex.ToExceptionMessage()}");
                Console.BackgroundColor = ConsoleColor.Black;

                throw ex;
            }
        }
コード例 #7
0
        public async Task WithValidParams_ReturnsTrue()
        {
            var basicJson = await JsonClient.Get <BasicJson>(new Uri($"{DefaultHttp}{Api}/WithValidParams"));

            Assert.IsNotNull(basicJson);
        }
コード例 #8
0
 public void WithNullUrl_ThrowsArgumentNullException()
 {
     Assert.ThrowsAsync <ArgumentNullException>(async() =>
                                                await JsonClient.Get <BasicJson>(null));
 }