Chronos Plugins 5.4.0
This documentation covers the plugin interfaces definitions and an example implementation.
Loading...
Searching...
No Matches
Train.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
5// ReSharper disable UnusedMember.Global
6
7namespace MockPlugin.Device
8{
12 // ReSharper disable once ClassNeverInstantiated.Global
14 {
15 public string DisplayedTypeName => "Train";
16 public string DeviceTypeDescription => "Public Transport Train";
17 public string Name { get; set; }
18 public void Connect()
19 {
20 // connection state is irrelevant for the scope of this demonstration.
21 }
22
23 public void Disconnect()
24 {
25 }
26
27 private readonly List<TrainPart> mAllParts = new List<TrainPart>();
28
32 public Train()
33 {
34 mAllParts.Add(new TrainPart(this,TrainPartType.Locomotive));
35 mAllParts.Add(new TrainPart(this, TrainPartType.DiningCar));
36 for (int i = 0; i < 7; ++i)
37 {
38 mAllParts.Add(new TrainPart(this, TrainPartType.PassengerCar) {Num = i+57});
39 }
40 }
41
45 public event Action<ConnectionState> ConnectionStateChanged
46 {
47 add { }
48 remove { }
49 }
50
51 public IReadOnlyCollection<IDevice> Parts => mAllParts;
52
53 internal void ClosedSomeDoor()
54 {
55 if (mAllParts.All(somePart => !somePart.DoorsOpen))
56 {
57 // Very important information about some events can be written to the runlog.
58 WriteToRunlog?.Invoke($"Important: Train {Name} has all doors closed.");
59 }
60 }
61
62 public event Action<string> WriteToRunlog;
63 }
64
65 public enum TrainPartType
66 {
70 }
71
76 {
77 private readonly Train mTrain;
78 private readonly TrainPartType mMyType;
79 public string DisplayedTypeName => "Part of a train";
80 public string DeviceTypeDescription => "Locomotive or car";
85 public string Name
86 {
87 get => BuildName();
88 set { var dummy = value; }
89 }
90
95 public override string ToString() => Name;
96
97 public int Num { get; set; }
98
99 private string BuildName()
100 {
101 switch (mMyType)
102 {
103 case TrainPartType.DiningCar:
104 return $"{mTrain.Name}:Diner";
105 case TrainPartType.Locomotive:
106 return $"{mTrain.Name}:Locomotive";
107 default:
108 return $"{mTrain.Name}:Car{Num}";
109 }
110 }
111
112 public void Connect()
113 {
114
115 }
116
117 public void Disconnect()
118 {
119
120 }
121
122 public TrainPart(Train parent, TrainPartType myType)
123 {
124 mTrain = parent;
125 mMyType = myType;
126 }
127
128 private bool mDoorsAreOpen;
129 public bool DoorsOpen
130 {
131 get => mDoorsAreOpen;
132 set
133 {
134 if (value != mDoorsAreOpen)
135 {
136 mDoorsAreOpen = value;
137 SetStatusMessage?.Invoke($"Doors are {(value ? "open" : "closed")}");
138 if (!value)
139 {
140 mTrain.ClosedSomeDoor();
141 }
142 }
143 }
144 }
145
149 public event Action<ConnectionState> ConnectionStateChanged
150 {
151 add { }
152 remove { }
153 }
154
155 public event Action<string> SetStatusMessage;
156 }
157}
Classes and interfaces that are meant for plugins. The classes and interfaces below this namespace ar...
A fake device. This namespace contains the fake device driver and auxiliary classes for settings,...
To be implemented by the "device driver" part of a Chronos plugin.
Implement this interface if you want to keep the user up-to-date about what your device is doing.
Implement this interface if your device consists of multiple parts which can be used in parallel - li...
Implement this interface if you have messages for our run log.
For lack of a better idea, the demonstration for the multipart device is a train consisting of a loco...
Definition: Train.cs:14
void Disconnect()
You may disconnect now.
Definition: Train.cs:23
string Name
User-selected name for the device instance.
Definition: Train.cs:17
readonly List< TrainPart > mAllParts
Definition: Train.cs:27
Action< string > WriteToRunlog
Definition: Train.cs:62
Action< ConnectionState > ConnectionStateChanged
Not used.
Definition: Train.cs:46
string DisplayedTypeName
Text which is displayed in the instruments settings "Autosampler Type" column and in many other place...
Definition: Train.cs:15
string DeviceTypeDescription
Text which is displayed to make clear which kind of device a named sampler is.
Definition: Train.cs:16
IReadOnlyCollection< IDevice > Parts
Collection of all available parts.
Definition: Train.cs:51
Train()
Just adding all parts of the train. The parts keep references to the full train.
Definition: Train.cs:32
void Connect()
You may have connected to the device before this, but make sure you are connected after this.
Definition: Train.cs:18
The device part (well, train part) can't do much, just send status messages when the doors are opened...
Definition: Train.cs:76
TrainPart(Train parent, TrainPartType myType)
Definition: Train.cs:122
void Disconnect()
You may disconnect now.
Definition: Train.cs:117
string DisplayedTypeName
Text which is displayed in the instruments settings "Autosampler Type" column and in many other place...
Definition: Train.cs:79
readonly TrainPartType mMyType
Definition: Train.cs:78
string Name
We have to return a descriptive name that also allows identification of the base device - just do it ...
Definition: Train.cs:86
readonly Train mTrain
Definition: Train.cs:77
string DeviceTypeDescription
Text which is displayed to make clear which kind of device a named sampler is.
Definition: Train.cs:80
override string ToString()
Important! Without overriding ToString here, you will not be able to pick the device from an autosamp...
Action< string > SetStatusMessage
Definition: Train.cs:155
Action< ConnectionState > ConnectionStateChanged
Not used.
Definition: Train.cs:150
void Connect()
You may have connected to the device before this, but make sure you are connected after this.
Definition: Train.cs:112