Chronos Plugins 5.9.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
Tasks/MockDynamicPropsDependingOnDevice.cs
Go to the documentation of this file.
1using System;
2using System.ComponentModel;
3using System.Text;
5
6namespace MockPlugin.Tasks
7{
15 {
16 private const string NoDevice = "No device";
17 private string mDevName;
18 private string mDynPropValue;
19 private IDevice mDevice;
20
21 #region Not interesting for this example
22
23 public void PreValidate()
24 {
25 }
26
27 public void PostValidate()
28 {
29 }
30
31 public void Execute()
32 {
33 }
34
35 public string GetTaskAction() => "Do nothing";
36
37 #endregion
38
43 [DynamicPropertyMaster]
44 public void SetDevice(IDevice yourDevice)
45 {
46 if (mDevice != yourDevice)
47 {
48 mDevice = yourDevice;
49 // The PropertyEdited handler is called by Chronos for texts that can not be converted to a device instance.
50 // Otherwise, we get the device set here. If so, we must react in the same way.
51 PropertyEdited("Autosampler",mDevice);
52 }
53 }
54
60 public void PropertyEdited(string propName, object propValue)
61 {
62 if (propName == "Autosampler")
63 {
64 var newDevName = ((propValue as IDevice)?.Name) ?? NoDevice;
65 if (mDevName != newDevName)
66 {
67 mDevName = newDevName;
68 TypeDescriptor.Refresh(this);
69 }
70 }
71 }
72
73 public override PropertyDescriptorCollection GetProperties()
74 {
75 var dynProp = new MyPropertyDescriptor(this);
76 return new PropertyDescriptorCollection(new PropertyDescriptor[]{dynProp});
77 }
78
79 public override object GetPropertyOwner(PropertyDescriptor pd)
80 {
81 return pd is MyPropertyDescriptor ? this : null;
82 }
83
87 public class MyPropertyDescriptor : PropertyDescriptor
88 {
90
92 {
93 mParent = parent;
94 }
95
96 private static string BuildPropName(string parentDevName)
97 {
98 var sb = new StringBuilder("DynPropFor");
99 foreach (var someChar in parentDevName?? "NoDevice")
100 {
101 if (char.IsLetter(someChar))
102 {
103 sb.Append(someChar);
104 }
105 }
106 return sb.ToString();
107 }
108
109 public override bool CanResetValue(object component) => false;
110
111 public override object GetValue(object component) => mParent.mDynPropValue;
112
113 public override void ResetValue(object component)
114 {
115 }
116
117 public override void SetValue(object component, object value) => mParent.mDynPropValue = value?.ToString();
118
119 public override bool ShouldSerializeValue(object component) => true;
120
121 public override Type ComponentType => typeof(MockDynamicPropsDependingOnDevice);
122 public override bool IsReadOnly => false;
123 public override Type PropertyType => typeof(string);
124 }
125 }
126}
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,...
To be implemented by the "device driver" part of a Chronos plugin.
To be implemented if the task needs to access a device ("Autosampler" property in Chronos)
Implement this interface in your task if you want the method editor to notify it of changed propertie...
This task demonstrates how to make the property list depend on the picked autosampler.
string GetTaskAction()
Description of the tasks's action (for hints/time table)
void PostValidate()
Called after the schedule construction is completed.
void SetDevice(IDevice yourDevice)
React to a picked device.
void Execute()
Do whatever you have to do with your parameters.
void PreValidate()
Called before the schedule construction is completed.
void PropertyEdited(string propName, object propValue)
This will be called as soon as a property was changed in the method editor.
Just a dynamic property named after the picked autosampler. The value is just redirected to the mDynP...
override void SetValue(object component, object value)