Exemplo n.º 1
0
        /// <summary>
        /// 获取程序集中的实现类对应的多个接口
        /// </summary>
        /// <param name="plan"></param>
        /// <returns></returns>
        public static Dictionary <Type, Type[]> Jobs(this IooinPlan plan)
        {
            if (plan == null)
            {
                throw new ArgumentException(nameof(plan));
            }

            var assembly = Assembly.LoadFile(plan.DllPath);

            if (assembly == null)
            {
                throw new ArgumentNullException(nameof(assembly));
            }

            List <Type> types = assembly.GetTypes().ToList();

            var result = new Dictionary <Type, Type[]>();

            foreach (var item in types.Where(s => !s.IsInterface))
            {
                var interfaceType = item.GetInterfaces();

                if (interfaceType.Any(c => c.Name.Equals(plan.InterfaceName)))
                {
                    result.Add(item, interfaceType);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public async Task InjectionPlan(IooinPlan plan)
        {
            Dictionary <Type, Type[]> jobs = plan.Jobs();

            foreach (var item in jobs)
            {
                var        instance = Activator.CreateInstance(item.Key);
                MethodInfo method   = (item.Key).GetMethod(plan.MethodName);
                string     jobName  = (item.Key).GetProperty("JobName")?.GetValue(instance).ToString() ?? "";


                IJobDetail job = JobBuilder.Create(typeof(BaseJob))
                                 .WithIdentity(jobName, plan.GroupName)
                                 .Build();

                ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
                                         .WithIdentity($"{plan.GroupName}_{jobName}_trigger")
                                         .StartAt(plan.StartTime)
                                         .EndAt(plan.EndTime)
                                         .ForJob(jobName, plan.GroupName)
                                         .TriggerFrequency(plan)
                                         .Build();



                JobListener listener = new JobListener
                {
                    Name   = jobName,
                    Action = () => method.Invoke(instance, null)
                };

                IMatcher <JobKey> matcher = KeyMatcher <JobKey> .KeyEquals(job.Key);

                scheduler.ListenerManager.AddJobListener(listener, matcher);

                await scheduler.ScheduleJob(job, trigger);
            }
        }
Exemplo n.º 3
0
        public static TriggerBuilder TriggerFrequency(this TriggerBuilder triggerBuilder, IooinPlan plan)
        {
            if (plan.WithRepeatCount == 0)
            {
                return(triggerBuilder.WithSimpleSchedule(x => x.WithIntervalInSeconds(plan.WithIntervalInSeconds).RepeatForever()));
            }

            return(triggerBuilder.WithSimpleSchedule(x => x.WithIntervalInSeconds(plan.WithIntervalInSeconds).WithRepeatCount(plan.WithRepeatCount)));
        }