protected override void Process(ImportArgs args) { if (FileSystem.FileSystem.Local.Directory.Exists(args.temporaryPathToUnpack)) { FileSystem.FileSystem.Local.Directory.TryDelete(args.temporaryPathToUnpack); } }
protected override void Process(ImportArgs args) { var pathToConnectionStringsConfig = args.rootPath.PathCombine("Website").PathCombine("App_Config").PathCombine("ConnectionStrings.config"); var connectionStringsDocument = new XmlDocumentEx(); connectionStringsDocument.Load(pathToConnectionStringsConfig); var connectionsStringsElement = new XmlElementEx(connectionStringsDocument.DocumentElement, connectionStringsDocument); ConnectionStringCollection connStringCollection = this.GetConnectionStringCollection(connectionsStringsElement); foreach (var conn in connStringCollection) { if (conn.IsSqlConnectionString) { var builder = new SqlConnectionStringBuilder(conn.Value) { IntegratedSecurity = false, DataSource = args.connectionString.DataSource, UserID = args.connectionString.UserID, Password = args.connectionString.Password }; if (args.databaseNameAppend != -1) { builder.InitialCatalog = builder.InitialCatalog + "_" + args.databaseNameAppend.ToString(); } else { builder.InitialCatalog = builder.InitialCatalog; } conn.Value = builder.ToString(); } } connStringCollection.Save(); }
private void GetSettingsFromIISFiles(ImportArgs args) { using (WebServerManager.WebServerContext context = WebServerManager.CreateContext("ImportSolution.Initialization")) { string appPoolFilePath = FileSystem.FileSystem.Local.Zip.ZipUnpackFile(args.PathToExportedInstance, args.temporaryPathToUnpack, ImportArgs.appPoolSettingsFileName); string websiteSettingsFilePath = FileSystem.FileSystem.Local.Zip.ZipUnpackFile(args.PathToExportedInstance, args.temporaryPathToUnpack, ImportArgs.websiteSettingsFileName); XmlDocumentEx appPool = new XmlDocumentEx(); appPool.Load(appPoolFilePath); XmlDocumentEx websiteSettings = new XmlDocumentEx(); websiteSettings.Load(websiteSettingsFilePath); args.oldSiteName = websiteSettings.GetElementAttributeValue("/appcmd/SITE/site", "name"); if (args.siteName == string.Empty) { args.siteName = websiteSettings.GetElementAttributeValue("/appcmd/SITE/site", "name"); } args.virtualDirectoryPath = websiteSettings.GetElementAttributeValue("/appcmd/SITE/site/application/virtualDirectory", "path"); if (args.virtualDirectoryPhysicalPath == string.Empty) { args.virtualDirectoryPhysicalPath = websiteSettings.GetElementAttributeValue("/appcmd/SITE/site/application/virtualDirectory", "physicalPath"); } args.appPoolName = appPool.GetElementAttributeValue("/appcmd/APPPOOL", "APPPOOL.NAME"); // need to set appPoolName in both files if (args.appPoolName != args.siteName) { args.appPoolName = args.siteName; } args.appPoolName = SetupWebsiteHelper.ChooseAppPoolName(args.appPoolName, context.ApplicationPools); args.siteID = long.Parse(websiteSettings.GetElementAttributeValue("/appcmd/SITE", "SITE.ID")); } }
protected override void Process(ImportArgs args) { var pathToConnectionStringsConfig = args.rootPath.PathCombine("Website").PathCombine("App_Config").PathCombine("ConnectionStrings.config"); var connectionStringsDocument = new XmlDocumentEx(); connectionStringsDocument.Load(pathToConnectionStringsConfig); var connectionsStringsElement = new XmlElementEx(connectionStringsDocument.DocumentElement, connectionStringsDocument); ConnectionStringCollection connStringCollection = this.GetConnectionStringCollection(connectionsStringsElement); foreach (var conn in connStringCollection) { if (conn.IsSqlConnectionString) { var connectionStringBuilder = new SqlConnectionStringBuilder(conn.Value) { IntegratedSecurity = false, DataSource = args.connectionString.DataSource, UserID = args.connectionString.UserID, Password = args.connectionString.Password }; connectionStringBuilder.InitialCatalog = DatabaseNameHelper.GetDatabaseNameFromSiteAndName( args.siteName, DatabaseNameHelper.GetDatabaseNameFromFiles(connectionStringBuilder.InitialCatalog), false); conn.Value = connectionStringBuilder.ToString(); } else if (conn.IsMongoConnectionString) { conn.Value = DatabaseNameHelper.ProcessMongoConnectionString(args.siteName, conn.Value); } } connStringCollection.Save(); }
protected override void Process(ImportArgs args) { if (args.updateLicense) { string pathToDataFolder = args.rootPath.PathCombine("Data"); FileSystem.FileSystem.Local.File.Copy(args.pathToLicenseFile, pathToDataFolder.PathCombine("license.xml")); } }
private void CreateDirectoriesTree(ImportArgs args) { string rootPath = FileSystem.FileSystem.Local.Directory.GetParent(args.virtualDirectoryPhysicalPath).FullName; FileSystem.FileSystem.Local.Directory.CreateDirectory(rootPath); FileSystem.FileSystem.Local.Directory.CreateDirectory(rootPath.PathCombine("Data")); FileSystem.FileSystem.Local.Directory.CreateDirectory(rootPath.PathCombine("Databases")); FileSystem.FileSystem.Local.Directory.CreateDirectory(rootPath.PathCombine("Website")); }
protected override void Process(ImportArgs args) { var folder = FileSystem.FileSystem.Local.Directory.Ensure(args.temporaryPathToUnpack.PathCombine("MongoDatabases")); FileSystem.FileSystem.Local.Zip.ZipUnpackFolder(args.PathToExportedInstance, args.temporaryPathToUnpack, "MongoDatabases"); foreach (var directoryPath in FileSystem.FileSystem.Local.Directory.GetDirectories(folder)) { MongoHelper.Restore(directoryPath); } }
protected override void Process(ImportArgs args) { // Assert.IsTrue(FileSystem.Instance.ZipContainsFile(args.PathToExportedInstance, ImportArgs.appPoolSettingsFileName), "Not valid package for import."); // Assert.IsTrue(FileSystem.Instance.ZipContainsFile(args.PathToExportedInstance, ImportArgs.websiteSettingsFileName), "Not valid package for import."); // args.temporaryPathToUnpack = Path.GetTempPath(); this.GetSettingsFromIISFiles(args); // CreateDirectoriesTree(args); }
protected override void Process(ImportArgs args) { // Assert.IsTrue(FileSystem.Instance.ZipContainsSingleFile(args.PathToExportedInstance, ImportArgs.appPoolSettingsFileName), "Not valid package for import."); // Assert.IsTrue(FileSystem.Instance.ZipContainsSingleFile(args.PathToExportedInstance, ImportArgs.websiteSettingsFileName), "Not valid package for import."); // args.temporaryPathToUnpack = Path.GetTempPath(); string webRootName = args.virtualDirectoryPhysicalPath.Split('\\')[args.virtualDirectoryPhysicalPath.Split('\\').Length - 1]; FileSystem.FileSystem.Local.Zip.ZipUnpackFolder(args.PathToExportedInstance, args.rootPath, "Data"); FileSystem.FileSystem.Local.Zip.ZipUnpackFolder(args.PathToExportedInstance, args.rootPath, webRootName); }
private List<string> ExtractDatabases(ImportArgs args) { List<string> result = new List<string>(); string folderWithExtractedBackups = FileSystem.FileSystem.Local.Zip.ZipUnpackFolder(args.PathToExportedInstance, args.rootPath.PathCombine("Databases"), "Databases"); foreach (string file in FileSystem.FileSystem.Local.Directory.GetFiles(folderWithExtractedBackups, "*.bak")) { result.Add(file); } return result; }
protected override void Process(ImportArgs args) { var folder = FileSystem.FileSystem.Local.Directory.Ensure(args.temporaryPathToUnpack.PathCombine("MongoDatabases")); FileSystem.FileSystem.Local.Zip.ZipUnpackFolder(args.PathToExportedInstance, args.temporaryPathToUnpack, "MongoDatabases"); foreach (var directoryPath in FileSystem.FileSystem.Local.Directory.GetDirectories(folder)) { var fullName = Path.GetFileName(directoryPath); var dbName = DatabaseNameHelper.GetDatabaseNameFromFiles(fullName); var fullDbName = DatabaseNameHelper.GetDatabaseNameFromSiteAndName(args.siteName, dbName, isMongo: true); MongoHelper.Restore(fullDbName, directoryPath); } }
protected override void Process(ImportArgs args) { if (args._Bindings.Count == 0) { Hosts.Append(args._SiteName); } else { foreach (string hostname in args._Bindings.Keys) { Hosts.Append(hostname); } } }
protected override void Process(ImportArgs args) { if (args.bindings.Count == 0) { Hosts.Append(args.siteName); } else { foreach (string hostname in args.bindings.Keys) { Hosts.Append(hostname); } } }
private void ChangeWebsiteSettingsIfNeeded(string path, ImportArgs args) { XmlDocumentEx websiteSettings = new XmlDocumentEx(); websiteSettings.Load(path); args.siteName = this.CreateNewSiteName(InstanceManager.Instances, args.siteName); websiteSettings.SetElementAttributeValue("/appcmd/SITE", "SITE.NAME", args.siteName); websiteSettings.SetElementAttributeValue("/appcmd/SITE/site", "name", args.siteName); websiteSettings.SetElementAttributeValue("/appcmd/SITE", "bindings", "http/*:80:" + args.siteName); // need to change site ID args.siteID = this.CreateNewID(args.siteID); websiteSettings.SetElementAttributeValue("/appcmd/SITE", "SITE.ID", args.siteID.ToString()); websiteSettings.SetElementAttributeValue("/appcmd/SITE/site", "id", args.siteID.ToString()); // change apppool name websiteSettings.SetElementAttributeValue("/appcmd/SITE/site/application", "applicationPool", args.appPoolName); websiteSettings.SetElementAttributeValue("/appcmd/SITE/site/applicationDefaults", "applicationPool", args.appPoolName); // change root folder websiteSettings.SetElementAttributeValue("/appcmd/SITE/site/application/virtualDirectory", "physicalPath", args.rootPath + "\\Website"); // TODO: need to change bindings in right way(maybe with the UI dialog) // websiteSettings.SetElementAttributeValue("/appcmd/SITE/site/bindings/binding[@bindingInformation='*:80:" + args.oldSiteName + "']", "bindingInformation", "*:80:" + args.siteName); XmlElement bindingsElement = websiteSettings.SelectSingleElement("/appcmd/SITE/site/bindings"); if (bindingsElement != null) { bindingsElement.InnerXml = string.Empty; // it's a f*****g HACK, I can't work with xml nodes foreach (var key in args.bindings.Keys) { bindingsElement.InnerXml += "<binding protocol=\"http\" bindingInformation=\"*:{1}:{0}\" />".FormatWith(key, args.bindings[key].ToString()); } // foreach (XmlElement bindingElement in bindingsElement.ChildNodes) // { // //if (bindingElement.Attributes["bindingInformation"].Value.Split(':').Last() != null && bindingElement.Attributes["bindingInformation"].Value.Split(':').Last() != "") // // args.siteBindingsHostnames.Add(bindingElement.Attributes["bindingInformation"].Value.Split(':').Last()); // //if(bindingElement.Attributes["bindingInformation"].Value.Split(':').Last() != null && bindingElement.Attributes["bindingInformation"].Value.Split(':').Last() != "") // //bindingElement.Attributes["bindingInformation"].Value = bindingElement.Attributes["bindingInformation"].Value.Replace(bindingElement.Attributes["bindingInformation"].Value.Split(':').Last(), args.siteName); // } } websiteSettings.Save(websiteSettings.FilePath + ".fixed.xml"); }
protected override void Process(ImportArgs args) { Args = args; EnsureEmptyExtractedBackupFolder(); ExtractDatabases(); if (!Args.ExtractedMongoDatabases.Any()) { return; } SetDatabasesFinalName(); foreach (var database in Args.ExtractedMongoDatabases) { MongoHelper.Restore(database.DirectoryPath, database.FinalName); } }
private void RestoreDatabases(ImportArgs args) { if (FileSystem.FileSystem.Local.Directory.Exists(args.temporaryPathToUnpack.PathCombine("Databases"))) { foreach (string file in FileSystem.FileSystem.Local.Directory.GetFiles(args.temporaryPathToUnpack.PathCombine("Databases"))) { FileSystem.FileSystem.Local.File.Delete(file); } } List <string> backupsPaths = this.ExtractDatabases(args); if (backupsPaths.Count == 0) { return; } var backupInfo = new SqlServerManager.BackupInfo(); this.GetPostfixForDatabases(backupsPaths, args.connectionString, ref args.databaseNameAppend); foreach (string backup in backupsPaths) { backupInfo = SqlServerManager.Instance.GetDatabasesNameFromBackup(args.connectionString, backup); string dbName = backupInfo.dbOriginalName; // dbName = GetDatabaseName(dbName, args.connectionString, ref args.databaseNameAppend); dbName = this.GetDatabaseName(dbName, ref args.databaseNameAppend); // dbName = dbName + GetDBNameAppend(dbName, args.connectionString, 0); SqlServerManager.Instance.RestoreDatabase(dbName, args.connectionString, backup, FileSystem.FileSystem.Local.Directory.GetParent(args.virtualDirectoryPhysicalPath).FullName.PathCombine("Databases"), backupInfo); } }
private void RestoreDatabases(ImportArgs args) { if (FileSystem.FileSystem.Local.Directory.Exists(args.temporaryPathToUnpack.PathCombine("Databases"))) { foreach (string file in FileSystem.FileSystem.Local.Directory.GetFiles(args.temporaryPathToUnpack.PathCombine("Databases"))) { FileSystem.FileSystem.Local.File.Delete(file); } } List<string> backupsPaths = this.ExtractDatabases(args); if (backupsPaths.Count == 0) { return; } foreach (string backup in backupsPaths) { var databasesNameFromBackup = SqlServerManager.Instance.GetDatabasesNameFromBackup(args.connectionString, backup); var databaseName = DatabaseNameHelper.GetDatabaseNameFromFiles(databasesNameFromBackup.dbOriginalName); var fullDatabaseName = DatabaseNameHelper.GetDatabaseNameFromSiteAndName(args.siteName, databaseName, false); SqlServerManager.Instance.RestoreDatabase(fullDatabaseName, args.connectionString, backup, FileSystem.FileSystem.Local.Directory.GetParent(args.virtualDirectoryPhysicalPath).FullName.PathCombine("Databases"), databasesNameFromBackup); } }
protected override void Process(ImportArgs args) { // SqlServerManager.Instance.BackupInfo b = new SqlServerManager.Instance.BackupInfo(); // SqlServerManager.Instance.GetDatabasesNameFromBackup( this.RestoreDatabases(args); // DEBUG }
private void RestoreDatabases(ImportArgs args) { if (FileSystem.FileSystem.Local.Directory.Exists(args.temporaryPathToUnpack.PathCombine("Databases"))) { foreach (string file in FileSystem.FileSystem.Local.Directory.GetFiles(args.temporaryPathToUnpack.PathCombine("Databases"))) { FileSystem.FileSystem.Local.File.Delete(file); } } List<string> backupsPaths = this.ExtractDatabases(args); if (backupsPaths.Count == 0) { return; } var backupInfo = new SqlServerManager.BackupInfo(); this.GetPostfixForDatabases(backupsPaths, args.connectionString, ref args.databaseNameAppend); foreach (string backup in backupsPaths) { backupInfo = SqlServerManager.Instance.GetDatabasesNameFromBackup(args.connectionString, backup); string dbName = backupInfo.dbOriginalName; // dbName = GetDatabaseName(dbName, args.connectionString, ref args.databaseNameAppend); dbName = this.GetDatabaseName(dbName, ref args.databaseNameAppend); // dbName = dbName + GetDBNameAppend(dbName, args.connectionString, 0); SqlServerManager.Instance.RestoreDatabase(dbName, args.connectionString, backup, FileSystem.FileSystem.Local.Directory.GetParent(args.virtualDirectoryPhysicalPath).FullName.PathCombine("Databases"), backupInfo); } }
protected virtual long EvaluateStepsCount(ImportArgs args) { return 1; }
protected virtual bool IsRequireProcessing([NotNull] ImportArgs args) { Assert.ArgumentNotNull(args, nameof(args)); return(true); }
protected override void Process(ImportArgs args) { // var websiteName = args.Instance.Name; // var appPoolName = WebServerManager.CreateContext(string.Empty).Sites[websiteName].ApplicationDefaults.ApplicationPoolName; this.ChangeAppPoolSettingsIfNeeded(args.temporaryPathToUnpack.PathCombine(ImportArgs.appPoolSettingsFileName), args); this.ChangeWebsiteSettingsIfNeeded(args.temporaryPathToUnpack.PathCombine(ImportArgs.websiteSettingsFileName), args); var importAppPoolSettingsCommand = string.Format(@"%windir%\system32\inetsrv\appcmd add apppool /in < {0}", args.temporaryPathToUnpack.PathCombine(ImportArgs.appPoolSettingsFileName) + ".fixed.xml"); var importWebsiteSettingsCommand = string.Format(@"%windir%\system32\inetsrv\appcmd add site /in < {0}", args.temporaryPathToUnpack.PathCombine(ImportArgs.websiteSettingsFileName) + ".fixed.xml"); ExecuteCommand(importAppPoolSettingsCommand); ExecuteCommand(importWebsiteSettingsCommand); }
protected override void Process(ImportArgs args) { this.RestoreDatabases(args); }
protected override void Process(ImportArgs args) { string websiteFolderPath = args.rootPath; SetupWebsiteHelper.SetDataFolder(websiteFolderPath); }
private void ChangeAppPoolSettingsIfNeeded(string path, ImportArgs args) { // should be executed before ChangeWebsiteSettingsIfNeeded // need to change AppName XmlDocumentEx appPoolSettings = new XmlDocumentEx(); appPoolSettings.Load(path); args.appPoolName = this.CreateNewAppPoolName(args.appPoolName); appPoolSettings.SetElementAttributeValue("/appcmd/APPPOOL", "APPPOOL.NAME", args.appPoolName); appPoolSettings.SetElementAttributeValue("appcmd/APPPOOL/add", "name", args.appPoolName); appPoolSettings.Save(appPoolSettings.FilePath + ".fixed.xml"); }
protected abstract void Process([NotNull] ImportArgs args);
protected virtual long EvaluateStepsCount(ImportArgs args) { return(1); }