예제 #1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            taskDB = new TaskDataContext(TaskDataContext.DBConnectionString);
            this.DataContext = this;
        }
예제 #2
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;
            }

            #region create the xml file in the isostorage
            // Create the xml file to save the user task data.
            // Only create the xml root element.
            //var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
            //if (!appStorage.FileExists(fileName))
            //{
            //    XDocument taskXML = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("Tasks"));

            //    using (IsolatedStorageFileStream appStream = appStorage.OpenFile(fileName, System.IO.FileMode.OpenOrCreate))
            //    {
            //        using (StreamWriter sw = new StreamWriter(appStream))
            //        {
            //            taskXML.Save(sw);
            //        }
            //    }
            //}
            #endregion

            #region create the database if it does not exist
            // Create the database if it does not yet exist.
            using (TaskDataContext context = new TaskDataContext(TaskDataContext.DBConnectionString))
            {
                if (context.DatabaseExists() == false)
                {
                    // Create the database.
                    context.CreateDatabase();
                }
            }
            #endregion
        }