public void OnFirstStart() { // Load locally stored schedule XmlSerializer serializer = new XmlSerializer(typeof(schedule)); XDocument document = XDocument.Load("scheduleModel/schedule.en.xml"); schedule tempschedule = (schedule)serializer.Deserialize(document.CreateReader()); tempschedule.Clean(); IsolatedStorageFileHandler isfh = new IsolatedStorageFileHandler(); isfh.SaveSchedule(tempschedule); AppSettings.ScheduleVersionDownloaded = tempschedule.Version; 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 = _schedule.Version; 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(); }); }
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 = _schedule.Version; 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(); }); }