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);
 }
Esempio n. 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;
                }
            }
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
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;
                }
            }
        }
Esempio n. 5
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)
     {
     }
 }