public static void CopyAppBinContent(ISharePointCommandContext context) { SPServiceInstance localContent = SPWebServiceInstance.LocalContent; if ((localContent != null) && (localContent.Status == SPObjectStatus.Online)) { SPWebService.ContentService.ApplyApplicationContentToLocalServer(); } localContent = SPWebServiceInstance.LocalAdministration; if ((localContent != null) && (localContent.Status == SPObjectStatus.Online)) { SPWebService.AdministrationService.ApplyApplicationContentToLocalServer(); } }
public static List <AttributeValuePair> GetSPServiceInstanceAttributes(SPServiceInstance serviceInstance) { List <AttributeValuePair> serviceInstanceAttributes = new List <AttributeValuePair>(); try { serviceInstanceAttributes.Add(new AttributeValuePair("Instance", serviceInstance.Instance)); serviceInstanceAttributes.Add(new AttributeValuePair("TypeName", serviceInstance.TypeName)); serviceInstanceAttributes.Add(new AttributeValuePair("Id", serviceInstance.Id.ToString())); serviceInstanceAttributes.Add(new AttributeValuePair("SystemService", serviceInstance.SystemService.ToString())); } catch (Exception e) { serviceInstanceAttributes.Add(new AttributeValuePair("Exception", e.ToString())); } return(serviceInstanceAttributes); }
// Methods public static bool IsWebFrontEndServer(this SPServer server) { if (server.Role == SPServerRole.Invalid) { goto End; } using (IEnumerator <SPServiceInstance> enumerator = server.ServiceInstances.GetEnumerator()) { while (enumerator.MoveNext()) { SPServiceInstance current = enumerator.Current; if (((current is SPWebServiceInstance) && (current.Name != WssAdministration)) && (current.Status != SPObjectStatus.Disabled)) { return(true); } } } End: return(false); }
private XmlNode GetServerDatabasesNode(SPServiceInstance serviceInstance) { XmlNode databaseServiceInstances = FarmXml.CreateElement("DatabaseServiceInstances"); SPDatabaseServiceInstanceCollection databaseServiceInstanceCollection = new SPDatabaseServiceInstanceCollection(serviceInstance.Server); XmlNode countAttribute = FarmXml.CreateAttribute("Count"); countAttribute.Value = databaseServiceInstanceCollection.Count.ToString(); databaseServiceInstances.Attributes.SetNamedItem(countAttribute); // Need to test this in a farm using multiple SQL Servers to store databases to validate this foreach (SPDatabaseServiceInstance databaseServiceInstance in databaseServiceInstanceCollection) { XmlNode databaseServiceInstanceNode = FarmXml.CreateElement("DatabaseServiceInstance"); XmlNode databases = FarmXml.CreateElement("Databases"); XmlNode count = FarmXml.CreateAttribute("Count"); count.Value = databaseServiceInstance.Databases.Count.ToString(); databases.Attributes.SetNamedItem(count); foreach (SPDatabase spDatabase in databaseServiceInstance.Databases) { XmlNode database = FarmXml.CreateElement("Database"); List <AttributeValuePair> databaseAttribues = SPAttributes.GetSPDatabaseAttributes(spDatabase); foreach (AttributeValuePair databaseAttribute in databaseAttribues) { database.Attributes.SetNamedItem(GetXmlAttribute(databaseAttribute)); } databases.AppendChild(database); } databaseServiceInstanceNode.AppendChild(databases); databaseServiceInstances.AppendChild(databaseServiceInstanceNode); } return(databaseServiceInstances); }
/// <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, StringDictionary keyValues, out string output) { output = string.Empty; Logger.Verbose = true; string dbserver = Params["dbserver"].Value; string dbname = Params["dbname"].Value; if (string.IsNullOrEmpty(dbserver)) { dbserver = SPWebService.ContentService.DefaultDatabaseInstance.NormalizedDataSource; } SPWebApplication webApp = SPWebApplication.Lookup(new Uri(Params["webapp"].Value)); SPContentDatabase db = null; foreach (SPContentDatabase tempDB in webApp.ContentDatabases) { if (tempDB.Name.ToLower() == dbname.ToLower()) { db = tempDB; break; } } if (db != null) { throw new Exception("Content database already exists."); } SPObjectStatus status = (SPObjectStatus)Enum.Parse(typeof(SPObjectStatus), Params["status"].Value, true); db = webApp.ContentDatabases.Add(dbserver, dbname, null, null, int.Parse(Params["warningsitecount"].Value), int.Parse(Params["maxsites"].Value), (status == SPObjectStatus.Online?0:1)); if (Params["searchserver"].UserTypedIn && !string.IsNullOrEmpty(Params["searchserver"].Value)) { // If they specified a search server then we need to try and find a valid // matching search server using the server address property. #if SP2010 SPSearchService service = SPFarm.Local.Services.GetValue <SPSearchService>("SPSearch"); #elif SP2013 SPSearchService service = SPFarm.Local.Services.GetValue <SPSearchService>("SPSearch4"); #endif SPServiceInstance searchServiceServer = null; foreach (SPServiceInstance tempsvc in service.Instances) { if (!(tempsvc is SPSearchServiceInstance)) { continue; } if (tempsvc.Status != SPObjectStatus.Online) { continue; } if (tempsvc.Server.Address.ToLowerInvariant() == Params["searchserver"].Value.ToLowerInvariant()) { // We found a match so bug out of the loop. searchServiceServer = tempsvc; break; } } if (searchServiceServer != null) { db.SearchServiceInstance = searchServiceServer; } else { Logger.Write("Search server \"{0}\" not found.", EventLogEntryType.Warning, Params["searchserver"].Value); } } else if (Params["searchserver"].UserTypedIn) { // The user specified the searchserver switch with no value which is what we use to indicate // clearing the value. db.SearchServiceInstance = null; } db.Update(); return((int)ErrorCodes.NoError); }
/// <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, StringDictionary keyValues, out string output) { output = string.Empty; Logger.Verbose = true; if (Params["setmaxsitestocurrent"].UserTypedIn && Params["maxsites"].UserTypedIn) { throw new SPException(SPResource.GetString("ExclusiveArgs", new object[] { "setmaxsitestocurrent, maxsites" })); } string dbname = Params["dbname"].Value; SPWebApplication webApp = SPWebApplication.Lookup(new Uri(Params["webapp"].Value)); SPContentDatabase db = null; foreach (SPContentDatabase tempDB in webApp.ContentDatabases) { if (tempDB.Name.ToLower() == dbname.ToLower()) { db = tempDB; break; } } if (db == null) { throw new Exception("Content database not found."); } bool modified = false; if (Params["status"].UserTypedIn) { db.Status = (SPObjectStatus)Enum.Parse(typeof(SPObjectStatus), Params["status"].Value, true); modified = true; } if (Params["maxsites"].UserTypedIn) { db.MaximumSiteCount = int.Parse(Params["maxsites"].Value); modified = true; } else if (Params["setmaxsitestocurrent"].UserTypedIn) { if (db.CurrentSiteCount < db.WarningSiteCount) { db.WarningSiteCount = db.CurrentSiteCount - 1; } db.MaximumSiteCount = db.CurrentSiteCount; modified = true; } if (Params["warningsitecount"].UserTypedIn) { db.WarningSiteCount = int.Parse(Params["warningsitecount"].Value); modified = true; } if (Params["searchserver"].UserTypedIn && !string.IsNullOrEmpty(Params["searchserver"].Value)) { // If they specified a search server then we need to try and find a valid // matching search server using the server address property. #if SP2010 SPSearchService service = SPFarm.Local.Services.GetValue <SPSearchService>("SPSearch"); #elif SP2013 SPSearchService service = SPFarm.Local.Services.GetValue <SPSearchService>("SPSearch4"); #endif SPServiceInstance searchServiceServer = null; foreach (SPServiceInstance tempsvc in service.Instances) { if (!(tempsvc is SPSearchServiceInstance)) { continue; } if (tempsvc.Status != SPObjectStatus.Online) { continue; } if (tempsvc.Server.Address.ToLowerInvariant() == Params["searchserver"].Value.ToLowerInvariant()) { // We found a match so bug out of the loop. searchServiceServer = tempsvc; break; } } if (searchServiceServer != null) { db.SearchServiceInstance = searchServiceServer; modified = true; } else { Logger.Write("Search server \"{0}\" not found.", EventLogEntryType.Warning, Params["searchserver"].Value); } } else if (Params["searchserver"].UserTypedIn) { // The user specified the searchserver switch with no value which is what we use to indicate // clearing the value. db.SearchServiceInstance = null; modified = true; } if (modified) { db.Update(); } return((int)ErrorCodes.NoError); }