Exemple #1
0
 private void createWizardTaskBtn_Click(object sender, EventArgs e)
 {
     using (var taskService = new TaskService())
     {
         var wizard = new TaskSchedulerWizard(taskService, null, true);
         wizard.ShowDialog();
     }
 }
        internal static void WizardTest(TaskService ts, System.IO.TextWriter output, params string[] arg)
        {
            try
            {
                string FolderName = "My Folder";
                bool   v2         = ts.HighestSupportedVersion > new Version(1, 1);
                var    taskFolder = ts.RootFolder;
                if (v2)
                {
                    try
                    {
                        taskFolder = ts.GetFolder(FolderName);
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        taskFolder = ts.RootFolder.CreateFolder(FolderName);
                    }
                }

                using (var taskSchedulerWizard = new TaskSchedulerWizard())
                {
                    var newTaskDefinition = ts.NewTask();
                    newTaskDefinition.Actions.Add(new ExecAction("notepad.exe"));
                    taskSchedulerWizard.Initialize(ts, newTaskDefinition);
                    taskSchedulerWizard.TaskFolder           = FolderName;
                    taskSchedulerWizard.RegisterTaskOnFinish = true;
                    taskSchedulerWizard.AvailableTriggers    = TaskSchedulerWizard.AvailableWizardTriggers.Event;
                    taskSchedulerWizard.AvailablePages       = TaskSchedulerWizard.AvailableWizardPages.IntroPage |
                                                               //TaskSchedulerWizard.AvailableWizardPages.TriggerSelectPage |
                                                               TaskSchedulerWizard.AvailableWizardPages.TriggerEditPage |
                                                               //TaskSchedulerWizard.AvailableWizardPages.TriggerPropertiesPage |
                                                               TaskSchedulerWizard.AvailableWizardPages.ActionEditPage |
                                                               //TaskSchedulerWizard.AvailableWizardPages.SecurityPage |
                                                               TaskSchedulerWizard.AvailableWizardPages.SummaryPage;

                    if (taskSchedulerWizard.ShowDialog() == DialogResult.OK)
                    {
                        taskFolder.DeleteTask(taskSchedulerWizard.Task.Name);
                    }
                    //    _tlv.Tasks = taskFolder.Tasks;
                }

                // Create a new task definition and assign properties

                /*TaskSchedulerWizard wiz = new TaskSchedulerWizard(ts, null, true) { TaskFolder = @"\Microsoft" };
                 * if (wiz.ShowDialog() == DialogResult.OK)
                 * {
                 *      Task t = wiz.Task;
                 *      if (t.Definition.Triggers.Count > 1)
                 *              new TaskEditDialog(t).ShowDialog();
                 *      else
                 *      {
                 *              wiz.AvailablePages = TaskSchedulerWizard.AvailableWizardPages.TriggerPropertiesPage | TaskSchedulerWizard.AvailableWizardPages.TriggerSelectPage | TaskSchedulerWizard.AvailableWizardPages.SummaryPage;
                 *              wiz.AvailableTriggers = TaskSchedulerWizard.AvailableWizardTriggers.Daily | TaskSchedulerWizard.AvailableWizardTriggers.Time | TaskSchedulerWizard.AvailableWizardTriggers.Weekly | TaskSchedulerWizard.AvailableWizardTriggers.Monthly | TaskSchedulerWizard.AvailableWizardTriggers.MonthlyDOW;
                 *              wiz.AllowEditorOnFinish = true;
                 *              wiz.EditorOnFinishText = "Show dialog";
                 *              wiz.TriggerPagePrompt = "When???";
                 *              wiz.RegisterTaskOnFinish = true;
                 *              wiz.SummaryRegistrationNotice = "Done when you click Finish";
                 *              wiz.SummaryFormatString = "Name: {0}\r\nDescription: {1}\r\nTrigger: {2}";
                 *              wiz.Title = "My Wizard";
                 *              wiz.Initialize(t);
                 *              wiz.ShowDialog();
                 *      }
                 * }
                 *
                 * if (wiz.Task != null)
                 *      ts.RootFolder.DeleteTask(wiz.Task.Path);*/
            }
            catch (Exception ex)
            {
                output.WriteLine(ex.ToString());
            }
        }