/// <summary>
        /// Deserialize XML from OpenWeatherMap
        /// </summary>
        /// <param name="file">File to deserialize</param>
        /// <returns>The Forecas object </returns>
        public static async Task <Weatherdata> GetForecast(StorageFile file)
        {
            Weatherdata   forecastFromXML = null;
            XmlSerializer serializer      = new XmlSerializer(typeof(Weatherdata));

            Stream stream = await file.OpenStreamForReadAsync().ConfigureAwait(false);

            forecastFromXML = (Weatherdata)serializer.Deserialize(stream);

            stream.Dispose();
            return(forecastFromXML);
        }
Пример #2
0
        private async void  OpenWeatherMap_onDownloadComplete(bool status)
        {
            if (status)
            {
                this.LastSuccessForecastDownload = DateTime.Now;
            }
            XMLDownloaded = status;

            /*
             * !!!!  Běží na vedlejším vlákně !!!!
             */


            XMLForecastAvailable = await OpenWeatherMap.IsOfflineXMLAvailable("forecast.xml");

            IsSomethingToShow = false;

            if (XMLForecastAvailable)
            {
                // Get forecast object;
                StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                StorageFile   XMLFile     = await localFolder.GetFileAsync("forecast.xml");

                this.Forecast = await OpenWeatherMap.GetForecast(XMLFile);

                if (this.Forecast.ForecasForNowAvailable)
                {
                    IsSomethingToShow  = true;
                    OldXMLForecastUsed = !status;
                }
            }


            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
                                      () =>
            {
                // Toto probehne na hlavnim vlakne
                ShowForecast(IsSomethingToShow);
            });
        }