Esempio n. 1
0
    public override NextCall Invoke(WorkflowMethod invoker)
    {
        var cfd = new ContentFormDefinition();
        ScheduledTask task = Session.GetContent<ScheduledTask>(_taskNodeId);
        //cfd.AddPropertyCheckBox("Enabled", "Enabled", task.Enabled);
        cfd.AddPropertyShortString("Typename", "Typename", task.TypeName, true);
        cfd.AddPropertyShortString("FriendlyName", "Friendly name", task.FriendlyName, false);
        var intervalOptions = new Dictionary<string, CsdStringSetting>();
        intervalOptions.Add(((int)TaskShedulerIntervalUnit.Continuous).ToString(), new CsdStringSetting("CONTINOUSLY, with below interval as break between each run"));
        intervalOptions.Add(((int)TaskShedulerIntervalUnit.Minute).ToString(), new CsdStringSetting("MINUTE, but delay each start with interval below"));
        intervalOptions.Add(((int)TaskShedulerIntervalUnit.Hour).ToString(), new CsdStringSetting("HOUR, but delay each start with interval below"));
        intervalOptions.Add(((int)TaskShedulerIntervalUnit.Day).ToString(), new CsdStringSetting("DAY, but delay each start with interval below"));
        intervalOptions.Add(((int)TaskShedulerIntervalUnit.Week).ToString(), new CsdStringSetting("WEEK, but delay each start with interval below"));
        intervalOptions.Add(((int)TaskShedulerIntervalUnit.Month).ToString(), new CsdStringSetting("MONTH, but delay each start with interval below"));
        intervalOptions.Add(((int)TaskShedulerIntervalUnit.Quarter).ToString(), new CsdStringSetting("QUARTER, but delay each start with interval below"));
        intervalOptions.Add(((int)TaskShedulerIntervalUnit.Year).ToString(), new CsdStringSetting("YEAR, but delay each start with interval below"));
        cfd.AddPropertyShortString("IntervalUnit", "Run every", ((int)task.IntervalUnit).ToString(), null, new ShortStringPropertySettings() {
            ControlType = ShortStringControlType.DropDown, Items = intervalOptions
        });
        int secs;
        string startAtUnit;
        if (task.StartAt == 0) {
            startAtUnit = "Seconds";
            secs = 0;
        } else if (task.StartAt % (60 * 60 * 24) == 0) {
            startAtUnit = "Days";
            secs = task.StartAt / (60 * 60 * 24);
        } else if (task.StartAt % (60 * 60) == 0) {
            startAtUnit = "Hours";
            secs = task.StartAt / (60 * 60);
        } else if (task.StartAt % 60 == 0) {
            startAtUnit = "Minutes";
            secs = task.StartAt / 60;
        } else {
            startAtUnit = "Seconds";
            secs = task.StartAt;
        }

        cfd.AddPropertyInteger("StartAt", "Interval", secs);
        var startAtOptions = new Dictionary<string, CsdStringSetting>();
        startAtOptions.Add("Seconds", new CsdStringSetting("Seconds"));
        startAtOptions.Add("Minutes", new CsdStringSetting("Minutes"));
        startAtOptions.Add("Hours", new CsdStringSetting("Hours"));
        startAtOptions.Add("Days", new CsdStringSetting("Days"));
        cfd.AddPropertyShortString("StartAtUnit", "Interval unit", startAtUnit, null, new ShortStringPropertySettings() {
            ControlType = ShortStringControlType.DropDown, Items = startAtOptions
        });
        if (task.FailuresBeforeDisabling > 0) cfd.AddPropertyDescription("<font color=\"gray\"><br />The task will be automatically disabled after " + task.FailuresBeforeDisabling + " exceptions. </font>", true);
        _showSettingsButton = false;
        string friendlyTypeName = null;
        if (task.TypeName.Length > 0) {
            Type t;
            try {
                t = Utils.GetType(task.TypeName);
                if (typeof(IWorkflowMethodTaskWithSettings).IsAssignableFrom(t)) {
                    _showSettingsButton = true;
                    friendlyTypeName = t.Name;
                }
            } catch { }
        }
        string[] buttons;
        if (_showSettingsButton) {
            buttons = new string[] { "Configure " + friendlyTypeName, "Check Typename", "Task details", "Save & Close" };
        } else {
            buttons = new string[] { "Check Typename", "Task details", "Save & Close" };
        }
        var diag = new WMContentForm(DialogueIcon.Info, "Task options", 600, 160, cfd, buttons, true);
        return new NextCall(diag, onCompleteSettingsFromTask);
    }