public virtual void Initialize()
        {
            // Disable medium trust
            var transform = TransformWebConfig("Release");

            var assemblyPath = TestHelper.CurrentAssemblyDirectory;

            assemblyPath = Path.Combine(assemblyPath, @"..\..\..\Umbraco.Web.UI\");
            var webUiPath = Path.GetFullPath(new Uri(assemblyPath).LocalPath);

            var installedPackagesConfig = string.Format("{0}App_Data\\packages\\installed\\installedPackages.config", webUiPath);

            if (File.Exists(installedPackagesConfig))
            {
                File.Delete(installedPackagesConfig);
            }

            var databaseDataPath = string.Format(@"{0}\App_Data\Umbraco.sdf", webUiPath);
            var connectionString = string.Format(@"Data Source={0}", databaseDataPath);

            //Create the Sql CE database
            using (var engine = new SqlCeEngine(connectionString))
            {
                if (File.Exists(databaseDataPath) == false)
                {
                    engine.CreateDatabase();
                }
            }

            var syntaxProvider = new SqlCeSyntaxProvider();

            SqlSyntaxContext.SqlSyntaxProvider = syntaxProvider;

            _database = new UmbracoDatabase(connectionString, Constants.DatabaseProviders.SqlCe, Mock.Of <ILogger>());

            // First remove anything in the database
            var creation = new DatabaseSchemaCreation(_database, Mock.Of <ILogger>(), syntaxProvider);

            creation.UninstallDatabaseSchema();

            // Then populate it with fresh data
            _database.CreateDatabaseSchema(false);

            _database.Execute("UPDATE umbracoUser SET userName = '******', userPassword = '******', userEmail = 'none' WHERE id = 0"); // password: test

            // Recycle app pool so the new user can log in
            //var webConfigFilePath = string.Format(@"{0}\web.config", webUiPath);
            //File.SetLastWriteTime(webConfigFilePath, DateTime.Now);

            // Disable medium trust
            transform = TransformWebConfig("Release");

            Driver              = new FirefoxDriver();
            BaseUrl             = "http://localhost:61639/";
            _verificationErrors = new StringBuilder();
        }
Exemplo n.º 2
0
        public static void ConfigureDatabase()
        {
            var installer = new SqlCEInstaller(new SqlCEHelper(ConnectionString));

            if (installer.CanConnect)
            {
                UmbracoDatabase umbracoDatabase = new UmbracoDatabase(ConnectionString, ProviderName);
                umbracoDatabase.CreateDatabaseSchema();
            }
        }
Exemplo n.º 3
0
        internal Result CreateDatabaseSchemaAndDataOrUpgrade()
        {
            if (_configured == false || (string.IsNullOrEmpty(_connectionString) || string.IsNullOrEmpty(ProviderName)))
            {
                return(new Result
                {
                    Message =
                        "Database configuration is invalid. Please check that the entered database exists and that the provided username and password has write access to the database.",
                    Success = false,
                    Percentage = "10"
                });
            }

            try
            {
                LogHelper.Info <DatabaseContext>("Database configuration status: Started");

                var message = string.Empty;

                var database = new UmbracoDatabase(_connectionString, ProviderName);
                var supportsCaseInsensitiveQueries = SqlSyntaxContext.SqlSyntaxProvider.SupportsCaseInsensitiveQueries(database);
                if (supportsCaseInsensitiveQueries == false)
                {
                    message = "<p>&nbsp;</p><p>The database you're trying to use does not support case insensitive queries. <br />We currently do not support these types of databases.</p>" +
                              "<p>You can fix this by changing the following setting in your my.ini file in your MySQL installation directory:</p>" +
                              "<pre>lower_case_table_names=1</pre><br />" +
                              "<p>Note: Make sure to check with your hosting provider if they support case insensitive queries as well.</p>" +
                              "<p>For more technical information on case sensitivity in MySQL, have a look at " +
                              "<a href='http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html'>the documentation on the subject</a></p>";

                    return(new Result {
                        Message = message, Success = false, Percentage = "15"
                    });
                }
                else if (supportsCaseInsensitiveQueries == null)
                {
                    message = "<p>&nbsp;</p><p>Warning! Could not check if your database type supports case insensitive queries. <br />We currently do not support these databases that do not support case insensitive queries.</p>" +
                              "<p>You can check this by looking for the following setting in your my.ini file in your MySQL installation directory:</p>" +
                              "<pre>lower_case_table_names=1</pre><br />" +
                              "<p>Note: Make sure to check with your hosting provider if they support case insensitive queries as well.</p>" +
                              "<p>For more technical information on case sensitivity in MySQL, have a look at " +
                              "<a href='http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html'>the documentation on the subject</a></p>";
                }
                else
                {
                    if (SqlSyntaxContext.SqlSyntaxProvider.GetType() == typeof(MySqlSyntaxProvider))
                    {
                        message = "<p>&nbsp;</p><p>Congratulations, the database step ran successfully!</p>" +
                                  "<p>Note: You're using MySQL and the database instance you're connecting to seems to support case insensitive queries.</p>" +
                                  "<p>However, your hosting provider may not support this option. Umbraco does not currently support MySQL installs that do not support case insensitive queries</p>" +
                                  "<p>Make sure to check with your hosting provider if they support case insensitive queries as well.</p>" +
                                  "<p>They can check this by looking for the following setting in the my.ini file in their MySQL installation directory:</p>" +
                                  "<pre>lower_case_table_names=1</pre><br />" +
                                  "<p>For more technical information on case sensitivity in MySQL, have a look at " +
                                  "<a href='http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html'>the documentation on the subject</a></p>";
                    }
                }

                var schemaResult     = ValidateDatabaseSchema();
                var installedVersion = schemaResult.DetermineInstalledVersion();


                //If Configuration Status is empty and the determined version is "empty" its a new install - otherwise upgrade the existing
                if (string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus) && installedVersion.Equals(new Version(0, 0, 0)))
                {
                    database.CreateDatabaseSchema();
                    message = message + "<p>Installation completed!</p>";
                }
                else
                {
                    var configuredVersion = string.IsNullOrEmpty(GlobalSettings.ConfigurationStatus)
                                                ? installedVersion
                                                : new Version(GlobalSettings.ConfigurationStatus);
                    var targetVersion = UmbracoVersion.Current;
                    var runner        = new MigrationRunner(configuredVersion, targetVersion, GlobalSettings.UmbracoMigrationName);
                    var upgraded      = runner.Execute(database, true);
                    message = message + "<p>Upgrade completed!</p>";
                }

                //now that everything is done, we need to determine the version of SQL server that is executing

                LogHelper.Info <DatabaseContext>("Database configuration status: " + message);

                return(new Result {
                    Message = message, Success = true, Percentage = "100"
                });
            }
            catch (Exception ex)
            {
                LogHelper.Info <DatabaseContext>("Database configuration failed with the following error and stack trace: " + ex.Message + "\n" + ex.StackTrace);

                if (_result != null)
                {
                    LogHelper.Info <DatabaseContext>("The database schema validation produced the following summary: \n" + _result.GetSummary());
                }

                return(new Result
                {
                    Message =
                        "The database configuration failed with the following message: " + ex.Message +
                        "\n Please check log file for additional information (can be found in '/App_Data/Logs/UmbracoTraceLog.txt')",
                    Success = false,
                    Percentage = "90"
                });
            }
        }