Chronos Plugins 5.9.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
MockDynamicPropsDependingOnDevice.cs
Go to the documentation of this file.
1using System;
2using System.ComponentModel;
3using System.Text;
5
7{
11 public class MockDynamicPropsDependingOnDevice : CustomTypeDescriptor, ITaskForDevice, IWantEditorUpdates
12 {
13 private const string NoDevice = "No device";
14 private string mDevName;
15 private string mDynPropValue;
17
18 public void PreValidate()
19 {
20 }
21
22 public void PostValidate()
23 {
24 }
25
26 public void Execute()
27 {
28 }
29
30 public string GetTaskAction() => "Do nothing";
31
32 [DynamicPropertyMaster]
33 public void SetDevice(IDevice yourDevice)
34 {
35 if (mDevice != yourDevice)
36 {
37 mDevice = yourDevice;
38 // The PropertyEdited handler is called by Chronos for texts that can not be converted to a device instance.
39 // Otherwise, we get the device set here. If so, we must react in the same way.
40 PropertyEdited("Autosampler",mDevice);
41 }
42 }
43
44 public void PropertyEdited(string propName, object propValue)
45 {
46 if (propName == "Autosampler")
47 {
48 var newDevName = ((propValue as IDevice)?.Name) ?? NoDevice;
49 if (mDevName != newDevName)
50 {
51 mDevName = newDevName;
52 TypeDescriptor.Refresh(this);
53 }
54 }
55 }
56
57 public override PropertyDescriptorCollection GetProperties()
58 {
59 var dynProp = new MyPropertyDescriptor(this);
60 return new PropertyDescriptorCollection(new PropertyDescriptor[]{dynProp});
61 }
62
63 public override object GetPropertyOwner(PropertyDescriptor pd)
64 {
65 return pd is MyPropertyDescriptor ? this : null;
66 }
67
68 public class MyPropertyDescriptor : PropertyDescriptor
69 {
71
73 {
74 mParent = parent;
75 }
76
77 private static string BuildPropName(string parentDevName)
78 {
79 var sb = new StringBuilder("DynPropFor");
80 foreach (var someChar in parentDevName?? "NoDevice")
81 {
82 if (char.IsLetter(someChar))
83 {
84 sb.Append(someChar);
85 }
86 }
87 return sb.ToString();
88 }
89
90 public override bool CanResetValue(object component) => false;
91
92 public override object GetValue(object component) => mParent.mDynPropValue;
93
94 public override void ResetValue(object component)
95 {
96 }
97
98 public override void SetValue(object component, object value) => mParent.mDynPropValue = value?.ToString();
99
100 public override bool ShouldSerializeValue(object component) => true;
101
102 public override Type ComponentType => typeof(MockDynamicPropsDependingOnDevice);
103 public override bool IsReadOnly => false;
104 public override Type PropertyType => typeof(string);
105 }
106 }
107}
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)
Will be called by chronos when building the schedule.
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)