public ReinstallArgs(Instance instance, SqlConnectionStringBuilder connectionString, string license, string webServerIdentity, bool serverSideRedirect) { ConnectionString = connectionString; Name = instance.Name; _Bindings = instance.Bindings; Product = instance.Product; WebRootPath = instance.WebRootPath; RootPath = instance.RootPath; DataFolderPath = instance.DataFolderPath; DatabasesFolderPath = Path.Combine(RootPath, "Databases"); WebServerIdentity = webServerIdentity; LicenseFilePath = license; _Modules = new Product[0]; IsClassic = instance.IsClassic; Is32Bit = instance.Is32Bit; ForceNetFramework4 = instance.IsNetFramework4; ServerSideRedirect = serverSideRedirect; TempFolder = Path.Combine(RootPath, "Temp"); _InstanceDatabases = instance.AttachedDatabases; instanceName = instance.Name; _StopInstance = instance.Stop; WebsiteID = instance.ID; SqlPrefix = AttachDatabasesHelper.GetSqlPrefix(instance); var executionTimeout = UpdateWebConfigHelper.GetHttpRuntime(instance.GetWebResultConfig()).GetAttribute("executionTimeout"); IncreaseExecutionTimeout = string.IsNullOrEmpty(executionTimeout) || executionTimeout != "600"; }
private static void Process(Instance instance) { var firstDatabase = instance.AttachedDatabases?.FirstOrDefault(); Assert.IsNotNull(firstDatabase, "The databases information is not available"); var databaseFilePath = firstDatabase.FileName.EmptyToNull(); Assert.IsNotNull(databaseFilePath, nameof(databaseFilePath)); var databasesFolderPath = Path.GetDirectoryName(databaseFilePath); Assert.IsNotNull(databasesFolderPath, nameof(databasesFolderPath)); var reportingCstr = instance.Configuration.ConnectionStrings.FirstOrDefault(x => x.Name == "reporting"); if (reportingCstr != null) { var sqlName = new SqlConnectionStringBuilder(reportingCstr.Value).InitialCatalog; var database = instance.AttachedDatabases.FirstOrDefault(x => x.RealName.Equals(sqlName)); var fileName = database?.FileName; if (fileName != null) { var file = new FileInfo(fileName); Assert.IsTrue(!file.Exists, $"The {file.FullName} reporting database file already exist"); } reportingCstr.Delete(); } var reportingFile = new FileInfo(Path.Combine(databasesFolderPath, "Sitecore.Reporting.mdf")); if (reportingFile.Exists) { reportingFile.Delete(); } AttachDatabasesHelper.ExtractReportingDatabase(instance, reportingFile); var sqlPrefix = AttachDatabasesHelper.GetSqlPrefix(instance); var reportingSqlName = sqlPrefix + "_reporting"; var mgmtText = Profile.Read().ConnectionString; var mgmtValue = new SqlConnectionStringBuilder(mgmtText); SqlServerManager.Instance.AttachDatabase(reportingSqlName, reportingFile.FullName, mgmtValue); var reportingValue = new SqlConnectionStringBuilder(mgmtText) { InitialCatalog = reportingSqlName }; instance.Configuration.ConnectionStrings.Add("reporting", reportingValue); }
private static void Process(Instance instance) { var database = instance.AttachedDatabases?.FirstOrDefault(); Assert.IsNotNull(database, "The databases information is not available"); var databaseFilePath = database.FileName.EmptyToNull(); Assert.IsNotNull(databaseFilePath, nameof(databaseFilePath)); var databasesFolderPath = Path.GetDirectoryName(databaseFilePath); Assert.IsNotNull(databasesFolderPath, nameof(databasesFolderPath)); var primaryCstr = instance.Configuration.ConnectionStrings.FirstOrDefault(x => x.Name == "reporting"); Assert.IsNotNull(primaryCstr, "reporting connection string is missing"); var primarySqlName = new SqlConnectionStringBuilder(primaryCstr.Value).InitialCatalog; var primaryDatabase = instance.AttachedDatabases.FirstOrDefault(x => x.RealName.Equals(primarySqlName)); Assert.IsNotNull(primaryDatabase, nameof(primaryDatabase)); var primaryFile = new FileInfo(primaryDatabase.FileName); Assert.IsTrue(primaryFile.Exists, $"The {primaryFile.FullName} reporting database file does not exist"); var secondaryCstr = instance.Configuration.ConnectionStrings.FirstOrDefault(x => x.Name == "reporting.secondary"); var mgmtCstr = new SqlConnectionStringBuilder(Profile.Read().ConnectionString); if (secondaryCstr != null) { var name = new SqlConnectionStringBuilder(secondaryCstr.Value).InitialCatalog; if (SqlServerManager.Instance.DatabaseExists(name, mgmtCstr)) { SqlServerManager.Instance.DeleteDatabase(name, mgmtCstr); } secondaryCstr.Delete(); } var primaryIsSecondary = primaryFile.Name.EndsWith("secondary.mdf", StringComparison.OrdinalIgnoreCase); var secondaryFile = new FileInfo(Path.Combine(databasesFolderPath, primaryIsSecondary ? "Sitecore.Reporting.mdf" : "Sitecore.Reporting.Secondary.mdf")); if (secondaryFile.Exists) { secondaryFile.Delete(); } AttachDatabasesHelper.ExtractReportingDatabase(instance, secondaryFile); var sqlPrefix = AttachDatabasesHelper.GetSqlPrefix(instance); var sqlName = sqlPrefix + "_reporting"; if (sqlName.EqualsIgnoreCase(primarySqlName)) { sqlName += "_secondary"; } SqlServerManager.Instance.AttachDatabase(sqlName, secondaryFile.FullName, mgmtCstr); var secondaryBuilder = new SqlConnectionStringBuilder(mgmtCstr.ToString()) { InitialCatalog = sqlName }; instance.Configuration.ConnectionStrings.Add("reporting.secondary", secondaryBuilder); }