コード例 #1
0
        public static ScheduleInfo GetSchedule(int scheduleId)
        {
            DataSet      ds = DataProvider.GetSchedule(SecurityContext.User.UserId, scheduleId);
            ScheduleInfo si = ObjectUtils.FillObjectFromDataView <ScheduleInfo>(ds.Tables[0].DefaultView);

            return(si);
        }
コード例 #2
0
        public static int AddSchedule(ScheduleInfo schedule)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // check quota
            if (PackageController.GetPackageQuota(schedule.PackageId, Quotas.OS_SCHEDULEDTASKS).QuotaExhausted)
            {
                return(BusinessErrorCodes.ERROR_OS_SCHEDULED_TASK_QUOTA_LIMIT);
            }

            CalculateNextStartTime(schedule);

            string xmlParameters = BuildParametersXml(schedule.Parameters);

            int scheduleId = DataProvider.AddSchedule(SecurityContext.User.UserId,
                                                      schedule.TaskId, schedule.PackageId, schedule.ScheduleName, schedule.ScheduleTypeId,
                                                      schedule.Interval, schedule.FromTime, schedule.ToTime, schedule.StartTime,
                                                      schedule.NextRun, schedule.Enabled, schedule.PriorityId,
                                                      schedule.HistoriesNumber, schedule.MaxExecutionTime, schedule.WeekMonthDay, xmlParameters);

            // re-schedule tasks
            Scheduler.ScheduleTasks();

            return(scheduleId);
        }
コード例 #3
0
        public static int UpdateSchedule(ScheduleInfo schedule)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);

            if (accountCheck < 0)
            {
                return(accountCheck);
            }

            // load original schedule
            ScheduleInfo originalSchedule = GetScheduleInternal(schedule.ScheduleId);

            schedule.LastRun = schedule.LastRun;
            CalculateNextStartTime(schedule);

            string xmlParameters = BuildParametersXml(schedule.Parameters);

            DataProvider.UpdateSchedule(SecurityContext.User.UserId,
                                        schedule.ScheduleId, schedule.TaskId, schedule.ScheduleName, schedule.ScheduleTypeId,
                                        schedule.Interval, schedule.FromTime, schedule.ToTime, schedule.StartTime,
                                        schedule.LastRun, schedule.NextRun, schedule.Enabled, schedule.PriorityId,
                                        schedule.HistoriesNumber, schedule.MaxExecutionTime, schedule.WeekMonthDay, xmlParameters);

            // re-schedule tasks
            Scheduler.ScheduleTasks();

            return(0);
        }
コード例 #4
0
        public static void CalculateNextStartTime(ScheduleInfo schedule)
        {
            if (schedule.ScheduleType == ScheduleType.OneTime)
            {
                // start time stay intact
                // we only disable this task for the next time
                schedule.NextRun = schedule.StartTime;
            }
            else if (schedule.ScheduleType == ScheduleType.Interval)
            {
                DateTime lastRun = schedule.LastRun;
                DateTime now = DateTime.Now;

                // the task is running first time by default
                DateTime nextStart = DateTime.Now;

                if (lastRun != DateTime.MinValue)
                {
                    // the task is running next times
                    nextStart = lastRun.AddSeconds(schedule.Interval);
                }

                if(nextStart < now)
                    nextStart = now; // run immediately

                // check if start time is in allowed interval
                DateTime fromTime = new DateTime(now.Year, now.Month, now.Day,
                    schedule.FromTime.Hour, schedule.FromTime.Minute, schedule.FromTime.Second);

                DateTime toTime = new DateTime(now.Year, now.Month, now.Day,
                    schedule.ToTime.Hour, schedule.ToTime.Minute, schedule.ToTime.Second);

                if (!(nextStart >= fromTime && nextStart <= toTime))
                {
                    // run task in the start of the interval, but only tomorrow
                    nextStart = fromTime.AddDays(1);
                }
                schedule.NextRun = nextStart;
            }
            else if (schedule.ScheduleType == ScheduleType.Daily)
            {
                DateTime now = DateTime.Now;
                DateTime startTime = schedule.StartTime;
                DateTime nextStart = new DateTime(now.Year, now.Month, now.Day,
                    startTime.Hour, startTime.Minute, startTime.Second);
                if (nextStart < now) // start time is in the past
                    nextStart = nextStart.AddDays(1); // run tomorrow
                schedule.NextRun = nextStart;
            }
            else if (schedule.ScheduleType == ScheduleType.Weekly)
            {
                DateTime now = DateTime.Now;
                DateTime startTime = schedule.StartTime;
                DateTime nextStart = new DateTime(now.Year, now.Month, now.Day,
                    startTime.Hour, startTime.Minute, startTime.Second);
                int todayWeekDay = (int)now.DayOfWeek;
                nextStart = nextStart.AddDays(schedule.WeekMonthDay - todayWeekDay);

                if (nextStart < now) // start time is in the past
                    nextStart = nextStart.AddDays(7); // run next week
                schedule.NextRun = nextStart;
            }
            else if (schedule.ScheduleType == ScheduleType.Monthly)
            {
                DateTime now = DateTime.Now;
                DateTime startTime = schedule.StartTime;
                DateTime nextStart = new DateTime(now.Year, now.Month, now.Day,
                    startTime.Hour, startTime.Minute, startTime.Second);
                int todayDay = now.Day;
                nextStart = nextStart.AddDays(schedule.WeekMonthDay - todayDay);

                if (nextStart < now) // start time is in the past
                    nextStart = nextStart.AddMonths(1); // run next month
                schedule.NextRun = nextStart;
            }
        }
コード例 #5
0
 public int UpdateSchedule(ScheduleInfo schedule)
 {
     return SchedulerController.UpdateSchedule(schedule);
 }
コード例 #6
0
        public static void CalculateNextStartTime(ScheduleInfo schedule)
        {
            if (schedule.ScheduleType == ScheduleType.OneTime)
            {
                // start time stay intact
                // we only disable this task for the next time
                schedule.NextRun = schedule.StartTime;
            }
            else if (schedule.ScheduleType == ScheduleType.Interval)
            {
                DateTime lastRun = schedule.LastRun;
                DateTime now     = DateTime.Now;

                // the task is running first time by default
                DateTime nextStart = DateTime.Now;

                if (lastRun != DateTime.MinValue)
                {
                    // the task is running next times
                    nextStart = lastRun.AddSeconds(schedule.Interval);
                }

                if (nextStart < now)
                {
                    nextStart = now; // run immediately
                }
                // check if start time is in allowed interval
                DateTime fromTime = new DateTime(now.Year, now.Month, now.Day,
                                                 schedule.FromTime.Hour, schedule.FromTime.Minute, schedule.FromTime.Second);

                DateTime toTime = new DateTime(now.Year, now.Month, now.Day,
                                               schedule.ToTime.Hour, schedule.ToTime.Minute, schedule.ToTime.Second);

                if (!(nextStart >= fromTime && nextStart <= toTime))
                {
                    // run task in the start of the interval, but only tomorrow
                    nextStart = fromTime.AddDays(1);
                }
                schedule.NextRun = nextStart;
            }
            else if (schedule.ScheduleType == ScheduleType.Daily)
            {
                DateTime now       = DateTime.Now;
                DateTime startTime = schedule.StartTime;
                DateTime nextStart = new DateTime(now.Year, now.Month, now.Day,
                                                  startTime.Hour, startTime.Minute, startTime.Second);
                if (nextStart < now)                  // start time is in the past
                {
                    nextStart = nextStart.AddDays(1); // run tomorrow
                }
                schedule.NextRun = nextStart;
            }
            else if (schedule.ScheduleType == ScheduleType.Weekly)
            {
                DateTime now       = DateTime.Now;
                DateTime startTime = schedule.StartTime;
                DateTime nextStart = new DateTime(now.Year, now.Month, now.Day,
                                                  startTime.Hour, startTime.Minute, startTime.Second);
                int todayWeekDay = (int)now.DayOfWeek;
                nextStart = nextStart.AddDays(schedule.WeekMonthDay - todayWeekDay);

                if (nextStart < now)                  // start time is in the past
                {
                    nextStart = nextStart.AddDays(7); // run next week
                }
                schedule.NextRun = nextStart;
            }
            else if (schedule.ScheduleType == ScheduleType.Monthly)
            {
                DateTime now       = DateTime.Now;
                DateTime startTime = schedule.StartTime;
                DateTime nextStart = new DateTime(now.Year, now.Month, now.Day,
                                                  startTime.Hour, startTime.Minute, startTime.Second);
                int todayDay = now.Day;
                nextStart = nextStart.AddDays(schedule.WeekMonthDay - todayDay);

                if (nextStart < now)                    // start time is in the past
                {
                    nextStart = nextStart.AddMonths(1); // run next month
                }
                schedule.NextRun = nextStart;
            }
        }
コード例 #7
0
        private void SaveTask()
        {
            // gather form parameters
            ScheduleInfo sc = new ScheduleInfo();
            sc.ScheduleId = PanelRequest.ScheduleID;
            sc.ScheduleName = Server.HtmlEncode(txtTaskName.Text.Trim());
            sc.TaskId = ddlTaskType.SelectedValue;

            sc.PackageId = PanelSecurity.PackageId;

            sc.ScheduleTypeId = ddlSchedule.SelectedValue;
            sc.FromTime = timeFromTime.SelectedValue;
            sc.ToTime = timeToTime.SelectedValue;

            sc.StartTime = timeStartTime.SelectedValue;
            sc.Interval = intInterval.Interval;

            // check maximum interval
            // load context
            PackageContext cntx = PackagesHelper.GetCachedPackageContext(PackageId);
            if(cntx.Quotas.ContainsKey(Quotas.OS_MINIMUMTASKINTERVAL))
            {
                int minInterval = cntx.Quotas[Quotas.OS_MINIMUMTASKINTERVAL].QuotaAllocatedValue;
                if (minInterval != -1 && sc.Interval < (minInterval * 60))
                    sc.Interval = (minInterval * 60);
            }

            // run once
            if (ddlSchedule.SelectedIndex == 3)
            {
                DateTime tm = timeStartTime.SelectedValue;
                DateTime dt = DateTime.Parse(txtStartDate.Text);
                DateTime startTime = new DateTime(dt.Year, dt.Month, dt.Day, tm.Hour, tm.Minute, tm.Second);
                sc.StartTime = startTime;
            }

            sc.WeekMonthDay = Utils.ParseInt(txtWeekDay.Text, 0);
            if (ddlSchedule.SelectedIndex == 2)
                sc.WeekMonthDay = Utils.ParseInt(txtMonthDay.Text, 0);


            sc.Enabled = chkEnabled.Checked;
            sc.PriorityId = ddlPriority.SelectedValue;
            sc.HistoriesNumber = 0;
            sc.MaxExecutionTime = intMaxExecutionTime.Interval;

            // gather parameters
            List<ScheduleTaskParameterInfo> parameters = new List<ScheduleTaskParameterInfo>();
            foreach (GridViewRow row in gvTaskParameters.Rows)
            {
                ParameterEditor txtValue = (ParameterEditor)row.FindControl("txtValue");
                if (txtValue == null)
                    continue;

                string prmId = (string)gvTaskParameters.DataKeys[row.RowIndex][0];

                ScheduleTaskParameterInfo parameter = new ScheduleTaskParameterInfo();
                parameter.ParameterId = prmId;
                parameter.ParameterValue = txtValue.Value;
                parameters.Add(parameter);
            }

            sc.Parameters = parameters.ToArray();

			// Gather parameters from view.
			if (this.configurationView != null)
			{
				sc.Parameters = this.configurationView.GetParameters();
			}

            // save
            if (PanelRequest.ScheduleID == 0)
            {
                // add new schedule
                try
                {
                    int result = ES.Services.Scheduler.AddSchedule(sc);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("SCHEDULE_ADD_TASK", ex);
                    return;
                }
            }
            else
            {
                // update existing
                try
                {
                    int result = ES.Services.Scheduler.UpdateSchedule(sc);
                    if (result < 0)
                    {
                        ShowResultMessage(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("SCHEDULE_UPDATE_TASK", ex);
                    return;
                }
            }

            // redirect
            RedirectSpaceHomePage();
        }
コード例 #8
0
 public int UpdateSchedule(ScheduleInfo schedule)
 {
     return(SchedulerController.UpdateSchedule(schedule));
 }
コード例 #9
0
		/// <remarks/>
		public void UpdateScheduleAsync(ScheduleInfo schedule)
		{
			this.UpdateScheduleAsync(schedule, null);
		}
コード例 #10
0
		/// <remarks/>
		public void UpdateScheduleAsync(ScheduleInfo schedule, object userState)
		{
			if ((this.UpdateScheduleOperationCompleted == null))
			{
				this.UpdateScheduleOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateScheduleOperationCompleted);
			}
			this.InvokeAsync("UpdateSchedule", new object[] {
                        schedule}, this.UpdateScheduleOperationCompleted, userState);
		}
コード例 #11
0
		/// <remarks/>
		public System.IAsyncResult BeginUpdateSchedule(ScheduleInfo schedule, System.AsyncCallback callback, object asyncState)
		{
			return this.BeginInvoke("UpdateSchedule", new object[] {
                        schedule}, callback, asyncState);
		}
コード例 #12
0
		public int UpdateSchedule(ScheduleInfo schedule)
		{
			object[] results = this.Invoke("UpdateSchedule", new object[] {
                        schedule});
			return ((int)(results[0]));
		}
コード例 #13
0
		/// <remarks/>
		public void AddScheduleAsync(ScheduleInfo schedule)
		{
			this.AddScheduleAsync(schedule, null);
		}
コード例 #14
0
        public static int AddSchedule(ScheduleInfo schedule)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // check quota
            if(PackageController.GetPackageQuota(schedule.PackageId, Quotas.OS_SCHEDULEDTASKS).QuotaExhausted)
                return BusinessErrorCodes.ERROR_OS_SCHEDULED_TASK_QUOTA_LIMIT;

            CalculateNextStartTime(schedule);

            string xmlParameters = BuildParametersXml(schedule.Parameters);

            int scheduleId = DataProvider.AddSchedule(SecurityContext.User.UserId,
                schedule.TaskId, schedule.PackageId, schedule.ScheduleName, schedule.ScheduleTypeId,
                schedule.Interval, schedule.FromTime, schedule.ToTime, schedule.StartTime,
                schedule.NextRun, schedule.Enabled, schedule.PriorityId,
                schedule.HistoriesNumber, schedule.MaxExecutionTime, schedule.WeekMonthDay, xmlParameters);

            // re-schedule tasks
            Scheduler.ScheduleTasks();

            return scheduleId;
        }
コード例 #15
0
 public int AddSchedule(ScheduleInfo schedule)
 {
     return SchedulerController.AddSchedule(schedule);
 }
コード例 #16
0
        public static int UpdateSchedule(ScheduleInfo schedule)
        {
            // check account
            int accountCheck = SecurityContext.CheckAccount(DemandAccount.NotDemo | DemandAccount.IsActive);
            if (accountCheck < 0) return accountCheck;

            // load original schedule
            ScheduleInfo originalSchedule = GetScheduleInternal(schedule.ScheduleId);

            schedule.LastRun = schedule.LastRun;
            CalculateNextStartTime(schedule);

            string xmlParameters = BuildParametersXml(schedule.Parameters);

            DataProvider.UpdateSchedule(SecurityContext.User.UserId,
                schedule.ScheduleId, schedule.TaskId, schedule.ScheduleName, schedule.ScheduleTypeId,
                schedule.Interval, schedule.FromTime, schedule.ToTime, schedule.StartTime,
                schedule.LastRun, schedule.NextRun, schedule.Enabled, schedule.PriorityId,
                schedule.HistoriesNumber, schedule.MaxExecutionTime, schedule.WeekMonthDay, xmlParameters);

            // re-schedule tasks
            Scheduler.ScheduleTasks();

            return 0;
        }
コード例 #17
0
 public int AddSchedule(ScheduleInfo schedule)
 {
     return(SchedulerController.AddSchedule(schedule));
 }