0

Microsoft online code analysis framework , as we know i used to analyze the code [.wsp]

My code contains the timer job which is activated via feature. After running the MSOCAF on my WSP , i get warning as :

Implementation of Timer Job

Resolution : FeatureActivated event of SPFeatureReceiver does not contain the definition for job exist check. First verify if there exist any job with the same name. If exists delete the existing job and then use the new.

Code :

// make sure the job isn't already registered
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
    if (job.Name == TASK_LOGGER_JOB_NAME)
    {
         job.Delete();
         break; 
    }
}

Let me know how to delete job so as to remove the MSOCAF warning.

1

Looking at the rule's internals using Reflector tells me you are required to pass the following, in order for the rule not to trigger:

You must use (in FeatureActivated):

  • Call new Microsoft.SharePoint.SPMinuteSchedule()
  • and Get Microsoft.SharePoint.Administration.SPJobDefinition.Schedule
  • and Call Microsoft.SharePoint.Administration.SPPersistedObject.Update
  • and Get Microsoft.SharePoint.Administration.SPWebApplication.JobDefinitions

You must use (in FeatureDeactivated):

  • Get Microsoft.SharePoint.Administration.SPWebApplication.JobDefinitions
  • and Call Microsoft.SharePoint.Administration.SPPersistedObject.Delete

Exactly how to write the code isn't specified in the code of the rule.

But I'm guessing this will come close: http://www.sharepointkings.com/2009/04/creating-and-working-with-sharepoint.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.