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 = ; 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("", "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”.

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

  1. How to upgrade workflow assembly in MOSS 2007

    This problem generally start when you are having an existing custom workflow and there are instances ...

  2. Custom Web Servic In MOSS 2007

    Tools: Visual Studio 2008,Visual Studio 2008 Command Prompt, Sharepoint Server 2007 Generate .disco ...

  3. MOSS 2007 错误0x80040E14解决

    今天公司内网莫名的出现错误,只能新建列表条目,不能创建网站,到后来列表条目也不能创建了,一直报0x80040E14错误.于是Google一把,搜索这个错误号,然后在apearce 的Blog找到了原因 ...

  4. Using XSLT and Open XML to Create a Word 2007 Document

    Summary: Learn how to transform XML data into a Word 2007 document by starting with an existing docu ...

  5. Embedding Documents in Word 2007 by Using the Open XML SDK 2.0 for Microsoft Office

    Download the sample code This visual how-to article presents a solution that creates a Word 2007 doc ...

  6. 转贴:sudo apt-get install 可以安装的一些软件

    Ubuntu 下的一些软件安装sudo apt-get install virtualbox#华主席推荐 2007年年度最佳软件,最佳编辑选择奖得主.....sudo apt-get install ...

  7. SharePoint 2007 页面定制(一)

    转:http://www.nanmu.net/SharePoint-MOSS-WSS-Silverlight/Lists/Posts/Post.aspx?ID=74 本文主要包括以下几方面内容: 1. ...

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

    下载npoi2.0.1dll文件:http://download.csdn.net/detail/pukuimin1226/5851747 public static void test1()     ...

  9. NPOI兼容 excel2003,2007版本

    根据项目需要,需要对excel进行导入导出,所以选择NPOI,优点在这里就不详细介绍了,下面进入正题. public int Import(string path) { IList<Studen ...

随机推荐

  1. 关于Java加载属性文件放在web容器不好使的解决办法

    //使用Spring的工具就行了1 import java.util.Properties; import org.springframework.core.io.support.Properties ...

  2. android源码中,在系统多媒体数据库中增加一个字段

    由于项目需求,在系统多媒体管理数据库里的存储图像文件的表中需要新增加一个字段,源码在:项目\packages\providers\MediaProvider\MediaProvider.java下,在 ...

  3. app里使用163邮箱发送邮件,被163认为是垃圾邮件的坑爹经历!_ !

    最近有个项目,要发邮件给用户设定的邮箱报警,然后就用了163邮箱,代码是网上借来的^^,如下: package com.smartdoorbell.util; import android.os.As ...

  4. Class.forName()用法及与new区别

    平时开发中我们经常会发现:用到Class.forName()方法.为什么要用呢? 下面分析一下: 主要功能Class.forName(xxx.xx.xx)返回的是一个类Class.forName(xx ...

  5. FireMonkey 保存图片到JPG的方法 BMP转JPG

    习惯VCL的做法了,到了FireMonkey里面,好像查不到单独的JPEG单元了,不少朋友就郁闷如何处理JPG了,这么大件事,不可能没有处理方法的,具体就请看代码: uses FMX.Surfaces ...

  6. PowerShell添加或修改注册表开机启动项脚本

    代码如下: $name = Read-Host "请输入开机启动项的名字(随便起)" $value = Read-Host "请输入开机启动项的值" try{ ...

  7. 使用Xmanager远程访问Redhat Enterprise Linux 6.1

    使用Xmanager远程访问Redhat Enterprise Linux 6.1   在Linux服务器开启gdm 配置防火墙 配置selinux 使用xmanager连接linux服务器 在Lin ...

  8. linux -- nano

    今天在git commit的时候碰到了一种编辑方式 -- 不会用 T.T,然后找了下相关的文档. ^G -- ctrl+g 帮助文档 ^O -- ctrl+o 写出,会出现下面的一行提示,是否保存,直 ...

  9. java里面interface,implement和extends的作用和用法

    今天阅读<设计模式示例>,看到一段代码涉及到了interface,implements和extends,其实在C++中经常用到.今天特百度,比较了一下: interface是一个接口,类似 ...

  10. Arduino 极速入门系列 - 光控灯(2) - 关于开关,上拉、下拉电阻那些事

    接上篇,这次继续讲解光控灯的另外两个组成部分 - 开关和光敏电阻,光控灯里面将会有自锁开关按钮和光敏电阻.这此主要给新玩电子的朋友解释一下开关按钮的做法. 开关按钮的引脚电平读取问题 - 新手专用 我 ...