Chronos Plugins 5.9.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
MockDynamicParAcquisitionService.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Diagnostics.CodeAnalysis;
5using System.Linq;
7
9{
13 [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
14 [SuppressMessage("ReSharper", "UnusedMember.Global")]
15 public class DynamicAcqPars : CustomTypeDescriptor
16 {
17 private int mNoOfFakePars = 3;
18 private readonly List<PropertyDescriptor> mPropList = new List<PropertyDescriptor>();
19 private readonly List<string> mFakePars = new List<string>();
20
22 {
24 }
25 [DynamicPropertyMaster]
26 public uint NoOfFakePars
27 {
28 get => (uint)mNoOfFakePars;
29 set
30 {
31 mNoOfFakePars = (int)value;
33 }
34 }
35
36 private void UpdateParlist()
37 {
38 mPropList.Clear();
39 mPropList.AddRange(TypeDescriptor.GetProperties(this,noCustomTypeDesc:true).OfType<PropertyDescriptor>());
40 var oldCount = mFakePars.Count;
41 if (oldCount > mNoOfFakePars)
42 {
43 mFakePars.RemoveRange(mNoOfFakePars,oldCount-mNoOfFakePars);
44 }
45 else if(oldCount < mNoOfFakePars)
46 {
47 for (var i = oldCount + 1; i <= mNoOfFakePars; ++i)
48 {
49 mFakePars.Add($"Placeholder {i}");
50 }
51 }
52 else
53 {
54 // wenn nichts geändert wurde, kein Refresh nötig
55 return;
56 }
57 TypeDescriptor.Refresh(this);
58 }
59
60 #region Overrides of CustomTypeDescriptor
61
62 public override PropertyDescriptorCollection GetProperties()
63 {
64 return new PropertyDescriptorCollection(mPropList.Concat(GetFakePropDescriptors()).ToArray());
65 }
66
67 private IEnumerable<PropertyDescriptor> GetFakePropDescriptors()
68 {
69 for(var index = 0; index < mFakePars.Count; ++index)
70 {
71 yield return new StringListPropertyDescriptor(mFakePars, index);
72 }
73 }
74
78 private class StringListPropertyDescriptor : PropertyDescriptor
79 {
80 private readonly int mIndex;
81 private readonly List<string> mParList;
82
83 public StringListPropertyDescriptor(List<string> fakePars, int index) : base(name:$"DynPar{index+1}",attrs: new Attribute[] { })
84 {
85 mParList = fakePars;
86 mIndex = index;
87 }
88
89 #region Overrides of PropertyDescriptor
90
91 public override bool CanResetValue(object component)
92 {
93 return false;
94 }
95
96 public override object GetValue(object component)
97 {
98 return mParList[mIndex];
99 }
100
101 public override void ResetValue(object component)
102 {
103
104 }
105
106 public override void SetValue(object component, object value)
107 {
108 mParList[mIndex] = value?.ToString();
109 }
110
111 public override bool ShouldSerializeValue(object component)
112 {
113 return true;
114 }
115
116 public override Type ComponentType => typeof(DynamicAcqPars);
117 public override bool IsReadOnly => false;
118 public override Type PropertyType => typeof(string);
119
120 #endregion
121 }
122
123 #endregion
124
125 public override string ToString()
126 {
127 return $"{mNoOfFakePars} Parameters, Values: {string.Join(", ", mFakePars)}";
128 }
129 }
134 {
135 #region Implementation of IAcquisitionServiceBase
136
137 public string Name => "MockDynamicParAcquisition";
138 public bool IsAvailable => true;
139 // ReSharper disable once UnusedAutoPropertyAccessor.Local
140 public bool Abort { private get; set; } = false;
141
142 #endregion
143
144 #region Implementation of IAcquisitionService<DynamicAcqPars>
145
146 public void Validate(DynamicAcqPars parameters)
147 {
148 // nothing
149 }
150
151 public void RunAcquisition(DynamicAcqPars parameters)
152 {
153 // nothing
154 }
155 #endregion
156 #region Implementation of IStandbySupportingAcquisitionService
157
158 public void GoToStandby()
159 {
160 WriteToRunlog?.Invoke("Mock acquisition service going to standby mode");
161 }
162 #endregion
163 #region Implementation of IHaveRunlogOutput
164
165 public event Action<string> WriteToRunlog;
166
167 #endregion
168
169
170
171
172 }
173}
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....
Implement this interface if you want to provide an acquisition service that is loaded on program star...
For services that can be put into some kind of standby mode (by an error method, for example)
Implement this interface if you have messages for our run log.
Parameter class for an acquisition service that has a variable number of properties.
override PropertyDescriptorCollection GetProperties()
Acquisition service for a parameter class that has a variable number of properties.
bool IsAvailable
The place to check if you can actually use the acquisition service.
string Name
Name that is visible to the user in the list of acquisition services. Do not localize.
bool Abort
Will be set to true if you should abort the current acquisition. Will be set to false when everything...