이번 시간에는 쉐어포인트의 스케줄(TimerJob) 을 만들어 보도록 하겠습니다.
먼저 프로젝트를 만듭니다.
Sharepoint –> 빈 Sharepoint 프로젝트
팜 솔루션을 선택합니다.
그리고 JobDefinition class를 만듭니다.
저는 이름을 현재 작업 중인 업무명으로 하였습니다.
그리고 아래와 같이 직접 코딩합니다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace HPW.Portal.JobTools.BizRequest.TimerJob
{
public class BizRequestJobDefinition : SPJobDefinition
{
#region Contructor
#region // BizRequestJobDefinition() : base() //
public BizRequestJobDefinition()
: base()
{
}
#endregion
#region // BizRequestJobDefinition(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType) //
public BizRequestJobDefinition(string jobName, SPService service, SPServer server, SPJobLockType targetType)
: base(jobName, service, server, targetType)
{
}
#endregion
#region // BizRequestJobDefinition(string jobName, SPWebApplication webApplication) : base(jobName, webApplication, null, SPJobLockType.ContentDatabase) //
public BizRequestJobDefinition(string jobName, SPWebApplication webApplication)
: base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
{
this.Title = "BizReqeust VOC Progress Timer Job";
}
#endregion
#endregion
#region Instance Variables
#endregion
#region Properties
#endregion
#region Initialize and Shutdown methods
#endregion
#region Private Methods
#endregion
#region Override Methods
#region // override void Execute(Guid targetInstanceId) //
public override void Execute(Guid targetInstanceId)
{
// Code Here...
//SPWebApplication webApplication = this.Parent as SPWebApplication;
//SPContentDatabase contentDb = webApplication.ContentDatabases[targetInstanceId];
//SPList Listjob = contentDb.Sites[0].RootWeb.Lists["ListTimerJob"];
//SPListItem newList = Listjob.Items.Add();
//newList["Title"] = DateTime.Now.ToString();
//newList.Update();
}
#endregion
#endregion
#region Event Handlers
#endregion
}
}
그리고 Feature를 생성합니다.
생성 후 이름을 변경하고 그리고 이벤트 수신기(EventReceiver)를 만듭니다.
그리고 아래와 같이 코딩.
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Administration;
namespace HPW.Portal.JobTools.BizRequest.TimerJob.Features.VOCProgressSendMail
{
/// <summary>
/// 이 클래스는 기능을 활성화, 비활성화, 설치, 제거 및 업그레이드하는 동안 발생하는 이벤트를 처리합니다.
/// </summary>
/// <remarks>
/// 패키지하는 동안 이 클래스에 연결된 GUID를 사용할 수 있으며 수정하지 않아야 합니다.
/// </remarks>
[Guid("664bc876-c03e-4120-bba4-f1644c1970cb")]
public class VOCProgressSendMailEventReceiver : SPFeatureReceiver
{
private const string JOB_NAME = "VOCProgressSendMail";
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.Equals(JOB_NAME))
job.Delete();
}
// install the job
BizRequestJobDefinition listLoggerJob = new BizRequestJobDefinition(JOB_NAME, site.WebApplication);
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 5;
listLoggerJob.Schedule = schedule;
listLoggerJob.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.Equals(JOB_NAME))
job.Delete();
}
}
// 기능이 설치된 후에 발생하는 이벤트를 처리하려면 아래 메서드의 주석 처리를 제거합니다.
//public override void FeatureInstalled(SPFeatureReceiverProperties properties)
//{
//}
// 기능이 제거되기 전에 발생하는 이벤트를 처리하려면 아래 메서드의 주석 처리를 제거합니다.
//public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
//{
//}
// 기능이 업그레이드될 때 발생하는 이벤트를 처리하려면 아래 메서드의 주석 처리를 제거합니다.
//public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
//{
//}
}
}
중요한 부분은 SPMinuteSchedule 입니다.
분단위 스케줄의 경우에는 위와 같은 클래스를 사용하고 아닌 경우에는 아래 클래스를 사용합니다.
시간 별 : SPHourlySchedule
일 별 : SPDailySchedule
주 별 : SPWeeklySchedule
월 별 : SPMonthlySchedule
그리고 해당 Feature의 범위를 Site로 수정합니다.
그리고 배포 하시면 됩니다.
확인은 아래와 같이 합니다.
중앙 관리 –> Monitoring –> Check job status –> Scheduled 그리고 해당 제목으로 검색하시면 찾으실 수 있습니다.
제가 스케쥴로 만든 것이 바로 아래 리스트에 제목을 입력한 것이었습니다.
아래와 같이 정상적으로 출력 되는 것을 확인 할 수 있습니다.
위의 내용은 MSDN을 참고하였습니다.
여기를 선택하여 이동하시기 바랍니다.
감사합니다.