In order to understand the WSS model, we need to first understand the different types of services used by SharePoint. SharePoint uses two major services in IIS, non-data service and SQL Server, i.e., database related services.
SharePoint was designed from the view point that it can be used in web farms. So let's first visualize web farms and then we will try to understand how SharePoint visualizes web farms. The figure below shows two aspects: a normal visualization of a web farm and the SharePoint view point. In our normal view (i.e., the left hand side of the image), we can think of farms having servers and servers having two services (i.e., IIS and DB service). When SharePoint visualizes the farm infrastructure, it’s a bit different.
SharePoint visualizes the farm infrastructure in terms of database services and non-database services. So it visualizes database services attached to servers and non-database services like IIS differently.
Note: We are not sure why there is a change in visualization.
So let’s visualize how the WSS object model of SharePoint is seen.
- The parent object in the SharePoint hierarchy is the
SPfarm
object. SPFarm
will have a collection of server objects, i.e.,SPServer
objects.SPServer
objects further haveSPDatabaseServiceInstance
objects.SPDatabaseServiceInstance
has aSPContentDatabase
object instance.- From
SPFarm
, you can also browse to services on the farm level.SPFarm
has aSPService
collection. SPService
in turn allow us to browse through the IIS application, i.e.,SPWebApplication
.SPWebApplication
has a site collection which in turn has a site object which can be browsed using theSPSite
object.
Now let’s understand the object hierarchy below
SPSite
. SPSite
/ Site
belongs to site collection. In other words, one site collection can have many sites
inside it. A site will have lists and a list will have fields.Below is the code snippet which takes the
Farm
object, browses through all its services, using the service object browses through all web applications,
and then uses a web application to browse through all sites.// Get The local farm object
SPFarm oFarm = SPFarm.Local;
// Get all the services from the farm object
foreach (SPService objService in oFarm.Services)
{
// Check if this is a WebService type of object
if (objService is SPWebService)
{
// Cast it to a WebService object
SPWebService oWebService = (SPWebService)objService ;
// Get all Webapplications from the WebApplications collection
foreach (SPWebApplication oWebApplication in oWebService.WebApplications)
{
// Loop through all the sites
foreach (SPSite oSite in oWebApplication.Sites)
{
// Get reference of the Root object
SPWeb oWebRoot = oSite.RootWeb;
// Any kind of processing
// Do not forget to dispose
oWeb.Dispose();
oSite.Dispose();
}
}
}
}
0 comments:
Post a Comment