public void OnFirstStart() { // Load locally stored schedule XmlSerializer serializer = new XmlSerializer(typeof(schedule)); XDocument document = XDocument.Load("schedule.en.xml"); schedule tempschedule = (schedule)serializer.Deserialize(document.CreateReader()); IsolatedStorageFileHandler isfh = new IsolatedStorageFileHandler(); isfh.SaveSchedule(tempschedule); AppSettings.FirstStart = false; }
void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { ManualResetEvent CompletedNotifier = new ManualResetEvent(false); scheduleDownloader scheduleDownloader = new scheduleDownloader(); IsolatedStorageFileHandler isfh = new IsolatedStorageFileHandler(); if (scheduleDownloader.DownloadRequired && !AppSettings.FirstStart) { ManualResetEvent VersionCompletedNotifier = new ManualResetEvent(false); string scheduleVersion = AppSettings.ScheduleVersionDownloaded; scheduleDownloader.GetScheduleVersion((ex, version) => { if (ex != null) { this.Dispatcher.BeginInvoke(() => { MessageBox.Show("Schedule couldn't be retrieved!"); VersionCompletedNotifier.Set(); }); } else { scheduleVersion = version; VersionCompletedNotifier.Set(); } }); VersionCompletedNotifier.WaitOne(); if (AppSettings.ScheduleVersionDownloaded != scheduleVersion) { scheduleDownloader.Download((ex2, _schedule) => { if (ex2 != null) { this.Dispatcher.BeginInvoke(() => { MessageBox.Show("Schedule couldn't be retrieved!"); CompletedNotifier.Set(); return; }); } else { try { this.Dispatcher.BeginInvoke(() => { isfh.SaveSchedule(_schedule); AppSettings.LastTimeDownloaded = DateTime.Now; AppSettings.ScheduleVersionDownloaded = scheduleVersion; CompletedNotifier.Set(); }); } catch { this.Dispatcher.BeginInvoke(() => { MessageBox.Show("Schedule couldn't be retrieved!"); CompletedNotifier.Set(); }); } } }); CompletedNotifier.WaitOne(); } } this.Dispatcher.BeginInvoke(() => { if (AppSettings.FirstStart == true) this.OnFirstStart(); (App.Current as App).schedule = isfh.GetSchedule(); setDataContexts(); }); }