Chronos Plugins 5.9.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
75 [NoPlugin]
77 {
78 private readonly Train mTrain;
79 private readonly TrainPartType mMyType;
80 public string DisplayedTypeName => "Part of a train";
81 public string DeviceTypeDescription => "Locomotive or car";
86 public string Name
87 {
88 get => BuildName();
89 set { var dummy = value; }
90 }
91
96 public override string ToString() => Name;
97
98 public int Num { get; set; }
99
100 private string BuildName()
101 {
102 switch (mMyType)
103 {
104 case TrainPartType.DiningCar:
105 return $"{mTrain.Name}:Diner";
106 case TrainPartType.Locomotive:
107 return $"{mTrain.Name}:Locomotive";
108 default:
109 return $"{mTrain.Name}:Car{Num}";
110 }
111 }
112
113 public void Connect()
114 {
115
116 }
117
118 public void Disconnect()
119 {
120
121 }
122
123 internal TrainPart(Train parent, TrainPartType myType)
124 {
125 mTrain = parent;
126 mMyType = myType;
127 }
128
129 private bool mDoorsAreOpen;
130 public bool DoorsOpen
131 {
132 get => mDoorsAreOpen;
133 set
134 {
135 if (value != mDoorsAreOpen)
136 {
137 mDoorsAreOpen = value;
138 SetStatusMessage?.Invoke($"Doors are {(value ? "open" : "closed")}");
139 if (!value)
140 {
141 mTrain.ClosedSomeDoor();
142 }
143 }
144 }
145 }
146
150 public event Action<ConnectionState> ConnectionStateChanged
151 {
152 add { }
153 remove { }
154 }
155
156 public event Action<string> SetStatusMessage;
157 }
158}
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:77
void Disconnect()
You may disconnect now.
Definition Train.cs:118
string DisplayedTypeName
Text which is displayed in the instruments settings "Autosampler Type" column and in many other place...
Definition Train.cs:80
readonly TrainPartType mMyType
Definition Train.cs:79
string Name
We have to return a descriptive name that also allows identification of the base device - just do it ...
Definition Train.cs:87
readonly Train mTrain
Definition Train.cs:78
string DeviceTypeDescription
Text which is displayed to make clear which kind of device a named sampler is.
Definition Train.cs:81
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:156
Action< ConnectionState > ConnectionStateChanged
Not used.
Definition Train.cs:151
void Connect()
You may have connected to the device before this, but make sure you are connected after this.
Definition Train.cs:113