static TaskDefinition DisplayTask(Task t, bool editable)
 {
     if (editorForm == null)
     {
         editorForm = new TaskEditDialog();
     }
     editorForm.Editable = editable;
     editorForm.Initialize(t);
     editorForm.RegisterTaskOnAccept = true;
     editorForm.AvailableTabs        = AvailableTaskTabs.All;
     return((editorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) ? editorForm.TaskDefinition : null);
 }
Beispiel #2
0
        /// <summary>
        /// Open the Scheduled Tasks Form with blank data so that a new record may be entered.
        /// </summary>
        /// <remarks>Created: Theo Crous 18/09/2012</remarks>
        protected override void OnNewRecord()
        {
            try
            {
                base.OnNewRecord();

                //ScheduledTaskForm childForm = new ScheduledTaskForm();
                //TODO: Add Mainform refelction method call
                //ShowForm(childForm);
                //   TaskDescriptor task = new TaskDescriptor();
                //http://technet.microsoft.com/en-us/library/cc766266.aspx
                //using (TaskService ts = new TaskService("\\HENKO-PC", "Henko", "HENKO-PC", "rabbit"))
                using (TaskService ts = new TaskService())
                {
                    TaskDefinition task       = ts.NewTask();
                    TaskEditDialog editorForm = new TaskEditDialog();
                    editorForm.Editable = true;
                    editorForm.Initialize(ts, task);
                    if (editorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        if (editorForm.TaskName != string.Empty)
                        {
                            ts.RootFolder.RegisterTaskDefinition(editorForm.TaskName, editorForm.TaskDefinition);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
Beispiel #3
0
 private void createTaskBtn_Click(object sender, EventArgs e)
 {
     using (var taskService = new TaskService())
     {
         var taskDialog = new TaskEditDialog(taskService);
         taskDialog.ShowDialog();
     }
 }
Beispiel #4
0
        private void btnTask_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbExePath.Text.Trim()))
            {
                MessageBox.Show("请选择执行文件");
                return;
            }
            var exePath = tbExePath.Text.Trim();

            //            TaskService.Instance.AddTask("test", QuickTriggerType.Daily, "initData.exe");
            using (TaskService ts = new TaskService())
            {
                DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month
                                           , DateTime.Now.Day, 0, 0, 0);
                var    list         = ts.AllTasks;
                string taskName     = lbTaskName.Text.Trim();
                var    taskNameList = new List <string>();
                foreach (var task in list)
                {
                    taskNameList.Add(task.Name);
                }

                if (taskNameList.Contains(taskName))
                {
                    ts.RootFolder.DeleteTask(taskName);
                }

                var addTask = ts.AddTask(taskName, new DailyTrigger()
                {
                    StartBoundary = dt,
                    EndBoundary   = dt + TimeSpan.FromDays(10000),

                    Enabled = true
                }, new ExecAction(exePath));
                var definition = addTask.Definition;
                definition.RegistrationInfo.Description        = "发票备份,每天00:00:00开始执行";
                definition.Settings.DisallowStartIfOnBatteries = false;
                definition.Settings.Enabled           = true;
                definition.Settings.MultipleInstances = TaskInstancesPolicy.StopExisting;
//                definition.Settings.RestartInterval=TimeSpan.FromSeconds(100);
//                definition.Settings.Compatibility
//                definition.Settings.ExecutionTimeLimit = TimeSpan.FromMinutes(2);
//                definition.Settings.IdleSettings.IdleDuration = TimeSpan.FromMinutes(3);
//                definition.Settings.AllowDemandStart = true;
                definition.Settings.Priority = ProcessPriorityClass.High;
                definition.Settings.StopIfGoingOnBatteries = false;
                //definition.Settings.
                TaskEditDialog edit = new TaskEditDialog();
//                edit.
                edit.Editable             = true;
                edit.RegisterTaskOnAccept = true;
                edit.Initialize(addTask);
                edit.ShowDialog();

                //                ts.RootFolder.DeleteTask("ksd");
//                int i = 0;
            }
        }
Beispiel #5
0
 public static List <Task> EditTask(List <Task> tasks)
 {
     if (tasks.Count > 0)
     {
         TaskEditDialog editorForm = new TaskEditDialog(tasks.First());
         editorForm.ShowDialog();
     }
     return(tasks);
 }
Beispiel #6
0
 private void editTaskBtn_Click(object sender, EventArgs e)
 {
     using (var taskService = new TaskService())
     {
         var task = taskService.GetTask(_path);
         if (task != null)
         {
             var taskDialog = new TaskEditDialog(task, true);
             taskDialog.ShowDialog();
         }
     }
 }
Beispiel #7
0
        public void EditTask(string taskName = defaultTaskName)
        {
            Microsoft.Win32.TaskScheduler.Task t = TaskService.Instance.GetTask(taskName);
            if (t == null)
            {
                return;
            }

            TaskEditDialog editorForm = new TaskEditDialog(t, true, true);

            editorForm.ShowDialog();
        }
Beispiel #8
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                if (taskListView.SelectedIndex < 0)
                {
                    return;
                }

                if (string.IsNullOrEmpty(TaskNameSelected))
                {
                    return;
                }

                using (TaskService ts = new TaskService())
                {
                    if (ts.RootFolder.SubFolders.Exists(TASK_FOLDER))
                    {
                        TaskFolder tf = ts.GetFolder(TASK_FOLDER);

                        foreach (Task task in tf.Tasks)
                        {
                            if (task.Name != TaskNameSelected)
                            {
                                continue;
                            }
                            // Edit task and re-register if user clicks Ok
                            TaskEditDialog frm = new TaskEditDialog(task);
                            frm.AvailableTabs       |= AvailableTaskTabs.RunTimes;
                            frm.RegisterTaskOnAccept = true;
                            frm.ShowDialog(this);
                            break;
                        }
                    }
                }

                DisplayTaskScheduleItems();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Beispiel #9
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                EnableScheduleButtons(false);

                using (TaskService ts = new TaskService())
                {
                    Task target = ts.GetTask(TaskName);
                    if (target == null)
                    {
                        GetTaskTemplate();
                        target = ts.GetTask(TaskName);
                    }
                    using (target)
                    {
                        //// Edit task and re-register if user clicks Ok
                        using (TaskEditDialog editorForm = new TaskEditDialog(target)
                        {
                            Editable = true,
                            RegisterTaskOnAccept = true
                        })
                        {
                            editorForm.AvailableTabs |= AvailableTaskTabs.RunTimes;

                            editorForm.ShowDialog();
                        }
                    }
                }
                btnGetSchedules_Click(sender, e);
            }
            catch (Exception ex)
            {
                Log.Error("btnEdit_Click has thrown: ", ex);
                MessageBox.Show(this, ex.Message, "Edit Schedule Task");
            }
            finally
            {
                EnableScheduleButtons(true);
            }
        }
Beispiel #10
0
        //protected override IQueryable GetQueryable()
        //{
        //    return GetTasks().AsQueryable<TaskDescriptor>();
        //}

        /// <summary>
        /// Open the Scheduled Tasks form for the record indicated in the parameter.
        /// </summary>
        /// <param name="Id">The id (primary key) of the record to open.</param>
        /// <remarks>Created: Theo Crous 14/11/2011</remarks>
        protected override void OnOpenRecord(long Id)
        {
            try
            {
                base.OnOpenRecord(Id);

                string task = (GetTasks().AsQueryable <TaskDescriptor>()).Where(n => n.Id == Id).Select(n => n.Name).FirstOrDefault();
                //http://technet.microsoft.com/en-us/library/cc766266.aspx
                //using (TaskService ts = new TaskService("\\HENKO-PC", "Henko", "HENKO-PC", "rabbit"))
                using (TaskService ts = new TaskService())
                {
                    //Microsoft.Win32.TaskScheduler.TaskEditDialog ted = new TaskEditDialog(ts.RootFolder.Tasks.FirstOrDefault(n => n.Name == task.Name));
                    //TaskSchedulerWizard wis = new TaskSchedulerWizard(ts.RootFolder.Tasks.FirstOrDefault(n => n.Name == task.Name));
                    //ted.Show();

                    Task t = ts.RootFolder.Tasks.FirstOrDefault(n => n.Name == task);

                    TaskEditDialog editorForm = new TaskEditDialog();
                    editorForm.Editable = true;
                    editorForm.Initialize(t);
                    if (editorForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        ts.RootFolder.RegisterTaskDefinition(t.Name, editorForm.TaskDefinition);
                    }
                }


                //ScheduledTaskForm childForm = new ScheduledTaskForm();
                //childForm.OpenRecord(task.Name);
                //ShowForm(childForm);
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
Beispiel #11
0
        public static List <Task> CreateTask(List <Task> tasks)
        {
            const string taskName = "New Task";
            Task         t        = TaskService.Instance.AddTask(taskName,
                                                                 new TimeTrigger()
            {
                StartBoundary = DateTime.Now + TimeSpan.FromHours(1),
                Enabled       = false
            },
                                                                 new ShowMessageAction("Hello world", "Title"));

            // Edit task and re-register if user clicks Ok
            TaskEditDialog editorForm = new TaskEditDialog(t);

            // ** The four lines above can be replaced by using the full constructor
            // TaskEditDialog editorForm = new TaskEditDialog(t, true, true);
            editorForm.ShowDialog();

            return(new List <Task>()
            {
                t
            });
        }
Beispiel #12
0
 private void btnScheduleTest_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         string taskName = txtTaskName.Text;
         if (string.IsNullOrEmpty(taskName))
         {
             MessageBox.Show("Please enter task name.");
             return;
         }
         var xmlScenario = XMLSerializer.SerializeObject(lstSchScenario);
         var schArgument = schBrowser + "|" + xmlScenario + "|" + hostURL + "|" + schRoleconfig.username + "|" + schRoleconfig.password;
         //Triggering scheduler using win32 dll
         using (TaskService ts = new TaskService())
         {
             // Create a new task
             //const string taskName = "CRMAutomation";
             Task t = ts.AddTask(taskName,
                                 new TimeTrigger()
             {
                 StartBoundary = DateTime.Now + TimeSpan.FromHours(1),
                 Enabled       = false,
             },
                                 new ExecAction(@"D:\AutomationFramework\Microsoft.Dynamics365.UIAutomation.AutomationScheduler\bin\Debug\Microsoft.Dynamics365.UIAutomation.AutomationScheduler.exe", schArgument, @"D:\"));
             // Edit task and re-register if user clicks Ok
             TaskEditDialog editorForm = new TaskEditDialog();
             editorForm.Editable             = true;
             editorForm.RegisterTaskOnAccept = true;
             editorForm.Initialize(t);
             // ** The four lines above can be replaced by using the full constructor
             editorForm.ShowDialog();
         }
     }
     catch (Exception ex)
     {
     }
 }