Example #1
0
 public JobService(IMapper mapper, ILogger <JobService> logger, IJobRepository jobRepository, IQuartzServer quartzServer)
 {
     _mapper        = mapper;
     _logger        = logger;
     _jobRepository = jobRepository;
     _quartzServer  = quartzServer;
 }
Example #2
0
 public JobService(IMapper mapper, IJobRepository repository, ILogger <JobService> logger, IQuartzServer quartzServer, IJobLogRepository logRepository)
 {
     _mapper        = mapper;
     _repository    = repository;
     _logger        = logger;
     _quartzServer  = quartzServer;
     _logRepository = logRepository;
 }
Example #3
0
        public TYDNewsService()
        {
            InitializeComponent();

            server = QuartzServerFactory.CreateServer();

            server.Initialize();
        }
 public TaskService(TaskRepository repository, TaskLogRepository logRepository, ILogger <TaskService> logger, QuartzTaskCollection collect, IQuartzServer quartzServer)
 {
     _repository    = repository;
     _logRepository = logRepository;
     _collect       = collect;
     _quartzServer  = quartzServer;
     _logger        = logger;
 }
Example #5
0
 public JobService(IMapper mapper, IJobRepository repository, ILogger <JobService> logger, IQuartzServer quartzServer, IJobLogRepository logRepository, QuartzDbContext dbContext)
 {
     _mapper        = mapper;
     _repository    = repository;
     _logger        = logger;
     _quartzServer  = quartzServer;
     _logRepository = logRepository;
     _dbContext     = dbContext;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="QuartzService"/> class.
        /// </summary>
        public QuartzService()
        {
            logger = LogManager.GetLogger(GetType());

            logger.Debug("Obtaining instance of an IQuartzServer");
            server = QuartzServerFactory.CreateServer();

            logger.Debug("Initializing server");
            server.Initialize();
            logger.Debug("Server initialized");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="QuartzService"/> class.
        /// </summary>
		public QuartzService()
		{
            logger = LogManager.GetLogger(GetType());

            logger.Debug("Obtaining instance of an IQuartzServer");
		    server = QuartzServerFactory.CreateServer();

			logger.Debug("Initializing server");
            server.Initialize();
            logger.Debug("Server initialized");
		}
Example #8
0
        public virtual void Run()
        {
            ILog log = LogManager.GetLogger(typeof(HelloRun));

            log.Info("------- Initializing ----------------------");

            // First we must get a reference to a scheduler
            //ISchedulerFactory sf = new StdSchedulerFactory();
            //IScheduler sched = sf.GetScheduler();
            IQuartzServer server = QuartzServerFactory.CreateServer();

            server.Initialize();
            IScheduler sched = server.GetScheduler();

            log.Info("------- Initialization Complete -----------");


            // computer a time that is on the next round minute
            DateTimeOffset runTime = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);

            log.Info("------- Scheduling Job  -------------------");

            // define the job and tie it to our HelloJob class
            IJobDetail job = JobBuilder.Create <HelloJob>()
                             .WithIdentity("job1", "group1")
                             .Build();

            // Trigger the job to run on the next round minute
            ITrigger trigger = TriggerBuilder.Create()
                               .WithIdentity("trigger1", "group1")
                               .StartAt(runTime)
                               .Build();

            // Tell quartz to schedule the job using our trigger
            sched.ScheduleJob(job, trigger);
            log.Info(string.Format("{0} will run at: {1}", job.Key, runTime.ToString("r")));

            // Start up the scheduler (nothing can actually run until the
            // scheduler has been started)
            sched.Start();
            log.Info("------- Started Scheduler -----------------");

            // wait long enough so that the scheduler as an opportunity to
            // run the job!
            log.Info("------- Waiting 65 seconds... -------------");

            // wait 65 seconds to show jobs
            Thread.Sleep(TimeSpan.FromSeconds(65));

            // shut down the scheduler
            log.Info("------- Shutting Down ---------------------");
            sched.Shutdown(true);
            log.Info("------- Shutdown Complete -----------------");
        }
Example #9
0
        /// <summary>
        /// Creates a new instance of an Quartz.NET server core.
        /// </summary>
        /// <returns></returns>
        public static IQuartzServer CreateServer()
        {
            string typeName = Configuration.ServerImplementationType;

            Type t = Type.GetType(typeName, true);

            logger.Debug("Creating new instance of server type '" + typeName + "'");
            IQuartzServer retValue = (IQuartzServer)Activator.CreateInstance(t);

            logger.Debug("Instance successfully created");
            return(retValue);
        }
        /// <summary>
        /// 创建新的任务调度实例
        /// </summary>
        /// <param name="typeFullName">计划任务调度类型名称(GetType().FullName)</param>
        /// <param name="autoStart">是否自动初始化并启动任务实例</param>
        /// <returns></returns>
        public static IQuartzServer CreateSchedulerServer(string typeFullName, bool autoStart = false)
        {
            IQuartzServer serverInstance = null;

            try
            {
                //1、先从缓存中读取同名的任务调度实例
                if (string.IsNullOrWhiteSpace(typeFullName))
                {
                    logger.FatalFormat("==>计划任务调度类型名称不能为空:'{0}'", typeFullName);
                    throw new ArgumentNullException("CreateSchedulerServer.typeFullName 参数不能为空!");
                }
                //typeFullName = typeFullName ?? HostServiceConfigurationLoader.HostServiceCfg.serverImplementationTypeName;
                if (_quartzServerInstances.ContainsKey(typeFullName) && _quartzServerInstances[typeFullName] != null)
                {
                    serverInstance = _quartzServerInstances[typeFullName];
                    return(serverInstance);
                }
                //2、缓存不存在则重新创建新的任务调度实例
                if (!_quartzServiceTypes.ContainsKey(typeFullName))
                {
                    lock (Locker)
                    {
                        if (!_quartzServiceTypes.ContainsKey(typeFullName))
                        {
                            LoadAssemblyForQuartzServer();
                        }
                    }
                }
                logger.Debug(String.Format("==>创建新的任务服务实例:'{0}',时间:{1}", typeFullName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                Type t = _quartzServiceTypes[typeFullName];
                serverInstance = ObjectUtils.InstantiateType <IQuartzServer>(t);   //(IQuartzServer)Activator.CreateInstance(t);
                if (autoStart)
                {
                    serverInstance.Initialize(true);
                    logger.Debug(String.Format("==>任务服务实例初始化成功! 时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                }
                //3、缓存创建的任务调度实例
                if (serverInstance != null)
                {
                    _quartzServerInstances.AddOrUpdate(typeFullName, serverInstance, (key, oldInstance) => {
                        return(serverInstance);
                    });
                }
            }
            catch (Exception Ex)
            {
                logger.FatalFormat("==>任务服务实例创建出错:{0}", Ex.Message);
            }
            return(serverInstance);
        }
        /// <summary>
        /// 获取已创建的任务调度实例
        /// </summary>
        /// <param name="typeFullName">计划任务调度类型名称(GetType().FullName)</param>
        /// <returns></returns>
        public static IQuartzServer GetSchedulerServer(string typeFullName)
        {
            IQuartzServer serverInstance = null;

            try
            {
                if (_quartzServerInstances.ContainsKey(typeFullName) && _quartzServerInstances[typeFullName] != null)
                {
                    serverInstance = _quartzServerInstances[typeFullName];
                }
            }
            catch (Exception Ex)
            {
                logger.FatalFormat("==>获取任务调度实例<{0}>出错:{1}", typeFullName, Ex.Message);
            }
            return(serverInstance);
        }
		/// <summary>
		/// 初始化 ServerStatusCommand 类的新实例。
		/// </summary>
		/// <param name="name">命令名称。</param>
		/// <param name="server">调度服务器实例。</param>
		public ServerStatusCommand(string name, IQuartzServer server) : base(name, server)
		{

		}
Example #13
0
        public static void Initialize()
        {
            var container = new WindsorContainer();

            container
            .Register(Component.For <IJsonSerializer>().ImplementedBy <JsonSerializer>())
            .Register(Component.For <ExceptionInterceptor>().LifeStyle.PerWcfOperation())
            .Kernel.AddFacility <WcfFacility>();


            // WCF Config

            //Enables debugging and help information features for a Windows Communication Foundation (WCF) service.
            var returnFaults = new ServiceDebugBehavior
            {
                IncludeExceptionDetailInFaults = true,
                HttpHelpPageEnabled            = true
            };

            //Configures run-time throughput settings that enable you to tune service performance.
            var serviceThrottlingBehavior = new ServiceThrottlingBehavior
            {
                MaxConcurrentCalls     = 16,
                MaxConcurrentInstances = 10,
                MaxConcurrentSessions  = Int32.MaxValue
            };

            container.Register(Component.For <IServiceBehavior>().Instance(returnFaults));
            container.Register(Component.For <IServiceBehavior>().Instance(serviceThrottlingBehavior));


            container.Register(Component.For <ISchedulerService>()
                               .ImplementedBy <SchedulerService>().LifestyleTransient()
                               .Interceptors(InterceptorReference.ForType <ExceptionInterceptor>()).Anywhere
                               .AsWcfService(new DefaultServiceModel()
                                             .AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding
            {
                MaxReceivedMessageSize = 200000,
                MaxBufferSize          = 200000,
                MaxBufferPoolSize      = 200000,
            }
                                                                               ).At(ConfigurationManager.AppSettings.Get("QuartzSoapAddress") + "BasicHttpEndPoint"))
                                             .AddBaseAddresses(ConfigurationManager.AppSettings.Get("QuartzServiceUrl"))
                                             .PublishMetadata(extension => extension.EnableHttpGet())
                                             ));

            bool isAllValid = true;

            foreach (IHandler handler in container.Kernel.GetAssignableHandlers(typeof(object)))
            {
                if (handler.CurrentState != HandlerState.Valid)
                {
                    Console.WriteLine("HandlerState NOT Valid for : " + handler.ComponentModel.ComponentName + " - " + handler.CurrentState);
                    isAllValid = false;
                }
            }
            if (!isAllValid)
            {
                throw new Exception("Invalid components !");
            }
            IQuartzServer server = QuartzServerFactory.CreateServer();

            server.Initialize();

            server.Start();
        }
Example #14
0
 public QuartzConfigChangedEvent(IQuartzServer quartzServer)
 {
     _quartzServer = quartzServer;
 }
 public ModuleOptionsChangedEvent(IQuartzServer server)
 {
     _server = server;
 }
 public QuartzAppShutdownHandler(IQuartzServer server, ILogger <QuartzAppShutdownHandler> logger)
 {
     _server = server;
     _logger = logger;
 }
		/// <summary>
		/// 初始化 ServerPauseCommand 类的新实例。
		/// </summary>
		/// <param name="name">命令名称。</param>
		/// <param name="server">调度服务器实例。</param>
		public ServerPauseCommand(string name, IQuartzServer server) : base(name, server)
		{

		}
Example #18
0
 public QuartzController(IQuartzServer quartzServer)
 {
     _quartzServer = quartzServer ?? throw new ArgumentNullException(nameof(quartzServer));
 }