示例#1
0
        public Installation Post([FromBody] InstallConfig config)
        {
            //TODO Security ????
            var installation = new Installation {
                Success = false, Message = ""
            };

            if (ModelState.IsValid && (!_databaseManager.IsInstalled || !config.IsMaster))
            {
                bool master = config.IsMaster;

                config.Alias = config.Alias ?? HttpContext.Request.Host.Value;
                var result = DatabaseManager.InstallDatabase(config);

                if (result.Success)
                {
                    if (master)
                    {
                        _config.Reload();
                    }

                    installation.Success = true;
                    return(installation);
                }

                installation.Message = result.Message;
                return(installation);
            }

            installation.Message = "Application Is Already Installed";
            return(installation);
        }
        public PageUninstall(Control parent, InstallConfig config, Navigator navigator)
        {
            InitializeComponent();
            this.Visible = false;
            this.Parent  = parent;
            this.Dock    = DockStyle.Fill;
            _config      = config;
            _navigator   = navigator;

            string installFolder = RegHelper.GetRegInstallPath();

            if (string.IsNullOrWhiteSpace(installFolder))
            {
                textBoxInstallLocation.Text = string.Format(NotFound, AppInfo.Name);
                labelConfirm.Text           = string.Format(NoInstall, AppInfo.Name);
            }
            else
            {
                _config.InstallLocation     = installFolder;
                textBoxInstallLocation.Text = installFolder;

                labelConfirm.MaximumSize = new Size(460, 0);
                labelConfirm.Text        = string.Format(ConfirmUninstall, AppInfo.Name);

                flatButtonUninstall.Enabled = true;
                _installed = true;
            }
        }
        private Installation MigrateTenants(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            string[] versions = Constants.ReleaseVersions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var upgrades = scope.ServiceProvider.GetRequiredService <IUpgradeManager>();

                using (var db = new InstallationContext(NormalizeConnectionString(_config.GetConnectionString(SettingKeys.ConnectionStringKey))))
                {
                    foreach (var tenant in db.Tenant.ToList())
                    {
                        MigrateScriptNamingConvention("Tenant", tenant.DBConnectionString);

                        var upgradeConfig = DeployChanges.To.SqlDatabase(NormalizeConnectionString(tenant.DBConnectionString))
                                            .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly(), s => s.Contains("Tenant.") && s.EndsWith(".sql", StringComparison.OrdinalIgnoreCase));

                        var upgrade = upgradeConfig.Build();
                        if (upgrade.IsUpgradeRequired())
                        {
                            var upgradeResult = upgrade.PerformUpgrade();
                            result.Success = upgradeResult.Successful;
                            if (!result.Success)
                            {
                                result.Message = upgradeResult.Error.Message;
                            }
                        }

                        // execute any version specific upgrade logic
                        string version = tenant.Version;
                        int    index   = Array.FindIndex(versions, item => item == version);
                        if (index != (versions.Length - 1))
                        {
                            if (index == -1)
                            {
                                index = 0;
                            }
                            for (int i = index; i < versions.Length; i++)
                            {
                                upgrades.Upgrade(tenant, versions[i]);
                            }
                            tenant.Version         = versions[versions.Length - 1];
                            db.Entry(tenant).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(result.Message))
            {
                result.Success = true;
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// Updates and synchronizes DotNetNuke.install.config with Web.config
        /// </summary>
        /// <param name="installInfo"></param>
        private static void UpdateInstallConfig(Dictionary <string, string> installInfo)
        {
            _installConfig = new InstallConfig();
            // SuperUser Config
            _installConfig.SuperUser          = new SuperUserConfig();
            _installConfig.SuperUser.UserName = installInfo["username"];
            _installConfig.SuperUser.Password = installInfo["password"];
            _installConfig.SuperUser.Locale   = _culture;
            // Defaults
            _installConfig.SuperUser.Email     = "*****@*****.**";
            _installConfig.SuperUser.FirstName = "SuperUser";
            _installConfig.SuperUser.LastName  = "Account";

            // website culture
            _installConfig.InstallCulture = installInfo["language"];

            // Website Portal Config
            var portalConfig = new PortalConfig();

            portalConfig.PortalName       = installInfo["websiteName"];
            portalConfig.TemplateFileName = installInfo["template"];
            portalConfig.IsChild          = false;
            _installConfig.Portals        = new List <PortalConfig>();
            _installConfig.Portals.Add(portalConfig);

            InstallController.Instance.SetInstallConfig(_installConfig);
        }
示例#5
0
        private Installation CreateTenant(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            if (!string.IsNullOrEmpty(install.TenantName) && !string.IsNullOrEmpty(install.Aliases))
            {
                using (var db = GetInstallationContext())
                {
                    Tenant tenant;
                    if (install.IsNewTenant)
                    {
                        tenant = new Tenant
                        {
                            Name = install.TenantName,
                            DBConnectionString = DenormalizeConnectionString(install.ConnectionString),
                            DBType             = install.DatabaseType,
                            CreatedBy          = "",
                            CreatedOn          = DateTime.UtcNow,
                            ModifiedBy         = "",
                            ModifiedOn         = DateTime.UtcNow
                        };
                        db.Tenant.Add(tenant);
                        db.SaveChanges();
                        _cache.Remove("tenants");
                    }
                    else
                    {
                        tenant = db.Tenant.FirstOrDefault(item => item.Name == install.TenantName);
                    }

                    foreach (var aliasName in install.Aliases.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        if (tenant != null)
                        {
                            var alias = new Alias
                            {
                                Name       = aliasName,
                                TenantId   = tenant.TenantId,
                                SiteId     = -1,
                                CreatedBy  = "",
                                CreatedOn  = DateTime.UtcNow,
                                ModifiedBy = "",
                                ModifiedOn = DateTime.UtcNow
                            };
                            db.Alias.Add(alias);
                        }

                        db.SaveChanges();
                    }

                    _cache.Remove("aliases");
                }
            }

            result.Success = true;

            return(result);
        }
示例#6
0
 public PageInstall(Control parent, InstallConfig config, Navigator navigator)
 {
     InitializeComponent();
     this.Visible = false;
     this.Parent  = parent;
     this.Dock    = DockStyle.Fill;
     _config      = config;
     _navigator   = navigator;
 }
示例#7
0
        private Installation InstallDatabase(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            try
            {
                var databaseType = install.DatabaseType;

                //Get database Type
                var type = Type.GetType(databaseType);

                //Deploy the database components (if necessary)
                if (type == null)
                {
                    //Rename bak extension
                    var packageFolderName = "Packages";
                    var path           = _environment.ContentRootPath;
                    var packagesFolder = new DirectoryInfo(Path.Combine(path, packageFolderName));

                    // iterate through Nuget packages in source folder
                    foreach (var package in packagesFolder.GetFiles("*.nupkg.bak"))
                    {
                        if (package.Name.StartsWith(Utilities.GetAssemblyName(install.DatabaseType)))
                        {
                            //rename file
                            var packageName = Path.Combine(package.DirectoryName, package.Name);
                            packageName = packageName.Substring(0, packageName.IndexOf(".bak"));
                            package.MoveTo(packageName, true);
                        }
                    }

                    //Call InstallationManager to install Database Package
                    using (var scope = _serviceScopeFactory.CreateScope())
                    {
                        var installationManager = scope.ServiceProvider.GetRequiredService <IInstallationManager>();
                        installationManager.InstallPackages();

                        var assemblyPath     = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
                        var assembliesFolder = new DirectoryInfo(assemblyPath);
                        var assemblyFile     = new FileInfo($"{assembliesFolder}/{Utilities.GetAssemblyName(install.DatabaseType)}.dll");

                        AssemblyLoadContext.Default.LoadOqtaneAssembly(assemblyFile);

                        result.Success = true;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            return(result);
        }
        private async Task Install()
        {
            if (_serverName != "" && _databaseName != "" && _hostUsername != "" && _hostPassword.Length >= 6 && _hostPassword == _confirmPassword && _hostEmail != "")
            {
                _loadingDisplay = "";
                StateHasChanged();

                var connectionstring = "";
                if (_databaseType == "LocalDB")
                {
                    connectionstring = "Data Source=" + _serverName + ";AttachDbFilename=|DataDirectory|\\" + _databaseName + ".mdf;Initial Catalog=" + _databaseName + ";Integrated Security=SSPI;";
                }
                else
                {
                    connectionstring = "Data Source=" + _serverName + ";Initial Catalog=" + _databaseName + ";";
                    if (_integratedSecurityDisplay == "display: none;")
                    {
                        connectionstring += "Integrated Security=SSPI;";
                    }
                    else
                    {
                        connectionstring += "User ID=" + _username + ";Password="******"://" + uri.Authority, true);
                }
                else
                {
                    _message        = "<div class=\"alert alert-danger\" role=\"alert\">" + installation.Message + "</div>";
                    _loadingDisplay = "display: none;";
                }
            }
            else
            {
                _message = "<div class=\"alert alert-danger\" role=\"alert\">Please Enter All Fields And Ensure Passwords Match And Are Greater Than 5 Characters In Length</div>";
            }
        }
示例#9
0
        private Installation InstallDatabase(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            try
            {
                bool installPackages = false;

                // iterate database packages in installation folder
                var packagesFolder = new DirectoryInfo(Path.Combine(_environment.ContentRootPath, "Packages"));
                foreach (var package in packagesFolder.GetFiles("*.nupkg.bak"))
                {
                    // determine if package needs to be upgraded or installed
                    bool upgrade = System.IO.File.Exists(package.FullName.Replace(".nupkg.bak", ".log"));
                    if (upgrade || package.Name.StartsWith(Utilities.GetAssemblyName(install.DatabaseType)))
                    {
                        var packageName = Path.Combine(package.DirectoryName, package.Name);
                        packageName = packageName.Substring(0, packageName.IndexOf(".bak"));
                        package.MoveTo(packageName, true);
                        installPackages = true;
                    }
                }
                if (installPackages)
                {
                    using (var scope = _serviceScopeFactory.CreateScope())
                    {
                        var installationManager = scope.ServiceProvider.GetRequiredService <IInstallationManager>();
                        installationManager.InstallPackages();
                    }
                }

                // load the installation database type (if necessary)
                if (Type.GetType(install.DatabaseType) == null)
                {
                    var assemblyPath     = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
                    var assembliesFolder = new DirectoryInfo(assemblyPath);
                    var assemblyFile     = new FileInfo($"{assembliesFolder}/{Utilities.GetAssemblyName(install.DatabaseType)}.dll");
                    AssemblyLoadContext.Default.LoadOqtaneAssembly(assemblyFile);
                }

                result.Success = true;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                _filelogger.LogError(Utilities.LogMessage(this, result.Message));
            }

            return(result);
        }
示例#10
0
        public PageOptions(Control parent, InstallConfig config, Navigator navigator)
        {
            InitializeComponent();
            this.Visible = false;
            this.Parent  = parent;
            this.Dock    = DockStyle.Fill;
            _config      = config;
            _navigator   = navigator;

            _config.DesktopShortcut    = checkBoxDesktop.Checked;
            _config.StartmenuShortcut  = checkBoxStartmenu.Checked;
            _config.StartOnSystemStart = checkBoxSystemStart.Checked;
        }
        private Installation CreateTenant(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            if (!string.IsNullOrEmpty(install.TenantName) && !string.IsNullOrEmpty(install.Aliases))
            {
                using (var db = new InstallationContext(NormalizeConnectionString(_config.GetConnectionString(SettingKeys.ConnectionStringKey))))
                {
                    Tenant tenant;
                    if (install.IsNewTenant)
                    {
                        tenant = new Tenant {
                            Name = install.TenantName, DBConnectionString = DenormalizeConnectionString(install.ConnectionString), CreatedBy = "", CreatedOn = DateTime.UtcNow, ModifiedBy = "", ModifiedOn = DateTime.UtcNow
                        };
                        db.Tenant.Add(tenant);
                        db.SaveChanges();
                        _cache.Remove("tenants");

                        if (install.TenantName == Constants.MasterTenant)
                        {
                            var job = new Job {
                                Name = "Notification Job", JobType = "Oqtane.Infrastructure.NotificationJob, Oqtane.Server", Frequency = "m", Interval = 1, StartDate = null, EndDate = null, IsEnabled = false, IsStarted = false, IsExecuting = false, NextExecution = null, RetentionHistory = 10, CreatedBy = "", CreatedOn = DateTime.UtcNow, ModifiedBy = "", ModifiedOn = DateTime.UtcNow
                            };
                            db.Job.Add(job);
                            db.SaveChanges();
                            _cache.Remove("jobs");
                        }
                    }
                    else
                    {
                        tenant = db.Tenant.FirstOrDefault(item => item.Name == install.TenantName);
                    }

                    foreach (string aliasname in install.Aliases.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        var alias = new Alias {
                            Name = aliasname, TenantId = tenant.TenantId, SiteId = -1, CreatedBy = "", CreatedOn = DateTime.UtcNow, ModifiedBy = "", ModifiedOn = DateTime.UtcNow
                        };
                        db.Alias.Add(alias);
                        db.SaveChanges();
                    }
                    _cache.Remove("aliases");
                }
            }

            result.Success = true;

            return(result);
        }
示例#12
0
        private Installation CreateDatabase(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            if (install.IsNewTenant)
            {
                try
                {
                    InstallDatabase(install);

                    var databaseType = install.DatabaseType;

                    //Get database Type
                    var type = Type.GetType(databaseType);

                    //Create database object from Type
                    var database = Activator.CreateInstance(type) as IDatabase;

                    //create data directory if does not exist
                    var dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString();
                    if (!Directory.Exists(dataDirectory))
                    {
                        Directory.CreateDirectory(dataDirectory ?? String.Empty);
                    }

                    var dbOptions = new DbContextOptionsBuilder().UseOqtaneDatabase(database, NormalizeConnectionString(install.ConnectionString)).Options;
                    using (var dbc = new DbContext(dbOptions))
                    {
                        // create empty database if it does not exist
                        dbc.Database.EnsureCreated();
                        result.Success = true;
                    }
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                    _filelogger.LogError(Utilities.LogMessage(this, result.Message));
                }
            }
            else
            {
                result.Success = true;
            }

            return(result);
        }
示例#13
0
        public FormMain()
        {
            InitializeComponent();

            this.Text = string.Format("{0} uninstaller", AppInfo.Name);

            _config    = new InstallConfig();
            _navigator = new Navigator(this);

            _pages    = new UserControl[3];
            _pages[0] = new Pages.PageUninstall(panelMain, _config, _navigator);

            _currentNavBorderPanel = borderPanelStepOne;
            _currentPage           = _pages[0];
            FocusStep(borderPanelStepOne, _pages[0]);
        }
 public void RemoveFromInstallConfig(string xmlNodePath)
 {
     InstallConfig config = GetInstallConfig();
     if (config == null)
     {
         return;
     }
     var installTemplate = new XmlDocument();
     Upgrade.GetInstallTemplate(installTemplate);
     XmlNodeList nodes = installTemplate.SelectNodes(xmlNodePath);
     if (nodes != null && nodes.Count > 0 && nodes[0].ParentNode != null)
     {
         nodes[0].ParentNode.RemoveChild(nodes[0]);
     }
     Upgrade.SetInstallTemplate(installTemplate);
 }
        public Installation Post([FromBody] InstallConfig config)
        {
            var installation = new Installation {
                Success = false, Message = ""
            };

            if (ModelState.IsValid && (User.IsInRole(Constants.HostRole) || string.IsNullOrEmpty(_config.GetConnectionString(SettingKeys.ConnectionStringKey))))
            {
                installation = _databaseManager.Install(config);
            }
            else
            {
                installation.Message = "Installation Not Authorized";
            }

            return(installation);
        }
示例#16
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Init runs when the Page is initialised
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        ///     [cnurse]	02/14/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            //if previous config deleted create new empty one
            string installConfig = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Install", "DotNetNuke.install.config");

            if (!File.Exists(installConfig))
            {
                File.Copy(installConfig + ".resources", installConfig);
            }
            GetInstallerLocales();
            if (!Page.IsPostBack || _installConfig == null)
            {
                _installConfig    = InstallController.Instance.GetInstallConfig();
                _connectionConfig = _installConfig.Connection;
            }
        }
示例#17
0
        public PageLocation(Control parent, InstallConfig config, Navigator navigator)
        {
            InitializeComponent();
            this.Visible = false;
            this.Parent  = parent;
            this.Dock    = DockStyle.Fill;
            _config      = config;
            _navigator   = navigator;

            string installFolder = RegHelper.GetRegInstallPath();

            if (string.IsNullOrWhiteSpace(installFolder))
            {
                installFolder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
                installFolder = Path.Combine(installFolder, AppInfo.Name);
            }
            textBoxInstallLocation.Text = installFolder;
            textBoxInstallLocation.Select(textBoxInstallLocation.Text.Length, 0);
        }
示例#18
0
        private Installation MigrateMaster(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            if (install.TenantName == TenantNames.Master)
            {
                using (var scope = _serviceScopeFactory.CreateScope())
                {
                    var sql = scope.ServiceProvider.GetRequiredService <ISqlRepository>();

                    var installation = IsInstalled();
                    try
                    {
                        UpdateConnectionString(install.ConnectionString);
                        UpdateDatabaseType(install.DatabaseType);

                        using (var masterDbContext = new MasterDBContext(new DbContextOptions <MasterDBContext>(), null, _config))
                        {
                            if (installation.Success && (install.DatabaseType == Constants.DefaultDBType))
                            {
                                UpgradeSqlServer(sql, install.ConnectionString, install.DatabaseType, true);
                            }
                            // Push latest model into database
                            masterDbContext.Database.Migrate();
                            result.Success = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        result.Message = ex.Message;
                        _filelogger.LogError(Utilities.LogMessage(this, result.Message));
                    }
                }
            }
            else
            {
                result.Success = true;
            }

            return(result);
        }
        private Installation MigrateMaster(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            if (install.TenantName == Constants.MasterTenant)
            {
                MigrateScriptNamingConvention("Master", install.ConnectionString);

                var upgradeConfig = DeployChanges
                                    .To
                                    .SqlDatabase(NormalizeConnectionString(install.ConnectionString))
                                    .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly(), s => s.Contains("Master.") && s.EndsWith(".sql", StringComparison.OrdinalIgnoreCase));

                var upgrade = upgradeConfig.Build();
                if (upgrade.IsUpgradeRequired())
                {
                    var upgradeResult = upgrade.PerformUpgrade();
                    result.Success = upgradeResult.Successful;
                    if (!result.Success)
                    {
                        result.Message = upgradeResult.Error.Message;
                    }
                }
                else
                {
                    result.Success = true;
                }

                if (result.Success)
                {
                    UpdateConnectionString(install.ConnectionString);
                }
            }
            else
            {
                result.Success = true;
            }

            return(result);
        }
示例#20
0
        public async Task <Installation> Post([FromBody] InstallConfig config)
        {
            var installation = new Installation {
                Success = false, Message = ""
            };

            if (ModelState.IsValid && (User.IsInRole(RoleNames.Host) || string.IsNullOrEmpty(_configManager.GetSetting("ConnectionStrings:" + SettingKeys.ConnectionStringKey, ""))))
            {
                installation = _databaseManager.Install(config);

                if (installation.Success && config.Register)
                {
                    await RegisterContact(config.HostEmail);
                }
            }
            else
            {
                installation.Message = "Installation Not Authorized";
            }

            return(installation);
        }
示例#21
0
        private Installation CreateDatabase(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            if (install.IsNewTenant)
            {
                try
                {
                    //create data directory if does not exist
                    var dataDirectory = AppDomain.CurrentDomain.GetData("DataDirectory")?.ToString();
                    if (!Directory.Exists(dataDirectory))
                    {
                        Directory.CreateDirectory(dataDirectory);
                    }

                    var connectionString = NormalizeConnectionString(install.ConnectionString);
                    using (var dbc = new DbContext(new DbContextOptionsBuilder().UseOqtaneDatabase(connectionString).Options))
                    {
                        // create empty database if it does not exist
                        dbc.Database.EnsureCreated();
                        result.Success = true;
                    }
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                }
            }
            else
            {
                result.Success = true;
            }

            return(result);
        }
        public Installation Install(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            // get configuration
            if (install == null)
            {
                // startup or silent installation
                install = new InstallConfig {
                    ConnectionString = _config.GetConnectionString(SettingKeys.ConnectionStringKey), TenantName = Constants.MasterTenant, IsNewTenant = false
                };

                if (!IsInstalled())
                {
                    install.Aliases      = GetInstallationConfig(SettingKeys.DefaultAliasKey, string.Empty);
                    install.HostPassword = GetInstallationConfig(SettingKeys.HostPasswordKey, string.Empty);
                    install.HostEmail    = GetInstallationConfig(SettingKeys.HostEmailKey, string.Empty);

                    if (!string.IsNullOrEmpty(install.ConnectionString) && !string.IsNullOrEmpty(install.Aliases) && !string.IsNullOrEmpty(install.HostPassword) && !string.IsNullOrEmpty(install.HostEmail))
                    {
                        // silent install
                        install.HostName         = Constants.HostUser;
                        install.SiteTemplate     = GetInstallationConfig(SettingKeys.SiteTemplateKey, Constants.DefaultSiteTemplate);
                        install.DefaultTheme     = GetInstallationConfig(SettingKeys.DefaultThemeKey, Constants.DefaultTheme);
                        install.DefaultLayout    = GetInstallationConfig(SettingKeys.DefaultLayoutKey, Constants.DefaultLayout);
                        install.DefaultContainer = GetInstallationConfig(SettingKeys.DefaultContainerKey, Constants.DefaultContainer);
                        install.SiteName         = Constants.DefaultSite;
                        install.IsNewTenant      = true;
                    }
                    else
                    {
                        // silent installation is missing required information
                        install.ConnectionString = "";
                    }
                }
            }
            else
            {
                // install wizard or add new site
                if (!string.IsNullOrEmpty(install.Aliases))
                {
                    if (string.IsNullOrEmpty(install.SiteTemplate))
                    {
                        install.SiteTemplate = GetInstallationConfig(SettingKeys.SiteTemplateKey, Constants.DefaultSiteTemplate);
                    }
                    if (string.IsNullOrEmpty(install.DefaultTheme))
                    {
                        install.DefaultTheme = GetInstallationConfig(SettingKeys.DefaultThemeKey, Constants.DefaultTheme);
                        if (string.IsNullOrEmpty(install.DefaultLayout))
                        {
                            install.DefaultLayout = GetInstallationConfig(SettingKeys.DefaultLayoutKey, Constants.DefaultLayout);
                        }
                    }
                    if (string.IsNullOrEmpty(install.DefaultContainer))
                    {
                        install.DefaultContainer = GetInstallationConfig(SettingKeys.DefaultContainerKey, Constants.DefaultContainer);
                    }
                }
                else
                {
                    result.Message           = "Invalid Installation Configuration";
                    install.ConnectionString = "";
                }
            }

            // proceed with installation/migration
            if (!string.IsNullOrEmpty(install.ConnectionString))
            {
                result = CreateDatabase(install);
                if (result.Success)
                {
                    result = MigrateMaster(install);
                    if (result.Success)
                    {
                        result = CreateTenant(install);
                        if (result.Success)
                        {
                            result = MigrateTenants(install);
                            if (result.Success)
                            {
                                result = MigrateModules(install);
                                if (result.Success)
                                {
                                    result = CreateSite(install);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
        private Installation CreateSite(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            if (!string.IsNullOrEmpty(install.TenantName) && !string.IsNullOrEmpty(install.Aliases) && !string.IsNullOrEmpty(install.SiteName))
            {
                using (var scope = _serviceScopeFactory.CreateScope())
                {
                    // use the SiteState to set the Alias explicitly so the tenant can be resolved
                    var    aliases    = scope.ServiceProvider.GetRequiredService <IAliasRepository>();
                    string firstalias = install.Aliases.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    var    alias      = aliases.GetAliases().FirstOrDefault(item => item.Name == firstalias);
                    var    siteState  = scope.ServiceProvider.GetRequiredService <SiteState>();
                    siteState.Alias = alias;

                    var sites = scope.ServiceProvider.GetRequiredService <ISiteRepository>();
                    var site  = sites.GetSites().FirstOrDefault(item => item.Name == install.SiteName);
                    if (site == null)
                    {
                        var tenants             = scope.ServiceProvider.GetRequiredService <ITenantRepository>();
                        var users               = scope.ServiceProvider.GetRequiredService <IUserRepository>();
                        var roles               = scope.ServiceProvider.GetRequiredService <IRoleRepository>();
                        var userroles           = scope.ServiceProvider.GetRequiredService <IUserRoleRepository>();
                        var folders             = scope.ServiceProvider.GetRequiredService <IFolderRepository>();
                        var log                 = scope.ServiceProvider.GetRequiredService <ILogManager>();
                        var identityUserManager = scope.ServiceProvider.GetRequiredService <UserManager <IdentityUser> >();

                        var tenant = tenants.GetTenants().FirstOrDefault(item => item.Name == install.TenantName);

                        site = new Site
                        {
                            TenantId             = tenant.TenantId,
                            Name                 = install.SiteName,
                            LogoFileId           = null,
                            DefaultThemeType     = install.DefaultTheme,
                            DefaultLayoutType    = install.DefaultLayout,
                            DefaultContainerType = install.DefaultContainer,
                            SiteTemplateType     = install.SiteTemplate
                        };
                        site = sites.AddSite(site);

                        IdentityUser identityUser = identityUserManager.FindByNameAsync(Constants.HostUser).GetAwaiter().GetResult();
                        if (identityUser == null)
                        {
                            identityUser = new IdentityUser {
                                UserName = Constants.HostUser, Email = install.HostEmail, EmailConfirmed = true
                            };
                            var create = identityUserManager.CreateAsync(identityUser, install.HostPassword).GetAwaiter().GetResult();
                            if (create.Succeeded)
                            {
                                var user = new User
                                {
                                    SiteId        = site.SiteId,
                                    Username      = Constants.HostUser,
                                    Password      = install.HostPassword,
                                    Email         = install.HostEmail,
                                    DisplayName   = install.HostName,
                                    LastIPAddress = "",
                                    LastLoginOn   = null
                                };

                                user = users.AddUser(user);
                                var hostRoleId = roles.GetRoles(user.SiteId, true).FirstOrDefault(item => item.Name == Constants.HostRole)?.RoleId ?? 0;
                                var userRole   = new UserRole {
                                    UserId = user.UserId, RoleId = hostRoleId, EffectiveDate = null, ExpiryDate = null
                                };
                                userroles.AddUserRole(userRole);

                                // add user folder
                                var folder = folders.GetFolder(user.SiteId, Utilities.PathCombine("Users", "\\"));
                                if (folder != null)
                                {
                                    folders.AddFolder(new Folder
                                    {
                                        SiteId      = folder.SiteId,
                                        ParentId    = folder.FolderId,
                                        Name        = "My Folder",
                                        Path        = Utilities.PathCombine(folder.Path, user.UserId.ToString(), "\\"),
                                        Order       = 1,
                                        IsSystem    = true,
                                        Permissions = new List <Permission>
                                        {
                                            new Permission(PermissionNames.Browse, user.UserId, true),
                                            new Permission(PermissionNames.View, Constants.AllUsersRole, true),
                                            new Permission(PermissionNames.Edit, user.UserId, true),
                                        }.EncodePermissions(),
                                    });
                                }
                            }
                        }

                        foreach (string aliasname in install.Aliases.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            alias        = aliases.GetAliases().FirstOrDefault(item => item.Name == aliasname);
                            alias.SiteId = site.SiteId;
                            aliases.UpdateAlias(alias);
                        }

                        tenant.Version = Constants.Version;
                        tenants.UpdateTenant(tenant);

                        log.Log(site.SiteId, LogLevel.Trace, this, LogFunction.Create, "Site Created {Site}", site);
                    }
                }
            }

            result.Success = true;

            return(result);
        }
        private Installation MigrateModules(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var moduledefinitions = scope.ServiceProvider.GetRequiredService <IModuleDefinitionRepository>();
                var sql = scope.ServiceProvider.GetRequiredService <ISqlRepository>();
                foreach (var moduledefinition in moduledefinitions.GetModuleDefinitions())
                {
                    if (!string.IsNullOrEmpty(moduledefinition.ReleaseVersions) && !string.IsNullOrEmpty(moduledefinition.ServerManagerType))
                    {
                        Type moduletype = Type.GetType(moduledefinition.ServerManagerType);

                        string[] versions = moduledefinition.ReleaseVersions.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        using (var db = new InstallationContext(NormalizeConnectionString(_config.GetConnectionString(SettingKeys.ConnectionStringKey))))
                        {
                            foreach (var tenant in db.Tenant.ToList())
                            {
                                int index = Array.FindIndex(versions, item => item == moduledefinition.Version);
                                if (tenant.Name == install.TenantName && install.TenantName != Constants.MasterTenant)
                                {
                                    index = -1;
                                }
                                if (index != (versions.Length - 1))
                                {
                                    if (index == -1)
                                    {
                                        index = 0;
                                    }
                                    for (int i = index; i < versions.Length; i++)
                                    {
                                        try
                                        {
                                            if (moduletype.GetInterface("IInstallable") != null)
                                            {
                                                var moduleobject = ActivatorUtilities.CreateInstance(scope.ServiceProvider, moduletype);
                                                ((IInstallable)moduleobject).Install(tenant, versions[i]);
                                            }
                                            else
                                            {
                                                sql.ExecuteScript(tenant, moduletype.Assembly, Utilities.GetTypeName(moduledefinition.ModuleDefinitionName) + "." + versions[i] + ".sql");
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            result.Message = "An Error Occurred Installing " + moduledefinition.Name + " Version " + versions[i] + " - " + ex.Message.ToString();
                                        }
                                    }
                                }
                            }
                            if (string.IsNullOrEmpty(result.Message) && moduledefinition.Version != versions[versions.Length - 1])
                            {
                                moduledefinition.Version         = versions[versions.Length - 1];
                                db.Entry(moduledefinition).State = EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(result.Message))
            {
                result.Success = true;
            }

            return(result);
        }
        /// <summary>
        /// GetInstallConfig - Returns configuration stored in DotNetNuke.Install.Config
        /// </summary>
        /// <returns>ConnectionConfig object. Null if information is not present in the config file</returns>
        public InstallConfig GetInstallConfig()
        {
            var installConfig = new InstallConfig();

            //Load Template
            var installTemplate = new XmlDocument {
                XmlResolver = null
            };

            Upgrade.GetInstallTemplate(installTemplate);

            //Parse the root node
            XmlNode rootNode = installTemplate.SelectSingleNode("//dotnetnuke");

            if (rootNode != null)
            {
                installConfig.Version             = XmlUtils.GetNodeValue(rootNode.CreateNavigator(), "version");
                installConfig.SupportLocalization = XmlUtils.GetNodeValueBoolean(rootNode.CreateNavigator(), "supportLocalization");
                installConfig.InstallCulture      = XmlUtils.GetNodeValue(rootNode.CreateNavigator(), "installCulture") ?? Localization.Localization.SystemLocale;
            }

            //Parse the scripts node
            XmlNode scriptsNode = installTemplate.SelectSingleNode("//dotnetnuke/scripts");

            if (scriptsNode != null)
            {
                foreach (XmlNode scriptNode in scriptsNode)
                {
                    if (scriptNode != null)
                    {
                        installConfig.Scripts.Add(scriptNode.InnerText);
                    }
                }
            }

            //Parse the connection node
            XmlNode connectionNode = installTemplate.SelectSingleNode("//dotnetnuke/connection");

            if (connectionNode != null)
            {
                var connectionConfig = new ConnectionConfig();

                //Build connection string from the file
                connectionConfig.Server                  = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "server");
                connectionConfig.Database                = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "database");
                connectionConfig.File                    = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "file");
                connectionConfig.Integrated              = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "integrated").ToLowerInvariant() == "true";
                connectionConfig.User                    = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "user");
                connectionConfig.Password                = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "password");
                connectionConfig.RunAsDbowner            = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "runasdbowner").ToLowerInvariant() == "true";
                connectionConfig.Qualifier               = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "qualifier");
                connectionConfig.UpgradeConnectionString = XmlUtils.GetNodeValue(connectionNode.CreateNavigator(), "upgradeconnectionstring");

                installConfig.Connection = connectionConfig;
            }

            //Parse the superuser node
            XmlNode superUserNode = installTemplate.SelectSingleNode("//dotnetnuke/superuser");

            if (superUserNode != null)
            {
                var superUserConfig = new SuperUserConfig();

                superUserConfig.FirstName      = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "firstname");
                superUserConfig.LastName       = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "lastname");
                superUserConfig.UserName       = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "username");
                superUserConfig.Password       = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "password");
                superUserConfig.Email          = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "email");
                superUserConfig.Locale         = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "locale");
                superUserConfig.UpdatePassword = XmlUtils.GetNodeValue(superUserNode.CreateNavigator(), "updatepassword").ToLowerInvariant() == "true";

                installConfig.SuperUser = superUserConfig;
            }

            //Parse the license node
            XmlNode licenseNode = installTemplate.SelectSingleNode("//dotnetnuke/license");

            if (licenseNode != null)
            {
                var licenseConfig = new LicenseConfig();

                licenseConfig.AccountEmail  = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "accountEmail");
                licenseConfig.InvoiceNumber = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "invoiceNumber");
                licenseConfig.WebServer     = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "webServer");
                licenseConfig.LicenseType   = XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "licenseType");

                if (!String.IsNullOrEmpty(XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "trial")))
                {
                    licenseConfig.TrialRequest = bool.Parse(XmlUtils.GetNodeValue(licenseNode.CreateNavigator(), "trial"));
                }

                installConfig.License = licenseConfig;
            }

            //Parse the settings node
            XmlNode settingsNode = installTemplate.SelectSingleNode("//dotnetnuke/settings");

            if (settingsNode != null)
            {
                foreach (XmlNode settingNode in settingsNode.ChildNodes)
                {
                    if (settingNode != null && !string.IsNullOrEmpty(settingNode.Name))
                    {
                        bool settingIsSecure = false;
                        if (settingNode.Attributes != null)
                        {
                            XmlAttribute secureAttrib = settingNode.Attributes["Secure"];
                            if ((secureAttrib != null))
                            {
                                if (secureAttrib.Value.ToLowerInvariant() == "true")
                                {
                                    settingIsSecure = true;
                                }
                            }
                        }
                        installConfig.Settings.Add(new HostSettingConfig {
                            Name = settingNode.Name, Value = settingNode.InnerText, IsSecure = settingIsSecure
                        });
                    }
                }
            }
            var folderMappingsNode = installTemplate.SelectSingleNode("//dotnetnuke/" + FolderMappingsConfigController.Instance.ConfigNode);

            installConfig.FolderMappingsSettings = (folderMappingsNode != null)? folderMappingsNode.InnerXml : String.Empty;

            //Parse the portals node
            XmlNodeList portalsNode = installTemplate.SelectNodes("//dotnetnuke/portals/portal");

            if (portalsNode != null)
            {
                foreach (XmlNode portalNode in portalsNode)
                {
                    if (portalNode != null)
                    {
                        var portalConfig = new PortalConfig();
                        portalConfig.PortalName = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "portalname");

                        XmlNode adminNode = portalNode.SelectSingleNode("administrator");
                        if (adminNode != null)
                        {
                            portalConfig.AdminFirstName = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "firstname");
                            portalConfig.AdminLastName  = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "lastname");
                            portalConfig.AdminUserName  = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "username");
                            portalConfig.AdminPassword  = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "password");
                            portalConfig.AdminEmail     = XmlUtils.GetNodeValue(adminNode.CreateNavigator(), "email");
                        }
                        portalConfig.Description      = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "description");
                        portalConfig.Keywords         = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "keywords");
                        portalConfig.TemplateFileName = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "templatefile");
                        portalConfig.IsChild          = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "ischild").ToLowerInvariant() == "true";
                        ;
                        portalConfig.HomeDirectory = XmlUtils.GetNodeValue(portalNode.CreateNavigator(), "homedirectory");

                        //Get the Portal Alias
                        XmlNodeList portalAliases = portalNode.SelectNodes("portalaliases/portalalias");
                        if (portalAliases != null)
                        {
                            foreach (XmlNode portalAliase in portalAliases)
                            {
                                if (!string.IsNullOrEmpty(portalAliase.InnerText))
                                {
                                    portalConfig.PortAliases.Add(portalAliase.InnerText);
                                }
                            }
                        }
                        installConfig.Portals.Add(portalConfig);
                    }
                }
            }

            return(installConfig);
        }
        /// <summary>
        /// SetInstallConfig - Saves configuration n DotNetNuke.Install.Config
        /// </summary>
        public void SetInstallConfig(InstallConfig installConfig)
        {
            if (installConfig == null)
            {
                return;
            }

            //Load Template
            var installTemplate = new XmlDocument {
                XmlResolver = null
            };

            Upgrade.GetInstallTemplate(installTemplate);
            XmlNode dotnetnukeNode = installTemplate.SelectSingleNode("//dotnetnuke");

            //Set Version
            if (!string.IsNullOrEmpty(installConfig.Version))
            {
                XmlNode versionNode = installTemplate.SelectSingleNode("//dotnetnuke/version");

                if (versionNode == null)
                {
                    versionNode = AppendNewXmlNode(ref installTemplate, ref dotnetnukeNode, "version", installConfig.Version);
                }

                versionNode.InnerText = installConfig.Version;
            }

            //Set installer culture
            if (!string.IsNullOrEmpty(installConfig.InstallCulture))
            {
                XmlNode versionNode = installTemplate.SelectSingleNode("//dotnetnuke/installCulture");

                if (versionNode == null)
                {
                    versionNode = AppendNewXmlNode(ref installTemplate, ref dotnetnukeNode, "installCulture", installConfig.InstallCulture);
                }

                versionNode.InnerText = installConfig.InstallCulture;
            }

            //Set SuperUser
            if (installConfig.SuperUser != null)
            {
                XmlNode superUserNode = installTemplate.SelectSingleNode("//dotnetnuke/superuser");
                if (superUserNode == null)
                {
                    superUserNode = AppendNewXmlNode(ref installTemplate, ref dotnetnukeNode, "superuser", installConfig.Version);
                }
                else
                {
                    superUserNode.RemoveAll();
                }

                AppendNewXmlNode(ref installTemplate, ref superUserNode, "firstname", installConfig.SuperUser.FirstName);
                AppendNewXmlNode(ref installTemplate, ref superUserNode, "lastname", installConfig.SuperUser.LastName);
                AppendNewXmlNode(ref installTemplate, ref superUserNode, "username", installConfig.SuperUser.UserName);
                AppendNewXmlNode(ref installTemplate, ref superUserNode, "password", installConfig.SuperUser.Password);
                AppendNewXmlNode(ref installTemplate, ref superUserNode, "email", installConfig.SuperUser.Email);
                AppendNewXmlNode(ref installTemplate, ref superUserNode, "updatepassword", "false");
            }

            //Set Folder Mappings Settings
            if (!string.IsNullOrEmpty(installConfig.FolderMappingsSettings))
            {
                XmlNode folderMappingsNode = installTemplate.SelectSingleNode("//dotnetnuke/" + FolderMappingsConfigController.Instance.ConfigNode);

                if (folderMappingsNode == null)
                {
                    folderMappingsNode = AppendNewXmlNode(ref installTemplate, ref dotnetnukeNode, FolderMappingsConfigController.Instance.ConfigNode, installConfig.FolderMappingsSettings);
                }

                folderMappingsNode.InnerText = installConfig.FolderMappingsSettings;
            }

            //Set Portals
            if (installConfig.Portals != null && installConfig.Portals.Count > 0)
            {
                XmlNode portalsNode = installTemplate.SelectSingleNode("//dotnetnuke/portals");
                if (portalsNode == null)
                {
                    portalsNode = AppendNewXmlNode(ref installTemplate, ref dotnetnukeNode, "portals", installConfig.Version);
                }
                else
                {
                    portalsNode.RemoveAll();
                }


                foreach (PortalConfig portalConfig in installConfig.Portals)
                {
                    XmlNode portalNode        = AppendNewXmlNode(ref installTemplate, ref portalsNode, "portal", null);
                    XmlNode administratorNode = AppendNewXmlNode(ref installTemplate, ref portalNode, "administrator", null);
                    XmlNode portalAliasesNode = AppendNewXmlNode(ref installTemplate, ref portalNode, "portalaliases", null);
                    AppendNewXmlNode(ref installTemplate, ref portalNode, "portalname", portalConfig.PortalName);
                    AppendNewXmlNode(ref installTemplate, ref administratorNode, "firstname", portalConfig.AdminFirstName);
                    AppendNewXmlNode(ref installTemplate, ref administratorNode, "lastname", portalConfig.AdminLastName);
                    AppendNewXmlNode(ref installTemplate, ref administratorNode, "username", portalConfig.AdminUserName);
                    AppendNewXmlNode(ref installTemplate, ref administratorNode, "password", portalConfig.AdminPassword);
                    AppendNewXmlNode(ref installTemplate, ref administratorNode, "email", portalConfig.AdminEmail);
                    AppendNewXmlNode(ref installTemplate, ref portalNode, "description", portalConfig.Description);
                    AppendNewXmlNode(ref installTemplate, ref portalNode, "keywords", portalConfig.Keywords);
                    AppendNewXmlNode(ref installTemplate, ref portalNode, "templatefile", portalConfig.TemplateFileName);
                    AppendNewXmlNode(ref installTemplate, ref portalNode, "ischild", portalConfig.IsChild.ToString().ToLowerInvariant());
                    AppendNewXmlNode(ref installTemplate, ref portalNode, "homedirectory", portalConfig.HomeDirectory);

                    foreach (string portalAliase in portalConfig.PortAliases)
                    {
                        AppendNewXmlNode(ref installTemplate, ref portalAliasesNode, "portalalias", portalAliase);
                    }
                }
            }

            //Set the settings
            if (installConfig.Settings != null && installConfig.Settings.Count > 0)
            {
                XmlNode settingsNode = installTemplate.SelectSingleNode("//dotnetnuke/settings");
                if (settingsNode == null)
                {
                    settingsNode = AppendNewXmlNode(ref installTemplate, ref dotnetnukeNode, "settings", null);
                }
                // DNN-8833: for this node specifically we should append/overwrite existing but not clear all
                //else
                //{
                //    settingsNode.RemoveAll();
                //}

                foreach (HostSettingConfig setting in installConfig.Settings)
                {
                    XmlNode settingNode = AppendNewXmlNode(ref installTemplate, ref settingsNode, setting.Name, setting.Value);
                    if (setting.IsSecure)
                    {
                        XmlAttribute attribute = installTemplate.CreateAttribute("Secure");
                        attribute.Value = "true";
                        settingNode.Attributes.Append(attribute);
                    }
                }
            }

            //Set Connection
            if (installConfig.Connection != null)
            {
                XmlNode connectionNode = installTemplate.SelectSingleNode("//dotnetnuke/connection");
                if (connectionNode == null)
                {
                    connectionNode = AppendNewXmlNode(ref installTemplate, ref dotnetnukeNode, "connection", null);
                }
                else
                {
                    connectionNode.RemoveAll();
                }

                AppendNewXmlNode(ref installTemplate, ref connectionNode, "server", installConfig.Connection.Server);
                AppendNewXmlNode(ref installTemplate, ref connectionNode, "database", installConfig.Connection.Database);
                AppendNewXmlNode(ref installTemplate, ref connectionNode, "file", installConfig.Connection.File);
                AppendNewXmlNode(ref installTemplate, ref connectionNode, "integrated", installConfig.Connection.Integrated.ToString().ToLowerInvariant());
                AppendNewXmlNode(ref installTemplate, ref connectionNode, "user", installConfig.Connection.User);
                AppendNewXmlNode(ref installTemplate, ref connectionNode, "password", installConfig.Connection.Password);
                AppendNewXmlNode(ref installTemplate, ref connectionNode, "runasdbowner", installConfig.Connection.RunAsDbowner.ToString().ToLowerInvariant());
                AppendNewXmlNode(ref installTemplate, ref connectionNode, "qualifier", installConfig.Connection.Qualifier);
                AppendNewXmlNode(ref installTemplate, ref connectionNode, "upgradeconnectionstring", installConfig.Connection.UpgradeConnectionString);
            }

            Upgrade.SetInstallTemplate(installTemplate);
        }
示例#27
0
 public async Task <Installation> Install(InstallConfig config)
 {
     return(await PostJsonAsync <InstallConfig, Installation>(ApiUrl, config));
 }
示例#28
0
            /// <summary>
            /// 添加新的产品
            /// </summary>
            /// <param name="ProductID">产品 ID</param>
            /// <param name="LanguageID">产品的语言</param>
            /// <param name="ExcludeApps">指定要排除的应用程序 ID</param>
            public void AddProduct(string ProductID, string MAK, List <string> LanguageID, List <string> ExcludeApps)
            {
                InstallConfig arguments = new InstallConfig(ProductID, MAK, LanguageID, "", ExcludeApps);

                ProductConfigList.Add(arguments);
            }
示例#29
0
            /// <summary>
            /// 添加新的产品
            /// </summary>
            /// <param name="ProductID">产品 ID</param>
            /// <param name="LanguageID">产品的语言</param>
            public void AddProduct(string ProductID, List <string> LanguageID)
            {
                InstallConfig arguments = new InstallConfig(ProductID, "", LanguageID, "", new List <string>());

                ProductConfigList.Add(arguments);
            }
示例#30
0
        public Installation Install(InstallConfig install)
        {
            var result = new Installation {
                Success = false, Message = string.Empty
            };

            ValidateConfiguration();

            // get configuration
            if (install == null)
            {
                // startup or silent installation
                install = new InstallConfig
                {
                    ConnectionString = _config.GetConnectionString(SettingKeys.ConnectionStringKey),
                    TenantName       = TenantNames.Master,
                    DatabaseType     = _config.GetSection(SettingKeys.DatabaseSection)[SettingKeys.DatabaseTypeKey],
                    IsNewTenant      = false
                };

                // on upgrade install the associated Nuget package
                if (!string.IsNullOrEmpty(install.ConnectionString))
                {
                    InstallDatabase(install);
                }

                var installation = IsInstalled();
                if (!installation.Success)
                {
                    install.Aliases      = GetInstallationConfig(SettingKeys.DefaultAliasKey, string.Empty);
                    install.HostUsername = GetInstallationConfig(SettingKeys.HostUsernameKey, UserNames.Host);
                    install.HostPassword = GetInstallationConfig(SettingKeys.HostPasswordKey, string.Empty);
                    install.HostEmail    = GetInstallationConfig(SettingKeys.HostEmailKey, string.Empty);
                    install.HostName     = GetInstallationConfig(SettingKeys.HostNameKey, UserNames.Host);

                    if (!string.IsNullOrEmpty(install.ConnectionString) && !string.IsNullOrEmpty(install.Aliases) && !string.IsNullOrEmpty(install.HostPassword) && !string.IsNullOrEmpty(install.HostEmail))
                    {
                        // silent install
                        install.SiteTemplate     = GetInstallationConfig(SettingKeys.SiteTemplateKey, Constants.DefaultSiteTemplate);
                        install.DefaultTheme     = GetInstallationConfig(SettingKeys.DefaultThemeKey, Constants.DefaultTheme);
                        install.DefaultContainer = GetInstallationConfig(SettingKeys.DefaultContainerKey, Constants.DefaultContainer);
                        install.SiteName         = Constants.DefaultSite;
                        install.IsNewTenant      = true;
                    }
                    else
                    {
                        // silent installation is missing required information
                        install.ConnectionString = "";
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(installation.Message))
                    {
                        // problem with prior installation
                        _filelogger.LogError(Utilities.LogMessage(this, installation.Message));
                        install.ConnectionString = "";
                    }
                }
            }
            else
            {
                // install wizard or add new site
                if (!string.IsNullOrEmpty(install.Aliases))
                {
                    if (string.IsNullOrEmpty(install.SiteTemplate))
                    {
                        install.SiteTemplate = GetInstallationConfig(SettingKeys.SiteTemplateKey, Constants.DefaultSiteTemplate);
                    }
                    if (string.IsNullOrEmpty(install.DefaultTheme))
                    {
                        install.DefaultTheme = GetInstallationConfig(SettingKeys.DefaultThemeKey, Constants.DefaultTheme);
                    }
                    if (string.IsNullOrEmpty(install.DefaultContainer))
                    {
                        install.DefaultContainer = GetInstallationConfig(SettingKeys.DefaultContainerKey, Constants.DefaultContainer);
                    }
                }
                else
                {
                    result.Message           = "Invalid Installation Configuration";
                    install.ConnectionString = "";
                }
            }

            // proceed with installation/migration
            if (!string.IsNullOrEmpty(install.ConnectionString))
            {
                result = CreateDatabase(install);
                if (result.Success)
                {
                    result = MigrateMaster(install);
                    if (result.Success)
                    {
                        result = CreateTenant(install);
                        if (result.Success)
                        {
                            result = MigrateTenants(install);
                            if (result.Success)
                            {
                                result = MigrateModules(install);
                                if (result.Success)
                                {
                                    result = CreateSite(install);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }