public ActionResult DoQuery(QueryViewModel model) { try { QueryWeatherRequest request = new QueryWeatherRequest(); //request.GPSLocationInfo = gpsLocationInfo; request.WCCode = model.WCCode; request.QueryDateTime = DateTime.Now; QueryWeatherResponse response = QueryServices.GetWeatherInfo(request); response.CurrentDay.QueryDate = request.QueryDateTime.ToString("yyyy/MM/dd"); response.CurrentDay.AreaCode = model.AreaCode; response.CurrentDay.AreaName = CityAndAreaConfig.Instance.getAreaNameByAreaCode(model.AreaCode); response.CurrentDay.WCCode = model.WCCode; response.CurrentDay.CountryName = CityAndAreaConfig.Instance.getWCCountryNameByWCCode(model.WCCode); ViewBag.CurrentDay = response.CurrentDay; ViewBag.OtherDays = response.OthreDays; } catch (System.Exception ex) { return(View("Error")); } return(View("Result")); //return RedirectToAction("Result"); }
public JsonResult QueryWeatherInfo(string weatherCountyCode, string Date) { QueryWeatherRequest request = new QueryWeatherRequest(); request.WCCode = weatherCountyCode; QueryWeatherResponse response = QueryServices.GetWeatherInfo(request); return(Json(new { WeatherInfo = response, IsSuccess = true, Msg = "" })); }
public ActionResult DoQuery(QueryViewModel model) { try { if (model == null) { throw new ArgumentNullException("model"); } //GPSLocation gpsLocationInfo = GPSLocationService.GetClientGPSLocationInfo(); QueryWeatherRequest request = new QueryWeatherRequest(); //request.GPSLocationInfo = gpsLocationInfo; request.AreaCode = model.AreaCode; request.WCCode = model.WCCode; request.QueryDateTime = DateTime.Now; QueryWeatherResponse response = QueryServices.GetWeatherInfo(request); response.CurrentDay.QueryDate = request.QueryDateTime.ToString("yyyy/MM/dd"); response.CurrentDay.AreaCode = model.AreaCode; response.CurrentDay.AreaName = CityAndAreaConfig.Instance.getAreaNameByAreaCode(model.AreaCode); response.CurrentDay.WCCode = model.WCCode; response.CurrentDay.CountryName = CityAndAreaConfig.Instance.getWCCountryNameByWCCode(model.WCCode); ViewBag.CurrentDay = response.CurrentDay; if (response == null || response.CurrentDay == null) { ViewData["NoData"] = "true"; return(View("Index")); } else { ViewData["NoData"] = "false"; return(View("Result")); } } catch (System.Net.WebException ex) { //ViewBag.ErrMsg = "網路斷線或遠端伺服器錯誤,請通知管理者"; ErrorPageModel errModel = new ErrorPageModel { ErrorTitle = "Network Error", ErrorMsg = "網路斷線或遠端伺服器錯誤,請通知管理者" }; return(View("Error", errModel)); } catch (System.Exception ex) { return(View("Error")); } //return RedirectToAction("Result"); }
public void GetWeatherInfo_Null_Test() { QueryServices.GetWeatherInfo(null); }
static void Main(string[] args) { DateTime starttime; DateTime endtime; TimeSpan spentime; int index = 1; List <WCCountry> wccountries = CityAndAreaConfig.Instance.getWCCountryList(); try { Console.WriteLine("=============================================================================="); starttime = DateTime.Now; Console.WriteLine(string.Format("Program start : Time =>{0}", starttime.ToString("yyyy/MM/dd HH:mm:ss"))); Console.WriteLine("=============================================================================="); foreach (var item in wccountries) { Console.WriteLine(""); Console.WriteLine("=============================================================================="); Console.WriteLine(string.Format("Index = {0} , WCCode = {1} , AreaName = {2} , Name ={3}", index, item.WCCode, CityAndAreaConfig.Instance.getAreaNameByAreaCode(item.AreaCode), item.Name)); QueryWeatherRequest request = new QueryWeatherRequest { WCCode = item.WCCode, AreaCode = item.AreaCode }; QueryWeatherResponse response = QueryServices.GetWeatherInfo(request); if (response != null && response.CurrentDay != null) { Console.WriteLine(string.Format("天氣狀況:{0} , 地點:{1} , 溫度:{2} , 舒適度:{3} , 溫度範圍:{4} ~ {5} , 濕度:{6} , 風速:{7} , 觀測時間:{8}" , response.CurrentDay.WeatherStatus , CityAndAreaConfig.Instance.getAreaNameByAreaCode(item.AreaCode) + " - " + CityAndAreaConfig.Instance.getWCCountryNameByWCCode(item.WCCode) , response.CurrentDay.Temperature , response.CurrentDay.Feelslike , response.CurrentDay.Low , response.CurrentDay.High , response.CurrentDay.Humidity , response.CurrentDay.Windspeed , response.CurrentDay.Observationtime )); WeatherDataDAO.NewWeatherData(response.CurrentDay); //WeatherDataDAO.AddForeseeWeatherData(response.OthreDays); } index++; Console.WriteLine("=============================================================================="); } Console.WriteLine(""); Console.WriteLine("=============================================================================="); endtime = DateTime.Now; Console.WriteLine(string.Format("Program End : Time =>{0}", endtime.ToString("yyyy/MM/dd HH:mm:ss"))); spentime = endtime - starttime; Console.WriteLine("Count : {0} , Spend Time:{1} 分 {2} 秒", index, spentime.Minutes, spentime.Seconds); Console.WriteLine("=============================================================================="); } catch (System.Exception ex) { Console.WriteLine(string.Format("System Error : {0}", ex.ToString())); } }