如何设置;职位描述;自定义SharePoint计时器作业的

如何设置;职位描述;自定义SharePoint计时器作业的,sharepoint,sharepoint-2010,timer-jobs,Sharepoint,Sharepoint 2010,Timer Jobs,我想知道,如何设置自定义SharePoint计时器作业的作业描述。当我们通过中央管理查看职务定义属性时,有一行“职务说明”。但在自定义计时器作业中它总是空的。 我找到了一些文章,它们必须解决这个问题 但他们都没有带来任何帮助 如果有人遇到了熟悉的问题并解决了,请分享决定。 我将非常感谢您的帮助。我的计时器作业是这样写的: public class YourJob : SPJobDefinition { private static string JOB_NAME = "YourJob

我想知道,如何设置自定义SharePoint计时器作业的作业描述。当我们通过中央管理查看职务定义属性时,有一行“职务说明”。但在自定义计时器作业中它总是空的。 我找到了一些文章,它们必须解决这个问题

但他们都没有带来任何帮助

如果有人遇到了熟悉的问题并解决了,请分享决定。
我将非常感谢您的帮助。

我的计时器作业是这样写的:

public class YourJob : SPJobDefinition
{
    private static string JOB_NAME = "YourJobName";
    public override string Description
    {
        get
        {
            return "YourDescription";
        }
    }
    public YourJob() : base() { }

    public YourJob(SPWebApplication webApp)
        : base(JOB_NAME, webApp, null, SPJobLockType.None)
    {
        this.Title = JOB_NAME;
        this.Schedule = GetSchedule();
    }
    //This job start to run every day between 00:00 to 00:30
    //There are several options
    private SPSchedule GetSchedule()
    {
        SPDailySchedule myDailySchedule = new SPDailySchedule();
        myDailySchedule.BeginHour = 00;
        myDailySchedule.BeginMinute = 00;
        myDailySchedule.BeginSecond = 0;
        myDailySchedule.EndHour = 00;
        myDailySchedule.EndMinute = 30;
        myDailySchedule.EndSecond = 0;

        return myDailySchedule;
    }

    public override void Execute(Guid targetInstanceId)
    {
        //Write here your code.
        //In this example we get value from SP (in every zone) web config to do something with it.
        foreach (SPUrlZone urlZone in Enum.GetValues(typeof(SPUrlZone)))
        {
            if (((SPWebApplication)this.Parent).IisSettings.ContainsKey(urlZone))
            {
                var zone = ((SPWebApplication)this.Parent).IisSettings[urlZone];
                var appName = zone.ServerComment;

                var WebConfigKey = GetAppSettings(appName, "WebConfigKey");
            }
        }
    }

    private string GetAppSettings(string appName, string Key)
    {
        string result = String.Empty;
        SPWebApplication webApplication = this.Parent as SPWebApplication;
        Configuration config = WebConfigurationManager.OpenWebConfiguration("/", appName);
        if (config.HasFile && config.AppSettings.Settings[Key] != null)
        {
            result = config.AppSettings.Settings[Key].Value;
        }
        return result;
    }
}
之后,您需要将作业添加到功能事件接收器

[Guid("46b3a9b4-793e-4ab9-99ba-b003a3601e3a")]
public class MainEventReceiver : SPFeatureReceiver
{
    public static string JOB_NAME = "YourJobName";

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPSite site = properties.Feature.Parent as SPSite;

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

        YourJob job = new YourJob(site.WebApplication);
        job.Update();
    }

    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
        SPSite site = properties.Feature.Parent as SPSite;

        // Delete the job.
        foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
        {
            if (job.Name == JOB_NAME)
                job.Delete();
        }
    }
}

最后,您可以在管理中心->监控->计时器作业-查看作业定义中看到您的作业。在这里,您可以重置日程定义。

您的两个链接都给出了准确的答案

的属性实现为:

public virtual string Description
{
    get
    {
        return string.Empty;
    }
}
因此,为了有一个自定义描述,您需要如下定义您的自定义作业定义:

public class MyCustomJobDefinition : SPJobDefinition
{
    public override string Description
    {
        get
        {
            return "This is my custom description";
        }
    }
}

谢谢,里奇。前面链接中的解决方案也确实有效。我遇到的麻烦在于过时的工作定义对象。我试图通过VisualStudio收回适当的解决方案,重新启动SharePoint计时器服务,但没有任何帮助。最终解决问题的决定是通过PowerShell卸载和删除解决方案。最后,我可以在我的工作定义中看到新的描述。