private XmlNode GetContentDatabasesNode(SPContentDatabaseCollection contentDatabases) { XmlNode contentDatabasesNode = FarmXml.CreateElement("ContentDatabases"); XmlNode countAttribute = FarmXml.CreateAttribute("Count"); countAttribute.Value = contentDatabases.Count.ToString(); contentDatabasesNode.Attributes.SetNamedItem(countAttribute); foreach (SPContentDatabase contentDb in contentDatabases) { XmlNode contentDatabaseNode = FarmXml.CreateElement("ContentDatabase"); List <AttributeValuePair> contentDbAttributes = SPAttributes.GetSPContentDatabaseAttributes(contentDb); foreach (AttributeValuePair contentDbAttribute in contentDbAttributes) { contentDatabaseNode.Attributes.SetNamedItem(GetXmlAttribute(contentDbAttribute)); } // If theres multiple content dbs, we also want to know what site collections are in each if (contentDatabases.Count > 1) { XmlNode siteCollectionsNode = GetSiteCollectionsNode(contentDb.Sites, false); contentDatabaseNode.AppendChild(siteCollectionsNode); } contentDatabasesNode.AppendChild(contentDatabaseNode); } return(contentDatabasesNode); }
public SPContentDatabaseCollectionInstance(ObjectInstance prototype, SPContentDatabaseCollection contentDatabaseCollection) : this(prototype) { if (contentDatabaseCollection == null) { throw new ArgumentNullException("contentDatabaseCollection"); } m_contentDatabaseCollection = contentDatabaseCollection; }
private SPContentDatabase EnsureTestContentDatabase(SPWebApplication defaultPortWebApp) { SPContentDatabaseCollection databaseCollection = defaultPortWebApp.ContentDatabases; SPContentDatabase defaultWebAppContentDatabase = defaultPortWebApp.ContentDatabases[0]; SPContentDatabase testContentDb = databaseCollection.Cast <SPContentDatabase>().FirstOrDefault(db => db.Name == TestContentDatabaseName); if (testContentDb != null) { // DB already exists, we gotta figure out if it's getting bloated or not. // A typical Content Database will weigh in at a almost 160MB right at the start. // After creating a couple of hundred site collection, even if we delete them // everytime, some space gets wasted and the disk size required for a backup // grows to more than 200MB. const ulong MaxNumberOfMb = 200; if (testContentDb.DiskSizeRequired > MaxNumberOfMb * 1024 * 1024) { // Repeated site collection recreation has left behind traces // in the content database, time to delete it and start fresh foreach (SPSite site in testContentDb.Sites) { // Delete any straggling site collection (and hope to god no one has // piggybacked onto our content database with an important site collection // of their own - their loss, anyway) site.Delete(); } testContentDb.Status = SPObjectStatus.Offline; testContentDb.Unprovision(); databaseCollection.Delete(testContentDb.Id); testContentDb = null; } else { // We haven't hit the size limit yet, let's re-use the same content database // ... } } if (testContentDb == null) { // DB doesn't exist yet (or has just been deleted): we should (re)create it. testContentDb = databaseCollection.Add( defaultWebAppContentDatabase.Server, TestContentDatabaseName, defaultWebAppContentDatabase.Username, defaultWebAppContentDatabase.Password, 2000, 5000, 0); // Status = 0 means the database is READY (instead of OFFLINE, which is Status = 1) } return(testContentDb); }
private void CapContentDB(SPSite site) { SPContentDatabaseCollection contentDBs = site.WebApplication.ContentDatabases; foreach (SPContentDatabase db in contentDBs) { if (db.Name == NewContentDBName) { db.WarningSiteCount = 0; db.MaximumSiteCount = 1; db.Update(); } } }