Esempio n. 1
0
        private static string AddScheduledTask(System.Type type, MethodInfo method, Scheduling.Attributes.Schedule schedule)
        {
            string key = type.FullName + "." + method.Name;

            if (!ScheduledTasks.ContainsKey(key))
            {
                // TOOD: If the key exists, we should actually stop the schedule and re-add it.
                ScheduledTask scheduleTask = new ScheduledTask()
                {
                    Type            = type,
                    Method          = method,
                    IntervalInHours = SchedulerHelper.Instance.GetIntervalInHours(schedule.IntervalType, schedule.Interval),
                    Start           = schedule.Start,
                    Stop            = schedule.Stop
                };
                ScheduledTasks.TryAdd(key, scheduleTask);
            }
            return(key);
        }
Esempio n. 2
0
        private static void InitateSchedules()
        {
            List <System.Type> types = GetSchedulerTypes();

            foreach (System.Type type in types)
            {
                Scheduling.Attributes.Scheduler scheduler = (Scheduling.Attributes.Scheduler)type.GetCustomAttribute(typeof(Scheduling.Attributes.Scheduler));
                List <MethodInfo> methods = new List <MethodInfo>();
                foreach (MethodInfo method in type.GetMethods())
                {
                    if (method.GetCustomAttributes(typeof(Scheduling.Attributes.Schedule), true).Length > 0)
                    {
                        methods.Add(method);
                    }
                }

                foreach (MethodInfo method in methods)
                {
                    Scheduling.Attributes.Schedule schedule = (Scheduling.Attributes.Schedule)method.GetCustomAttribute(typeof(Scheduling.Attributes.Schedule));
                    AddScheduledTask(type, method, schedule);
                }
            }
        }