Ejemplo n.º 1
0
        public ActionResult Create(TaskDescriptor task, FormCollection forms)
        {
            var recurringDaysOfMonth = forms["RecurringDaysOfMonth"];
            var recurringDaysOfWeek = forms["RecurringDaysOfWeek"];
            var recurringMonths = forms["RecurringMonths"];
            var jobType = forms["JobType"];

            if (task.Frequency == Frequencies.Weekly)
            {
                if (recurringDaysOfWeek != null && recurringDaysOfWeek.Length > 0)
                    task.RecurringDaysOfWeek = recurringDaysOfWeek.Split(',').Select(a => Convert.ToInt32(a)).ToArray();
            }

            if (task.Frequency == Frequencies.Monthly)
            {
                if (recurringDaysOfMonth != null && recurringDaysOfMonth.Length > 0)
                    task.RecurringDaysOfMonth = recurringDaysOfMonth.Split(',').Select(a => Convert.ToInt32(a)).ToArray();

                if (recurringMonths != null && recurringMonths.Length > 0)
                    task.RecurringMonths = recurringMonths.Split(',').Select(a => Convert.ToInt32(a)).ToArray();
            }

            if (!string.IsNullOrEmpty(jobType))
            {
                task.JobType = Type.GetType(jobType);
                var props = task.JobType.GetProperties();
                task.CommandData = new System.Collections.Generic.Dictionary<string, object>();

                foreach (var pro in props)
                {
                    var key = task.JobType.Name + "." + pro.Name;
                    if (forms[key] != null)
                        task.CommandData.Add(pro.Name, Convert.ChangeType(forms[key], pro.PropertyType));
                }
            }

            task.Name = DNA.Utility.TextUtility.Slug(task.JobType.FullName + "." + System.IO.Path.GetRandomFileName().Replace(".", ""));
            Scheduler.AddTask(task);
            return PartialView();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Add a new task to scheduler
 /// </summary>
 /// <param name="task"></param>
 public static void AddTask(TaskDescriptor task)
 {
     var t = _AddTask(task);
     if (t != null)
         Workers.Add(t);
 }
Ejemplo n.º 3
0
        private static WorkItem _AddTask(TaskDescriptor task)
        {
            var taskFile = HttpRuntime.AppDomainAppPath + "app_data\\tasks\\" + task.Name + ".xml";
            if (!File.Exists(taskFile))
            {
                var workItem = new WorkItem()
                {
                    Title = task.Title,
                    Name = task.Name,
                    Description = task.Description,
                    File = taskFile,
                    JobType = task.JobType,
                    Frequency = task.Frequency,
                    StartAt = task.StartAt,
                    NextStart = task.GetNextStart(task.StartAt),
                    Recurs = task.Recurs,
                    RecurringMonths = task.RecurringMonths,
                    RecurringDaysOfMonth = task.RecurringDaysOfMonth,
                    RecurringDaysOfWeek = task.RecurringDaysOfWeek
                };

                if (task.CommandData != null && task.CommandData.Count > 0)
                    workItem.CommandData = task.CommandData;

                workItem.Save();
                return workItem;
            }
            return null;
        }