Exemplo n.º 1
0
        private static void ImportObject(string packagePath, string userName)
        {
            string objectType = "";
            int    objectID   = 0;

            SiteImportSettings settings = new SiteImportSettings(UserInfoProvider.GetUserInfo(userName));

            settings.UseAutomaticSiteForTranslation = true;
            settings.LogSynchronization             = true;
            settings.WebsitePath    = SystemContext.WebApplicationPhysicalPath;
            settings.SourceFilePath = packagePath;

            var obj = ObjectSelections(objectType);

            var importObj = SingleObjectSelection(objectID, obj);

            if (importObj.ObjectSiteID > 0)
            {
                settings.SiteId            = importObj.ObjectSiteID;
                settings.ExistingSite      = true;
                settings.SiteIsContentOnly = settings.SiteInfo.SiteIsContentOnly;

                // Do not update site definition when restoring a single object
                settings.SetSettings(ImportExportHelper.SETTINGS_UPDATE_SITE_DEFINITION, false);
            }

            ImportProvider.CreateTemporaryFiles(settings);

            settings.LoadDefaultSelection();

            ImportProvider.ImportObjectsData(settings);
        }
    private void btnRestore_Click(object sender, EventArgs e)
    {
        if (!String.IsNullOrEmpty(lstImports.SelectedValue))
        {
            siteObject = (exportObj.ObjectSiteID > 0);

            // Prepare the settings
            ImportSettings = new SiteImportSettings(MembershipContext.AuthenticatedUser);

            ImportSettings.UseAutomaticSiteForTranslation = true;
            ImportSettings.LogSynchronization             = true;
            ImportSettings.WebsitePath    = Server.MapPath("~/");
            ImportSettings.SourceFilePath = GetSelectedFilePath();

            if (siteObject)
            {
                ImportSettings.SiteId            = exportObj.ObjectSiteID;
                ImportSettings.ExistingSite      = true;
                ImportSettings.SiteIsContentOnly = ImportSettings.SiteInfo.SiteIsContentOnly;

                // Do not update site definition when restoring a single object
                ImportSettings.SetSettings(ImportExportHelper.SETTINGS_UPDATE_SITE_DEFINITION, false);
            }

            // Set the filename
            lblProgress.Text = string.Format(GetString("RestoreObject.RestoreProgress"), exportObjectDisplayName);

            pnlDetails.Visible  = false;
            btnRestore.Enabled  = false;
            pnlProgress.Visible = true;

            try
            {
                // Export the data
                ScriptHelper.RegisterStartupScript(this, typeof(string), "StartTimer", "StartTimer();", true);
                ucAsyncControl.RunAsync(RestoreSingleObject, WindowsIdentity.GetCurrent());
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
        }
    }
Exemplo n.º 3
0
    protected void btnHiddenNext_onClick(object sender, EventArgs e)
    {
        StepOperation = 1;
        StepIndex++;

        switch (wzdInstaller.ActiveStepIndex)
        {
            case 0:
                ViewState["install.password"] = txtDBPassword.Text.Trim();

                // Set the authentication type
                authenticationType = radWindowsAuthentication.Checked ? SQLServerAuthenticationModeEnum.WindowsAuthentication : SQLServerAuthenticationModeEnum.SQLServerAuthentication;

                // Check the server name
                if (txtServerName.Text.Trim() == "")
                {
                    HandleError(ResHelper.GetFileString("Install.ErrorServerEmpty"));
                    return;
                }
                // Check if it is possible to connect to the database
                string res = ConnectionHelper.TestConnection(authenticationType, txtServerName.Text.Trim(), "", txtDBUsername.Text.Trim(), ViewState["install.password"].ToString());
                if (!string.IsNullOrEmpty(res))
                {
                    HandleError(res, "Install.ErrorSqlTroubleshoot", "SQLError");
                    return;
                }
                else
                {
                    wzdInstaller.ActiveStepIndex = 1;
                }
                break;

            case 1:
            case 8:
                // Get database name
                Database = TextHelper.LimitLength((radCreateNew.Checked ? txtNewDatabaseName.Text.Trim() : txtExistingDatabaseName.Text.Trim()), 100);

                // Set up the connection string
                if (SqlHelperClass.IsConnectionStringInitialized)
                {
                    ConnectionString = SqlHelperClass.ConnectionString;
                }
                else
                {
                    ConnectionString = ConnectionHelper.GetConnectionString(authenticationType, txtServerName.Text.Trim(), Database, txtDBUsername.Text.Trim(), ViewState["install.password"].ToString(), 240, false);
                }

                if (Database == "")
                {
                    HandleError(ResHelper.GetFileString("Install.ErrorDBNameEmpty"));
                    return;
                }

                // Check if existing DB has the same version as currently installed CMS
                if (radUseExisting.Checked && !chkCreateDatabaseObjects.Checked)
                {
                    string dbVersion = null;
                    try
                    {
                        dbVersion = CMSDatabaseHelper.GetDatabaseVersion(ConnectionString);
                    }
                    catch
                    {
                    }

                    if (String.IsNullOrEmpty(dbVersion))
                    {
                        // Unable to get DB version => DB objects missing
                        HandleError(ResHelper.GetFileString("Install.DBObjectsMissing"));
                        return;
                    }

                    if (dbVersion != CMSContext.SYSTEM_VERSION)
                    {
                        // Get wrong version number
                        HandleError(ResHelper.GetFileString("Install.WrongDBVersion"));
                        return;
                    }
                }

                string dbCollation = null;
                string dbSchema = "dbo";
                if (hdnAdvanced.Value == "1")
                {
                    dbSchema = txtSchema.Text;
                }

                InstallInfo.DBSchema = dbSchema;

                // Use existing database
                if (radUseExisting.Checked)
                {
                    // Check if DB exists
                    if (!ConnectionHelper.DatabaseExists(ConnectionString))
                    {
                        HandleError(string.Format(ResHelper.GetFileString("Install.ErrorDatabseDoesntExist"), Database));
                        return;
                    }

                    // Check if DB schema exists
                    if (!CMSDatabaseHelper.CheckIfSchemaExist(ConnectionString, dbSchema))
                    {
                        HandleError(string.Format(ResHelper.GetFileString("Install.ErrorDatabseSchemaDoesnotExist"), dbSchema, CMSDatabaseHelper.GetCurrentDefaultSchema(ConnectionString)));
                        return;
                    }

                    // Check if DB is in correct version

                    // Get collation of existing DB
                    string collation = ConnectionHelper.GetDatabaseCollation(ConnectionString);
                    if (String.IsNullOrEmpty(dbCollation))
                    {
                        dbCollation = collation;
                    }
                    ConnectionHelper.DatabaseCollation = collation;

                    if (wzdInstaller.ActiveStepIndex != 8)
                    {
                        // Check target database collation (ask the user if it is not fully supported)
                        if (String.Compare(dbCollation, COLLATION_CASE_INSENSITIVE, true) != 0)
                        {
                            lblCollation.Text = ResHelper.GetFileString("install.databasecollation");
                            rbLeaveCollation.Text = string.Format(ResHelper.GetFileString("install.leavecollation"), collation);
                            rbChangeCollationCI.Text = string.Format(ResHelper.GetFileString("install.changecollation"), COLLATION_CASE_INSENSITIVE);
                            wzdInstaller.ActiveStepIndex = 8;
                            return;
                        }
                        else
                        {
                            // Change collation if needed
                            if (String.Compare(dbCollation, collation, true) != 0)
                            {
                                ConnectionHelper.ChangeDatabaseCollation(ConnectionString, Database, dbCollation);
                            }
                        }
                    }
                    else
                    {
                        // Change database collation
                        if (!rbLeaveCollation.Checked)
                        {
                            if (rbChangeCollationCI.Checked)
                            {
                                ConnectionHelper.ChangeDatabaseCollation(ConnectionString, Database, COLLATION_CASE_INSENSITIVE);
                            }
                        }
                    }
                }
                else
                {
                    // Create a new database
                    if (!CreateDatabase(dbCollation))
                    {
                        HandleError(string.Format(ResHelper.GetFileString("Install.ErrorCreateDB"), txtNewDatabaseName.Text));
                        return;
                    }
                    else
                    {
                        txtExistingDatabaseName.Text = txtNewDatabaseName.Text;
                        radCreateNew.Checked = false;
                        radUseExisting.Checked = true;
                    }
                }

                if ((!AzureHelper.IsRunningOnAzure && writePermissions) || SqlHelperClass.IsConnectionStringInitialized)
                {
                    if (chkCreateDatabaseObjects.Checked)
                    {
                        if (DBInstalled && DBCreated)
                        {
                            ucDBAsyncControl.RaiseFinished(this, EventArgs.Empty);
                        }
                        else
                        {
                            InstallInfo.ScriptsFullPath = Server.MapPath("~/App_Data/Install/SQL");
                            InstallInfo.ConnectionString = ConnectionString;
                            InstallInfo.DBSchema = dbSchema;
                            InstallInfo.ClearLog();

                            ucDBAsyncControl.RunAsync(InstallDatabase, WindowsIdentity.GetCurrent());

                            NextButton.Attributes.Add("disabled", "true");
                            PreviousButton.Attributes.Add("disabled", "true");
                            wzdInstaller.ActiveStepIndex = 3;

                            ltlInstallScript.Text = ScriptHelper.GetScript("StartInstallStateTimer('DB');");
                        }
                    }
                    else
                    {
                        CreateDBObjects = false;

                        // Check the DB connection
                        pnlLog.Visible = false;

                        // Set connection string
                        if (SettingsHelper.SetConnectionString("CMSConnectionString", ConnectionString))
                        {
                            SqlHelperClass.ConnectionString = ConnectionString;

                            // If this is installation to existing BD and objects are not created
                            // Check if license key for current domain is present
                            LicenseKeyInfo lki = LicenseKeyInfoProvider.GetLicenseKeyInfo(hostName);
                            wzdInstaller.ActiveStepIndex = (lki == null) ? 4 : 5;
                            ucLicenseDialog.SetLicenseExpired();
                        }
                        else
                        {
                            string connStringDisplay = ConnectionHelper.GetConnectionString(authenticationType, txtServerName.Text.Trim(), Database, txtDBUsername.Text.Trim(), ViewState["install.password"].ToString(), 240, true);
                            wzdInstaller.ActiveStepIndex = 2;
                            string message = ResHelper.GetFileString("Install.ConnectionStringError") + " <br/><br/><strong>&lt;add name=\"CMSConnectionString\" connectionString=\"" + connStringDisplay + "\"/&gt;</strong><br/><br/>";
                            lblErrorConnMessage.Text = message;

                            // Show troubleshoot link
                            hlpTroubleshoot.Visible = true;
                            hlpTroubleshoot.TopicName = "DiskPermissions";
                            hlpTroubleshoot.Text = ResHelper.GetFileString("Install.ErrorPermissions");
                        }
                    }
                }
                else
                {
                    wzdInstaller.ActiveStepIndex = 2;
                    string message = string.Empty;
                    if (AzureHelper.IsRunningOnAzure)
                    {
                        string connStringValue = ConnectionHelper.GetConnectionString(authenticationType, txtServerName.Text.Trim(), Database, txtDBUsername.Text.Trim(), ViewState["install.password"].ToString(), "English", 240, true, true);
                        string connString = "&lt;add name=\"CMSConnectionString\" connectionString=\"" + connStringValue + "\"/&gt;";
                        string appSetting = "&lt;Setting name=\"CMSConnectionString\" value=\"" + connStringValue + "\"/&gt;";
                        message = string.Format(ResHelper.GetFileString("Install.ConnectionStringAzure"), connString, appSetting);
                    }
                    else
                    {
                        string connString = ConnectionHelper.GetConnectionString(authenticationType, txtServerName.Text.Trim(), Database, txtDBUsername.Text.Trim(), ViewState["install.password"].ToString(), 240, true);
                        message = ResHelper.GetFileString("Install.ConnectionStringError") + " <br/><br/><strong>&lt;add name=\"CMSConnectionString\" connectionString=\"" + connString + "\"/&gt;</strong><br/><br/>";

                        // Show troubleshoot link
                        hlpTroubleshoot.Visible = true;
                        hlpTroubleshoot.TopicName = "DiskPermissions";
                        hlpTroubleshoot.Text = ResHelper.GetFileString("Install.ErrorPermissions");
                    }

                    lblErrorConnMessage.Text = message;
                }

                break;

            // After DB install
            case 3:
                break;

            // After connection string save error
            case 2:
                //// Restart application to ensure connection string update
                //try
                //{
                //    // Try to restart applicatin by unload app domain
                //    HttpRuntime.UnloadAppDomain();
                //}
                //catch
                //{
                //}

                // If connectionstrings don't match
                if ((SettingsHelper.ConnectionStrings["CMSConnectionString"] == null) ||
                    (SettingsHelper.ConnectionStrings["CMSConnectionString"].ConnectionString == null) ||
                    (SettingsHelper.ConnectionStrings["CMSConnectionString"].ConnectionString.Trim() == "") ||
                    (SettingsHelper.ConnectionStrings["CMSConnectionString"].ConnectionString != ConnectionString))
                {
                    HandleError(ResHelper.GetFileString("Install.ErrorAddConnString"));
                    return;
                }
                else
                {
                    if (CreateDBObjects)
                    {
                        if (DBInstalled)
                        {
                            ucDBAsyncControl.RaiseFinished(this, EventArgs.Empty);
                        }
                        else
                        {
                            InstallInfo.ScriptsFullPath = Server.MapPath("~/App_Data/Install/SQL");
                            InstallInfo.ConnectionString = ConnectionString;
                            InstallInfo.DBSchema = InstallInfo.DBSchema;
                            InstallInfo.ClearLog();

                            ucDBAsyncControl.RunAsync(InstallDatabase, WindowsIdentity.GetCurrent());

                            NextButton.Attributes.Add("disabled", "true");
                            PreviousButton.Attributes.Add("disabled", "true");
                            wzdInstaller.ActiveStepIndex = 3;

                            ltlInstallScript.Text = ScriptHelper.GetScript("StartInstallStateTimer('DB');");
                        }
                    }
                    else
                    {
                        // If this is installation to existing DB and objects are not created
                        if ((hostName != "localhost") && (hostName != "127.0.0.1"))
                        {
                            wzdInstaller.ActiveStepIndex = 4;
                        }
                        else
                        {
                            wzdInstaller.ActiveStepIndex = 5;
                        }
                    }
                }
                break;

            // After license entering
            case 4:
                try
                {
                    if (ucLicenseDialog.Visible)
                    {
                        ucLicenseDialog.SetLicenseKey();
                        wzdInstaller.ActiveStepIndex = 5;
                    }
                    else
                    {
                        if (ucWagDialog.ProcessRegistration(ConnectionString))
                        {
                            wzdInstaller.ActiveStepIndex = 5;
                        }
                    }
                }
                catch (Exception ex)
                {
                    HandleError(ex.Message);
                    return;
                }
                break;

            // Site creation
            case 5:
                switch (ucSiteCreationDialog.CreationType)
                {
                    case CMSInstall_Controls_SiteCreationDialog.CreationTypeEnum.Template:
                        {
                            if (ucSiteCreationDialog.TemplateName == "")
                            {
                                HandleError(ResHelper.GetFileString("install.notemplate"));
                                return;
                            }

                            // Settings preparation
                            SiteImportSettings settings = new SiteImportSettings(ImportUser);
                            settings.ImportType = ImportTypeEnum.All;
                            settings.CopyFiles = false;
                            settings.EnableSearchTasks = false;

                            if (HttpContext.Current != null)
                            {
                                const string www = "www.";
                                if (hostName.StartsWith(www))
                                {
                                    hostName = hostName.Remove(0, www.Length);
                                }

                                if (!URLHelper.Url.IsDefaultPort)
                                {
                                    hostName += ":" + URLHelper.Url.Port;
                                }

                                settings.SiteDomain = hostName;
                                Domain = hostName;
                            }

                            // Create site
                            WebTemplateInfo ti = WebTemplateInfoProvider.GetWebTemplateInfo(ucSiteCreationDialog.TemplateName);
                            if (ti == null)
                            {
                                HandleError("[Install]: Template not found.");
                                return;
                            }

                            settings.SiteName = ti.WebTemplateName;
                            settings.SiteDisplayName = ti.WebTemplateDisplayName;

                            if (HttpContext.Current != null)
                            {
                                settings.SourceFilePath = HttpContext.Current.Server.MapPath(ti.WebTemplateFileName);
                                settings.WebsitePath = HttpContext.Current.Server.MapPath("~/");
                            }

                            settings.SetSettings(ImportExportHelper.SETTINGS_DELETE_SITE, true);
                            settings.SetSettings(ImportExportHelper.SETTINGS_DELETE_TEMPORARY_FILES, false);

                            SiteName = settings.SiteName;

                            // Init the Mimetype helper (required for the Import)
                            MimeTypeHelper.LoadMimeTypes();

                            // Import the site asynchronously
                            ImportManager.Settings = settings;

                            ucAsyncControl.RunAsync(ImportManager.Import, WindowsIdentity.GetCurrent());
                            NextButton.Attributes.Add("disabled", "true");
                            PreviousButton.Attributes.Add("disabled", "true");
                            wzdInstaller.ActiveStepIndex = 6;

                            ltlInstallScript.Text = ScriptHelper.GetScript("StartInstallStateTimer('IM');");
                        }
                        break;

                    // Else redirect to the site import
                    case CMSInstall_Controls_SiteCreationDialog.CreationTypeEnum.ExistingSite:
                        {
                            CMSContext.AuthenticateUser("administrator", false);
                            URLHelper.Redirect("~/cmssitemanager/default.aspx?section=sites&action=import");
                        }
                        break;

                    // Else redirect to the new site wizard
                    case CMSInstall_Controls_SiteCreationDialog.CreationTypeEnum.NewSiteWizard:
                        {
                            CMSContext.AuthenticateUser("administrator", false);
                            URLHelper.Redirect("~/cmssitemanager/default.aspx?section=sites&action=new");
                        }
                        break;
                }
                break;

            default:
                wzdInstaller.ActiveStepIndex++;
                break;
        }
    }
    protected void btnHiddenNext_onClick(object sender, EventArgs e)
    {
        StepOperation = 1;
        StepIndex++;

        switch (wzdInstaller.ActiveStepIndex)
        {
            case 0:
                Password = userServer.DBPassword;

                // Set the authentication type
                authenticationType = userServer.WindowsAuthenticationChecked ? SQLServerAuthenticationModeEnum.WindowsAuthentication : SQLServerAuthenticationModeEnum.SQLServerAuthentication;

                // Check the server name
                if (userServer.ServerName == String.Empty)
                {
                    HandleError(ResHelper.GetFileString("Install.ErrorServerEmpty"));
                    return;
                }

                // Check if it is possible to connect to the database
                string res = ConnectionHelper.TestConnection(authenticationType, userServer.ServerName, String.Empty, userServer.DBUsername, Password);
                if (!string.IsNullOrEmpty(res))
                {
                    HandleError(res, "Install.ErrorSqlTroubleshoot", HELP_TOPIC_SQL_ERROR_LINK);
                    return;
                }

                // Set credentials for the next step
                databaseDialog.AuthenticationType = authenticationType;
                databaseDialog.Password = Password;
                databaseDialog.Username = userServer.DBUsername;
                databaseDialog.ServerName = userServer.ServerName;

                // Move to the next step
                wzdInstaller.ActiveStepIndex = 1;
                break;

            case 1:
            case 8:
                // Get database name
                Database = TextHelper.LimitLength((databaseDialog.CreateNewChecked ? databaseDialog.NewDatabaseName : databaseDialog.ExistingDatabaseName), 100);

                if (string.IsNullOrEmpty(Database))
                {
                    HandleError(ResHelper.GetFileString("Install.ErrorDBNameEmpty"));
                    return;
                }

                // Set up the connection string
                if (ConnectionHelper.IsConnectionStringInitialized)
                {
                    ConnectionString = ConnectionHelper.ConnectionString;
                }
                else
                {
                    ConnectionString = ConnectionHelper.GetConnectionString(authenticationType, userServer.ServerName, Database, userServer.DBUsername, Password, SqlInstallationHelper.DB_CONNECTION_TIMEOUT, false);
                }

                // Check if existing DB has the same version as currently installed CMS
                if (databaseDialog.UseExistingChecked && !databaseDialog.CreateDatabaseObjects)
                {
                    string dbVersion = null;
                    try
                    {
                        dbVersion = SqlInstallationHelper.GetDatabaseVersion(ConnectionString);
                    }
                    catch
                    {
                    }

                    if (String.IsNullOrEmpty(dbVersion))
                    {
                        // Unable to get DB version => DB objects missing
                        HandleError(ResHelper.GetFileString("Install.DBObjectsMissing"));
                        return;
                    }

                    if (dbVersion != CMSVersion.MainVersion)
                    {
                        // Get wrong version number
                        HandleError(ResHelper.GetFileString("Install.WrongDBVersion"));
                        return;
                    }
                }

                // Set DB schema
                string dbSchema = null;
                if (hdnAdvanced.Value == "1")
                {
                    dbSchema = databaseDialog.SchemaText;
                }

                InstallInfo.DBSchema = dbSchema;

                // Use existing database
                if (databaseDialog.UseExistingChecked)
                {
                    // Check if DB exists
                    if (!DatabaseHelper.DatabaseExists(ConnectionString))
                    {
                        HandleError(string.Format(ResHelper.GetFileString("Install.ErrorDatabseDoesntExist"), Database));
                        return;
                    }

                    // Check if DB schema exists
                    if (!SqlInstallationHelper.CheckIfSchemaExist(ConnectionString, dbSchema))
                    {
                        HandleError(string.Format(ResHelper.GetFileString("Install.ErrorDatabseSchemaDoesnotExist"), dbSchema, SqlInstallationHelper.GetCurrentDefaultSchema(ConnectionString)));
                        return;
                    }

                    // Get collation of existing DB
                    string collation = DatabaseHelper.GetDatabaseCollation(ConnectionString);
                    string dbCollation = collation;
                    DatabaseHelper.DatabaseCollation = collation;

                    if (wzdInstaller.ActiveStepIndex != 8)
                    {
                        // Check target database collation (ask the user if it is not fully supported)
                        if (CMSString.Compare(dbCollation, COLLATION_CASE_INSENSITIVE, true) != 0)
                        {
                            lblCollation.Text = ResHelper.GetFileString("install.databasecollation");
                            rbLeaveCollation.Text = string.Format(ResHelper.GetFileString("install.leavecollation"), collation);
                            rbChangeCollationCI.Text = string.Format(ResHelper.GetFileString("install.changecollation"), COLLATION_CASE_INSENSITIVE);
                            wzdInstaller.ActiveStepIndex = 8;
                            return;
                        }
                    }
                    else
                    {
                        // Change database collation
                        if (!rbLeaveCollation.Checked)
                        {
                            if (rbChangeCollationCI.Checked)
                            {
                                DatabaseHelper.ChangeDatabaseCollation(ConnectionString, Database, COLLATION_CASE_INSENSITIVE);
                            }
                        }
                    }
                }
                else
                {
                    // Create a new database
                    if (!CreateDatabase(null))
                    {
                        HandleError(string.Format(ResHelper.GetFileString("Install.ErrorCreateDB"), databaseDialog.NewDatabaseName));
                        return;
                    }

                    databaseDialog.ExistingDatabaseName = databaseDialog.NewDatabaseName;
                    databaseDialog.CreateNewChecked = false;
                    databaseDialog.UseExistingChecked = true;
                }

                if ((!SystemContext.IsRunningOnAzure && writePermissions) || ConnectionHelper.IsConnectionStringInitialized)
                {
                    if (databaseDialog.CreateDatabaseObjects)
                    {
                        if (DBInstalled && DBCreated)
                        {
                            ucDBAsyncControl.RaiseFinished(this, EventArgs.Empty);
                        }
                        else
                        {
                            // Run SQL installation
                            RunSQLInstallation(dbSchema);
                        }
                    }
                    else
                    {
                        CreateDBObjects = false;

                        // Set connection string
                        if (SettingsHelper.SetConnectionString(ConnectionHelper.ConnectionStringName, ConnectionString))
                        {
                            // Set the application connection string
                            SetAppConnectionString();

                            // Check if license key for current domain is present
                            LicenseKeyInfo lki = LicenseKeyInfoProvider.GetLicenseKeyInfo(hostName);
                            wzdInstaller.ActiveStepIndex = (lki == null) ? 4 : 5;
                            ucLicenseDialog.SetLicenseExpired();
                        }
                        else
                        {
                            ManualConnectionStringInsertion();
                        }
                    }
                }
                else
                {
                    ManualConnectionStringInsertion();
                }

                break;

            // After connection string save error
            case 2:
                // If connection strings don't match
                if ((SettingsHelper.ConnectionStrings[ConnectionHelper.ConnectionStringName] == null) ||
                    (SettingsHelper.ConnectionStrings[ConnectionHelper.ConnectionStringName].ConnectionString == null) ||
                    (SettingsHelper.ConnectionStrings[ConnectionHelper.ConnectionStringName].ConnectionString.Trim() == "") ||
                    (SettingsHelper.ConnectionStrings[ConnectionHelper.ConnectionStringName].ConnectionString != ConnectionString))
                {
                    HandleError(ResHelper.GetFileString("Install.ErrorAddConnString"));
                    return;
                }

                if (CreateDBObjects)
                {
                    if (DBInstalled)
                    {
                        SetAppConnectionString();

                        // Continue with next step
                        CheckLicense();

                        RequestMetaFile();
                    }
                    else
                    {
                        // Run SQL installation
                        RunSQLInstallation(null);
                    }
                }
                else
                {
                    // If this is installation to existing DB and objects are not created
                    if ((hostName != "localhost") && (hostName != "127.0.0.1"))
                    {
                        wzdInstaller.ActiveStepIndex = 4;
                    }
                    else
                    {
                        wzdInstaller.ActiveStepIndex = 5;
                    }
                }
                break;

            // After DB install
            case 3:
                break;

            // After license entering
            case 4:
                try
                {
                    if (ucLicenseDialog.Visible)
                    {
                        ucLicenseDialog.SetLicenseKey();
                        wzdInstaller.ActiveStepIndex = 5;
                    }
                    else if (ucWagDialog.ProcessRegistration(ConnectionString))
                    {
                        wzdInstaller.ActiveStepIndex = 5;
                    }
                }
                catch (Exception ex)
                {
                    HandleError(ex.Message);
                }
                break;

            // Site creation
            case 5:
                switch (ucSiteCreationDialog.CreationType)
                {
                    case CMSInstall_Controls_WizardSteps_SiteCreationDialog.CreationTypeEnum.Template:
                        {
                            if (ucSiteCreationDialog.TemplateName == "")
                            {
                                HandleError(ResHelper.GetFileString("install.notemplate"));
                                return;
                            }

                            // Settings preparation
                            SiteImportSettings settings = new SiteImportSettings(ImportUser);
                            settings.IsWebTemplate = true;
                            settings.ImportType = ImportTypeEnum.AllNonConflicting;
                            settings.CopyFiles = false;
                            settings.EnableSearchTasks = false;
                            settings.CreateVersion = false;

                            if (HttpContext.Current != null)
                            {
                                const string www = "www.";
                                if (hostName.StartsWithCSafe(www))
                                {
                                    hostName = hostName.Remove(0, www.Length);
                                }

                                if (!RequestContext.URL.IsDefaultPort)
                                {
                                    hostName += ":" + RequestContext.URL.Port;
                                }

                                settings.SiteDomain = hostName;
                                Domain = hostName;
                            }

                            // Create site
                            WebTemplateInfo ti = WebTemplateInfoProvider.GetWebTemplateInfo(ucSiteCreationDialog.TemplateName);
                            if (ti == null)
                            {
                                HandleError("[Install]: Template not found.");
                                return;
                            }

                            settings.SiteName = ti.WebTemplateName;
                            settings.SiteDisplayName = ti.WebTemplateDisplayName;

                            if (HttpContext.Current != null)
                            {
                                string path = HttpContext.Current.Server.MapPath(ti.WebTemplateFileName);
                                if (File.Exists(path + "\\template.zip"))
                                {                                    // Template from zip file
                                    path += "\\" + ZipStorageProvider.GetZipFileName("template.zip");
                                    settings.TemporaryFilesPath = path;
                                    settings.SourceFilePath = path;
                                    settings.TemporaryFilesCreated = true;
                                }
                                else
                                {
                                    settings.SourceFilePath = path;
                                }
                                settings.WebsitePath = HttpContext.Current.Server.MapPath("~/");
                            }

                            settings.SetSettings(ImportExportHelper.SETTINGS_DELETE_SITE, true);
                            settings.SetSettings(ImportExportHelper.SETTINGS_DELETE_TEMPORARY_FILES, false);

                            SiteName = settings.SiteName;

                            // Init the Mimetype helper (required for the Import)
                            MimeTypeHelper.LoadMimeTypes();

                            // Import the site asynchronously
                            ImportManager.Settings = settings;

                            ucAsyncControl.RunAsync(ImportManager.Import, WindowsIdentity.GetCurrent());
                            NextButton.Attributes.Add("disabled", "true");
                            PreviousButton.Attributes.Add("disabled", "true");
                            wzdInstaller.ActiveStepIndex = 6;

                            ltlInstallScript.Text = ScriptHelper.GetScript("StartInstallStateTimer('IM');");
                        }
                        break;

                    // Else redirect to the site import
                    case CMSInstall_Controls_WizardSteps_SiteCreationDialog.CreationTypeEnum.ExistingSite:
                        {
                            AuthenticationHelper.AuthenticateUser("administrator", false);
                            URLHelper.Redirect(UIContextHelper.GetApplicationUrl("cms", "sites", "action=import"));
                        }
                        break;

                    // Else redirect to the new site wizard
                    case CMSInstall_Controls_WizardSteps_SiteCreationDialog.CreationTypeEnum.NewSiteWizard:
                        {
                            AuthenticationHelper.AuthenticateUser("administrator", false);
                            URLHelper.Redirect(UIContextHelper.GetApplicationUrl("cms", "sites", "action=new"));
                        }
                        break;
                }
                break;

            default:
                wzdInstaller.ActiveStepIndex++;
                break;
        }
    }
    private SiteImportSettings PrepareSettings(WebTemplateInfo ti)
    {
        // Settings preparation
        var settings = new SiteImportSettings(ImportUser);

        // Import all, but only add new data
        settings.ImportType = ImportTypeEnum.AllNonConflicting;
        settings.ImportOnlyNewObjects = true;
        settings.CopyFiles = false;

        // Allow bulk inserts for faster import, web templates must be consistent enough to allow this without collisions
        settings.AllowBulkInsert = true;

        settings.IsWebTemplate = true;
        settings.EnableSearchTasks = false;
        settings.CreateVersion = false;
        settings.SiteName = ti.WebTemplateName;
        settings.SiteDisplayName = ti.WebTemplateDisplayName;

        if (HttpContext.Current != null)
        {
            const string www = "www.";
            if (hostName.StartsWithCSafe(www))
            {
                hostName = hostName.Remove(0, www.Length);
            }

            if (!RequestContext.URL.IsDefaultPort)
            {
                hostName += ":" + RequestContext.URL.Port;
            }

            settings.SiteDomain = hostName;
            Domain = hostName;

            string path = HttpContext.Current.Server.MapPath(ti.WebTemplateFileName);
            if (File.Exists(path + "\\template.zip"))
            {
                // Template from zip file
                path += "\\" + ZipStorageProvider.GetZipFileName("template.zip");
                settings.TemporaryFilesPath = path;
                settings.SourceFilePath = path;
                settings.TemporaryFilesCreated = true;
            }
            else
            {
                settings.SourceFilePath = path;
            }

            settings.WebsitePath = HttpContext.Current.Server.MapPath("~/");
        }

        settings.SetSettings(ImportExportHelper.SETTINGS_DELETE_SITE, true);
        settings.SetSettings(ImportExportHelper.SETTINGS_DELETE_TEMPORARY_FILES, false);

        return settings;
    }