Beispiel #1
0
        public SPProcessAccountInstance(ObjectInstance prototype, SPProcessAccount processAccount)
            : this(prototype)
        {
            if (processAccount == null)
            {
                throw new ArgumentNullException("processAccount");
            }

            m_processAccount = processAccount;
        }
        public BaristaSearchService(SPFarm spFarm, SPManagedAccount managedAccount)
            : base(NtServiceName, spFarm)
        {
            if (managedAccount == null)
            {
                throw new ArgumentNullException("managedAccount");
            }

            ProcessIdentity.ProcessAccount = SPProcessAccount.LookupManagedAccount(managedAccount.Sid);
            ProcessIdentity.ManagedAccount = managedAccount;
            ProcessIdentity.IsCredentialDeploymentEnabled = true;
            ProcessIdentity.IsCredentialUpdateEnabled     = true;
        }
Beispiel #3
0
        public static OutputQueue GetOrCreateApplicationPool(string name, string username, string password, out SPIisWebServiceApplicationPool applicationPool)
        {
            var outputQueue = new OutputQueue();

            applicationPool = null;

            try
            {
                outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingExistingServiceApplicationPool, name));
                applicationPool = LocalFarm.Get().GetObject(name, Guid.Empty, typeof(SPIisWebServiceApplicationPool)) as SPIisWebServiceApplicationPool;
                if (applicationPool != null)
                {
                    outputQueue.Add(UserDisplay.ExistingServiceApplicationPoolFound);
                    return(outputQueue);
                }

                outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CreatingServiceApplicationPool, name));

                Type appPoolType = null;
                Type optionsType = null;

                appPoolType = Type.GetType(string.Format(CultureInfo.InvariantCulture,
                                                         "Microsoft.SharePoint.Administration.SPIisWebServiceApplicationPool, Microsoft.SharePoint, Version={0}.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c",
                                                         LocalFarm.Get().BuildVersion.Major));
                optionsType = Type.GetType(string.Format(CultureInfo.InvariantCulture,
                                                         "Microsoft.SharePoint.Administration.SPIisWebServiceApplicationPoolProvisioningOptions, Microsoft.SharePoint, Version={0}.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c",
                                                         LocalFarm.Get().BuildVersion.Major));

                if ((appPoolType != null) && (optionsType != null))
                {
                    var noneOption = optionsType.GetField("None").GetValue(optionsType);

                    SPProcessAccount processAccount = LocalFarm.Get().DefaultServiceAccount;

                    if (!string.IsNullOrEmpty(username))
                    {
                        NTAccount account = new NTAccount(username);
                        outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingExistingManagedAccount, username));
                        SPProcessAccount lookupAccount = SPProcessAccount.LookupManagedAccount((SecurityIdentifier)account.Translate(typeof(SecurityIdentifier)));
                        if (lookupAccount != null)
                        {
                            processAccount = lookupAccount;
                        }
                        else if (!string.IsNullOrEmpty(password))
                        {
                            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CreatingManagedAccount, username));
                            var securePassword     = password.ToSecureString();
                            var accountConstructor = typeof(SPProcessAccount).GetConstructor(new[] { typeof(NTAccount), typeof(SecureString) });
                            processAccount = (SPProcessAccount)accountConstructor.Invoke(new object[] { account, securePassword });
                            Reflection.ExecuteMethod(processAccount.GetType(), processAccount, "FindOrCreateManagedAccount", new Type[] { }, null);
                        }
                    }

                    MethodInfo beginProvision = appPoolType.GetMethod("BeginProvision", BindingFlags.Instance | BindingFlags.NonPublic);
                    outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.ProvisioningServiceApplicationPool, name));
                    applicationPool = (SPIisWebServiceApplicationPool)Reflection.ExecuteMethod(appPoolType, "Create", new Type[] { typeof(SPFarm), typeof(String), typeof(SPProcessAccount) }, new object[] { LocalFarm.Get(), name, processAccount });
                    applicationPool.Update();
                    beginProvision.Invoke(applicationPool, new object[] { noneOption });
                    WaitAppPoolJob(applicationPool);
                    outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.ProvisioningServiceApplicationPoolComplete, name));
                }
                else
                {
                    throw new InvalidOperationException("ApplicationPool");
                }
            }
            catch (Exception exception)
            {
                outputQueue.Add(string.Format(CultureInfo.CurrentUICulture, NewsGator.Install.Resources.Exceptions.ApplicationPoolException, name, exception.Message), OutputType.Error, exception.ToString(), exception);
            }

            return(outputQueue);
        }