Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MeterListener.cs
Go to the documentation of this file.
3
5
6public sealed class MeterListener : IDisposable
7{
9
11
12 private bool _disposed;
13
17
21
25
29
33
37
41
43
45
47 {
48 bool oldStateStored = false;
49 bool flag = false;
50 object arg = null;
52 {
53 if (instrument != null && !_disposed && !instrument.Meter.Disposed)
54 {
56 arg = instrument.EnableMeasurement(new ListenerSubscription(this, state), out oldStateStored);
57 flag = true;
58 }
59 }
60 if (flag)
61 {
63 {
65 }
66 }
67 else
68 {
70 }
71 }
72
74 {
75 object obj = null;
77 {
79 {
80 return null;
81 }
82 obj = instrument.DisableMeasurements(this);
83 }
85 return obj;
86 }
87
89 {
91 {
93 {
95 return;
96 }
98 {
100 {
102 return;
103 }
105 {
107 {
109 return;
110 }
112 {
114 {
116 return;
117 }
119 {
121 {
123 return;
124 }
126 {
128 {
130 return;
131 }
133 {
135 {
137 return;
138 }
140 }
141
142 public void Start()
143 {
144 List<Instrument> list = null;
146 {
147 if (_disposed)
148 {
149 return;
150 }
151 if (!s_allStartedListeners.Contains(this))
152 {
153 s_allStartedListeners.Add(this);
155 }
156 }
157 if (list == null)
158 {
159 return;
160 }
161 foreach (Instrument item in list)
162 {
163 InstrumentPublished?.Invoke(item, this);
164 }
165 }
166
168 {
169 List<Exception> list = null;
171 {
172 if (diagNode.Value.IsObservable)
173 {
174 try
175 {
176 diagNode.Value.Observe(this);
177 }
178 catch (Exception item)
179 {
180 if (list == null)
181 {
182 list = new List<Exception>();
183 }
184 list.Add(item);
185 }
186 }
187 }
188 if (list != null)
189 {
190 throw new AggregateException(list);
191 }
192 }
193
194 public void Dispose()
195 {
199 {
200 if (_disposed)
201 {
202 return;
203 }
204 _disposed = true;
205 s_allStartedListeners.Remove(this);
207 if (diagNode != null && measurementsCompleted != null)
208 {
210 do
211 {
212 object value = diagNode.Value.DisableMeasurements(this);
214 diagNode = diagNode.Next;
215 }
216 while (diagNode != null);
218 }
219 }
220 if (dictionary == null)
221 {
222 return;
223 }
225 {
226 measurementsCompleted?.Invoke(item.Key, item.Value);
227 }
228 }
229
231 {
232 if (s_allStartedListeners.Count != 0)
233 {
235 }
236 return null;
237 }
238
239 [MethodImpl(MethodImplOptions.AggressiveInlining)]
241 {
242 if (typeof(T) == typeof(byte))
243 {
244 _byteMeasurementCallback(instrument, (byte)(object)measurement, tags, state);
245 }
246 if (typeof(T) == typeof(short))
247 {
248 _shortMeasurementCallback(instrument, (short)(object)measurement, tags, state);
249 }
250 if (typeof(T) == typeof(int))
251 {
252 _intMeasurementCallback(instrument, (int)(object)measurement, tags, state);
253 }
254 if (typeof(T) == typeof(long))
255 {
256 _longMeasurementCallback(instrument, (long)(object)measurement, tags, state);
257 }
258 if (typeof(T) == typeof(float))
259 {
260 _floatMeasurementCallback(instrument, (float)(object)measurement, tags, state);
261 }
262 if (typeof(T) == typeof(double))
263 {
264 _doubleMeasurementCallback(instrument, (double)(object)measurement, tags, state);
265 }
266 if (typeof(T) == typeof(decimal))
267 {
268 _decimalMeasurementCallback(instrument, (decimal)(object)measurement, tags, state);
269 }
270 }
271}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
MeasurementCallback< decimal > _decimalMeasurementCallback
MeasurementCallback< int > _intMeasurementCallback
MeasurementCallback< byte > _byteMeasurementCallback
Action< Instrument, MeterListener >? InstrumentPublished
static List< MeterListener > GetAllListeners()
static List< MeterListener > s_allStartedListeners
void NotifyMeasurement< T >(Instrument instrument, T measurement, ReadOnlySpan< KeyValuePair< string, object > > tags, object state)
void EnableMeasurementEvents(Instrument instrument, object? state=null)
MeasurementCallback< double > _doubleMeasurementCallback
Action< Instrument, object?>? MeasurementsCompleted
DiagLinkedList< Instrument > _enabledMeasurementInstruments
MeasurementCallback< long > _longMeasurementCallback
void SetMeasurementEventCallback< T >(MeasurementCallback< T >? measurementCallback)
MeasurementCallback< float > _floatMeasurementCallback
MeasurementCallback< short > _shortMeasurementCallback
object? DisableMeasurementEvents(Instrument instrument)
static List< Instrument > GetPublishedInstruments()
Definition Meter.cs:111
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string UnsupportedType
Definition SR.cs:40
Definition SR.cs:7