/*-------------------------------------------------------------------------------*/ public void Get72HrForecast() { String uri = XML_FOLDER + Utils.GetXmlFileName(Navigation.ForecastCity, XML_72HR_POSTFIX); ForecastDownloader forecastDownloader = new ForecastDownloader(); forecastDownloader.DownloadStringCompleted += ((sender, e) => { if (e.Error != null) { if (e.Error.Message == WeatherForecast.Util.DownloadStringCompletedEventArgs.NETWORK_UNAVAILABLE) { Load72HrForecastData(); } } else if (e.Result == null) { Load72HrForecastData(); } else { Utils.saveXML(Utils.GetXmlFileName(Navigation.ForecastCity, XML_72HR_POSTFIX), e.Result); Load72HrForecastData(); TileUpdateWorker tileUpdateWorker = new TileUpdateWorker(); tileUpdateWorker.UpdateFromXml(); } }); forecastDownloader.DownloadStringAsync(new Uri(uri, UriKind.Absolute)); /* if (NetworkInterface.GetIsNetworkAvailable()) * { * try * { * WebClient downloader = new WebClient(); * //Uri rssUri = new Uri(XML_FOLDER + XML_WEEKDAY, UriKind.Absolute); * String uri = ""; * if (Navigation.ForecastCity.ID.StartsWith("630")) * uri = XML_FOLDER + GetXmlFileName(XML_72HR_POSTFIX); * else * uri = XML_FOLDER + GetXmlFileName(XML_72HR_POSTFIX); * Uri rssUri = new Uri(uri, UriKind.Absolute); * downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(On72HrForecastDownloaded); * downloader.DownloadStringAsync(rssUri); * } * catch (Exception ex) * { * MessageBox.Show("無法下載最新的天氣資訊!請檢查網路連線。"); * Load72HrForecastData(); * } * } * else * { * MessageBox.Show("無法下載最新的天氣資訊!請檢查網路連線。"); * Load72HrForecastData(); * }*/ }
public void GetLatestForecast() { //String uri = XML_FOLDER + Utils.GetXmlFileName(mForecastTown, XML_72HR_POSTFIX); String uri = XML_FOLDER + Utils.GetXmlFileName(mForecastTown, XML_WEEKDAY_POSTFIX); ForecastDownloader forecastDownloader = new ForecastDownloader(); forecastDownloader.DownloadStringCompleted += ((sender, e) => { if (e.Error != null || e.Result == null) { } else { //Utils.saveXML(Utils.GetXmlFileName(mForecastTown, XML_72HR_POSTFIX), e.Result); Utils.saveXML(Utils.GetXmlFileName(mForecastTown, XML_WEEKDAY_POSTFIX), e.Result); UpdateFromXml(); } OnUpdateCompleted(); }); forecastDownloader.DownloadStringAsync(new Uri(uri, UriKind.Absolute)); }