Пример #1
0
        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();
            });
        }
Пример #2
0
        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();
            });
        }