private string GetCommandText(Action action) { ExecAction execAction = action as ExecAction; ShowMessageAction showMessageAction = action as ShowMessageAction; ComHandlerAction comHandlerAction = action as ComHandlerAction; EmailAction emailAction = action as EmailAction; if (execAction != null) { return($"{execAction.Path} {execAction.Arguments}"); } else if (showMessageAction != null) { return($"Show message: '{showMessageAction.Title}'"); } else if (comHandlerAction != null) { return($"COM handler: '{comHandlerAction.ClassName}'"); } else if (emailAction != null) { return($"Send email: '{emailAction.Subject}'"); } else { return("unknown action."); } }
private void button3_Click(object sender, EventArgs e) { ShowMessageAction message = new ShowMessageAction(); message.Title = textBox1.Text; message.Content = textBox2.Text; //Parent.UserEvents.Items.Add(message); engine.UserEvents.Items.Add(message); }
private static void InitializeSchduledTask() { TimeSpan howOften = new TimeSpan(0, 0, 1, 0); TimeSpan howLong = new TimeSpan(0, 0, 3, 0); RepetitionPattern rp = new RepetitionPattern(howOften, howLong, stopAtDurationEnd: true); TimeTrigger tt = new TimeTrigger(); tt.StartBoundary = DateTime.Now; tt.Repetition = rp; ShowMessageAction msg = new ShowMessageAction("Jeg er en ost", "Hvad er du?"); TaskDefinition td = TaskService.Instance.NewTask(); td.RegistrationInfo.Author = "Holle TechNolle"; td.Actions.Add(msg); td.Triggers.Add(tt); TaskService.Instance.RootFolder.RegisterTaskDefinition("MsgTask", td); tt.Enabled = true; }
internal static void ShortTest(TaskService ts, System.IO.TextWriter output, params string[] arg) { // Get the service on the local machine try { /*string sub = "<QueryList><Query Id=\"0\" Path=\"Microsoft-Windows-TaskScheduler/Operational\">" + * "<Select Path=\"Microsoft-Windows-TaskScheduler/Operational\">" + * "*[System[Provider[@Name='Microsoft-Windows-TaskScheduler'] and (Computer='dahall1') and (Level=0 or Level=4) and (Task=100 or Task=101) and (EventID=129) and Security[@UserID='AMERICAS\\dahall'] and TimeCreated[timediff(@SystemTime) <= 86400000]]]" + * "*[EventData[Data[@Name='TaskName']='\\Maint' and Data[@Name='EventCode']='0']]" + * "</Select>" + * "</Query></QueryList>"; * using (var ed = new EventActionFilterEditor() { Subscription = sub }) * { * ed.ShowDialog(); * } * return;*/ /*Action<string> d = delegate(string s) { var ar = s.Split('|'); foreach (System.Text.RegularExpressions.Match m in System.Text.RegularExpressions.Regex.Matches(ar[2], @"\(A;(?<Flag>\w*);(?<Right>\w*);(?<Guid>\w*);(?<OIGuid>\w*);(?<Acct>[\w\-\d]*)(?:;[^\)]*)?\)")) output.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}", ar[0], ar[1], m.Groups["Flag"], m.Groups["Right"], m.Groups["Guid"], m.Groups["OIGuid"], m.Groups["Acct"]); }; * FolderTaskAction(ts.RootFolder, delegate(TaskFolder f) { d("F|" + f.Name + "|" + f.GetSecurityDescriptorSddlForm()); }, delegate(Task s) { d("T|" + s.Name + "|" + s.GetSecurityDescriptorSddlForm()); }); * return;*/ //FolderTaskAction(ts.RootFolder, null, delegate(Task tsk) { if (tsk.Definition.Triggers.ContainsType(typeof(CustomTrigger))) output.WriteLine(tsk.Path); }); // Create a new task definition and assign properties const string taskName = "Test"; TaskDefinition td = ts.NewTask(); td.RegistrationInfo.Documentation = "Does something"; td.Settings.ExecutionTimeLimit = TimeSpan.Zero; //td.Principal.LogonType = TaskLogonType.InteractiveToken; // Add a cron trigger //td.Triggers.AddRange(Trigger.FromCronFormat("15 */6 */30 * *")); // Add a trigger that will fire the task at this time every other day DailyTrigger dt = (DailyTrigger)td.Triggers.Add(new DailyTrigger { DaysInterval = 2 }); dt.Repetition.Duration = TimeSpan.FromHours(4); dt.Repetition.Interval = TimeSpan.FromHours(1); // Add a trigger that will fire every week on Friday td.Triggers.Add(new WeeklyTrigger { StartBoundary = DateTime.Today + TimeSpan.FromHours(2), DaysOfWeek = DaysOfTheWeek.Friday, Enabled = false }); // Add message and email actions if (ts.HighestSupportedVersion >= new Version(1, 2)) { ShowMessageAction sm = (ShowMessageAction)td.Actions.AddNew(TaskActionType.ShowMessage); sm.Title = "title"; sm.MessageBody = "body"; EmailAction ma = new EmailAction("Subject", "*****@*****.**", "[email protected]; [email protected]", "Body", "mail.google.com") { Bcc = "*****@*****.**", Cc = "*****@*****.**" }; ma.Attachments = new object[] { (string)new TemporaryScopedFile() }; ma.HeaderFields.Add("N1", "V1"); ma.HeaderFields.Add("N2", "V2"); td.Actions.Add(ma); } // Add an action that will launch Notepad whenever the trigger fires td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null)); output.WriteLine(td.XmlText); Task t = ts.RootFolder.RegisterTaskDefinition(taskName, td); //, TaskCreation.CreateOrUpdate, "username", "password", TaskLogonType.Password); t.Enabled = false; System.Threading.Thread.Sleep(1000); output.WriteLine("LastTime & Result: {0} ({1:x})", t.LastRunTime == DateTime.MinValue ? "Never" : t.LastRunTime.ToString("g"), t.LastTaskResult); output.WriteLine("NextRunTime: {0:g}", t.NextRunTime); //DisplayTask(t, true); using (var dlg = new TaskOptionsEditor { Editable = true }) { dlg.Initialize(t); dlg.ShowDialog(); } // Retrieve the task, add a trigger and save it. //t = ts.GetTask(taskName); //ts.RootFolder.DeleteTask(taskName); //td = t.Definition; /*td.Triggers.Clear(); * WeeklyTrigger wt = td.Triggers.AddNew(TaskTriggerType.Weekly) as WeeklyTrigger; * wt.DaysOfWeek = DaysOfTheWeek.Friday; * ((ExecAction)td.Actions[0]).Path = "calc.exe"; * * t = ts.RootFolder.RegisterTaskDefinition(taskName, td); * output.WriteLine("Principal: {1}; Triggers: {0}", t.Definition.Triggers, t.Definition.Principal);*/ ts.RootFolder.DeleteTask(taskName); } catch (Exception ex) { output.WriteLine(ex.ToString()); } }