예제 #1
0
        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Global handler for uncaught exceptions.
            UnhandledException += Application_UnhandledException;

            // Standard Silverlight initialization
            InitializeComponent();

            // 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;
            }



            // Check version of app
            bool IsVersionChanged = false;

            if (_IsolatedStorageSettings.Contains("AppCurrentVersion"))
            {
                if (_IsolatedStorageSettings["AppCurrentVersion"].Equals(PhoneHelper.GetAppAttribute("Version")))
                {
                    Debug.WriteLine("Version hasn't changed"); // do nothing
                }
                else
                {
                    // App Version has changed
                    _IsolatedStorageSettings.Remove("AppCurrentVersion");
                    _IsolatedStorageSettings.Add("AppCurrentVersion", PhoneHelper.GetAppAttribute("Version"));
                    Debug.WriteLine("New Version");
                    IsVersionChanged = true;
                    Debug.WriteLine("App Current Version = " + _IsolatedStorageSettings["AppCurrentVersion"]);
                }
            }
            else
            {
                // add the Version setting
                _IsolatedStorageSettings.Add("AppCurrentVersion", PhoneHelper.GetAppAttribute("Version"));
                Debug.WriteLine("App Current Version = " + _IsolatedStorageSettings["AppCurrentVersion"]);
            }
            _IsolatedStorageSettings.Save();



            // Specify the local database connection string.
            string DBConnectionString = "Data Source=isostore:/Translator.sdf";

            // Create the database if it does not exist.
            using (TranslatorDataContext db = new TranslatorDataContext(DBConnectionString))
            {
#if (DEBUG)
                //         Debug.WriteLine("Deleting database db");
                //       db.DeleteDatabase();
#endif
                if (db.DatabaseExists() == false)
                {
                    // Create the local database.
                    Debug.WriteLine("Creating database");
                    db.CreateDatabase();
                    // Save categories to the database.
                    db.SubmitChanges();
                }
                else if (db.DatabaseExists() == true && IsVersionChanged == true)
                {
                    // rebuild the database for new version of app
                    Debug.WriteLine("Rebuilding database ");

                    // dont need to rebuild for version 1.4
                    //  db.DeleteDatabase();
                    //  db.CreateDatabase();
                }
            }

            // Create the ViewModel object.
            viewModel = new TranslatorViewModel(DBConnectionString);

            // Query the local database and load observable collections.
            viewModel.LoadCollectionsFromDatabase();

            #region Nuance setup
            this.ApplicationLifetimeObjects.Add(new XNAAsyncDispatcher(TimeSpan.FromMilliseconds(50)));
            #endregion
        }
예제 #2
0
 // Class constructor, create the data context object.
 public TranslatorViewModel(string translatorDBConnectionString)
 {
     translatorDB = new TranslatorDataContext(translatorDBConnectionString);
 }