MOSS中的计时器作业

这方面的文章园子里有几篇了,不过大家基本上都是参考了http://www.andrewconnell.com/blog/articles/CreatingCustomSharePointTimerJobs.aspx这篇文章,在此我也推荐大家仔细看下本文及文中涉及到的相关文章。工作中也遇到了类似的需求,在此也做个总结。

1.MOSS中已经提供了定时器的功能,我们要开发自己的定时器需要继承自SPJobDefinition类,在重写的Execute方法写自己的业务逻辑。我的需求是找出列表中符合条件的item,并做mail通知,代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
namespace CaryTimer
{
    public class ListRemindEvent : SPJobDefinition
    {
        public ListRemindEvent() : base() { }

        public ListRemindEvent(string _timername, SPWebApplication _wp)
            : base(_timername, _wp, null, SPJobLockType.ContentDatabase)
        {
            this.Title = "TestTimer";
        }

        public override void Execute(Guid targetInstanceId)
        {    
                SPWebApplication webApp = this.Parent as SPWebApplication;
                SPContentDatabase contentDB = webApp.ContentDatabases[targetInstanceId];
                SPWeb web = contentDB.Sites[0].AllWebs[0];
                string sendTo = "";
                string mailTitle = "";
                string mailBody = "";
			 //实现自己业务逻辑,找出复合条件的并发mail做相关通知。
                SPUtility.SendEmail(web, false, false, sendTo, mailTitle, mailBody);                  
        }
     }
}

2.该类完成后我们使用Feature来部署该功能,我们写一个自己的安装类,如下:

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace CaryTimer
{
    public class ListRemindEventInstaller : SPFeatureReceiver
    {
        const string caryTimerName = "Testtimer";
        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        { }
        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        { }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
           SPSite site = properties.Feature.Parent as SPSite;
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
	      //判断是否已存在
                if (job.Name == caryTimerName)
                {
                    job.Delete();
                }
            }
            ListRemindEvent timer = new ListRemindEvent(caryTimerName, site.WebApplication);
	    /下边是设置定时器的执行计划部分。
              SPMinuteSchedule schedule = new SPMinuteSchedule();
            schedule.BeginSecond = 0;
            schedule.EndSecond = 59;
            schedule.Interval = 1;
            timer.Schedule = schedule;
            timer.Update();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == caryTimerName)
                {
                    job.Delete();
                }
            }
        }
    }
}

3.需要在"c:\program files\common files\microsoft shared\web server extensions\12\Template\features"文件夹下建立CaryTimer文件夹,在该文件夹下建一个Feature.xml,代码如下:

<Feature 
  Id="6283ADA0-B882-47fe-8507-D8CC763DC320" 
  Title="CaryTimer" 
  Description=" CaryTimer  des" 
  Scope="Site" 
  Hidden="FALSE"   
  ReceiverAssembly="HelloWorld, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b38a04419cc857d9"
  ReceiverClass="HelloWorld.ListRemindEventInstaller"
  xmlns="http://schemas.microsoft.com/sharepoint/"> 
</Feature>

4.然后我们使用一个批处理来安装Feature,批处理代码如下:

@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template"

@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"

@SET GACUTIL="d:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe"

Echo Installing HelloWorld.dll in GAC

%GACUTIL% -if bin\debug\HelloWorld.dll

Echo Copying files to TEMPLATE directory

xcopy /e /y TEMPLATE\* %TEMPLATEDIR%

Echo Installing feature

%STSADM% -o installfeature -filename HelloWorld\feature.xml -force

IISRESET

REM cscript c:\windows\system32\iisapp.vbs /a "SharePointDefaultAppPool" /r

5.项目完成后,我们要添加强命名密钥。部署成功后就可以在网站集功能中看见该Feature,激活该Feature后,在管理中心—操作—计时器作业定义中可以看见该定时器的相关信息,并且可以禁用和启用该定时器,在管理中心—操作—计时器作业状态中可以该定时器最后一次运行的情况。

6.如果我们要调试该定时器我们需要附加OwsTimer.exe进程,每次更改后需走以下步骤:
6.1.使用批处理从新部署Feature
6.2.先Deactivate feature, 然后activate feature.
6.3.命令行:net stop SPTimerV3
6.4.命令行:net start SPTimerV3
6.5.Visual Studio: Attach to process: OWSTIMER.EXE

7.如果你在ListRemindEvent类中需要读取外部文件的配置,直接读web.config是读不到的,我们需要在c:/program files/common files/microsoft shared/…/12/bin目录里新建一个文件OwsTimer.exe.config,并做相关配置如下:

<configuration>
  <appSettings>
   <add key="key" value="value" />
  </appSettings>
</configuration>
然后用ConfigurationManager.AppSettings.Get("key"); 来取得这个值。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值