Ejemplo n.º 1
0
        public ActionResult ScheduleTaskEvt(int[] Id, string Action)
        {
            // You have your books IDs on the deleteInputs array
            switch (Action.ToLower())
            {
            case "delete":

                if (Id != null && Id.Length > 0)
                {
                    int          length = Id.Length;
                    ScheduleTask objItem;
                    for (int i = 0; i <= length - 1; i++)
                    {
                        objItem = ScheduleTaskManager.GetById(Id[i], CurrentUser.CompanyID);
                        if (objItem != null)
                        {
                            ScheduleTaskManager.Delete(objItem);
                        }
                    }
                    return(View(ViewFolder + "list.cshtml", ScheduleTaskManager.GetAll(CurrentUser.CompanyID)));
                }
                break;
            }


            return(View("PostFrm"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the task manager
        /// </summary>
        public void Initialize()
        {
            this._taskThreads.Clear();

            //var taskService = EngineContext.Current.Resolve<IScheduleTaskService>();
            var scheduleTasks = ScheduleTaskManager.GetAll(1);

            //taskService
            //.GetAllTasks()
            //.OrderBy(x => x.Seconds)
            //.ToList();

            //group by threads with the same seconds
            foreach (var scheduleTaskGrouped in scheduleTasks.GroupBy(x => x.Seconds))
            {
                //create a thread
                var taskThread = new TaskThread
                {
                    Seconds = scheduleTaskGrouped.Key
                };
                foreach (var scheduleTask in scheduleTaskGrouped)
                {
                    var task = new Task(scheduleTask);
                    taskThread.AddTask(task);
                }
                this._taskThreads.Add(taskThread);
            }

            //sometimes a task period could be set to several hours (or even days).
            //in this case a probability that it'll be run is quite small (an application could be restarted)
            //we should manually run the tasks which weren't run for a long time
            var notRunTasks = scheduleTasks
                              //find tasks with "run period" more than 30 minutes
                              .Where(x => x.Seconds >= _notRunTasksInterval)
                              .Where(x => !x.LastStartUtc.HasValue || x.LastStartUtc.Value.AddSeconds(x.Seconds) < DateTime.UtcNow)
                              .ToList();

            //create a thread for the tasks which weren't run for a long time
            if (notRunTasks.Any())
            {
                var taskThread = new TaskThread
                {
                    RunOnlyOnce = true,
                    Seconds     = 60 * 5 //let's run such tasks in 5 minutes after application start
                };
                foreach (var scheduleTask in notRunTasks)
                {
                    var task = new Task(scheduleTask);
                    taskThread.AddTask(task);
                }
                this._taskThreads.Add(taskThread);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// ExportExcel File
        /// </summary>
        /// <returns></returns>
        public string ExportExcel()
        {
            ScheduleTaskCollection collection = ScheduleTaskManager.GetAll(CurrentUser.CompanyID);
            DataTable dt       = collection.ToDataTable <ScheduleTask>();
            string    fileName = "ScheduleTask_" + SystemConfig.CurrentDate.ToString("MM-dd-yyyy");

            string[] RemoveColumn = { "CompanyID", "TargetDisplayID", "ReturnDisplay", "TotalRecord", "CreatedUser", "CreatedDate" };
            for (int i = 0; i < RemoveColumn.Length; i++)
            {
                if (dt.Columns.Contains(RemoveColumn[i]))
                {
                    dt.Columns.Remove(RemoveColumn[i]);
                }
            }
            FileInputHelper.ExportExcel(dt, fileName, "ScheduleTask List", false);
            return(fileName);
        }
Ejemplo n.º 4
0
        public ActionResult Create(ScheduleTask model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.CompanyID = CurrentUser.CompanyID;

                    if (model.Id != 0)
                    {
                        //get default value
                        ScheduleTask objOldScheduleTask = ScheduleTaskManager.GetById(model.Id, CurrentUser.CompanyID);
                        if (objOldScheduleTask != null)
                        {
                            model.CreatedDate = objOldScheduleTask.CreatedDate;
                            model.CreatedUser = objOldScheduleTask.CreatedUser;
                        }

                        ScheduleTaskManager.Update(model);
                    }
                    else
                    {
                        // TODO: Add insert logic here
                        model.CreatedUser = CurrentUser.EmployeeCode;
                        model.CreatedDate = SystemConfig.CurrentDate;
                        ScheduleTaskManager.Add(model);
                    }
                    return(View(ViewFolder + "list.cshtml", ScheduleTaskManager.GetAll(CurrentUser.CompanyID)));
                }
            }
            catch (Exception ObjEx)
            {
                //LogHelper.AddLog(new IfindLog() {LinkUrl=Request.Url.AbsoluteUri,Exception= ObjEx.Message,Message = ObjEx.StackTrace});
                return(View(model));
            }
            return(View(model));
        }
Ejemplo n.º 5
0
        public ActionResult list()
        {
            ScheduleTaskCollection collection = ScheduleTaskManager.GetAll(CurrentUser.CompanyID);

            return(View(ViewFolder + "list.cshtml", collection));
        }