예제 #1
0
        public void ExtendVirtualServer(SharePointSite site, bool exclusiveNTLM)
		{
			try
			{
				WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();

				string siteUrl = "http://" + site.Name;

				// check input parameters
				if (String.IsNullOrEmpty(site.RootFolder)
					|| !Directory.Exists(site.RootFolder))
					throw new Exception("Could not create SharePoint site, because web site root folder does not exist. Open web site properties and click \"Update\" button to re-create site folder.");

				SPWebApplication app = SPWebApplication.Lookup(new Uri(siteUrl));
				if (app != null)
					throw new Exception("SharePoint is already installed on this web site.");

				//SPFarm farm = SPFarm.Local;
				SPFarm farm = SPFarm.Local;
				SPWebApplicationBuilder builder = new SPWebApplicationBuilder(farm);
				builder.ApplicationPoolId = site.ApplicationPool;
				builder.DatabaseServer = site.DatabaseServer;
				builder.DatabaseName = site.DatabaseName;
				builder.DatabaseUsername = site.DatabaseUser;
				builder.DatabasePassword = site.DatabasePassword;

				builder.ServerComment = site.Name;
				builder.HostHeader = site.Name;
				builder.Port = 80;

				builder.RootDirectory = new DirectoryInfo(site.RootFolder);
				builder.DefaultZoneUri = new Uri(siteUrl);
                builder.UseNTLMExclusively = exclusiveNTLM;

				app = builder.Create();
				app.Name = site.Name;

				app.Sites.Add(siteUrl, null, null, (uint)site.LocaleID, null, site.OwnerLogin, null, site.OwnerEmail);

				app.Update();
				app.Provision();

				wic.Undo();
			}
			catch (Exception ex)
			{
				try
				{
					// try to delete app if it was created
					SPWebApplication app = SPWebApplication.Lookup(new Uri("http://" + site.Name));
					if (app != null)
						app.Delete();
				}
				catch { /* nop */ }

				throw new Exception("Error creating SharePoint site", ex);
			}
		}
        private void BindItem()
        {
            try
            {
                if (!IsPostBack)
                {
                    // load item if required
                    if (PanelRequest.ItemID > 0)
                    {
                        // existing item
                        item = ES.Services.SharePointServers.GetSharePointSite(PanelRequest.ItemID);
                        if (item != null)
                        {
                            // save package info
                            ViewState["PackageId"] = item.PackageId;
                        }
                        else
                            RedirectToBrowsePage();
                    }
                    else
                    {
                        // new item
                        ViewState["PackageId"] = PanelSecurity.PackageId;
                        databaseName.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.MSSQL_POLICY, "DatabaseNamePolicy");
                        databaseUser.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.MSSQL_POLICY, "UserNamePolicy");
                        databasePassword.SetPackagePolicy(PanelSecurity.PackageId, UserSettings.MSSQL_POLICY, "UserPasswordPolicy");
                        BindDatabaseVersions();
                        BindWebSites(PanelSecurity.PackageId);
                        BindUsers(PanelSecurity.PackageId);
                    }
                }

                if (!IsPostBack)
                {
                    // bind item to controls
                    if (item != null)
                    {
                        // bind item to controls
                        litWebSite.Text = item.Name;
                        litLocaleID.Text = (item.LocaleID == 0) ? "1033" : item.LocaleID.ToString();
                        litSiteOwner.Text = item.OwnerLogin;
                        litOwnerEmail.Text = item.OwnerEmail;
                        litDatabaseName.Text = item.DatabaseName;
                        litDatabaseUser.Text = item.DatabaseUser;
                    }
                }

            }
            catch
            {
                ShowWarningMessage("INIT_SERVICE_ITEM_FORM");
                DisableFormControls(this, btnCancel);
                return;
            }
        }
예제 #3
0
        public virtual void ExtendVirtualServer(SharePointSite site)
        {
            // install SharePoint
            string cmdPath = GetAdminToolPath();
            string cmdArgs = String.Format(@"-o extendvs -url http://{0} -ownerlogin {1}\{2} -owneremail {3} -databaseserver {4} -databasename {5} -databaseuser {6} -databasepassword {7}",
                site.Name, Environment.MachineName, site.OwnerLogin, site.OwnerEmail,
                site.DatabaseServer, site.DatabaseName, site.DatabaseUser, site.DatabasePassword);

            ProcessExecutionResults result = ExecuteSystemCommand(cmdPath, cmdArgs);
            if (result.ExitCode < 0)
                throw new Exception("Error while installing SharePoint: " + result.Output);
        }
 public void ExtendVirtualServer(SharePointSite site)
 {
     try
     {
         Log.WriteStart("'{0}' ExtendVirtualServer", ProviderSettings.ProviderName);
         SPS.ExtendVirtualServer(site);
         Log.WriteEnd("'{0}' ExtendVirtualServer", ProviderSettings.ProviderName);
     }
     catch (Exception ex)
     {
         Log.WriteError(String.Format("Can't ExtendVirtualServer '{0}' provider", ProviderSettings.ProviderName), ex);
         throw;
     }
 }
예제 #5
0
		public override void ExtendVirtualServer(SharePointSite site)
		{
			AppDomain domain = null;
			try
			{
				domain = CreateAppDomain();
				Sps30Remote wss = CreateSps30Remote(domain);

				// call method
				wss.ExtendVirtualServer(site, ExclusiveNTLM);
			}
			finally
			{
				if (domain != null)
					AppDomain.Unload(domain);
			}
		}
        private void SaveItem()
        {
            if (!Page.IsValid)
                return;

            // get form data
            item = new SharePointSite();
            item.Id = PanelRequest.ItemID;
            item.PackageId = PanelSecurity.PackageId;
            item.Name = ddlWebSites.SelectedValue;
            item.LocaleID = Utils.ParseInt(txtLocaleID.Text.Trim(), 0);
            item.OwnerLogin = ddlSiteOwner.SelectedValue;
            item.OwnerEmail = txtOwnerEmail.Text;
            item.DatabaseGroupName = ddlDatabaseVersion.SelectedValue;
            item.DatabaseName = databaseName.Text;
            item.DatabaseUser = databaseUser.Text;
            item.DatabasePassword = databasePassword.Password;

            if (PanelRequest.ItemID == 0)
            {
                // new item
                try
                {
                    int result = ES.Services.SharePointServers.AddSharePointSite(item);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }

                }
                catch (Exception ex)
                {
                    ShowErrorMessage("SHAREPOINT_ADD_SITE", ex);
                    return;
                }
            }

            // return
            RedirectSpaceHomePage();
        }
 /// <remarks/>
 public void ExtendVirtualServerAsync(SharePointSite site)
 {
     this.ExtendVirtualServerAsync(site, null);
 }
 /// <remarks/>
 public void ExtendVirtualServerAsync(SharePointSite site, object userState)
 {
     if ((this.ExtendVirtualServerOperationCompleted == null))
     {
         this.ExtendVirtualServerOperationCompleted = new System.Threading.SendOrPostCallback(this.OnExtendVirtualServerOperationCompleted);
     }
     this.InvokeAsync("ExtendVirtualServer", new object[] {
                 site}, this.ExtendVirtualServerOperationCompleted, userState);
 }
 public void ExtendVirtualServer(SharePointSite site)
 {
     this.Invoke("ExtendVirtualServer", new object[] {
                 site});
 }
예제 #10
0
 /// <remarks/>
 public System.IAsyncResult BeginExtendVirtualServer(SharePointSite site, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("ExtendVirtualServer", new object[] {
                 site}, callback, asyncState);
 }
 public int AddSharePointSite(SharePointSite item)
 {
     object[] results = this.Invoke("AddSharePointSite", new object[] {
                 item});
     return ((int)(results[0]));
 }
예제 #12
0
        public void ExtendVirtualServer(SharePointSite site, bool exclusiveNTLM)
        {
            try
            {
                WindowsImpersonationContext wic = WindowsIdentity.GetCurrent().Impersonate();

                string siteUrl = "http://" + site.Name;

                // check input parameters
                if (String.IsNullOrEmpty(site.RootFolder) ||
                    !Directory.Exists(site.RootFolder))
                {
                    throw new Exception("Could not create SharePoint site, because web site root folder does not exist. Open web site properties and click \"Update\" button to re-create site folder.");
                }

                SPWebApplication app = SPWebApplication.Lookup(new Uri(siteUrl));
                if (app != null)
                {
                    throw new Exception("SharePoint is already installed on this web site.");
                }

                //SPFarm farm = SPFarm.Local;
                SPFarm farm = SPFarm.Local;
                SPWebApplicationBuilder builder = new SPWebApplicationBuilder(farm);
                builder.ApplicationPoolId = site.ApplicationPool;
                builder.DatabaseServer    = site.DatabaseServer;
                builder.DatabaseName      = site.DatabaseName;
                builder.DatabaseUsername  = site.DatabaseUser;
                builder.DatabasePassword  = site.DatabasePassword;

                builder.ServerComment = site.Name;
                builder.HostHeader    = site.Name;
                builder.Port          = 80;

                builder.RootDirectory      = new DirectoryInfo(site.RootFolder);
                builder.DefaultZoneUri     = new Uri(siteUrl);
                builder.UseNTLMExclusively = exclusiveNTLM;

                app      = builder.Create();
                app.Name = site.Name;

                app.Sites.Add(siteUrl, null, null, (uint)site.LocaleID, null, site.OwnerLogin, null, site.OwnerEmail);

                app.Update();
                app.Provision();

                wic.Undo();
            }
            catch (Exception ex)
            {
                try
                {
                    // try to delete app if it was created
                    SPWebApplication app = SPWebApplication.Lookup(new Uri("http://" + site.Name));
                    if (app != null)
                    {
                        app.Delete();
                    }
                }
                catch { /* nop */ }

                throw new Exception("Error creating SharePoint site", ex);
            }
        }
 public int AddSharePointSite(SharePointSite item)
 {
     return SharePointServerController.AddSite(item);
 }
        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();
            }
        }
 /// <remarks/>
 public void AddSharePointSiteAsync(SharePointSite item, object userState)
 {
     if ((this.AddSharePointSiteOperationCompleted == null))
     {
         this.AddSharePointSiteOperationCompleted = new System.Threading.SendOrPostCallback(this.OnAddSharePointSiteOperationCompleted);
     }
     this.InvokeAsync("AddSharePointSite", new object[] {
                 item}, this.AddSharePointSiteOperationCompleted, userState);
 }
 /// <remarks/>
 public void AddSharePointSiteAsync(SharePointSite item)
 {
     this.AddSharePointSiteAsync(item, null);
 }
 /// <remarks/>
 public System.IAsyncResult BeginAddSharePointSite(SharePointSite item, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("AddSharePointSite", new object[] {
                 item}, callback, asyncState);
 }