コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Delete_Click(object sender, DirectEventArgs e)
        {
            if (!string.IsNullOrEmpty(hdfMonth.Text) && !string.IsNullOrEmpty(hdfYear.Text))
            {
                if (!string.IsNullOrEmpty(hdfTimeSheetGroupListId.Text))
                {
                    var groupWorkShiftId = Convert.ToInt32(hdfTimeSheetGroupListId.Text);

                    //get all detail workShift
                    var order        = " [StartDate] ASC ";
                    var lstWorkShift =
                        TimeSheetWorkShiftController.GetAll(null, false, groupWorkShiftId, null, null, null, null, Convert.ToInt32(hdfMonth.Text), Convert.ToInt32(hdfYear.Text), order, null);

                    var listWorkShiftIds = lstWorkShift.Select(ws => ws.Id).ToList();
                    if (listWorkShiftIds.Count > 0)
                    {
                        TimeSheetEventController.DeleteByCondition(listWorkShiftIds, null, null, null, TimeSheetAdjustmentType.Default);
                    }

                    //Update status schedule create new timeSheet
                    var scheduler = SchedulerServices.GetSchedulerByName();
                    if (scheduler != null)
                    {
                        scheduler.Status    = SchedulerStatus.Ready;
                        scheduler.Arguments = "-m {0} -y {1} -groupWorkShiftId {2}".FormatWith(hdfMonth.Text, hdfYear.Text, hdfTimeSheetGroupListId.Text);

                        SchedulerServices.Update(scheduler);
                    }
                }

                wdWindow.Hide();
            }
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static SchedulerModel Update(SchedulerModel model)
        {
            // get entity from database
            var entity = SchedulerServices.GetById(model.Id);

            // set new properties from model
            model.FillEntity(ref entity);
            // update entity
            return(new SchedulerModel(SchedulerServices.Update(entity)));
        }
コード例 #3
0
ファイル: JobScheduler.cs プロジェクト: war-man/HRM
        /// <summary>
        ///
        /// </summary>
        /// <param name="scheduler"></param>
        private Task RunScheduler(Scheduler scheduler)
        {
            try
            {
                // next run time
                DateTime?nextRunTime = null;
                if (scheduler.NextRunTime == null)
                {
                    return(Task.FromCanceled(new CancellationToken(true)));
                }
                // switch repeat type
                switch (scheduler.RepeatType)
                {
                case SchedulerRepeatType.OneTime:
                    break;

                case SchedulerRepeatType.Monthly:
                    nextRunTime = scheduler.NextRunTime.Value.AddMonths(1);
                    break;

                case SchedulerRepeatType.Weekly:
                    nextRunTime = scheduler.NextRunTime.Value.AddDays(7);
                    break;

                case SchedulerRepeatType.Daily:
                    nextRunTime = scheduler.NextRunTime.Value.AddDays(1);
                    break;

                case SchedulerRepeatType.Hourly:
                    nextRunTime = scheduler.NextRunTime.Value.AddHours(1);
                    break;

                case SchedulerRepeatType.IntervalTime:
                    if (scheduler.IntervalTime > 0)
                    {
                        nextRunTime = scheduler.NextRunTime.Value.AddMinutes(scheduler.IntervalTime);
                    }
                    break;

                default:
                    return(Task.FromCanceled(new CancellationToken(true)));
                }

                // expired time
                DateTime?expiredTime = null;
                if (scheduler.ExpiredAfter > 0 && scheduler.RepeatType != SchedulerRepeatType.OneTime)
                {
                    expiredTime = scheduler.NextRunTime.Value.AddMinutes(scheduler.ExpiredAfter);
                }
                // update current scheduler status to running
                SchedulerServices.Update(scheduler.Id, SchedulerStatus.Running, DateTime.Now, nextRunTime, expiredTime);
                // init scheduler type
                var schedulerType = cat_BaseServices.GetById("cat_SchedulerType", scheduler.SchedulerTypeId);
                // init job type
                var jobType = Type.GetType("Web.Core.Framework.{0},Web.Core.Framework".FormatWith(schedulerType.Name));
                if (jobType == null)
                {
                    return(Task.FromCanceled(new CancellationToken(true)));
                }
                // init job
                var job = Activator.CreateInstance(jobType);
                // int job property
                ((BaseTask)job).Id        = scheduler.Id;
                ((BaseTask)job).Name      = scheduler.Name;
                ((BaseTask)job).Arguments = scheduler.Arguments;
                // execute job
                ((BaseTask)job).Excute(scheduler.Arguments);

                // update scheduler status when complete
                SchedulerServices.Update(scheduler.Id, scheduler.RepeatType == SchedulerRepeatType.OneTime
                    ? SchedulerStatus.Completed
                    : SchedulerStatus.Ready);
                return(Task.CompletedTask);
            }
            catch (Exception ex)
            {
                // log error
                SystemLogController.Create(new SystemLogModel("system", "RunScheduler", SystemAction.TrackError,
                                                              SystemLogType.ScheduleError, ex.Message, ex.ToString(), true));
                return(Task.FromException(ex));
            }
        }