SHAREPOINT定时器开发

Technorati 标签: TimeJob,定时器,sharepoint,moss

SHAREPOINT定时器开发其实比较简单,只是资料相对较少,我认为开发者只要参考这三篇文档既可。

第一篇:中文的资料,可以大致熟悉下思路和方法,但是其中的一些内容可能不是最新的了

http://www.cnblogs.com/zhalin/archive/2008/03/07/1094385.html

第二篇:AC最新写的HOW TO文章,非常详尽

http://msdn.microsoft.com/en-us/library/cc406686.aspx#WSSCustomTimerJobs_Conclusion

第三篇:第二篇的代码下载

http://code.msdn.microsoft.com/SharePointWarmupJob/Release/ProjectReleases.aspx?ReleaseId=1117

下面重新再总结下定时器的开发、部署与调试方法:

1 定时器开发

1)框架就照搬上面的源代码,要用VS2008开发

2)重新引用Microsoft.SharePoint.ApplicationPages.Administration 位置在:C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG\ADMINBIN\Microsoft.SharePoint.ApplicationPages.Administration.dll

3)在Execute方法中编写自定义代码

4) 如果需要获取外部的配置信息,需要写一个OwsTimer.exe.config ,放到C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN 中

OwsTimer.exe.config文件实例:

<configuration>
  <appSettings>
   <add key="CBSS" value="server=;database=;user id=;password=" />
  </appSettings>
</configuration>

5)编译后,自动会生成WSP

2 部署

1)用VS命令行方式注册MSDN.SharePoint.Samples.SharePointWarmupJob.dll到GAC

cls
d:
cd D:\mossproject\test\SharePointWarmupJob.Source\SharePointWarmupJob
"d:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -uf MSDN.SharePoint.Samples.SharePointWarmupJob
"d:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" -if bin\Debug\MSDN.SharePoint.Samples.SharePointWarmupJob.dll

iisreset

2)部署WarmUpJobManager.aspx

原来定时器需要另外一个SPFeatureReceiver类,因为我们需要一个Feature来把我们的Timer部署到服务器上去,通过Feature Activated/deactivated来触发/关闭这个TimerJob,TIMEJOB的间隔时间也在这里设置。

现在有了WarmUpJobManager.aspx就无需这么麻烦了。WarmUpJobManager.aspx在源代码中已经包含了,需要把TEMPLATE下的ADMIN文件夹整个拷贝到C:\Program Files\Common Files\Microsoft Shared\web server extensions\12中

在安装完solution 后就可以在应用程序管理中看到

image

3)安装solution

pushd %programfiles%\common files\microsoft shared\web server extensions\12\bin

stsadm -o addsolution -filename D:\mossproject\test\SharePointWarmupJob.Source\SharePointWarmupJob\wsp\Debug\SharePointWarmupJob.wsp

stsadm -o deploysolution -name SharePointWarmupJob.wsp -local -force –allowGacDeployment

4)触发/关闭这个TimerJob

image

5)重启TIMEJOB

net stop SPTimerV3
net start SPTimerV3

3 调试

1)确保代码是以DEBUG方式编译

2)Execute方法中编写的自定义代码头尾要加上

#if (DEBUG)

      GetOwsTimerTask();

#endif

3)每次都必需按照以下顺序操作才能正常调试

  • 把Assembly DLL放到 GAC
  • 命令行:iisreset
  • 在WarmUpJobManager.aspx中Deactivate feature, 然后activate feature.
  • 命令行:net stop SPTimerV3
  • 命令行:net start SPTimerV3
  • Visual Studio: Attach to process: OWSTIMER.EXE
  • 完。

     

  • posted @ 2010-08-30 09:26  China2008  阅读(539)  评论(0编辑  收藏  举报