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 AddSite(SharePointSite 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.SHAREPOINT_SITES); if (quota.QuotaExhausted) { return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT); } // check if stats resource is available int serviceId = PackageController.GetPackageServiceId(item.PackageId, ResourceGroups.SharePoint); if (serviceId == 0) { return(BusinessErrorCodes.ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE); } // check package items if (PackageController.GetPackageItemByName(item.PackageId, item.Name, typeof(SharePointSite)) != null) { return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS); } // place log record TaskManager.StartTask("SHAREPOINT", "ADD_SITE", item.Name); TaskManager.WriteParameter("Database group", item.DatabaseGroupName); TaskManager.WriteParameter("Database name", item.DatabaseName); TaskManager.WriteParameter("Database user", item.DatabaseUser); int databaseItemId = 0; int databaseUserItemId = 0; 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); ///////////////////////////////////////// // // PREPARE SHAREPOINT SITE INSTALLATION // ServiceInfo wssService = ServerController.GetServiceInfo(serviceId); bool wss30 = (wssService.ProviderId == 23); // WSS 3.0 // remember original web site bindings ServerBinding[] bindings = site.Bindings; // set application pool and root folder item.ApplicationPool = site.ApplicationPool; item.RootFolder = site.ContentPath; // change web site .NET framework if required bool siteUpdated = false; if (!wss30 && (site.AspNetInstalled != "1" || site.DedicatedApplicationPool)) { site.AspNetInstalled = "1"; site.DedicatedApplicationPool = false; web.UpdateSite(site); siteUpdated = true; } if (wss30 && site.AspNetInstalled != "2") { site.AspNetInstalled = "2"; web.UpdateSite(site); siteUpdated = true; } if (siteUpdated) { site = web.GetSite(siteItem.SiteId); item.ApplicationPool = site.ApplicationPool; } if (site.FrontPageInstalled) { // remove FrontPage web.UninstallFrontPage(siteItem.SiteId, siteItem.FrontPageAccount); } // create SQL database SqlDatabase database = new SqlDatabase(); database.PackageId = item.PackageId; database.Name = item.DatabaseName; databaseItemId = DatabaseServerController.AddSqlDatabase(database, item.DatabaseGroupName); if (databaseItemId < 0) { return(databaseItemId); } // create SQL user SqlUser dbUser = new SqlUser(); dbUser.PackageId = item.PackageId; dbUser.Name = item.DatabaseUser; dbUser.Password = item.DatabasePassword; databaseUserItemId = DatabaseServerController.AddSqlUser(dbUser, item.DatabaseGroupName); if (databaseUserItemId < 0) { return(databaseUserItemId); } // delete SQL database from service // and change database user role int sqlServiceId = PackageController.GetPackageServiceId(item.PackageId, item.DatabaseGroupName); if (sqlServiceId < 0) { return(BusinessErrorCodes.ERROR_MSSQL_RESOURCE_UNAVAILABLE); } // load server settings StringDictionary sqlSettings = ServerController.GetServiceSettings(sqlServiceId); item.DatabaseServer = sqlSettings["ExternalAddress"]; DatabaseServer dbServer = new DatabaseServer(); ServiceProviderProxy.Init(dbServer, sqlServiceId); // delete database from service dbServer.DeleteDatabase(database.Name); // give SQL user "db_creator" role dbServer.ExecuteSqlNonQuery("master", String.Format( "sp_addsrvrolemember '{0}', 'dbcreator'\nGO", dbUser.Name)); // install SharePoint site SharePointServer sps = GetSharePoint(serviceId); sps.ExtendVirtualServer(item); // remove SQL user from "db_creator" role dbServer.ExecuteSqlNonQuery("master", String.Format( "sp_dropsrvrolemember '{0}', 'dbcreator'\nGO", dbUser.Name)); // restore original web site bindings web.UpdateSiteBindings(site.SiteId, bindings, false); // save statistics item item.ServiceId = serviceId; int itemId = PackageController.AddPackageItem(item); TaskManager.ItemId = itemId; return(itemId); } catch (Exception ex) { // delete database if required if (databaseItemId > 0) { DatabaseServerController.DeleteSqlDatabase(databaseItemId); } // delete user if required if (databaseUserItemId > 0) { DatabaseServerController.DeleteSqlUser(databaseUserItemId); } throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }
public int DeleteSqlDatabase(int itemId) { return(DatabaseServerController.DeleteSqlDatabase(itemId)); }
public static int DeleteSite(int itemId) { // check account int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo); if (accountCheck < 0) { return(accountCheck); } // load original meta item SharePointSite origItem = (SharePointSite)PackageController.GetPackageItem(itemId); if (origItem == null) { return(BusinessErrorCodes.ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND); } // place log record TaskManager.StartTask("SHAREPOINT", "DELETE_SITE", origItem.Name, itemId); try { // get service SharePointServer sps = GetSharePoint(origItem.ServiceId); // delete service item sps.UnextendVirtualServer(origItem.Name, true); try { // delete database ServiceProviderItem dbItem = PackageController.GetPackageItemByName(origItem.PackageId, origItem.DatabaseGroupName, origItem.DatabaseName, typeof(SqlDatabase)); if (dbItem != null) { DatabaseServerController.DeleteSqlDatabase(dbItem.Id); } // delete database user dbItem = PackageController.GetPackageItemByName(origItem.PackageId, origItem.DatabaseGroupName, origItem.DatabaseUser, typeof(SqlUser)); if (dbItem != null) { DatabaseServerController.DeleteSqlUser(dbItem.Id); } } catch (Exception ex2) { TaskManager.WriteError(ex2); } // delete meta item PackageController.DeletePackageItem(origItem.Id); try { // start web site WebSite site = WebServerController.GetWebSite(origItem.PackageId, origItem.Name); if (site != null) { WebServerController.ChangeSiteState(site.Id, ServerState.Started); } } catch (Exception ex) { TaskManager.WriteError(ex); } return(0); } catch (Exception ex) { throw TaskManager.WriteError(ex); } finally { TaskManager.CompleteTask(); } }