Ejemplo n.º 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);
			}
		}
        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues,
                                    out string output)
        {
            output = string.Empty;

            Uri uri = new Uri(Params["url"].Value);

            SPWebApplicationBuilder builder = GetWebAppBuilder(uri);

            SPWebApplication app = builder.Create();

            SPAdministrationWebApplication local = SPAdministrationWebApplication.Local;

            // Set the TimeZone of the Application
            if (Params["timezone"].UserTypedIn)
            {
                app.DefaultTimeZone = ushort.Parse(Params["timezone"].Value);
            }

            app.Update();
            app.ProvisionGlobally();

            // Execute pending timer jobs before moving on.
            Common.TimerJobs.ExecAdmSvcJobs.Execute(false, true);
            // Recreate the web application object to avoid update conflicts.
            app = SPWebApplication.Lookup(uri);

            // Upload the newly created WebApplication to the List 'Web Application List' in Central Administration:
            SPWebService.AdministrationService.WebApplications.Add(app);

            if (!Params["donotcreatesite"].UserTypedIn)
            {
                uint   nLCID       = uint.Parse(Params["lcid"].Value);
                string webTemplate = Params["sitetemplate"].Value;
                string ownerLogin  = Params["ownerlogin"].Value;
                ownerLogin = Utilities.TryGetNT4StyleAccountName(ownerLogin, app);
                string ownerName  = Params["ownername"].Value;
                string ownerEmail = Params["owneremail"].Value;

                app.Sites.Add(uri.AbsolutePath, null, null, nLCID, webTemplate, ownerLogin, ownerName, ownerEmail, null, null, null);
            }


            Console.WriteLine(SPResource.GetString("PendingRestartInExtendWebFarm", new object[0]));
            Console.WriteLine();

            if (!Params["donotcreatesite"].UserTypedIn)
            {
                Console.WriteLine(SPResource.GetString("AccessSiteAt", new object[] { uri.ToString() }));
            }
            Console.WriteLine();

            return((int)ErrorCodes.NoError);
        }
        private void createNewWebApplications()
        {
            try
            {
                int currentPort = 80;
                var webAppNames = SampleData.GetRandomNonRepeatingValues(SampleData.WebApplications, WorkingDefinition.CreateNewWebApplications);
                for (int a = 0; a < WorkingDefinition.CreateNewWebApplications; a++)
                {
                    SPWebApplication        newApplication;
                    SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder(SPFarm.Local);

                    currentPort = Utils.GetNextAvailablePort(currentPort + 1);

                    var webApplicationName = string.Format("SharePoint {0} - {1}", webAppNames[a], currentPort.ToString("00"));
                    Owner.IncrementCurrentTaskProgress("Creating Web application '" + webApplicationName);
                    webAppBuilder.Port                    = currentPort;
                    webAppBuilder.RootDirectory           = new DirectoryInfo("C:\\inetpub\\wwwroot\\wss\\" + currentPort.ToString());
                    webAppBuilder.ApplicationPoolId       = string.Format("SharePoint {0} - {1} Pool", webAppNames[a], currentPort.ToString("00"));
                    webAppBuilder.IdentityType            = IdentityType.SpecificUser;
                    webAppBuilder.ApplicationPoolUsername = WorkingDefinition.WebAppOwnerLogin;
                    webAppBuilder.ApplicationPoolPassword = Utils.StringToSecureString(WorkingDefinition.WebAppOwnerPassword);


                    webAppBuilder.ServerComment     = webApplicationName;
                    webAppBuilder.CreateNewDatabase = true;
                    webAppBuilder.DatabaseServer    = WorkingDefinition.DatabaseServer;                                                 // DB server name
                    webAppBuilder.DatabaseName      = string.Format("WSS_Content_{0}_{1}", webAppNames[a], currentPort.ToString("00")); // DB Name
                    //webAppBuilder.HostHeader = "SPDG" + appNumer.ToString("00") + ".com"; //if any

                    webAppBuilder.UseNTLMExclusively   = true; // authentication provider for NTLM
                    webAppBuilder.AllowAnonymousAccess = true; // anonymous access permission

                    // Finally create web application
                    newApplication = webAppBuilder.Create();

                    //Enable Claims
                    newApplication.UseClaimsAuthentication = true;
                    newApplication.Update();
                    newApplication.Provision();


                    for (int s = 0; s < WorkingDefinition.CreateNewSiteCollections; s++)
                    {
                        CreateSiteCollection(newApplication);
                    }
                }
            }
            catch (Exception ex)
            {
                Errors.Log(ex);
            }
        }
Ejemplo n.º 4
0
        private void DeployWebApplication(FarmModelHost farmModelHost, SPFarm farm, WebApplicationDefinition webApplicationDefinition)
        {
            var webApps = SPWebService.ContentService.WebApplications;

            var webAppBuilder = new SPWebApplicationBuilder(farm);

            webAppBuilder.Port = webApplicationDefinition.Port;
            webAppBuilder.ApplicationPoolId = webApplicationDefinition.ApplicationPoolId;

            if (!string.IsNullOrEmpty(webApplicationDefinition.ManagedAccount))
            {
                webAppBuilder.IdentityType = IdentityType.SpecificUser;

                var managedAccounts = new SPFarmManagedAccountCollection(SPFarm.Local);
                var maccount        = managedAccounts.FindOrCreateAccount(webApplicationDefinition.ManagedAccount);

                webAppBuilder.ManagedAccount = maccount;
            }
            else
            {
                webAppBuilder.ApplicationPoolUsername = webApplicationDefinition.ApplicationPoolUsername;

                var password = new SecureString();

                foreach (char c in webApplicationDefinition.ApplicationPoolPassword.ToCharArray())
                {
                    password.AppendChar(c);
                }

                webAppBuilder.ApplicationPoolPassword = password;
            }

            webAppBuilder.CreateNewDatabase = webApplicationDefinition.CreateNewDatabase;

            webAppBuilder.DatabaseName   = webApplicationDefinition.DatabaseName;
            webAppBuilder.DatabaseServer = webApplicationDefinition.DatabaseServer;

            webAppBuilder.UseNTLMExclusively = webApplicationDefinition.UseNTLMExclusively;

            webAppBuilder.HostHeader            = webApplicationDefinition.HostHeader;
            webAppBuilder.AllowAnonymousAccess  = webApplicationDefinition.AllowAnonymousAccess;
            webAppBuilder.UseSecureSocketsLayer = webApplicationDefinition.UseSecureSocketsLayer;

            var webApp = webAppBuilder.Create();

            webApp.Provision();
        }
        private void DeployWebApplication(FarmModelHost farmModelHost, SPFarm farm, WebApplicationDefinition webApplicationDefinition)
        {
            var webApps = SPWebService.ContentService.WebApplications;

            var webAppBuilder = new SPWebApplicationBuilder(farm);

            webAppBuilder.Port = webApplicationDefinition.Port;
            webAppBuilder.ApplicationPoolId = webApplicationDefinition.ApplicationPoolId;

            if (!string.IsNullOrEmpty(webApplicationDefinition.ManagedAccount))
            {
                webAppBuilder.IdentityType = IdentityType.SpecificUser;

                var managedAccounts = new SPFarmManagedAccountCollection(SPFarm.Local);
                var maccount = managedAccounts.FindOrCreateAccount(webApplicationDefinition.ManagedAccount);

                webAppBuilder.ManagedAccount = maccount;
            }
            else
            {
                webAppBuilder.ApplicationPoolUsername = webApplicationDefinition.ApplicationPoolUsername;

                var password = new SecureString();

                foreach (char c in webApplicationDefinition.ApplicationPoolPassword.ToCharArray())
                    password.AppendChar(c);

                webAppBuilder.ApplicationPoolPassword = password;
            }

            webAppBuilder.CreateNewDatabase = webApplicationDefinition.CreateNewDatabase;

            webAppBuilder.DatabaseName = webApplicationDefinition.DatabaseName;
            webAppBuilder.DatabaseServer = webApplicationDefinition.DatabaseServer;

            webAppBuilder.UseNTLMExclusively = webApplicationDefinition.UseNTLMExclusively;

            webAppBuilder.HostHeader = webApplicationDefinition.HostHeader;
            webAppBuilder.AllowAnonymousAccess = webApplicationDefinition.AllowAnonymousAccess;
            webAppBuilder.UseSecureSocketsLayer = webApplicationDefinition.UseSecureSocketsLayer;

            var webApp = webAppBuilder.Create();
            webApp.Provision();
        }
        private void createNewWebApplications()
        {
            try
            {
                int currentPort = 80;
                var webAppNames = SampleData.GetRandomNonRepeatingValues(SampleData.WebApplications, WorkingDefinition.CreateNewWebApplications);
                for (int a = 0; a < WorkingDefinition.CreateNewWebApplications; a++)
                {
                    SPWebApplication newApplication;
                    SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder(SPFarm.Local);

                    currentPort = Utils.GetNextAvailablePort(currentPort + 1);

                    var webApplicationName = string.Format("SharePoint {0} - {1}", webAppNames[a], currentPort.ToString("00"));
                    Owner.IncrementCurrentTaskProgress("Creating Web application '" + webApplicationName);
                    webAppBuilder.Port = currentPort;
                    webAppBuilder.RootDirectory = new DirectoryInfo("C:\\inetpub\\wwwroot\\wss\\" + currentPort.ToString());
                    webAppBuilder.ApplicationPoolId = string.Format("SharePoint {0} - {1} Pool", webAppNames[a], currentPort.ToString("00"));
                    webAppBuilder.IdentityType = IdentityType.SpecificUser;
                    webAppBuilder.ApplicationPoolUsername = WorkingDefinition.WebAppOwnerLogin;
                    webAppBuilder.ApplicationPoolPassword = Utils.StringToSecureString(WorkingDefinition.WebAppOwnerPassword);

                    webAppBuilder.ServerComment = webApplicationName;
                    webAppBuilder.CreateNewDatabase = true;
                    webAppBuilder.DatabaseServer = WorkingDefinition.DatabaseServer; // DB server name
                    webAppBuilder.DatabaseName = string.Format("WSS_Content_{0}_{1}", webAppNames[a], currentPort.ToString("00"));// DB Name
                    //webAppBuilder.HostHeader = "SPDG" + appNumer.ToString("00") + ".com"; //if any

                    webAppBuilder.UseNTLMExclusively = true;  // authentication provider for NTLM
                    webAppBuilder.AllowAnonymousAccess = true; // anonymous access permission

                    // Finally create web application
                    newApplication = webAppBuilder.Create();

                    //Enable Claims
                    newApplication.UseClaimsAuthentication = true;
                    newApplication.Update();
                    newApplication.Provision();

                    for (int s = 0; s < WorkingDefinition.CreateNewSiteCollections; s++)
                    {
                        CreateSiteCollection(newApplication);
                    }
                }
            }
            catch (Exception ex)
            {
                Errors.Log(ex);
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        private void DeployWebApplication(FarmModelHost farmModelHost,
                                          SPFarm farm,
                                          WebApplicationDefinition definition)
        {
            var webApps        = SPWebService.ContentService.WebApplications;
            var existingWebApp = FindWebApplication(definition, webApps);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingWebApp,
                ObjectType       = typeof(SPWebApplication),
                ObjectDefinition = definition,
                ModelHost        = farmModelHost
            });

            if (existingWebApp == null)
            {
                var webAppBuilder = new SPWebApplicationBuilder(farm);

                webAppBuilder.Port = definition.Port;
                webAppBuilder.ApplicationPoolId = definition.ApplicationPoolId;

                if (!string.IsNullOrEmpty(definition.ManagedAccount))
                {
                    webAppBuilder.IdentityType = IdentityType.SpecificUser;

                    var managedAccounts = new SPFarmManagedAccountCollection(SPFarm.Local);
                    var maccount        = managedAccounts.FindOrCreateAccount(definition.ManagedAccount);

                    webAppBuilder.ManagedAccount = maccount;
                }
                else
                {
                    webAppBuilder.ApplicationPoolUsername = definition.ApplicationPoolUsername;

                    var password = new SecureString();

                    foreach (char c in definition.ApplicationPoolPassword.ToCharArray())
                    {
                        password.AppendChar(c);
                    }

                    webAppBuilder.ApplicationPoolPassword = password;
                }

                webAppBuilder.CreateNewDatabase = definition.CreateNewDatabase;

                webAppBuilder.DatabaseName   = definition.DatabaseName;
                webAppBuilder.DatabaseServer = definition.DatabaseServer;

                webAppBuilder.UseNTLMExclusively = definition.UseNTLMExclusively;

                webAppBuilder.HostHeader            = definition.HostHeader;
                webAppBuilder.AllowAnonymousAccess  = definition.AllowAnonymousAccess;
                webAppBuilder.UseSecureSocketsLayer = definition.UseSecureSocketsLayer;

                var webApp = webAppBuilder.Create();
                webApp.Provision();

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model            = null,
                    EventType        = ModelEventType.OnProvisioned,
                    Object           = webApp,
                    ObjectType       = typeof(SPWebApplication),
                    ObjectDefinition = definition,
                    ModelHost        = farmModelHost
                });
            }
            else
            {
                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model            = null,
                    EventType        = ModelEventType.OnProvisioned,
                    Object           = existingWebApp,
                    ObjectType       = typeof(SPWebApplication),
                    ObjectDefinition = definition,
                    ModelHost        = farmModelHost
                });
            }
        }