private ServiceBusResponse getWeather(GetWeatherRequest getWeatherRequest)
        {
            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("Weather");
            return(requestingEndpoint.Request <ServiceBusResponse>(getWeatherRequest, sendOptions).ConfigureAwait(false).GetAwaiter().GetResult());
        }
示例#2
0
        public List <WeatherInformation> WeatherGet(string zipCode, bool metricSystem)
        {
            var request  = new GetWeatherRequest(zipCode, metricSystem);
            var response = ExecuteRequest <GetWeatherRequest, GetWeatherResponse>(request, nameof(WeatherGet));

            return(response.Information);
        }
        public GetWeatherRespose GetWeather(GetWeatherRequest req)
        {
            var resp = new GetWeatherRespose();
            var r    = new Random();

            int celsius = r.Next(-20, 50);

            if (req.TemperatureType == TemperatureType.Celsius)
            {
                resp.Temperature = celsius;
            }
            else
            {
                resp.Temperature = (212 - 32) / 100 * celsius + 32;
            }

            if (req.City == "Redmond")
            {
                resp.Condition = TemperatureCondition.Rainy;
            }
            else
            {
                resp.Condition = (TemperatureCondition)r.Next(0, 3);
            }

            return(resp);
        }
示例#4
0
 public GetWeatherResponse GetWeather(GetWeatherRequest request)
 {
     if (request.Date.HasValue)
     {
         var weather = DataContext.Weathers.Include(x => x.Value).FirstOrDefault(x => x.Date == request.Date.Value);
         if (weather != null)
         {
             var resp = weather.MapTo <GetWeatherResponse>();
             resp.ValueId = weather.Value.Id;
             return(resp);
         }
         return(new GetWeatherResponse());
     }
     else
     {
         if (request.ByDate)
         {
             var weather = DataContext.Weathers.Include(x => x.Value).OrderByDescending(x => x.Date).FirstOrDefault();
             if (weather != null)
             {
                 var resp = weather.MapTo <GetWeatherResponse>();
                 resp.ValueId = weather.Value.Id;
                 return(resp);
             }
             return(new GetWeatherResponse());
         }
         else
         {
             var weather = DataContext.Weathers.Include(x => x.Value).FirstOrDefault(x => x.Id == request.Id);
             var resp    = weather.MapTo <GetWeatherResponse>();
             resp.ValueId = weather.Value.Id;
             return(resp);
         }
     }
 }
 public override Task <GetWeatherResponse> GetWeather(GetWeatherRequest request, ServerCallContext context)
 {
     return(Task.FromResult(new GetWeatherResponse
     {
         Message = "Hello " + request.Name,
         Languages = ""
     }));
 }
示例#6
0
        public async Task <GetWeatherResponse> GetWeather(GetWeatherRequest request)
        {
            var weatherItems = await OpenWeatherMapWebClient.GetWeatherItems(request);

            var googleTimeZones = await GoogleTimeZonesWebClient.GetTimeZones(weatherItems);

            return(await ResponseFactory.CreateGetWeatherResponse(weatherItems, googleTimeZones));
        }
示例#7
0
        List <WeatherItem> ResultGenerator(GetWeatherRequest request)
        {
            var metricSystemValue = request.MetricSystem ? MetricSystem.Imperial : MetricSystem.Metric;
            var searchResponse    = InternalClient.Instance.Search.GetByName(request.ZipCode, metricSystemValue);

            searchResponse.Wait(HttpClientTimeout);
            return(searchResponse.Result.List.GroupBy(item => item.City.Id)
                   .Select(groupByElement => groupByElement.First()).ToList());
        }
    public System.Threading.Tasks.Task <GetWeatherResponse> GetWeatherAsync(string CityName, string CountryName)
    {
        GetWeatherRequest inValue = new GetWeatherRequest();

        inValue.Body             = new GetWeatherRequestBody();
        inValue.Body.CityName    = CityName;
        inValue.Body.CountryName = CountryName;
        return(((GlobalWeatherSoap)(this)).GetWeatherAsync(inValue));
    }
    public string GetWeather(string CityName, string CountryName)
    {
        GetWeatherRequest inValue = new GetWeatherRequest();

        inValue.Body             = new GetWeatherRequestBody();
        inValue.Body.CityName    = CityName;
        inValue.Body.CountryName = CountryName;
        GetWeatherResponse retVal = ((GlobalWeatherSoap)(this)).GetWeather(inValue);

        return(retVal.Body.GetWeatherResult);
    }
        /// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName = id;

            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            ViewBag.CompanyInfo = infoResponse.companyInfo;

            GetWeatherRequest  weatherRequest  = new GetWeatherRequest(infoResponse.companyInfo.city, infoResponse.companyInfo.province);
            GetWeatherResponse weatherResponse = connection.getWeather(weatherRequest);

            ViewBag.foundWeather = weatherResponse.result;
            if (weatherResponse.result)
            {
                ViewBag.currentTemp = weatherResponse.weather.Temperature.Metric.Value;
                ViewBag.feelTemp    = weatherResponse.weather.RealFeelTemperature.Metric.Value;
                ViewBag.weatherText = weatherResponse.weather.WeatherText;
                WeatherIcon url = new WeatherIcon();
                ViewBag.weatherIconURL = url.weatherURL[weatherResponse.weather.WeatherIcon];
            }
            else
            {
                ViewBag.currentTemp = "N/A";
                ViewBag.feelTemp    = "N/A";
                ViewBag.weatherText = "N/A";
            }

            string            company        = ViewBag.CompanyName;
            GetReviewRequest  reviewRequest  = new GetReviewRequest(company);
            GetReviewResponse reviewResponse = connection.getCompanyReviews(reviewRequest);

            ViewBag.companyReviews = reviewResponse.reviews;

            return(View("DisplayCompany"));
        }
        public CityWeatherCondition GetCityWeatherCondition(string cityName, string countryName)
        {
            var request = new GetWeatherRequest(cityName, countryName);
            var citiesByCountryResult = _globalWeatherSoapClient.GetWeather(request).GetWeatherResult;

            if (citiesByCountryResult == "Data Not Found")
            {
                throw new GlobalWeatherDataNotFoundException();
            }
            XmlDocument xml = new XmlDocument();

            xml.LoadXml(citiesByCountryResult);
            return(new CityWeatherCondition());
        }
示例#12
0
文件: Form1.cs 项目: niuniuliu/CSharp
        private void OnGetWeather(object sender, EventArgs e)
        {
            var req = new GetWeatherRequest();
            if (radioButtonCelsius.Checked)
                req.TemperatureType = TemperatureType.Celsius;
            else
                req.TemperatureType = TemperatureType.Fahrenheit;
            req.City = textCity.Text;

            var client = new SampleServiceSoapClient();
            GetWeatherResponse resp = client.GetWeather(req);
            textWeatherCondition.Text = resp.Condition.ToString();
            textTemperature.Text = resp.Temperature.ToString();         
        }
示例#13
0
        public async Task <GetWeatherResponse> Get([FromQuery] GetWeatherRequest request)
        {
            var weatherResponse = await _weatherService.GetAsync(request.ZipCode, request.Units);

            var timeZoneResponse = await _timeZoneService.GetAsync(
                weatherResponse.coord.lon.ToString(),
                weatherResponse.coord.lat.ToString(),
                weatherResponse.dt.ToString());

            var result = _mapper.Map <GetWeatherResponse>(weatherResponse);

            result.TimeZone = timeZoneResponse.timeZoneName;

            return(result);
        }
示例#14
0
        private ServiceBusResponse getWeather(GetWeatherRequest request)
        {
            // check that the user is logged in.
            if (authenticated == false)
            {
                return(new ServiceBusResponse(false, "Error: You must be logged in to use the weather functionality."));
            }

            // This class indicates to the request function where
            SendOptions sendOptions = new SendOptions();

            sendOptions.SetDestination("Weather");

            return(requestingEndpoint.Request <ServiceBusResponse>(request, sendOptions).
                   ConfigureAwait(false).GetAwaiter().GetResult());
        }
示例#15
0
        private void buttonGetWeather_Click(object sender, EventArgs e)
        {
            var req = new GetWeatherRequest();

            if (radioButtonCelsius.Checked)
            {
                req.TemperatureType = TemperatureType.Celsius;
            }
            else
            {
                req.TemperatureType = TemperatureType.Fahrenheit;
            }
            req.City = textCity.Text;
            var client = new SampleServiceSoapClient();
            GetWeatherResponse resp = client.GetWeather(req);

            textWeatherCondition.Text = resp.Condition.ToString();
            textTemperature.Text      = resp.Temperature.ToString();
        }
        protected void OnGetWeather(object sender, EventArgs e)
        {
            var req = new GetWeatherRequest();

            if(RadioButtonCelsius.Checked) {
                req.TemperatureType = TemperatureType.Celsius;
            } else {
                req.TemperatureType = TemperatureType.Fahrenheit;

            }
            if( (textCity.Text != null) || (textCity.Text != String.Empty)){
                req.City = textCity.Text;

                var client = new WebServicesSample.SampleServiceSoapClient();
                GetWeatherResponse resp = client.GetWeather(req);

               textWeatherCondition.Text = resp.Condition.ToString();
               textTemperature.Text = resp.Temperature.ToString();
               }
        }
示例#17
0
        public IHttpActionResult WeatherByCity([FromUri] GetWeatherRequest model)
        {
            try
            {
                var result = weatherService.GetCurrentWeather(new GetWeatherModel
                {
                    City    = model.City,
                    Country = model.Country
                });
                if (result == null)
                {
                    return(NotFound());
                }
                return(Ok <CurrentWeatherResponseModel>(result));
            }

            catch (Exception ex)
            {
                return(InternalServerError());
            }
        }
示例#18
0
        private void btnGetWeather_Click(object sender, EventArgs e)
        {
            GetWeatherRequest req = new GetWeatherRequest();

            if (rabCelsius.Checked)
            {
                req.TemperatureType = TemperatureType.Celsius;
            }
            else
            {
                req.TemperatureType = TemperatureType.Fahrenheit;
            }

            req.City = txtCity.Text;

            SampleSvc.SampleServiceSoapClient svc = new SampleSvc.SampleServiceSoapClient();
            GetWeatherResponse resp = svc.GetWeature(req);

            txtTemperature.Text  = resp.Temperature.ToString();
            txtWeaCondition.Text = resp.Condition.ToString();
        }
        /// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName = id;
            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            if (infoResponse.result)
            {
                ViewBag.CheckReviews = true;
                ViewBag.CompanyInfo  = infoResponse.companyInfo;
                if (infoResponse.companyInfo.reviewList.reviews == null)
                {
                    ViewBag.CheckReviews = false;
                }
                else
                {
                    List <ReviewInstance> r     = infoResponse.companyInfo.reviewList.reviews;
                    string[] timestamp_readable = new string[r.Count];

                    for (int i = 0; i < timestamp_readable.Length; i++)
                    {
                        System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                        dtDateTime            = dtDateTime.AddSeconds(Convert.ToInt64(r[i].timestamp)).ToLocalTime();
                        timestamp_readable[i] = Convert.ToString(dtDateTime);
                    }
                    ViewBag.Timestamp = timestamp_readable;
                }
            }

            //Still assume location array is of one value.
            GetWeatherRequest weatherRequest = new GetWeatherRequest(new CompanyWeather {
                location = infoResponse.companyInfo.locations[0]
            });
            GetWeatherResponse weatherResponse = connection.getWeather(weatherRequest);

            if (!weatherResponse.result)
            {
                ViewBag.success = false;
            }
            else
            {
                ViewBag.success     = true;
                ViewBag.realFeel    = weatherResponse.companyWeather.realFeelTemperature;
                ViewBag.temp        = weatherResponse.companyWeather.temperature;
                ViewBag.weatherText = weatherResponse.companyWeather.weatherText;
            }

            return(View("DisplayCompany"));
        }
示例#20
0
 private void button2_Click(object sender, EventArgs e)
 {
     var req = new GetWeatherRequest();
 }
 GetWeatherResponse GlobalWeatherSoap.GetWeather(GetWeatherRequest request)
 {
     return(base.Channel.GetWeather(request));
 }
示例#22
0
 public async Task <HttpResponseMessage> GetData([FromBody] GetWeatherRequest request)
 {
     return(await ExecuteAction(request, Repository.GetWeather));
 }
示例#23
0
 public async Task <GetWeatherResponse> GetWeather(GetWeatherRequest request) =>
 await SendMessage <GetWeatherResponse>(request,
                                        Path.Combine("WeatherService", "GetWeather"), GetWeatherResponse.Parser);
 public GetWeatherResponse getWeather(GetWeatherRequest request)
 {
     send(request);
     return((GetWeatherResponse)readUntilEOF());
 }
 System.Threading.Tasks.Task <GetWeatherResponse> GlobalWeatherSoap.GetWeatherAsync(GetWeatherRequest request)
 {
     return(base.Channel.GetWeatherAsync(request));
 }
示例#26
0
 public async Task <List <WeatherItem> > GetWeatherItems(GetWeatherRequest request) => await AwaitTaskCreator.Create(request, ResultGenerator);
示例#27
0
 public async Task <GetWeatherResponse> GetWeather(GetWeatherRequest request)
 {
     _logger.LogInformation("[{Service}] [{Method}] [{TraceId}]", "gRPC API Gateway", "GetWeather",
                            Activity.Current.RootId);
     return(await _weatherClient.GetWeatherAsync(request));
 }