Esempio n. 1
0
        /// <summary>
        /// Initialize data storage for the application
        /// This is a static method since the basic storage location for the application must be configured before
        ///   a database context can be created.
        /// </summary>
        public static void Initialize()
        {
            // Set the root directory where the database file will be placed
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                // End-user install, create and use the application data directory for this user and application
                var appStoragePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                  "SoDotCash");

                // Create the directory if it does not exist
                if (!Directory.Exists(appStoragePath))
                {
                    Directory.CreateDirectory(appStoragePath);
                }

                AppDomain.CurrentDomain.SetData("DataDirectory", appStoragePath);
            }
            else
            {
                // Developer. Use the directory of the application executable
                AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ""));
            }


            // TODO: FIXME: For now we drop and recreate the database if the model changes.
            //   This is fine for development and demonstration purposes, but should be changed
            //   for long-term maintained production.
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges <SoCashDbContext>());

            // Open the database and perform necessary schema adjustments
            using (var dataService = new DataService())
            {
                dataService.InitializeDatabase();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initialize data storage for the application
        /// This is a static method since the basic storage location for the application must be configured before
        ///   a database context can be created.
        /// </summary>
        public static void Initialize()
        {
            // Set the root directory where the database file will be placed
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                // End-user install, create and use the application data directory for this user and application
                var appStoragePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                    "SoDotCash");

                // Create the directory if it does not exist
                if (!Directory.Exists(appStoragePath))
                    Directory.CreateDirectory(appStoragePath);

                AppDomain.CurrentDomain.SetData("DataDirectory", appStoragePath);
            }
            else
            {
                // Developer. Use the directory of the application executable
                AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ""));
            }

            // TODO: FIXME: For now we drop and recreate the database if the model changes.
            //   This is fine for development and demonstration purposes, but should be changed
            //   for long-term maintained production.
            Database.SetInitializer(new DropCreateDatabaseIfModelChanges<SoCashDbContext>());

            // Open the database and perform necessary schema adjustments
            using (var dataService = new DataService())
            {
                dataService.InitializeDatabase();
            }
        }