public void ImportItem(int packageId, int itemTypeId, Type itemType, ResourceGroupInfo group, string itemName) { // get service id int serviceId = PackageController.GetPackageServiceId(packageId, group.GroupName); if (serviceId == 0) { return; } // FTP provider FTPServer ftp = new FTPServer(); ServiceProviderProxy.Init(ftp, serviceId); if (itemType == typeof(FtpAccount)) { // load FTP account FtpAccount account = ftp.GetAccount(itemName); account.Folder = FilesController.GetFullPackagePath(packageId, "\\"); // root space folder // update FTP account ftp.UpdateAccount(account); // save account account.ServiceId = serviceId; account.PackageId = packageId; PackageController.AddPackageItem(account); } }
public static bool RemoteServerFolderWriteAccessible(int packageId, string path) { try { // copy to space folder int osServiceId = PackageController.GetPackageServiceId(packageId, ResourceGroups.Os); if (osServiceId > 0) { OS.OperatingSystem os = new OS.OperatingSystem(); ServiceProviderProxy.Init(os, osServiceId); string remoteServerPathCheck = FilesController.GetFullPackagePath(packageId, Path.Combine(path, "check.txt")); // os.CreateFile(remoteServerPathCheck); os.AppendFileBinaryContent(remoteServerPathCheck, Encoding.UTF8.GetBytes(remoteServerPathCheck)); os.DeleteFile(remoteServerPathCheck); } // return(true); } catch { // return(false); } }
private static FtpAccount ConvertItemToFtpAccount(ServiceProviderItem item) { FtpAccount account = (FtpAccount)item; string homeFolder = FilesController.GetHomeFolder(account.PackageId); if (!String.IsNullOrEmpty(account.Folder) && account.Folder.IndexOf(":") != -1) { account.Folder = account.Folder.Substring(homeFolder.Length); } account.Folder = (account.Folder == "") ? "\\" : account.Folder; // decode password account.Password = CryptoUtils.Decrypt(account.Password); return(account); }
public static int CreateBackupZip(int packageId, string archivePath) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // check package int packageCheck = SecurityContext.CheckPackage(packageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // place log record TaskManager.StartTask("FILES", "ZIP_FILES", archivePath, packageId); try { OS.OperatingSystem os = FilesController.GetOS(packageId); string zipFilePath = FilesController.GetFullPackagePath(packageId, archivePath); string rootFolder = FilesController.GetFullPackagePath(packageId, ""); os.CreateBackupZip(zipFilePath, rootFolder); return(0); } catch (Exception ex) { //Log and return a generic error rather than throwing an exception TaskManager.WriteError(ex); return(BusinessErrorCodes.ERROR_FILE_GENERIC_LOGGED); } finally { TaskManager.CompleteTask(); } }
public static FtpAccount GetFtpAccount(int itemId) { // load meta item FtpAccount item = (FtpAccount)PackageController.GetPackageItem(itemId); // load service item FTPServer ftp = new FTPServer(); ServiceProviderProxy.Init(ftp, item.ServiceId); FtpAccount account = ftp.GetAccount(item.Name); // truncate home folder account.Folder = FilesController.GetVirtualPackagePath(item.PackageId, account.Folder); account.Id = item.Id; account.PackageId = item.PackageId; account.ServiceId = item.ServiceId; account.Password = CryptoUtils.Decrypt(item.Password); return(account); }
public static SystemDSN GetOdbcSource(int itemId) { // load meta item SystemDSN item = (SystemDSN)PackageController.GetPackageItem(itemId); // load service item OS.OperatingSystem os = GetOS(item.ServiceId); SystemDSN dsn = os.GetDSN(item.Name); // add common properties dsn.Id = item.Id; dsn.PackageId = item.PackageId; dsn.ServiceId = item.ServiceId; if (dsn.Driver == "MsAccess" || dsn.Driver == "Excel" || dsn.Driver == "Text") { dsn.DatabaseName = FilesController.GetVirtualPackagePath(item.PackageId, dsn.DatabaseName); } return(dsn); }
public override void DoWork() { // Input parameters: // - FOLDER // - ZIP_FILE BackgroundTask topTask = TaskManager.TopTask; // get input parameters string filesList = (string)topTask.GetParamValue("FOLDER"); string zipFile = (string)topTask.GetParamValue("ZIP_FILE"); // check input parameters if (String.IsNullOrEmpty(filesList)) { TaskManager.WriteWarning("Specify 'Files List' task parameter"); return; } if (String.IsNullOrEmpty(zipFile)) { TaskManager.WriteWarning("Specify 'Zip File' task parameter"); return; } // substitute parameters DateTime d = DateTime.Now; string date = d.ToString("yyyyMMdd"); string time = d.ToString("HHmm"); filesList = Utils.ReplaceStringVariable(filesList, "date", date); filesList = Utils.ReplaceStringVariable(filesList, "time", time); zipFile = Utils.ReplaceStringVariable(zipFile, "date", date); zipFile = Utils.ReplaceStringVariable(zipFile, "time", time); // zip files and folders FilesController.ZipFiles(topTask.PackageId, new string[] { filesList }, zipFile); }
private void RollbackInstallation(InstallationInfo inst) { // remove virtual dir if (inst[PROPERTY_VDIR_CREATED] != null) { // delete virtual directory WebServerController.DeleteAppVirtualDirectory(inst.WebSiteId, inst.VirtualDir); // delete folder FilesController.DeleteFiles(inst.PackageId, new string[] { inst[PROPERTY_CONTENT_PATH] }); } // remove database if (inst[PROPERTY_DATABASE_CREATED] != null) { DatabaseServerController.DeleteSqlDatabase(inst.DatabaseId); } // remove database user if (inst[PROPERTY_USER_CREATED] != null) { DatabaseServerController.DeleteSqlUser(inst.UserId); } }
public static int UpdateFtpAccount(FtpAccount item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // load original meta item FtpAccount origItem = (FtpAccount)PackageController.GetPackageItem(item.Id); if (origItem == null) { return(BusinessErrorCodes.ERROR_FTP_PACKAGE_ITEM_NOT_FOUND); } // check package int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // place log record TaskManager.StartTask("FTP_ACCOUNT", "UPDATE", origItem.Name, item.Id); TaskManager.WriteParameter("Folder", item.Folder); TaskManager.WriteParameter("CanRead", item.CanRead); TaskManager.WriteParameter("CanWrite", item.CanWrite); try { // get service FTPServer ftp = new FTPServer(); ServiceProviderProxy.Init(ftp, origItem.ServiceId); // store original folder string origFolder = item.Folder; // convert folder StringDictionary ftpSettings = ServerController.GetServiceSettings(origItem.ServiceId); if (Utils.ParseBool(ftpSettings["BuildUncFilesPath"], false)) { // UNC // get OS service int osServiceId = PackageController.GetPackageServiceId(origItem.PackageId, ResourceGroups.Os); item.Folder = FilesController.GetFullUncPackagePath(origItem.PackageId, osServiceId, item.Folder); } else { // Absolute item.Folder = FilesController.GetFullPackagePath(origItem.PackageId, item.Folder); } item.Enabled = true; // add service item ftp.UpdateAccount(item); // save item item.Password = String.IsNullOrEmpty(item.Password) ? origItem.Password : CryptoUtils.Encrypt(item.Password); item.Folder = (origFolder == "") ? "\\" : origFolder; PackageController.UpdatePackageItem(item); return(0); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public static int AddFtpAccount(FtpAccount item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // check package int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // check quota QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.FTP_ACCOUNTS); if (quota.QuotaExhausted) { return(BusinessErrorCodes.ERROR_FTP_RESOURCE_QUOTA_LIMIT); } // check if FTP account already exists int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Ftp); if (serviceId == 0) { return(BusinessErrorCodes.ERROR_FTP_RESOURCE_UNAVAILABLE); } // place log record TaskManager.StartTask("FTP_ACCOUNT", "ADD", item.Name); TaskManager.WriteParameter("Folder", item.Folder); TaskManager.WriteParameter("CanRead", item.CanRead); TaskManager.WriteParameter("CanWrite", item.CanWrite); try { // check package items if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(FtpAccount)) != null) { return(BusinessErrorCodes.ERROR_FTP_PACKAGE_ITEM_EXISTS); } // check service items FTPServer ftp = new FTPServer(); ServiceProviderProxy.Init(ftp, serviceId); if (ftp.AccountExists(item.Name)) { return(BusinessErrorCodes.ERROR_FTP_SERVICE_ITEM_EXISTS); } // store original path string origFolder = item.Folder; // convert folder StringDictionary ftpSettings = ServerController.GetServiceSettings(serviceId); if (Utils.ParseBool(ftpSettings["BuildUncFilesPath"], false)) { // UNC // get OS service int osServiceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Os); item.Folder = FilesController.GetFullUncPackagePath(item.PackageId, osServiceId, item.Folder); } else { // Absolute item.Folder = FilesController.GetFullPackagePath(item.PackageId, item.Folder); } item.Enabled = true; // add service item ftp.CreateAccount(item); // save item item.Password = CryptoUtils.Encrypt(item.Password); item.ServiceId = serviceId; item.Folder = (origFolder == "") ? "\\" : origFolder; int itemId = PackageController.AddPackageItem(item); TaskManager.ItemId = itemId; return(itemId); } catch (Exception ex) { TaskManager.WriteError(ex); throw; } finally { TaskManager.CompleteTask(); } }
public void ExecuteSyncActions(int packageId, FileSyncAction[] actions) { FilesController.ExecuteSyncActions(packageId, actions); }
public static string GetHomeFolder(int packageId) { return(FilesController.GetHomeFolder(packageId)); }
public UserPermission[] GetFilePermissions(int packageId, string path) { return(FilesController.GetFilePermissions(packageId, path)); }
public static int UpdateOdbcSource(SystemDSN item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // load original meta item SystemDSN origItem = (SystemDSN)PackageController.GetPackageItem(item.Id); if (origItem == null) { return(BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_NOT_FOUND); } // check package int packageCheck = SecurityContext.CheckPackage(origItem.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // place log record TaskManager.StartTask("ODBC_DSN", "UPDATE", origItem.Name); TaskManager.ItemId = item.Id; try { // get service OS.OperatingSystem os = GetOS(origItem.ServiceId); // password item.Driver = origItem.Driver; item.Name = origItem.Name; if (item.DatabasePassword == "") { item.DatabasePassword = CryptoUtils.Decrypt(origItem.DatabasePassword); } string[] dbNameParts = item.DatabaseName.Split('|'); string groupName = null; if (dbNameParts.Length > 1) { item.DatabaseName = dbNameParts[0]; groupName = dbNameParts[1]; } // get database server address item.DatabaseServer = GetDatabaseServerName(groupName, item.PackageId); if (item.Driver == "MsAccess" || item.Driver == "Excel" || item.Driver == "Text") { item.DatabaseName = FilesController.GetFullPackagePath(origItem.PackageId, item.DatabaseName); } // update service item os.UpdateDSN(item); // update meta item if (item.DatabasePassword != "") { item.DatabasePassword = CryptoUtils.Encrypt(item.DatabasePassword); PackageController.UpdatePackageItem(item); } return(0); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public static int AddSite(StatsSite item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // check package int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // check quota QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.STATS_SITES); if (quota.QuotaExhausted) { return(BusinessErrorCodes.ERROR_STATS_RESOURCE_QUOTA_LIMIT); } // check if stats resource is available int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Statistics); if (serviceId == 0) { return(BusinessErrorCodes.ERROR_STATS_RESOURCE_UNAVAILABLE); } // check package items if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(StatsSite)) != null) { return(BusinessErrorCodes.ERROR_STATS_PACKAGE_ITEM_EXISTS); } // place log record TaskManager.StartTask("STATS_SITE", "ADD", item.Name); try { // load web site WebSite siteItem = (WebSite)PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(WebSite)); if (siteItem == null) { return(BusinessErrorCodes.ERROR_WEB_SITE_SERVICE_UNAVAILABLE); } // get service web site WebServer web = new WebServer(); ServiceProviderProxy.Init(web, siteItem.ServiceId); WebSite site = web.GetSite(siteItem.SiteId); List <DomainInfo> pointers = WebServerController.GetWebSitePointers(siteItem.Id); List <string> aliases = new List <string>(); foreach (DomainInfo pointer in pointers) { aliases.Add(pointer.DomainName); } StatisticsServer stats = new StatisticsServer(); ServiceProviderProxy.Init(stats, serviceId); string siteNumber = (site.IIs7) ? site[WebSite.IIS7_SITE_ID] : siteItem.SiteId.Replace("/", ""); string logsCommonFolder = site.LogsPath; string logsFolder = Path.Combine(logsCommonFolder, siteNumber); // get service settings StringDictionary settings = ServerController.GetServiceSettings(serviceId); if (Utils.ParseBool(settings["BuildUncLogsPath"], false)) { logsFolder = FilesController.ConvertToUncPath(siteItem.ServiceId, logsFolder); } item.LogDirectory = logsFolder; item.DomainAliases = aliases.ToArray(); // install statistics item.SiteId = stats.AddSite(item); // save statistics item item.ServiceId = serviceId; int itemId = PackageController.AddPackageItem(item); TaskManager.ItemId = itemId; return(itemId); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public int UpdateFileBinaryContentUsingEncoding(int packageId, string path, byte[] content, string encoding) { return(FilesController.UpdateFileBinaryContentUsingEncoding(packageId, path, content, encoding)); }
public int UpdateFileBinaryContent(int packageId, string path, byte[] content) { return(FilesController.UpdateFileBinaryContent(packageId, path, content)); }
public byte[] GetFileBinaryContentUsingEncoding(int packageId, string path, string encoding) { return(FilesController.GetFileBinaryContentUsingEncoding(packageId, path, encoding)); }
public byte[] GetFileBinaryContent(int packageId, string path) { return(FilesController.GetFileBinaryContent(packageId, path)); }
public List <SystemFile> GetFilesByMask(int packageId, string path, string filesMask) { return(FilesController.GetFilesByMask(packageId, path, filesMask)); }
public List <SystemFile> GetFiles(int packageId, string path, bool includeFiles) { return(FilesController.GetFiles(packageId, path, includeFiles)); }
public FolderGraph GetFolderGraph(int packageId, string path) { return(FilesController.GetFolderGraph(packageId, path)); }
public int SetFilePermissions(int packageId, string path, UserPermission[] users, bool resetChildPermissions) { return(FilesController.SetFilePermissions(packageId, path, users, resetChildPermissions)); }
public int CalculatePackageDiskspace(int packageId) { return(FilesController.CalculatePackageDiskspace(packageId)); }
public static int AddOdbcSource(SystemDSN item) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive); if (accountCheck < 0) { return(accountCheck); } // check package int packageCheck = SecurityContext.CheckPackage(item.PackageId, DemandPackage.IsActive); if (packageCheck < 0) { return(packageCheck); } // check quota QuotaValueInfo quota = PackageController.GetPackageQuota(item.PackageId, Quotas.OS_ODBC); if (quota.QuotaExhausted) { return(BusinessErrorCodes.ERROR_OS_DSN_RESOURCE_QUOTA_LIMIT); } // check if mail resource is available int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.Os); if (serviceId == 0) { return(BusinessErrorCodes.ERROR_OS_RESOURCE_UNAVAILABLE); } // check package items if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SystemDSN)) != null) { return(BusinessErrorCodes.ERROR_OS_DSN_PACKAGE_ITEM_EXISTS); } // place log record TaskManager.StartTask("ODBC_DSN", "ADD", item.Name); try { // check service items OS.OperatingSystem os = GetOS(serviceId); if (os.GetDSN(item.Name) != null) { return(BusinessErrorCodes.ERROR_OS_DSN_SERVICE_ITEM_EXISTS); } string[] dbNameParts = item.DatabaseName.Split('|'); string groupName = null; if (dbNameParts.Length > 1) { item.DatabaseName = dbNameParts[0]; groupName = dbNameParts[1]; } // get database server address item.DatabaseServer = GetDatabaseServerName(groupName, item.PackageId); if (item.Driver == "MsAccess" || item.Driver == "Excel" || item.Driver == "Text") { item.DatabaseName = FilesController.GetFullPackagePath(item.PackageId, item.DatabaseName); } // add service item os.CreateDSN(item); // save item item.DatabasePassword = CryptoUtils.Encrypt(item.DatabasePassword); item.ServiceId = serviceId; int itemId = PackageController.AddPackageItem(item); TaskManager.ItemId = itemId; return(itemId); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
private int RunScenario(string scenarioPath, InstallationInfo inst, bool throwExceptions) { // load XML document XmlDocument docScenario = new XmlDocument(); docScenario.Load(scenarioPath); // go through "check" section XmlNode nodeCheck = docScenario.SelectSingleNode("//check"); if (nodeCheck != null) { foreach (XmlNode nodeStep in nodeCheck.ChildNodes) { if (nodeStep.Name == "fileExists") { /* * // check if the specified file exists * string fileName = nodeStep.Attributes["path"].Value; * fileName = ExpandVariables(fileName, inst); * if (fileName.StartsWith("\\")) * { * fileName = fileName.Substring(1); * } * //get full path to instal folder * PackageInfo package = PackageController.GetPackage(inst.PackageId); * string fullPath = Path.Combine(GetFullPathToInstallFolder(package.UserId), fileName); * if (os.FileExists(fullPath)) * return BusinessErrorCodes.ERROR_WEB_INSTALLER_TARGET_WEBSITE_UNSUITABLE; */ } else if (nodeStep.Name == "sql") { string cmdText = nodeStep.InnerText; cmdText = ExpandVariables(cmdText, inst); DataSet dsResults = sql.ExecuteSqlQuery(inst.DatabaseName, cmdText); if (dsResults.Tables[0].Rows.Count > 0) { return(BusinessErrorCodes.ERROR_WEB_INSTALLER_TARGET_DATABASE_UNSUITABLE); } } } } // go through "commands" section XmlNode nodeCommands = docScenario.SelectSingleNode("//commands"); if (nodeCommands != null) { foreach (XmlNode nodeCommand in nodeCommands.ChildNodes) { if (nodeCommand.Name == "processFile") { // process remote file string fileName = nodeCommand.Attributes["path"].Value; fileName = ExpandVariables(fileName, inst); byte[] fileBinaryContent = FilesController.GetFileBinaryContent(inst.PackageId, fileName); if (fileBinaryContent == null) { throw new Exception("Could not process scenario file: " + fileName); } string fileContent = Encoding.UTF8.GetString(fileBinaryContent); fileContent = ExpandVariables(fileContent, inst); FilesController.UpdateFileBinaryContent(inst.PackageId, fileName, Encoding.UTF8.GetBytes(fileContent)); } else if (nodeCommand.Name == "runSql") { string cmdText = nodeCommand.InnerText; if (nodeCommand.Attributes["path"] != null) { // load SQL from file string sqlPath = Path.Combine(app.Folder, nodeCommand.Attributes["path"].Value); if (!File.Exists(sqlPath)) { continue; } StreamReader reader = new StreamReader(sqlPath); cmdText = reader.ReadToEnd(); reader.Close(); } bool run = true; if (nodeCommand.Attributes["dependsOnProperty"] != null) { string[] propNames = nodeCommand.Attributes["dependsOnProperty"].Value.Split(','); foreach (string propName in propNames) { if (inst[propName.Trim()] == null) { run = false; break; } } } if (run) { try { cmdText = ExpandVariables(cmdText, inst); sql.ExecuteSqlNonQuerySafe(inst.DatabaseName, inst.Username, inst.Password, cmdText); } catch (Exception ex) { if (throwExceptions) { throw ex; } } } } } } return(0); }
public int BackupItem(string tempFolder, System.Xml.XmlWriter writer, ServiceProviderItem item, ResourceGroupInfo group) { if (item is HomeFolder) { // backup home folder files string backupName = String.Format("SpaceFiles_{0}_{1}.zip", item.Id, DateTime.Now.Ticks); // get the list of remote files List <SystemFile> files = FilesController.GetFiles(item.PackageId, "\\", true); string[] zipFiles = new string[files.Count]; for (int i = 0; i < zipFiles.Length; i++) { zipFiles[i] = files[i].Name; } // zip remote files FilesController.ZipFiles(item.PackageId, zipFiles, backupName); // download zipped file string localBackupPath = Path.Combine(tempFolder, backupName); byte[] buffer = null; FileStream stream = new FileStream(localBackupPath, FileMode.Create, FileAccess.Write); int offset = 0; long length = 0; do { // read remote content buffer = FilesController.GetFileBinaryChunk(item.PackageId, backupName, offset, FILE_BUFFER_LENGTH); // write remote content stream.Write(buffer, 0, buffer.Length); length += buffer.Length; offset += FILE_BUFFER_LENGTH; }while (buffer.Length == FILE_BUFFER_LENGTH); stream.Close(); // delete zipped file if (FilesController.FileExists(item.PackageId, backupName)) { FilesController.DeleteFiles(item.PackageId, new string[] { backupName }); } // add file pointer BackupController.WriteFileElement(writer, "SpaceFiles", backupName, length); // store meta item XmlSerializer serializer = new XmlSerializer(typeof(HomeFolder)); serializer.Serialize(writer, item); } else if (item is SystemDSN) { // backup ODBC DSN OS.OperatingSystem os = GetOS(item.ServiceId); // read DSN info SystemDSN itemDsn = item as SystemDSN; SystemDSN dsn = os.GetDSN(item.Name); dsn.DatabasePassword = itemDsn.DatabasePassword; XmlSerializer serializer = new XmlSerializer(typeof(SystemDSN)); serializer.Serialize(writer, dsn); } return(0); }
public int ApplyEnableHardQuotaFeature(int packageId) { return(FilesController.ApplyEnableHardQuotaFeature(packageId)); }
public int InstallWebApplication(InstallationInfo inst) { // place log record TaskManager.StartTask("APP_INSTALLER", "INSTALL_APPLICATION", inst.PackageId); TaskManager.WriteParameter("Virtual directory", inst.VirtualDir); TaskManager.WriteParameter("Database group", inst.DatabaseGroup); try { // get application info app = GetApplication(inst.PackageId, inst.ApplicationId); BackgroundTask topTask = TaskManager.TopTask; topTask.ItemName = app.Name; TaskController.UpdateTask(topTask); // check web site for existance WebSite webSite = WebServerController.GetWebSite(inst.WebSiteId); if (webSite == null) { return(BusinessErrorCodes.ERROR_WEB_INSTALLER_WEBSITE_NOT_EXISTS); } TaskManager.WriteParameter("Web site", webSite.Name); webSiteName = webSite.Name; siteId = webSite.SiteId; // change web site properties if required if (String.IsNullOrEmpty(inst.VirtualDir)) { ChangeAppVirtualDirectoryProperties(webSite, app.WebSettings); WebServerController.UpdateWebSite(webSite); } // get OS service int osId = PackageController.GetPackageServiceId(inst.PackageId, "os"); os = new OS.OperatingSystem(); ServiceProviderProxy.Init(os, osId); // get remote content path contentPath = webSite.ContentPath; // create virtual dir if required if (!String.IsNullOrEmpty(inst.VirtualDir)) { // check if the required virtual dir already exists contentPath = Path.Combine(contentPath, inst.VirtualDir); WebAppVirtualDirectory vdir = null; int result = WebServerController.AddAppVirtualDirectory(inst.WebSiteId, inst.VirtualDir, contentPath); if (result == BusinessErrorCodes.ERROR_VDIR_ALREADY_EXISTS) { // the directory alredy exists vdir = WebServerController.GetAppVirtualDirectory( inst.WebSiteId, inst.VirtualDir); contentPath = vdir.ContentPath; } else { vdir = WebServerController.GetAppVirtualDirectory( inst.WebSiteId, inst.VirtualDir); inst[PROPERTY_VDIR_CREATED] = "True"; } // change virtual directory properties if required ChangeAppVirtualDirectoryProperties(vdir, app.WebSettings); WebServerController.UpdateAppVirtualDirectory(inst.WebSiteId, vdir); } // deploy application codebase ZIP and then unpack it string codebasePath = app.Codebase; string remoteCodebasePath = Path.Combine(contentPath, Path.GetFileName(app.Codebase)); // make content path absolute string absContentPath = FilesController.GetFullPackagePath(inst.PackageId, contentPath); // save content path inst[PROPERTY_CONTENT_PATH] = contentPath; inst[PROPERTY_ABSOLUTE_CONTENT_PATH] = absContentPath; // copy ZIP to the target server FileStream stream = File.OpenRead(codebasePath); int BUFFER_LENGTH = 5000000; byte[] buffer = new byte[BUFFER_LENGTH]; int readBytes = 0; while (true) { readBytes = stream.Read(buffer, 0, BUFFER_LENGTH); if (readBytes < BUFFER_LENGTH) { Array.Resize <byte>(ref buffer, readBytes); } FilesController.AppendFileBinaryChunk(inst.PackageId, remoteCodebasePath, buffer); if (readBytes < BUFFER_LENGTH) { break; } } // unpack codebase inst[PROPERTY_INSTALLED_FILES] = String.Join(";", FilesController.UnzipFiles(inst.PackageId, new string[] { remoteCodebasePath })); // delete codebase zip FilesController.DeleteFiles(inst.PackageId, new string[] { remoteCodebasePath }); // check/create databases if (!String.IsNullOrEmpty(inst.DatabaseGroup) && String.Compare(inst.DatabaseGroup, "None", true) != 0) { // database if (inst.DatabaseId == 0) { TaskManager.WriteParameter("Database name", inst.DatabaseName); // we should create a new database SqlDatabase db = new SqlDatabase(); db.PackageId = inst.PackageId; db.Name = inst.DatabaseName; inst.DatabaseId = DatabaseServerController.AddSqlDatabase(db, inst.DatabaseGroup); if (inst.DatabaseId < 0) { // rollback installation RollbackInstallation(inst); // return error return(inst.DatabaseId); // there was an error when creating database } inst[PROPERTY_DATABASE_CREATED] = "True"; } else { // existing database SqlDatabase db = DatabaseServerController.GetSqlDatabase(inst.DatabaseId); inst.DatabaseName = db.Name; TaskManager.WriteParameter("Database name", inst.DatabaseName); } SqlUser user = null; // database user if (inst.UserId == 0) { TaskManager.WriteParameter("Database user", inst.Username); // NEW USER user = new SqlUser(); user.PackageId = inst.PackageId; user.Name = inst.Username; user.Databases = new string[] { inst.DatabaseName }; user.Password = inst.Password; inst.UserId = DatabaseServerController.AddSqlUser(user, inst.DatabaseGroup); if (inst.UserId < 0) { // rollback installation RollbackInstallation(inst); // return error return(inst.UserId); // error while adding user } inst[PROPERTY_USER_CREATED] = "True"; } else { // EXISTING USER user = DatabaseServerController.GetSqlUser(inst.UserId); inst.Username = user.Name; TaskManager.WriteParameter("Database user", inst.Username); List <string> databases = new List <string>(); databases.AddRange(user.Databases); if (!databases.Contains(inst.DatabaseName)) { databases.Add(inst.DatabaseName); user.Databases = databases.ToArray(); DatabaseServerController.UpdateSqlUser(user); } } // check connectivity with SQL Server and credentials provided // load user item int sqlServiceId = PackageController.GetPackageServiceId(inst.PackageId, inst.DatabaseGroup); sql = new DatabaseServer(); ServiceProviderProxy.Init(sql, sqlServiceId); if (!sql.CheckConnectivity(inst.DatabaseName, inst.Username, inst.Password)) { // can't connect to the database RollbackInstallation(inst); return(BusinessErrorCodes.ERROR_WEB_INSTALLER_CANT_CONNECT_DATABASE); } // read SQL server settings StringDictionary settings = ServerController.GetServiceSettings(sqlServiceId); serverIpAddressExternal = settings["ExternalAddress"]; if (settings.ContainsKey("InternalAddress")) { serverIpAddressInternal = settings["InternalAddress"]; } } // ********* RUN INSTALL SCENARIO *********** int scriptResult = RunInstallScenario(inst); if (scriptResult < 0) { // rollback installation RollbackInstallation(inst); // return error return(scriptResult); } // add new installation to the database return(0); } catch (Exception ex) { // rollback installation RollbackInstallation(inst); throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public SystemSettings GetFileManagerSettings() { return(FilesController.GetFileManagerSettings()); }