Create and Install Timer Job in MOSS 2007

Excute Timerjob

 public class TriggerLoadCacheTimerJob : SPJobDefinition
    {
        string ExceptionFlag = string.Empty;

        public TriggerLoadCacheTimerJob()
            : base()
        {
        }
        // Overriding the parameterized constructor
        public TriggerLoadCacheTimerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)
            : base(jobName, service, server, targetType) { }

        public TriggerLoadCacheTimerJob(string jobName, SPWebApplication webApp)
            : base(jobName, webApp, null, SPJobLockType.Job)
        {
            // create the timer job with the name passed in Constructor and assign title
            this.Title = Constants.TIMERJOB_NAME;
        }
        public override void Execute(Guid targetInstanceId)
        {

            TriggerLoadCacheWebService();
        }
}

private void TriggerLoadCacheWebService()
        {
            try
            {
                SPWebApplication webApp = this.Parent as SPWebApplication;
                Configuration config = WebConfigurationManager.OpenWebConfiguration("/", webApp.Name);
                string CustomWebServiceURLs = config.AppSettings.Settings["CustomWebServiceUrls"].Value;
                string AccountName = config.AppSettings.Settings["AccountName"].Value;
                string Password = config.AppSettings.Settings["Password"].Value;
                string Domain = config.AppSettings.Settings["Domain"].Value;
                ExceptionFlag = config.AppSettings.Settings[Constants.LogExceptionFlag].Value;
                string[] customWSURLs = CustomWebServiceURLs.Split(‘;‘);
                for (int i = 0; i < customWSURLs.Length; i++)
                {
                    AEnhancement.PSWebService mywebService = new AEnhancement.PSWebService();
                    mywebService.Url = customWSURLs[i].ToString();
                    NetworkCredential credential = new NetworkCredential(AccountName, Password, Domain);
                    //mywebService.Timeout=300000;
                    mywebService.Credentials = credential;
                    mywebService.LoadCacheAsync();
                }
            }
            catch (Exception ex)
            {
                if (ExceptionFlag.ToLower() == "true")
                {
                    TraceLog.Error("Message:" + ex.Message + "Source:" + ex.Source + "TargetSite:" + Convert.ToString(ex.TargetSite), "TriggerLoadCacheWebService Method in Timer Job");
                }
            }
        }

Timerjob inherited SPJobDefinition, it is based on webapplication(CA). You are able to debug timerjob via OWSTimer.exe.

Install TimerJob-Feature Active

class TimerJobFeatureReceiver : SPFeatureReceiver
    {
        string ExceptionFlag = string.Empty;
        string InfoFlag = string.Empty;
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                TraceLog.Information("Activate Feature Start", "Activate Feature");
                SPSite CurrentSite = properties.Feature.Parent as SPSite;

                if (CurrentSite == null)
                {
                    TraceLog.Information("Current Site is NULL", "Activate Feature");
                    return;
                }
                else
                {
                    TraceLog.Information("Current Site " + CurrentSite.Url, "Activate Feature");
                }

                SPWebApplication webapp = CurrentSite.WebApplication;

                if (webapp == null)
                {
                    TraceLog.Information("Web APP is NULL", "Activate Feature");
                    return;
                }
                else
                {
                    TraceLog.Information("WebAPP "+webapp.Name, "Activate Feature");
                }
                // deletes the timer job if already exists
                foreach (SPJobDefinition job in webapp.JobDefinitions)
                {
                    if (job.Name == Constants.TIMERJOB_NAME)
                    {
                        job.Delete();
                        TraceLog.Information("Timer Job Delete Firstly", "Activate Feature");
                        break;
                    }
                }

                // install the job
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    TraceLog.Information("Install Timer Job Begin", "Activate Feature");
                    TriggerLoadCacheTimerJob customTimerjob = new TriggerLoadCacheTimerJob(Constants.TIMERJOB_NAME, webapp);
                    TraceLog.Information("111", "Activate Feature");
                    Configuration config = WebConfigurationManager.OpenWebConfiguration("/", CurrentSite.WebApplication.Name);
                    TraceLog.Information("config created", "Activate Feature");
                    string TimerJobSchedule = config.AppSettings.Settings["TimerJobSchedule"].Value;
                    TraceLog.Information(TimerJobSchedule, "Activate Feature");
                    ExceptionFlag = config.AppSettings.Settings[Constants.LogExceptionFlag].Value;
                    SPSchedule schedule = SPSchedule.FromString("daily at " + TimerJobSchedule);

                    //SPMinuteSchedule schedule = new SPMinuteSchedule();
                    //schedule.BeginSecond = 0;
                    //schedule.EndSecond = 59;
                    //schedule.Interval = 5;

                    customTimerjob.Schedule = schedule;
                    TraceLog.Information("Timer Job UPdate Method Start", "Activate Feature");
                    customTimerjob.Update();
                    TraceLog.Information("Timer Job UPdate Method End", "Activate Feature");
                    TraceLog.Information("Install Timer Job End", "Activate Feature");
                });
            }
            catch (Exception ex)
            {
                if (ExceptionFlag.ToLower() == "true")
                {
                    TraceLog.Error("Message:" + ex.Message + "Source:" + ex.Source + "TargetSite:" + Convert.ToString(ex.TargetSite), "TriggerLoadCacheWebService Method in Timer Job");
                }
            }

        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {

            try
            {
                SPSite CurrentSite = properties.Feature.Parent as SPSite;
                if (CurrentSite == null)
                    return;
                SPWebApplication webapp = CurrentSite.WebApplication;
                if (webapp == null)
                    return;
                // deletes the timer job if already exists
                foreach (SPJobDefinition job in webapp.JobDefinitions)
                {
                    if (job.Name == Constants.TIMERJOB_NAME)
                    {
                        job.Delete();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ExceptionFlag.ToLower() == "true")
                {
                    TraceLog.Error("Message:" + ex.Message + "Source:" + ex.Source + "TargetSite:" + Convert.ToString(ex.TargetSite), "TriggerLoadCacheWebService Method in Timer Job");
                }
            }
        }
}

Feature base on site

Create Config file in bin Folder

  1. Create OWSTimer.EXE.Config file in bin folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\bin
  2. Add these infomation in the file or you can put the file in bin folder.

  

<configuration>

  <appSettings>

    <add key="AccountName" value="Jenny" />
    <add key="Password" value="c003#" />
    <add key="Domain" value="abc" />
    <add key="CustomWebServiceUrls" value="http://sp2007:11908/_vti_bin/AWebService/PSWebService.asmx;http://sp2007:11909/_vti_bin/AWebService/PSWebService.asmx" />
    <add key="Detail_PeopleSearch_Debug" value="True" />
    <add key="PeopleSearch_Exception" value="True" />

  </appSettings>

</configuration>

Explanation of Key, Value in Configuration files

  1. AccountName, Password and Domain keys

Account should be the same as account which is used to run Windows SharePoint Services Timer service

  1. CustomWebServiceUrls key

It means customwebServiceUrls which you will use in several WFE, you have to configure these several links which is split by " ; ".

  1. MaxRecords key

It means how many records will get back when user keys in characters.

  1. TimerJobSchedule key

It stands for when timer job runs

  1. Detail_PeopleSearch_Debug and PeopleSearch_Exception keys

They are used to enable to note down log when they are set as “True”.

时间: 2024-10-10 12:09:28

Create and Install Timer Job in MOSS 2007的相关文章

Custom Web Servic In MOSS 2007

Tools: Visual Studio 2008,Visual Studio 2008 Command Prompt, Sharepoint Server 2007 Generate .disco and .wsdl files through Visual Studio 2008 Command Prompt in Visual Studio Tools Run command: Disco http://sp2007:14908/_vti_bin/PSWebService.asmx <%@

MOSS 2007 错误0x80040E14解决

今天公司内网莫名的出现错误,只能新建列表条目,不能创建网站,到后来列表条目也不能创建了,一直报0x80040E14错误.于是Google一把,搜索这个错误号,然后在apearce 的Blog找到了原因.原文如下: HRESULT: 0x80040E14 when adding items to SharePoint If you receive HRESULT: 0x80040E14 when trying to add an item like announcements/webpart/sa

记录在Sungard工作时对ejb3.1的研究(2)--ejb3 集群(ejb timer/MDB)

以前和人家谈论sungard的工作时,总是被质疑:"你们还在使用ejb啊?太老了吧". "早就是spring的年代了". 我总是反击,你们真的了解ejb吗?了解ejb在分布式应用里集群部署和spring比较有多方便吗?不要总是把什么IOC, AOP肤浅的挂在嘴上, 现在早已不是ejb2的时代了. ejb3 dependency injection也很容易,除了在非javaee容器管理的资源里受限(需要借助javaee6 CDI). AOP?ejb也有intercep

在moss 服务器上访问自己的sharepoint 网站,输入用户名密码无效

环境:sharepoint 2007 ,windows server 2003 x64 sp2 该服务器部署了moss 2007 ,客户端访问正常,但在该服务器上访问moss的时候,不断提示需要输入用户名密码,并且输入无效. 根据微软知识库解释:当网站使用集成身份验证并具有映射到本机环回地址的名称时,将出现此问题. 解决办法: 方法 1:禁用环回检查 将 DisableStrictNameChecking 注册表项设置为 1. 有关具体操作方法的更多信息,请单击下面的文章编号,以查看 Micro

sharepoint 2007 无法自动跳转到default.aspx

环境:moss 2007 sp2 ,server 2003 r2 X64,一台管理中心,四台前端,一台search,一台其他开发功能server. 使用NLB访问正常,域名为http://www.test.com 如果将hosts 中的域名直接指定到管理中心的地址,直接通过管理中心的Web Application 访问时,如果使用http://www.test.com/default.aspx访问正常,使用http://www.test.com访问时,不断弹出输入用户名密码的对话框,并且输入无效

sharepoint 2007 升级到 sharepoint 2013

从moss 2007不能直接升级到moss2013,必须要先升级到moss2010,再升级到moss2013才可以. 一.需要将moss 2007打到sp2补丁(如果已经打过补丁,可以跳过此步骤) 如果还没有打sp1补丁,需要先打sp1补丁,然后再打sp2补丁.打完sp2后,sharepoint的版本号是12.0.0.6421,未打任何补丁之前的版本号是4518或者更小. 按照如下顺序打补丁.如果不想在生产环境上动刀,那么就搭一个虚拟机吧.moss2007环境的搭建可以参照这个:http://w

C#中npoi操作Excel[版本2.0.1读写2003、2007格式]

public static void test1()       {           NpoiHelper np = new NpoiHelper();           DataTable dt1 = np.ReadExcel(AppDomain.CurrentDomain.BaseDirectory + "1测试数据.xls", 2).Tables[0];//读2003格式数据           DataSet ds1 = new DataSet();           

使用NPOI 2.1.1读取EXCEL2003/2007返回DataTable

一,不借助插件读取Excel2003.2007: string strConn = "Provider=Microsoft.Ace.OleDb.12.0;" + "Data Source=" + path + ";" + "Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'"; OleDbConnection conn = new OleDbConnection(strConn)

NPOI兼容 excel2003,2007版本

根据项目需要,需要对excel进行导入导出,所以选择NPOI,优点在这里就不详细介绍了,下面进入正题. 1 public int Import(string path) 2 { 3 IList<Student> list = new List<Student>(); 4 5 try 6 { 7 string strFileName = path; 8 using (FileStream file = new FileStream(strFileName, FileMode.Open