/// <summary> /// See http://taskscheduler.codeplex.com/ for help on using the TaskService wrapper library. /// </summary> /// <param name="context"></param> protected override void Execute(CodeActivityContext context) { try { using (TaskService ts = new TaskService()) { TaskDefinition td = ts.NewTask(); td.RegistrationInfo.Description = TaskDescription.Get(context); var triggers = Triggers.Get(context); if (triggers != null) { triggers.ToList().ForEach(t => td.Triggers.Add(t)); } td.Actions.Add(new ExecAction(FileName.Get(context), Arguments.Get(context), WorkingDirectory.Get(context))); string username = Username.Get(context); string password = Password.Get(context); if (string.IsNullOrEmpty(username)) { username = WindowsIdentity.GetCurrent().Name; } ts.RootFolder.RegisterTaskDefinition( TaskName.Get(context), td, TaskCreation.CreateOrUpdate, username, password); } } catch { throw; } }
protected override void Execute(NativeActivityContext context) { context.CreateBookmark(TaskName.Get(context), new BookmarkCallback(OnTaskComplete)); context.GetExtension <ITaskExtension>().ExecuteTask(TaskName.Get(context)); }