Chronos Plugins 5.9.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
MockSimpleTask.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Threading.Tasks;
4using System.Windows.Media;
6// ReSharper disable LocalizableElement
7
13namespace MockPlugin.Tasks
14{
18 [ScheduleDiagramColor(nameof(Colors.Coral))]
20 // ambigous name otherwise when referring to Chronos.exe: For historical reasons, Chronos has a type of the same name in the global namespace, sorry!
21 global::AxelSemrau.Chronos.Plugin.IReactOnCultureChanges,
23 {
27
28 [DefaultGreetings]
29 public string GreetingsText { get; set; } = DefaultGreetingsAttribute.DefGreeting;
30
34 public bool OkThisIsGoodbye { get; set; }
35
39 private class DefaultGreetingsAttribute : Attribute, System.Collections.IEnumerable
40 {
41 internal const string DefGreeting = "Some default greeting";
42 private readonly string[] mDefGreetings = { DefGreeting, "Howdy!", "Good day!" };
43
44 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
45 {
46 var greetingsList = mDefGreetings.ToList();
47 greetingsList.Add($"Current greeting of {DateTime.Now:HH:mm:ss}");
48 return greetingsList.GetEnumerator();
49 }
50 }
51
52 public void PreValidate()
53 {
54 System.Windows.Forms.MessageBox.Show(Helpers.Gui.MainWindow,"PreValidate");
55 }
56
57 public void PostValidate()
58 {
59 System.Windows.Forms.MessageBox.Show(Helpers.Gui.MainWindow,"PostValidate");
60 }
61
66 public void Execute()
67 {
68 TraceWrite?.Invoke(this, new TraceWriteEventArgs($"Executing with greeting {GreetingsText}"));
69 WriteToRunlog?.Invoke(string.Format(Properties.LocalizeMockPlugin.ShowingAMessageboxWithTheTextX0, GreetingsText));
70 System.Windows.Forms.MessageBox.Show(Helpers.Gui.MainWindow,
71 "Simple task shows a message:\r\n" + GreetingsText,
72 "Message shown by the mock task",
73 System.Windows.Forms.MessageBoxButtons.OK);
74
75 // Stop the schedule if this flag was set.
77 {
78 StopRun?.Invoke(new StopRunArgs(){How = StopRunArgs.StopMode.NoNewJobs,Reason = "It is time to say goodbye",RestartRemainingJobs = false, StopQueue = false});
79 }
80 }
81
82 public void DemoExecute()
83 {
84 System.Windows.Forms.MessageBox.Show(Helpers.Gui.MainWindow,"If we were really executing, we would show something else.", "Demo Execution of Plugin Task");
85 }
86
91 public string GetTaskAction()
92 {
93 return $"Just shows a message box with {GreetingsText}{(OkThisIsGoodbye ? ", then makes the schedule stop.": "")}";
94 }
95
96 public event Action<string> WriteToRunlog;
97
98 public event EventHandler<TraceWriteEventArgs> TraceWrite;
99
104 public void UICultureChanged(System.Globalization.CultureInfo newCulture)
105 {
106 Properties.LocalizeMockPlugin.Culture = newCulture;
107 }
108
109 public Func<StopRunArgs, Task> StopRun { get; set; }
110 }
111}
Classes and interfaces that are meant for plugins. The classes and interfaces below this namespace ar...
Example task implementations. Since there are lots of things that can be done from a task,...
IWin32Window MainWindow
If you need to set the owner window yourself or want to show message boxes.
Definition Helpers.cs:37
Static instance for access to utility functions and resources.
Definition Helpers.cs:78
static IGuiHelper Gui
Utility functions for window handling.
Definition Helpers.cs:92
Implement this interface if you have messages for our run log.
Allows you to support runtime language switching just like Chronos does.
For future extension (categories, priorities...)
Writes some text to the trace log.
Implement this interface with your device or sample list worker to get fine-grained control about sto...
Options for stopping the schedule/queue.
StopMode
Details how to stop the run.
To be implemented by the "task" part of a Chronos plugin. Public properties of the implementing type ...
For tasks that try to do some special actions during schedule demo execution.
A task which does not need access to the custom device.
string GetTaskAction()
The result of this function will be shown in the timetable.
Func< StopRunArgs, Task > StopRun
Callback function returning a task that completes once the schedule queue was stopped.
void PreValidate()
Called before the schedule construction is completed.
bool OkThisIsGoodbye
See in .Execute - this is just a flag to tell us if we should stop the schedule.
EventHandler< TraceWriteEventArgs > TraceWrite
string GreetingsText
Parameter which can be edited in the method editor, with some predefined values.
void Execute()
Pretend we are doing some work by showing a message box.
void DemoExecute()
Will be called when the task is executed in demo mode.
void PostValidate()
Called after the schedule construction is completed.
void UICultureChanged(System.Globalization.CultureInfo newCulture)
Switch the resources with localized items to the newly selected culture.
Simple example how to provide a combobox with standard values for a property.
System.Collections.IEnumerator System.Collections.IEnumerable. GetEnumerator()