Sign In
zevenseas logo
What we offer
Work
Community
Who and where
Communities
Consultancy
Products
With us
Industries
Through us
Get on board
Jobs in the US
Blogs
Stuff
Codeplex
News
Who are we
Where are we
 
Navigation
  • Community Home
  • Blogs Home
  • This Blog's Home
Archives
  • February 2008 (4)
  • March 2008 (22)
  • April 2008 (5)
  • May 2008 (4)
  • June 2008 (3)
  • July 2008 (7)
  • August 2008 (1)
Categories
  • Support
  • Code
  • How-to
  • Governance
  • MOSS Search
  • LoveLinks
  • Workflow
RSS Feed Feed your read!

Programmatically retrieving if Usage Analysis is set 

Tags:

During the development of the LCM, I needed to know when a site is marked as 'unused' using the following three choices :

  • Last Content Modified Date
  • Last Security Modified Date
  • Last Usage Date

Now the first two choices are easily retrieved using the SPSite.LastSecurityModifiedDate and SPSite.LastContentModifiedDate methods. The third option is more of a challenge, but giving the fact that in V1 of the LifeCycleManagement source this was already developed (and nothing has changed since 2003->2007 in that area) I could re-use that code ;) Now the challenge here is that we have to determine first if Usage Analysis is properly set in the Central Admin, else we only get errors while retrieving the UsageDetails (SPWeb.GetUsageData)..

 

So I looked in the OM to find the first setting.. the so called "WSS Usage logging". To retrieve this setting you can use the following bit of code:

SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue<SPWebService>("");
WSSUsageAnalysis = service.UsageSettings.UsageProcessingEnabled;

Up to the Office SharePoint Usage Processing setting! Now this is a bit harder since there is no OM available to get this option. Thankfully Gary Lapointe (the guy who is responsible for the excellent STSADM Custom Extensions blog) paved the way for me here! This post about Set Usage Analysis directed me in the right direction.. in order to get the setting we have the use reflection on the Microsoft.SharePoint.Portal.Analytics.Configuration class (pretty funny that Microsoft still uses the good 'ol .Portal namespace).

Now when we use reflection on this class we see the following methods we can use :

  • Boolean IsAnalyticsEnabledOnSrp(Microsoft.Office.Server.Administration.SharedResourceProvider)
  • Boolean IsAnalyticsEnabledOnWebApp(Microsoft.SharePoint.Administration.SPWebApplication)
  • Void SetAnalyticsEnabledOnSrp(Microsoft.Office.Server.Administration.SharedResourceProvider, Boolean)
  • System.DateTime GetLastLocalImportDayForWebApp(Microsoft.SharePoint.Administration.SPWebApplication)
  • Void SetLastLocalImportDayForWebApp(Microsoft.SharePoint.Administration.SPWebApplication, System.DateTime)
  • Boolean HaveLocalWebAppLogsEverBeenImported(Microsoft.SharePoint.Administration.SPWebApplication)

Well we want to know if Usage Analytics is set on the SSP so we go for the IsAnalyticsEnabledOnSrp method. All we have to do now is to create a instance of Microsoft.Office.Server.Administration.SharedResourceProvider (the SSP context). To do this we use the Microsoft.Office.Server namespace where we can use the ServerContext.GetContext("SSP Name") to have an instance. The code to do all this looks like this :

string sspname = "SharedServices1";
ServerContext current = ServerContext.GetContext(sspname);
object sharedResourceProvider = current.GetType().GetProperty("SharedResourceProvider", 
AllBindings).GetValue(current, null); Type configurationType = Type.GetType("Microsoft.SharePoint.Portal.Analytics.Configuration,
Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
); MethodInfo methodinfo = configurationType.GetMethod("IsAnalyticsEnabledOnSrp"); object IsAnalyticsEnabledOnSrp = methodinfo.Invoke(null, new object[] { sharedResourceProvider }); OfficeUsageAnalysis = (bool)IsAnalyticsEnabledOnSrp;

I'm still a bit of newbie when it comes to reflection so don't ask any specific details on what I'm doing here.. but it works! :)

 
Posted by Robin Meure on 25-Mar-08
0 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 
Failed to render control: Value does not fall within the expected range.

Comments

Name

Url

Email

Comments

CAPTCHA Image Validation


 

© 2007 Community Kit For SharePoint