Chronos Plugins  5.2.0
This documentation covers the plugin interfaces definitions and an example implementation.
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. More...
 
void Dispose ()
 

Static Public Member Functions

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

Protected Member Functions

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

Properties

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

Events

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

Private Member Functions

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

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  }
System.Threading.Tasks.TaskScheduler GuiThreadScheduler
Use this scheduler to do actions on the thread that owns the main GUI.
Definition: Helpers.cs:24
Static instance for access to utility functions and resources.
Definition: Helpers.cs:80
static IGuiHelper Gui
Utility functions for window handling
Definition: Helpers.cs:94

References AxelSemrau.Chronos.Plugin.Helpers.Gui, AxelSemrau.Chronos.Plugin.IGuiHelper.GuiThreadScheduler, and MockPlugin.SampleList.MockSampleListWorker.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 MockPlugin.SampleList.MockSampleListWorker.mGuiFactory.

Referenced by MockPlugin.SampleList.MockSampleListWorker.DoYourJob(), and MockPlugin.SampleList.MockSampleListWorker.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";
85 
86  DoOnGUIThread(() =>
87  {
88  // checking if it also works when called from the GUI thread
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
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,
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;
128  OnPropertyChanged(nameof(ButtonIcon));
130  }
131  }
Access to some parts of the core of the Chronos program.
Definition: Core.cs:14
static IScheduleQueue ExecutionQueue
The list of schedules that have run, are running or will be run.
Definition: Core.cs:18
void RemoveFailedPlanners()
Tries to remove failed planners. Use this if you are hiding the normal Chronos GUI from your user and...
void OwnMyWindow(IntPtr handle)
Make the window with the given handle owned by the Chronos main window. This prevents it from droppin...
IWin32Window MainWindow
If you need to set the owner window yourself or want to show message boxes.
Definition: Helpers.cs:39
void TraceWrite(string text, params object[] arguments)
Write something to the Chronos trace log.
static IDebugHelper Debug
Utility functions for debugging
Definition: Helpers.cs:99
Parameters for sample list loading and schedule creation
virtual void OnPropertyChanged([CallerMemberName] string propertyName=null)
void HandleStopButton(ShowPluginIsInCharge win)
void DoOnGUIThread(Action theAction)
Execute the specified action in the GUI thread's context.
bool OneMoreScheduleWanted(Window ownerWin)
Ask the user if he wants to start more schedules.
void HandleAbortButton(ShowPluginIsInCharge win)

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

◆ GetFakeLogs()

static 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  }
152  };
153  }
Options for stopping the schedule/queue.
StopMode
Details how to stop the run

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

Referenced by MockPlugin.SampleList.MockSampleListWorker.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  }
174  };
175  }

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

Referenced by MockPlugin.SampleList.MockSampleListWorker.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 MockPlugin.SampleList.MockSampleListWorker.DoOnGUIThread().

Referenced by MockPlugin.SampleList.MockSampleListWorker.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 MockPlugin.SampleList.MockSampleListWorker.PropertyChanged.

Referenced by MockPlugin.SampleList.MockSampleListWorker.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  }
Provides access to some options and configuration information for the PAL3 samplers even out of the s...

References MockPlugin.SampleList.MockSampleListWorker.ConfiguredDevices.

Referenced by MockPlugin.SampleList.MockSampleListWorker.DoYourJob().

Member Data Documentation

◆ mGuiFactory

readonly TaskFactory MockPlugin.SampleList.MockSampleListWorker.mGuiFactory
private

◆ mStopRun

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

◆ NormalButtonLabel

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

Property Documentation

◆ ButtonCaption

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

Definition at line 48 of file MockSampleListWorker.cs.

48 { get; private set; } = NormalButtonLabel;

Referenced by MockPlugin.SampleList.MockSampleListWorker.DoYourJob().

◆ ButtonIcon

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

Definition at line 50 of file MockSampleListWorker.cs.

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

Referenced by MockPlugin.SampleList.MockSampleListWorker.DoYourJob().

◆ ConfiguredDevices

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

Definition at line 214 of file MockSampleListWorker.cs.

214 { get; set; }

Referenced by MockPlugin.SampleList.MockSampleListWorker.TurnOffResets().

◆ LogPaths

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

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.

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

Definition at line 248 of file MockSampleListWorker.cs.

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

Event Documentation

◆ PropertyChanged

PropertyChangedEventHandler MockPlugin.SampleList.MockSampleListWorker.PropertyChanged

◆ RunSampleList

RunSampleListHandler MockPlugin.SampleList.MockSampleListWorker.RunSampleList

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