Chronos Plugins 5.9.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
MockPlugin.Tasks.FlexibleArguments Class Reference

This task demonstrates how to use a custom type descriptor to implement a dynamic list of properties. The number of properties can be changed by setting the PropCount property. More...

+ Inheritance diagram for MockPlugin.Tasks.FlexibleArguments:
+ Collaboration diagram for MockPlugin.Tasks.FlexibleArguments:

Classes

class  MyMemberDescriptor
 Member descriptor "implementation" - the defaults are ok for us. More...
 
class  MyPropertyDescriptor
 Custom property descriptor, redirecting get/set into our mPropsValues dictionary. More...
 

Public Member Functions

void PreValidate ()
 Called before the schedule construction is completed.
 
void PostValidate ()
 Called after the schedule construction is completed.
 
void Execute ()
 Do whatever you have to do with your parameters.
 
string GetTaskAction ()
 Description of the tasks's action (for hints/time table)
 
 FlexibleArguments ()
 
override object GetPropertyOwner (PropertyDescriptor pd)
 Must be overridden, else you'll get NullRefrences when trying to work with the descriptor.
 
override PropertyDescriptorCollection GetProperties ()
 
override AttributeCollection GetAttributes ()
 
- Public Member Functions inherited from AxelSemrau.Chronos.Plugin.ITask

Properties

uint PropCount [get, set]
 

Private Member Functions

string GetArgList ()
 

Private Attributes

readonly Dictionary< string, object > mPropsValues = new Dictionary<string, object>()
 Storage for fake property names and values.
 
PropertyDescriptorCollection mPropDescColl
 Caches the list resulting from set_PropCount.
 
readonly List< PropertyDescriptor > mProps = new List<PropertyDescriptor>()
 
readonly AttributeCollection mAttrs
 
uint mPropCount
 

Detailed Description

This task demonstrates how to use a custom type descriptor to implement a dynamic list of properties. The number of properties can be changed by setting the PropCount property.

Definition at line 17 of file MockDynamicProperties.cs.

Constructor & Destructor Documentation

◆ FlexibleArguments()

MockPlugin.Tasks.FlexibleArguments.FlexibleArguments ( )

Definition at line 66 of file MockDynamicProperties.cs.

67 {
68 // if we don't return this when asked, the ScheduleDiagramColor declaration above will not be seen by Chronos.
69 mAttrs = TypeDescriptor.GetAttributes(this, noCustomTypeDesc: true);
70 // Default descriptor for the only real property
71 var reflProp = TypeDescriptor.GetProperties(this, noCustomTypeDesc: true).Find(nameof(PropCount), false);
72 mProps.Add(reflProp);
73 // Add some fake properties to start with
74 // This one has a unit:
75 mProps.Add(new MyPropertyDescriptor("SomeIntParam", typeof(int), "s"));
76 var resProp = new MyPropertyDescriptor("SomeCalculationResult", typeof(int));
77 resProp.AddAttribute(new ReadOnlyAttribute(true));
78 mProps.Add(resProp);
79 mProps.Add(new MyPropertyDescriptor("SomeStringParam", typeof(string)));
80 mProps.Add(new MyPropertyDescriptor("SomeBoolParam", typeof(bool)));
81 PropCount = (uint)mProps.Count;
82 }
readonly AttributeCollection mAttrs
readonly List< PropertyDescriptor > mProps

References MockPlugin.Tasks.FlexibleArguments.mAttrs, MockPlugin.Tasks.FlexibleArguments.mProps, and MockPlugin.Tasks.FlexibleArguments.PropCount.

Referenced by MockPlugin.Tasks.FlexibleArguments.MyPropertyDescriptor.GetValue(), and MockPlugin.Tasks.FlexibleArguments.MyPropertyDescriptor.SetValue().

Member Function Documentation

◆ Execute()

void MockPlugin.Tasks.FlexibleArguments.Execute ( )

Do whatever you have to do with your parameters.

Implements AxelSemrau.Chronos.Plugin.ITask.

Definition at line 31 of file MockDynamicProperties.cs.

32 {
33 // nothing
34 }

◆ GetArgList()

string MockPlugin.Tasks.FlexibleArguments.GetArgList ( )
private

Definition at line 36 of file MockDynamicProperties.cs.

37 {
38 var sb = new System.Text.StringBuilder();
39 foreach (var key in mPropsValues.Keys)
40 {
41 sb.AppendFormat("{0}={1};", key, mPropsValues[key]);
42 }
43 if (sb.Length > 0)
44 {
45 sb.Length -= 1;
46 }
47 else
48 {
49 return "No properties";
50 }
51 return sb.ToString();
52 }
readonly Dictionary< string, object > mPropsValues
Storage for fake property names and values.

References MockPlugin.Tasks.FlexibleArguments.mPropsValues.

Referenced by MockPlugin.Tasks.FlexibleArguments.GetTaskAction().

◆ GetAttributes()

override AttributeCollection MockPlugin.Tasks.FlexibleArguments.GetAttributes ( )

◆ GetProperties()

override PropertyDescriptorCollection MockPlugin.Tasks.FlexibleArguments.GetProperties ( )

Definition at line 176 of file MockDynamicProperties.cs.

177 {
178 return mPropDescColl;
179 }
PropertyDescriptorCollection mPropDescColl
Caches the list resulting from set_PropCount.

References MockPlugin.Tasks.FlexibleArguments.mPropDescColl.

◆ GetPropertyOwner()

override object MockPlugin.Tasks.FlexibleArguments.GetPropertyOwner ( PropertyDescriptor pd)

Must be overridden, else you'll get NullRefrences when trying to work with the descriptor.

Parameters
pd
Returns

Definition at line 166 of file MockDynamicProperties.cs.

167 {
168 return mProps.Contains(pd) ? this : null;
169 }

References MockPlugin.Tasks.FlexibleArguments.mProps.

◆ GetTaskAction()

string MockPlugin.Tasks.FlexibleArguments.GetTaskAction ( )

Description of the tasks's action (for hints/time table)

Implements AxelSemrau.Chronos.Plugin.ITask.

Definition at line 54 of file MockDynamicProperties.cs.

55 {
56 return GetArgList();
57 }

References MockPlugin.Tasks.FlexibleArguments.GetArgList().

◆ PostValidate()

void MockPlugin.Tasks.FlexibleArguments.PostValidate ( )

Called after the schedule construction is completed.

Implements AxelSemrau.Chronos.Plugin.ITask.

Definition at line 26 of file MockDynamicProperties.cs.

27 {
28 // nothing
29 }

◆ PreValidate()

void MockPlugin.Tasks.FlexibleArguments.PreValidate ( )

Called before the schedule construction is completed.

Implements AxelSemrau.Chronos.Plugin.ITask.

Definition at line 21 of file MockDynamicProperties.cs.

22 {
23 // nothing
24 }

Member Data Documentation

◆ mAttrs

readonly AttributeCollection MockPlugin.Tasks.FlexibleArguments.mAttrs
private

◆ mPropCount

uint MockPlugin.Tasks.FlexibleArguments.mPropCount
private

Definition at line 187 of file MockDynamicProperties.cs.

◆ mPropDescColl

PropertyDescriptorCollection MockPlugin.Tasks.FlexibleArguments.mPropDescColl
private

Caches the list resulting from set_PropCount.

Definition at line 174 of file MockDynamicProperties.cs.

Referenced by MockPlugin.Tasks.FlexibleArguments.GetProperties().

◆ mProps

readonly List<PropertyDescriptor> MockPlugin.Tasks.FlexibleArguments.mProps = new List<PropertyDescriptor>()
private

◆ mPropsValues

readonly Dictionary<string, object> MockPlugin.Tasks.FlexibleArguments.mPropsValues = new Dictionary<string, object>()
private

Property Documentation

◆ PropCount

uint MockPlugin.Tasks.FlexibleArguments.PropCount
getset

Definition at line 190 of file MockDynamicProperties.cs.

191 {
192 get => mPropCount;
193 set
194 {
195 var oldCount = mPropCount;
196 // fill up to whatever the user wants, but do not let him hide PropCount
197 mPropCount = Math.Max(1, value);
198 if (oldCount != mPropCount)
199 {
200 for (int i = mProps.Count; i < mPropCount; ++i)
201 {
202 mProps.Add(new MyPropertyDescriptor($"FakeProp{i}", typeof(string)));
203 }
204 // when the number is decreased, we just present a part of our internal list
205 mPropDescColl = new PropertyDescriptorCollection(mProps.Take((int)mPropCount).ToArray());
206
207 // the list of dynamic properties has just changed,
208 // alert the reflection manager so the time table can access the new properties
209 TypeDescriptor.Refresh(this);
210 }
211 }
212 }

Referenced by MockPlugin.Tasks.FlexibleArguments.FlexibleArguments().


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