Chronos Plugins 5.11.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
MockPlugin.SampleList.MockSampleListWorker Class Reference

Provides an endless supply of nonsense sample lists. More...

Inheritance diagram for MockPlugin.SampleList.MockSampleListWorker:
Collaboration diagram for MockPlugin.SampleList.MockSampleListWorker:

Public Member Functions

 MockSampleListWorker ()
void DoYourJob ()
 Take over control. When this function exits, Chronos is in charge again.
void Dispose ()

Static Public Member Functions

static IEnumerable< string > GetFakeLogs (string creator)
 Creates a few fake log files.

Protected Member Functions

virtual void OnPropertyChanged ([CallerMemberName] string propertyName=null)

Properties

string ButtonCaption = NormalButtonLabel [get, private set]
 Shown on the sample list page.
System.Drawing.Icon ButtonIcon = Properties.Resources.MockNormal [get, private set]
 Shown in the button, preferred size 22x22.
ISampleListAccessor SampleList [set]
 Here we get an helper that allows us to manipulate the current sample list.
IEnumerable< IDeviceConfiguredDevices [get, set]
 List of IDevice for all configured devices in Chronos.
IEnumerable< string > LogPaths [get]
 Provide full paths to each of your log files here.
Func< StopRunArgs, Task > StopRun [set]
 Callback function returning a task that completes once the schedule queue was stopped.

Events

RunSampleListHandler RunSampleList
PropertyChangedEventHandler PropertyChanged
Events inherited from AxelSemrau.Chronos.Plugin.INeedToRunSampleLists
RunSampleListHandler RunSampleList
 Trigger this event to actually create and run a schedule.

Private Member Functions

bool OneMoreScheduleWanted (Window ownerWin)
 Ask the user if he wants to start more schedules.
void HandleAbortButton (ShowPluginIsInCharge win)
void HandleStopButton (ShowPluginIsInCharge win)
void TurnOffResets ()
void DoOnGUIThread (Action theAction)
 Execute the specified action in the GUI thread's context.

Private Attributes

readonly TaskFactory mGuiFactory
Func< StopRunArgs, Task > mStopRun

Static Private Attributes

const string NormalButtonLabel = "Run plugin provided\r\nsample lists"

Detailed Description

Provides an endless supply of nonsense sample lists.

A possible serious use would be to generate sample lists from LIMS data and to feed them to Chronos.

Definition at line 30 of file MockSampleListWorker.cs.

Constructor & Destructor Documentation

◆ MockSampleListWorker()

MockPlugin.SampleList.MockSampleListWorker.MockSampleListWorker ( )

Definition at line 40 of file MockSampleListWorker.cs.

41 {
42 // for GUI synchronized operations
43 mGuiFactory = new TaskFactory(Helpers.Gui.GuiThreadScheduler);
44 // for the remote access example
45 RemotePluginService.StartService();
46 }

References AxelSemrau.Chronos.Plugin.Helpers.Gui, AxelSemrau.Chronos.Plugin.IGuiHelper.GuiThreadScheduler, and mGuiFactory.

Member Function Documentation

◆ Dispose()

void MockPlugin.SampleList.MockSampleListWorker.Dispose ( )

Definition at line 218 of file MockSampleListWorker.cs.

219 {
220 RemotePluginService.StopService();
221 }

References MockPlugin.SampleList.RemotePluginService.StopService().

◆ DoOnGUIThread()

void MockPlugin.SampleList.MockSampleListWorker.DoOnGUIThread ( Action theAction)
private

Execute the specified action in the GUI thread's context.

Parameters
theAction

Definition at line 190 of file MockSampleListWorker.cs.

191 {
192 mGuiFactory.StartNew(theAction).GetAwaiter().GetResult();
193 }

References mGuiFactory.

Referenced by DoYourJob(), and OneMoreScheduleWanted().

◆ DoYourJob()

void MockPlugin.SampleList.MockSampleListWorker.DoYourJob ( )

Take over control. When this function exits, Chronos is in charge again.

We show some dialog window to make clear what we are doing, and that we are in charge.

Implements AxelSemrau.Chronos.Plugin.IWorkWithSampleLists.

Definition at line 76 of file MockSampleListWorker.cs.

77 {
78 // Use the process' main window as owner, so that our blocking
79 // window can not be hidden behind the main window.
80 ShowPluginIsInCharge win = null;
81 ButtonIcon = Properties.Resources.MockBusy;
82 ButtonCaption = "Plugin busy";
83 OnPropertyChanged(nameof(ButtonIcon));
84 OnPropertyChanged(nameof(ButtonCaption));
85
86 DoOnGUIThread(() =>
87 {
88 // checking if it also works when called from the GUI thread
89 Core.ExecutionQueue.RemoveFailedPlanners();
90 win = new ShowPluginIsInCharge();
91 var wih = new WindowInteropHelper(win);
92 var winHandle = wih.EnsureHandle();
93 HandleAbortButton(win);
94 HandleStopButton(win);
95 Helpers.Gui.OwnMyWindow(winHandle);
96 win.Show();
97 });
98 try
99 {
100 do
101 {
102 // prevent previously failed planners from stopping us
103 Core.ExecutionQueue.RemoveFailedPlanners();
104 Helpers.Debug.TraceWrite($"Just FYI: Standard sample lists are at {Helpers.Config.PathToSampleLists ?? "(N/A)"} and methods are at {Helpers.Config.PathToMethods ?? "(N/A)"}, the instrument config is at {Helpers.Config.PathToInstrumentConfig}");
105 TurnOffResets();
106 System.Threading.Thread.Sleep(5000);
107 var ex = RunSampleList?.Invoke(this,
108 new RunSampleListEventArgs()
109 {
110 //SampleListFile = @"C:\Users\Patrick\Documents\Chronos\MoveTest.csl"
111 ExtendLastPlanner = false,
112 StartAndWaitForEnd = false,
113 SwitchToSchedulesView = false,
114 RespectSelection = false
115 }
116 );
117 if (ex != null)
118 {
119 System.Windows.Forms.MessageBox.Show(Helpers.Gui.MainWindow,$"Error: {ex.Message}", "Plugin Provided Schedule",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
120 }
121 } while (OneMoreScheduleWanted(win));
122 }
123 finally
124 {
125 DoOnGUIThread(() => win.Close());
126 ButtonIcon = Properties.Resources.MockNormal;
127 ButtonCaption = NormalButtonLabel;
128 OnPropertyChanged(nameof(ButtonIcon));
129 OnPropertyChanged(nameof(ButtonCaption));
130 }
131 }

References ButtonCaption, ButtonIcon, AxelSemrau.Chronos.Plugin.Helpers.Debug, DoOnGUIThread(), AxelSemrau.Chronos.Core.ExecutionQueue, AxelSemrau.Chronos.Plugin.Helpers.Gui, HandleAbortButton(), HandleStopButton(), AxelSemrau.Chronos.Plugin.IGuiHelper.MainWindow, NormalButtonLabel, OneMoreScheduleWanted(), OnPropertyChanged(), AxelSemrau.Chronos.Plugin.IGuiHelper.OwnMyWindow(), AxelSemrau.Chronos.IScheduleQueue.RemoveFailedPlanners(), RunSampleList, AxelSemrau.Chronos.Plugin.IDebugHelper.TraceWrite(), and TurnOffResets().

◆ GetFakeLogs()

IEnumerable< string > MockPlugin.SampleList.MockSampleListWorker.GetFakeLogs ( string creator)
static

Creates a few fake log files.

Parameters
creator
Returns

Definition at line 237 of file MockSampleListWorker.cs.

238 {
239 for (var i = 1; i <= 5; ++i)
240 {
241 var fakePath = System.IO.Path.GetTempFileName();
242 System.IO.File.WriteAllText(fakePath, $"Fake log entry in file {i} created at {DateTime.Now:hh:mm:ss} by {creator}");
243 yield return fakePath;
244 }
245 }

◆ HandleAbortButton()

void MockPlugin.SampleList.MockSampleListWorker.HandleAbortButton ( ShowPluginIsInCharge win)
private

Definition at line 133 of file MockSampleListWorker.cs.

134 {
135 win.AbortButton.Click += (s, e) =>
136 {
137 // Click handler: This runs on the GUI thread
138 win.AbortButton.IsEnabled = false;
139 var abortWaiter = mStopRun.Invoke(new StopRunArgs() {How = StopRunArgs.StopMode.Immediately});
140 abortWaiter.ContinueWith((t) =>
141 {
142 // after the background abort call has finished, continue with enabling the button on the GUI thread.
143 try
144 {
145 win.AbortButton.IsEnabled = true;
146 }
147 catch
148 {
149 // suppress exceptions in case the button does not exist any more
150 }
151 }, Helpers.Gui.GuiThreadScheduler);
152 };
153 }

References AxelSemrau.Chronos.Plugin.Helpers.Gui, AxelSemrau.Chronos.Plugin.IGuiHelper.GuiThreadScheduler, and mStopRun.

Referenced by DoYourJob().

◆ HandleStopButton()

void MockPlugin.SampleList.MockSampleListWorker.HandleStopButton ( ShowPluginIsInCharge win)
private

Definition at line 155 of file MockSampleListWorker.cs.

156 {
157 // This is just a quick and dirty piece of code for showing the IStopRun interface usage.
158 //
159 win.StopButton.Click += (s, e) =>
160 {
161 win.StopButton.IsEnabled = false;
162 var stopWaiter = mStopRun.Invoke(new StopRunArgs() { How = StopRunArgs.StopMode.NoNewJobs, RestartRemainingJobs = false,StopQueue = true});
163 stopWaiter.ContinueWith((t) =>
164 {
165 try
166 {
167 win.StopButton.IsEnabled = true;
168 }
169 catch
170 {
171 // suppress exceptions in case the button does not exist any more
172 }
173 }, Helpers.Gui.GuiThreadScheduler);
174 };
175 }

References AxelSemrau.Chronos.Plugin.Helpers.Gui, AxelSemrau.Chronos.Plugin.IGuiHelper.GuiThreadScheduler, and mStopRun.

Referenced by DoYourJob().

◆ OneMoreScheduleWanted()

bool MockPlugin.SampleList.MockSampleListWorker.OneMoreScheduleWanted ( Window ownerWin)
private

Ask the user if he wants to start more schedules.

Parameters
ownerWin
Returns

For a real plugin, this could be some check whether the analytical results of the last sample require intervention or not, before injecting the next sample.

Definition at line 60 of file MockSampleListWorker.cs.

61 {
62 bool oneMore = false;
63 DoOnGUIThread(() => oneMore = MessageBox.Show(ownerWin, "Start one more?",
64 "Restart loop",
65 MessageBoxButton.YesNo,
66 MessageBoxImage.Question) == MessageBoxResult.Yes);
67 return oneMore;
68 }

References DoOnGUIThread().

Referenced by DoYourJob().

◆ OnPropertyChanged()

virtual void MockPlugin.SampleList.MockSampleListWorker.OnPropertyChanged ( [CallerMemberName] string propertyName = null)
protectedvirtual

Definition at line 225 of file MockSampleListWorker.cs.

226 {
227 PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
228 }

References PropertyChanged.

Referenced by DoYourJob().

◆ TurnOffResets()

void MockPlugin.SampleList.MockSampleListWorker.TurnOffResets ( )
private

Definition at line 177 of file MockSampleListWorker.cs.

178 {
179 foreach (var somePAL in ConfiguredDevices.OfType<IPal3Access>())
180 {
181 somePAL.Options.AlwaysResetAfterSequence = false;
182 somePAL.Options.ResetBeforeSequence = false;
183 }
184 }

References ConfiguredDevices.

Referenced by DoYourJob().

Member Data Documentation

◆ mGuiFactory

readonly TaskFactory MockPlugin.SampleList.MockSampleListWorker.mGuiFactory
private

Definition at line 38 of file MockSampleListWorker.cs.

Referenced by DoOnGUIThread(), and MockSampleListWorker().

◆ mStopRun

Func<StopRunArgs, Task> MockPlugin.SampleList.MockSampleListWorker.mStopRun
private

Definition at line 247 of file MockSampleListWorker.cs.

Referenced by HandleAbortButton(), and HandleStopButton().

◆ NormalButtonLabel

const string MockPlugin.SampleList.MockSampleListWorker.NormalButtonLabel = "Run plugin provided\r\nsample lists"
staticprivate

Definition at line 37 of file MockSampleListWorker.cs.

Referenced by DoYourJob().

Property Documentation

◆ ButtonCaption

string MockPlugin.SampleList.MockSampleListWorker.ButtonCaption = NormalButtonLabel
getprivate set

Shown on the sample list page.

You can update this using INotifyPropertyChanged.

Implements AxelSemrau.Chronos.Plugin.IWorkWithSampleLists.

Definition at line 48 of file MockSampleListWorker.cs.

48{ get; private set; } = NormalButtonLabel;

Referenced by DoYourJob().

◆ ButtonIcon

System.Drawing.Icon MockPlugin.SampleList.MockSampleListWorker.ButtonIcon = Properties.Resources.MockNormal
getprivate set

Shown in the button, preferred size 22x22.

You can update this using INotifyPropertyChanged.

Implements AxelSemrau.Chronos.Plugin.IWorkWithSampleLists.

Definition at line 50 of file MockSampleListWorker.cs.

50{ get; private set; } = Properties.Resources.MockNormal;

Referenced by DoYourJob().

◆ ConfiguredDevices

IEnumerable<IDevice> MockPlugin.SampleList.MockSampleListWorker.ConfiguredDevices
getset

List of IDevice for all configured devices in Chronos.

Use with caution!

Implements AxelSemrau.Chronos.Plugin.IDirectDeviceAccess.

Definition at line 214 of file MockSampleListWorker.cs.

214{ get; set; }

Referenced by TurnOffResets().

◆ LogPaths

IEnumerable<string> MockPlugin.SampleList.MockSampleListWorker.LogPaths
get

Provide full paths to each of your log files here.

Implements AxelSemrau.Chronos.Plugin.IProvideDiagnosticLogs.

Definition at line 230 of file MockSampleListWorker.cs.

◆ SampleList

ISampleListAccessor MockPlugin.SampleList.MockSampleListWorker.SampleList
set

Here we get an helper that allows us to manipulate the current sample list.

Implements AxelSemrau.Chronos.Plugin.INeedCellAccess.

Definition at line 202 of file MockSampleListWorker.cs.

203 {
204 set
205 {
206 // not using it in this demo plugin yet
207 }
208 }

◆ StopRun

Func<StopRunArgs, Task> MockPlugin.SampleList.MockSampleListWorker.StopRun
set

Callback function returning a task that completes once the schedule queue was stopped.

Implements AxelSemrau.Chronos.Plugin.IStopRuns.

Definition at line 248 of file MockSampleListWorker.cs.

249 {
250 set => mStopRun = value;
251 }

Event Documentation

◆ PropertyChanged

PropertyChangedEventHandler MockPlugin.SampleList.MockSampleListWorker.PropertyChanged

Definition at line 223 of file MockSampleListWorker.cs.

Referenced by OnPropertyChanged().

◆ RunSampleList

RunSampleListHandler MockPlugin.SampleList.MockSampleListWorker.RunSampleList

Definition at line 195 of file MockSampleListWorker.cs.

Referenced by DoYourJob().


The documentation for this class was generated from the following file: