コード例 #1
0
        public async Task<ActionResult> GetWeather(CancellationToken cancellationToken)
        {
            var serviceClient = new OWMServiceClient();
            serviceClient.SetSearchCriteriaStrategy(new SearchByCity("Veliko Turnovo, bg"));
            var task = serviceClient.GetWeatherAsync(
                OpenWeatherMapWebServiceClient.ResultType.Json, cancellationToken);
            await Task.WhenAll(task);

            return getJsonConentResult(task.Result.ToString());
        }
コード例 #2
0
        public async Task<ActionResult> ByIpHtml(CancellationToken cancellationToken)
        {
            var ipServiceClient = new FGIServiceClient();
            string ipAddress = getClientIp();
            var ipAddressTask = ipServiceClient.GetGeoIpInfoAsync(
                ipAddress, FreeGeoIpWebServiceClient.ResultType.Json,
                cancellationToken);
            await Task.WhenAll(ipAddressTask);

            var weatherServiceClient = new OWMServiceClient();
            weatherServiceClient.SetSearchCriteriaStrategy(
                new SearchByGeolocation(
                    ipAddressTask.Result.latitude,
                    ipAddressTask.Result.longitude
                    ));

            var weatherTask = weatherServiceClient.GetWeatherAsync(OpenWeatherMapWebServiceClient.ResultType.Html,
                cancellationToken);

            await Task.WhenAll(weatherTask);

            return Content(weatherTask.Result.ToString());
        }
コード例 #3
0
        public async Task<ActionResult> ByCityHtml(string cityName, CancellationToken cancellationToken)
        {
            var weatherServiceClient = new OWMServiceClient();
            weatherServiceClient.SetSearchCriteriaStrategy(
                new SearchByCity(cityName));

            var weatherTask = weatherServiceClient.GetWeatherAsync(OpenWeatherMapWebServiceClient.ResultType.Html,
                cancellationToken);

            await Task.WhenAll(weatherTask);

            return Content(weatherTask.Result.ToString());
        }