我想知道,如何設置自定義SharePoint計時器作業的作業描述。當我們通過中央管理部門查看作業定義屬性時,有'工作描述'這一行。但是在自定義計時器作業中它總是空的。 我發現了一些文章,它們必須解決這個問題。如何設置自定義SharePoint計時器作業的「作業描述」
但他們都沒有帶來任何幫助。
如果有人遇到熟悉的問題並解決問題,請分享一下。 我會感謝任何幫助。
我想知道,如何設置自定義SharePoint計時器作業的作業描述。當我們通過中央管理部門查看作業定義屬性時,有'工作描述'這一行。但是在自定義計時器作業中它總是空的。 我發現了一些文章,它們必須解決這個問題。如何設置自定義SharePoint計時器作業的「作業描述」
但他們都沒有帶來任何幫助。
如果有人遇到熟悉的問題並解決問題,請分享一下。 我會感謝任何幫助。
這兩個鏈接都給出了正確的答案。
的SPJobDefinition的Description屬性被實現爲:
public virtual string Description
{
get
{
return string.Empty;
}
}
所以,爲了有一個自定義的描述,您需要定義自定義的作業定義如下:
public class MyCustomJobDefinition : SPJobDefinition
{
public override string Description
{
get
{
return "This is my custom description";
}
}
}
我寫我的計時器作業是這樣的:
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();
}
}
}
最後,你可以看到在管理中心的工作後 - >監控 - >計時器作業 - 查看作業定義。在那裏你可以重置你的時間表定義。
謝謝,豐富。以前的鏈接中的解決方案也非常有效。我遇到的麻煩是過時的作業定義對象。我試圖通過Visual Studio收回適當的解決方案,重新啓動SharePoint Timer服務,但沒有任何幫助。通過PowerShell解決問題的決定是卸載和刪除解決方案。最後,我可以在我的作業定義中看到新的描述。 – Deniplane 2012-04-16 08:36:21