コード例 #1
0
        protected void gvTaskParameters_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            ParameterEditor txtValue = (ParameterEditor)e.Row.FindControl("txtValue");

            if (txtValue == null)
            {
                return;
            }

            ScheduleTaskParameterInfo prm = (ScheduleTaskParameterInfo)e.Row.DataItem;

            txtValue.DataType     = prm.DataTypeId;
            txtValue.DefaultValue = prm.DefaultValue;
            txtValue.Value        = prm.ParameterValue;
        }
コード例 #2
0
        private void SaveTask()
        {
            // gather form parameters
            ScheduleInfo sc = new ScheduleInfo();

            sc.ScheduleId   = PanelRequest.ScheduleID;
            sc.ScheduleName = 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();
        }