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"));
        }
Пример #3
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();
        }
Пример #4
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();
        }
        public Task Handle(GetWeatherRequest message, IMessageHandlerContext context)
        {
            // get location key
            string apikey   = "LcQxhKGWz5UNzaqEUuASyKJk0HHLxfYv";
            string apikey2  = "oLbX3UBxvo3G7zdA4q8AjtKr4RMG3MIV";
            string apikey3  = "5GkBfWDUle2KBTxdCHnP3AKVhmt9nUEH";
            string apikey4  = "ClB7bdIhjEr2kAAA928rGbRQfKCbHdOS";
            string city     = message.city;
            string province = message.province;
            string apiurl   = "http://dataservice.accuweather.com/locations/v1/cities/search?apikey=" + apikey2 + "&q=" + city + "%2C" +
                              province + "%2CCanada&language=en-ca&details=false&offset=1 HTTP/1.1";

            HttpResponseMessage httpresponse      = client.GetAsync(apiurl).Result;
            HttpContent         content           = httpresponse.Content;
            string             citysearchresponse = content.ReadAsStringAsync().Result;
            GetWeatherResponse response;

            // no city found
            if (citysearchresponse.Equals("[]"))
            {
                response = new GetWeatherResponse(false, "", new WeatherInfo());
            }
            else
            {
                string[] tokens      = citysearchresponse.Split('"');
                string   locationkey = tokens[5];
                // get weather info with location key
                apiurl = "http://dataservice.accuweather.com/currentconditions/v1/" + locationkey + "?apikey=" + apikey2 + "&language=en-ca&details=true";
                HttpResponseMessage  httpresponse2 = client.GetAsync(apiurl).Result;
                HttpContent          content2      = httpresponse2.Content;
                JavaScriptSerializer js            = new JavaScriptSerializer();
                WeatherInfo[]        weather       = js.Deserialize <WeatherInfo[]>(content2.ReadAsStringAsync().Result);
                response = new GetWeatherResponse(true, "", weather[0]);
            }
            return(context.Reply(response));

            // return context.Reply(new GetWeatherResponse(false, "", new WeatherInfo()));
        }
Пример #6
0
        public async Task <ActionResult <ZipGeoResponse> > GetZipGeo([FromQuery] string zipcode)
        {
            GetWeatherResponse weatherResponse = await _openWeatherMapApi.GetWeatherAsync(zipcode);

            if (!string.IsNullOrEmpty(weatherResponse.Message))
            {
                return(NotFound(weatherResponse));
            }

            Task <TimeZoneResponse>  timeZoneResponse  = _googleMapsApis.GetTimeZoneDataAsync(weatherResponse.Coord);
            Task <ElevationResponse> elevationResponse = _googleMapsApis.GetElevationDataAsync(weatherResponse.Coord);

            await Task.WhenAll(timeZoneResponse, elevationResponse);

            return(new ZipGeoResponse
            {
                ZipCode = zipcode,
                City = weatherResponse.Name,
                Temperature = weatherResponse.Main.Temp,
                TimeZoneName = timeZoneResponse.Result.TimeZoneName,
                Elevation = elevationResponse.Result.Results[0].Elevation.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"));
        }