コード例 #1
0
ファイル: App.xaml.cs プロジェクト: nrag/yapper
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            using (YapperDataContext locdb = new YapperDataContext())
            {
                if (locdb.DatabaseExists() == false)
                {
                    locdb.CreateDatabase();
                }
            }

            if (UserSettingsModel.Instance.IsAuthenticated())
            {
                DataSync.Instance.Sync();

                // kick off a background task to sync the conversation list from server
                // to phone and update the observable collection
                BackgroundWorker exceptionWorker = new BackgroundWorker();
                exceptionWorker.DoWork += this.UploadExceptions;
                exceptionWorker.RunWorkerAsync();

                BackgroundWorker unsentWorker = new BackgroundWorker();
                unsentWorker.DoWork += this.UploadUnsentMessages;
                unsentWorker.RunWorkerAsync();
            }
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: nrag/yapper
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            this.MergeCustomColors();

            // Phone-specific initialization
            InitializePhoneApplication();

            // Show graphics profiling information while debugging.
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Display the current frame rate counters.
                Application.Current.Host.Settings.EnableFrameRateCounter = true;

                // Show the areas of the app that are being redrawn in each frame.
                //Application.Current.Host.Settings.EnableRedrawRegions = true;

                // Enable non-production analysis visualization mode,
                // which shows areas of a page that are handed off to GPU with a colored overlay.
                //Application.Current.Host.Settings.EnableCacheVisualization = true;

                // Disable the application idle detection by setting the UserIdleDetectionMode property of the
                // application's PhoneApplicationService object to Disabled.
                // Caution:- Use this under debug mode only. Application that disables user idle detection will continue to run
                // and consume battery power when the user is not using the phone.
                PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            }

            // Create the data base here if it does not exist already
            using (YapperDataContext locdb = new YapperDataContext())
            {
                if (locdb.DatabaseExists() == false)
                {
                    locdb.CreateDatabase();

                    // Set the database version
                    DatabaseSchemaUpdater dbUpdater = locdb.CreateDatabaseSchemaUpdater();
                    dbUpdater.DatabaseSchemaVersion = YapperDataContext.DbVersion;
                    dbUpdater.Execute();
                }
                else
                {
                    // Check whether a database update is needed.
                    DatabaseSchemaUpdater dbUpdater = locdb.CreateDatabaseSchemaUpdater();

                    if (dbUpdater.DatabaseSchemaVersion < YapperDataContext.DbVersion)
                    {
                        int oldVersion = dbUpdater.DatabaseSchemaVersion;
                        for (int i = oldVersion + 1; i <= YapperDataContext.DbVersion; i++)
                        {
                            if (YapperDataContext.NewColumnsInVersion.ContainsKey(i))
                            {
                                Action <DatabaseSchemaUpdater> updater = YapperDataContext.NewColumnsInVersion[i];
                                updater(dbUpdater);
                            }
                        }

                        // Add the new database version.
                        dbUpdater.DatabaseSchemaVersion = YapperDataContext.DbVersion;

                        // Perform the database update in a single transaction.
                        dbUpdater.Execute();

                        // Post schema upgrade task
                        for (int i = oldVersion + 1; i <= YapperDataContext.DbVersion; i++)
                        {
                            if (YapperDataContext.PostDatabaseUpgradeOperation.ContainsKey(i))
                            {
                                Action updater = YapperDataContext.PostDatabaseUpgradeOperation[i];
                                updater();
                            }
                        }
                    }
                }
            }

            PhoneApplicationService.Current.Activated += Application_Activated;

            watcher = new Geolocator();
            watcher.MovementThreshold       = 100;
            watcher.DesiredAccuracy         = PositionAccuracy.High;
            watcher.DesiredAccuracyInMeters = 50;
        }