Chronos Plugins 5.9.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
MockSimpleAcquisitionService.cs
Go to the documentation of this file.
1using System;
2using System.Diagnostics;
3using System.Diagnostics.CodeAnalysis;
4using System.Xml.Linq;
6// ReSharper disable UnusedAutoPropertyAccessor.Global
7
13{
17 [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
18 [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")]
19 [SuppressMessage("ReSharper", "AutoPropertyCanBeMadeGetOnly.Global")]
20 public class SimpleParameters
21 {
22 public string InstrumentMethod { get; set; }
23 public int InstrumentNumber { get; set; } = 1;
24 public bool WaitForEmptyQueue { get; set; }
25
26 [DefaultUnit("min")]
27 public double GetReadyTimeout { get; set; }
28
29 [SuppressMessage("ReSharper", "UnusedMember.Global")]
30 public enum SampleTypeValue
31 {
35 }
36
37 public SampleTypeValue SampleType { get; set; } = SampleTypeValue.Analysis;
38
39 #region Overrides of Object
40
41 public override string ToString()
42 {
43 return $"Method = {InstrumentMethod}, Instrument = {InstrumentNumber}, WaitForEmptyQueue = {WaitForEmptyQueue}, GetReadyTimeout = {GetReadyTimeout}, SampleType = {SampleType}";
44 }
45
46 #endregion
47 }
48 // ReSharper disable once UnusedMember.Global
55 public class MockSimpleAcquisitionService : IAcquisitionService<SimpleParameters>,
61 ICommandUsingAcquisitionService<MockCommandAndParameters>,
63 {
64 #region Implementation of IAcquisitionServiceBase
65
66 public string Name => "MockSimpleAcquisition";
67
71 private readonly Stopwatch mAvailabilityTimer = Stopwatch.StartNew();
72
76 public static bool ImmediatelyAvailable { get; set; }
77
81 public bool IsAvailable
82 {
83 get
84 {
85 if (ImmediatelyAvailable || mAvailabilityTimer.Elapsed > TimeSpan.FromMinutes(2))
86 {
87 mAvailabilityTimer.Stop();
88 return true;
89 }
90
91 return false;
92 }
93 }
94
95 public bool Abort { set => TraceLog($"Abort flag {(value ? "set" : "reset")}"); }
97 {
98 WriteToRunlog?.Invoke($"Validating command '{cmdAndPars.SomeFakeCommand}' for instrument {cmdAndPars.InstrumentNumber}");
99 }
100
101 public void RunCommand(MockCommandAndParameters cmdAndPars)
102 {
103 WriteToRunlog?.Invoke($"Running command '{cmdAndPars.SomeFakeCommand}' for instrument {cmdAndPars.InstrumentNumber}");
104 }
105
106 #endregion
107
108 #region Implementation of IAcquisitionService<SimpleParameters>
109
110 public void Validate(SimpleParameters parameters)
111 {
112 TraceLog($"Validating simple parameters: {parameters}");
113 }
114
115 public void RunAcquisition(SimpleParameters parameters)
116 {
117 TraceLog($"Running acquisition with parameters: {parameters}");
118 }
119
120 #endregion
121
122 private void TraceLog(string txt)
123 {
124 TraceWrite?.Invoke(this, new TraceWriteEventArgs(txt));
125 }
126
127 #region Implementation of ITraceLogger
128
129 public event EventHandler<TraceWriteEventArgs> TraceWrite;
130
131 private const string RootEl = "MockServiceConfigRootElement";
132
133 #endregion
134
138 private string mConfigParam = "Foobar";
139
140 #region Implementation of IHaveConfigurator
141
142 public string ShowConfigDialog(IntPtr owner, string oldConfig)
143 {
144
145 var dlg = new ConfigDialog()
146 {
147 ParamText = ConfigFromXml(oldConfig)
148 };
149 var dummy = new System.Windows.Interop.WindowInteropHelper(dlg) { Owner = owner };
150 if (dlg.ShowDialog() ?? false)
151 {
152 return ConfigToXml(dlg.ParamText);
153 }
154 return oldConfig;
155 }
156
157 #endregion
158
159 #region Implementation of IConfigurableAcquisitionService
160
161 public string Configuration
162 {
164 set => mConfigParam = ConfigFromXml(value);
165 }
166
167 private string ConfigFromXml(string value)
168 {
169 if (!string.IsNullOrEmpty(value))
170 {
171 var el = XElement.Parse(value);
172 if (el.Name == RootEl)
173 {
174 return el.Value;
175 }
176 }
177 return mConfigParam;
178 }
179
180
181 private string ConfigToXml(string configParam)
182 {
183 var el = new XElement(RootEl) {Value = configParam};
184 return el.ToString();
185 }
186
187 #endregion
188
189 #region Implementation of ISequenceAwareAcquisitionService
190
191 public void BeginSequence(string pathToChronosSampleList)
192 {
193 TraceLog($"Sequence ${pathToChronosSampleList} was started.");
194 }
195
196 public void EndSequence()
197 {
198 TraceLog("Sequence has ended.");
199 }
200
201 #endregion
202
203 public event Action<string> WriteToRunlog;
204
205 #region Implementation of IPreseveringAcquisitionService
206
207 public TimeSpan RetryInterval => TimeSpan.FromSeconds(30);
208
209 #endregion
210
211 }
212
217 {
218 public int InstrumentNumber { get; set; }
219 public string SomeFakeCommand { get; set; } = "SayHello";
220 public override string ToString() => $"'{SomeFakeCommand}' (instrument {InstrumentNumber})";
221 }
222}
Classes and interfaces that are meant for plugins. The classes and interfaces below this namespace ar...
Enables you to add support for a Chromatography Data System (or similar) to Chronos....
Request retrying if IsAvailable returned false.
Implement this interface if you want to provide an acquisition service that is loaded on program star...
Implement this interface if your acquisition service requires some kind of configuration.
The GUI for the configuration can be managed seperately from the service.
Implement this if your acquisition service has to know when a Chronos sequence starts / ends.
Implement this interface if your acquisition service supports some kind of utility commands that coul...
Implement this interface if you have messages for our run log.
For future extension (categories, priorities...)
Writes some text to the trace log.
Interaktionslogik für ConfigDialog.xaml.
Example parameter set for an acquisition service.
An example acquisition service using a fixed list of parameters.
bool? Abort
Will be set to true if you should abort the current acquisition. Will be set to false when everything...
string ShowConfigDialog(IntPtr owner, string oldConfig)
Show a configuration dialog for your acquisition service.
string Configuration
XML Fragment containing the services configuration, if any.
void EndSequence()
The Chronos sequence has ended. Good moment, for example, to export sample information to a list for ...
static bool ImmediatelyAvailable
Allows us to bypass the delayed availability for test purposes.
readonly Stopwatch mAvailabilityTimer
We use this timer to pretend the service will only become available after a certain amount of time.
void BeginSequence(string pathToChronosSampleList)
A new Chronos sequence has started. You can use the path to the list file to construct your own seque...
string Name
Name that is visible to the user in the list of acquisition services. Do not localize.
bool IsAvailable
See above - we pretend the service becomes available only after some time.
TimeSpan RetryInterval
If you are sure the service will not be available, return TimeSpan.Zero. Else return a reasonable int...
Example definition of a command and its parameters that can be called for an AxelSemrau....