public void SetPropertyKeyValue(string key, object value) { if (value == null || value == Undefined.Value || value == Null.Value) { throw new ArgumentNullException("value"); } string stringValue; if (value is ObjectInstance) { stringValue = JSONObject.Stringify(this.Engine, value, null, null); } else { stringValue = value.ToString(); } if (m_iisWebServiceApplicationPool.Properties.ContainsKey(key)) { m_iisWebServiceApplicationPool.Properties[key] = stringValue; } else { m_iisWebServiceApplicationPool.Properties.Add(key, stringValue); } m_iisWebServiceApplicationPool.Update(); }
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); }