Export (0) Print
Expand All

The Timer Job Configuration Page

The Approved Estimates timer job must retrieve various configuration settings to be able to function correctly. To provide these settings, deploy a custom application page, TimerJobConfig.aspx, to the Central Administration Web site.

The timer job configuration page

Ff798356.1225fab4-42b7-48c8-b75f-411c590f40b5(en-us,PandP.10).png

The timer job configuration page enables the farm administrator to provide the following settings:

  • The relative URL of the destination site collection
  • The name of the Approved Estimates list on the destination site collection
  • A semicolon-separated list of source site collections

It also enables the administrator to immediately run the job. When the user clicks Apply Changes, the configuration settings are persisted to the property bag of the Approved Estimates timer job, as shown in the following code example.

protected void ApplyButton_Click(object sender, EventArgs e)
{
  IEnumerable<SPJobDefinition> allJobs = GetTimerJobsByName(Constants.jobTitle);

  foreach (SPJobDefinition selectedJob in allJobs)
  {
    if (!string.IsNullOrEmpty(ListNameTextBox.Text))
    {
      selectedJob.Properties[Constants.timerJobListNameAttribute] = 
        ListNameTextBox.Text;
    }

    if (!string.IsNullOrEmpty(SiteNamesTextBox.Text))
    {
      selectedJob.Properties[Constants.timerJobSiteNameAttribute] = 
        SiteNamesTextBox.Text;
    }

    if (!string.IsNullOrEmpty(DestinationSiteTextBox.Text))
    {
      selectedJob.Properties[Constants.timerJobDestinationSiteAttribute] = 
        DestinationSiteTextBox.Text;
    }

    selectedJob.Update();
  }
}


The click event handler uses the GetTimerJobsByName helper method to retrieve all instances of the Approved Estimates job from the server farm. This is necessary because several instances of the job could be associated with different service applications or Web applications.

private List<SPJobDefinition> GetTimerJobsByName(string displayName)
{
  List<SPJobDefinition> AllJobs = new List<SPJobDefinition>();

  // For all servers in the farm (the servers could be different).
  foreach (SPServer server in farm.Servers)
  {
    // For each service instance on the server.
    foreach (SPServiceInstance svc in server.ServiceInstances)
    {
      if (svc.Service.JobDefinitions.Count > 0)
      {
        // If it is a Web Service, then get the Web application from 
        // the Web Service entity.
        if (svc.Service is SPWebService)
        {
          SPWebService websvc = (SPWebService) svc.Service;
          AllJobs.AddRange(from webapp in websvc.WebApplications
                         from def in webapp.JobDefinitions
                         where def.DisplayName.ToLower() == displayName.ToLower()
                         select def);
        }
        else
        {
          //Otherwise Get it directly from the Service
          AllJobs.AddRange(svc.Service.JobDefinitions.Where(def => 
                           def.DisplayName.ToLower() == displayName.ToLower()));
        }
      }
    }
  }

  return AllJobs;
}

To make the timer job configuration page available to farm administrators, it is deployed to the Central Administration Web site.

Show:
© 2014 Microsoft