Quartz_TimeJob例子(C#)

 

执行入口:

using System;
using System.Collections.Generic;
using log4net;
using Quartz;
using ypt_base.Common.Model;
using ypt_base.Common.Util.AD;
using ypt_base.Urms.BLL;
using ypt_base.Urms.Model.Res;

namespace Quartz_TimerJob.TimeDevice
{
    /// <summary>
    /// 江苏YPT组织机构信息同步任务
    /// </summary>
    [DisallowConcurrentExecution]               //不允许此 Job 并发执行任务(禁止新开线程执行)
    public class SyncAdOrgUnitJob : IJob
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(SyncAdOrgUnitJob));

        public void Execute(IJobExecutionContext context)
        {
            try
            {
                Log.InfoFormat("从AD域同步组织机构信息开始:{0}", DateTime.Now);

                // 获取AD域组织信息
                List<ADModel> adList = new AdHelper().SyncOrgUnit();

                // 获取组织维度信息
                DictionaryManagerBLL dictBll = new DictionaryManagerBLL();
                IList<UrmsDictionary> dimensionList = dictBll.GetDictionaryItemByType("orgDimension");

                bool flag = false;
                MetaOrgBLL orgBll = new MetaOrgBLL();
                if (adList != null && adList.Count > 0)
                {
                    flag = orgBll.SaveOrgUnitAndOrgUser(adList, dimensionList);
                }
                else
                {
                    Log.WarnFormat("AD域中不存在所要获取的组织机构信息!");
                }

                Log.InfoFormat(flag ? "从AD域同步组织机构信息成功!" : "从AD域同步组织机构信息失败!");
            }

            catch (Exception ex)
            {
                Log.Error("从AD域同步组织机构信息异常", ex);
            }
        }
    }
}

配置文件:

?xml version="1.0" encoding="UTF-8"?>

<!-- This file contains job definitions in schema version 2.0 format -->

<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">

  <processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
  </processing-directives>

  <schedule>
    <!--江苏YPT同步组织机构任务配置-->
    <job>
      <name>SyncAdOrgUnitJob</name>
      <group>SyncAdOrgUnitGroup</group>
      <description>SyncAdOrgUnit job for Quartz Server</description>
      <job-type>Quartz_TimerJob.TimeDevice.SyncAdOrgUnitJob, Quartz_TimerJob</job-type>
      <durable>true</durable>
      <recover>false</recover>
    </job>

    <trigger>
      <cron>
        <name>SyncAdOrgUnitTrigger</name>
        <group>SyncAdOrgUnitGroup</group>
        <job-name>SyncAdOrgUnitJob</job-name>
        <job-group>SyncAdOrgUnitGroup</job-group>
        <cron-expression>0 23 15 * * ?</cron-expression>
        <!--[秒] [分] [小时] [日] [月] [周] [年]-->
      </cron>
    </trigger>

  </schedule>
</job-scheduling-data>

 

转载于:https://www.cnblogs.com/tldxh/p/8176256.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值