-
Notifications
You must be signed in to change notification settings - Fork 1
/
UnifyUI.cs
987 lines (824 loc) · 28 KB
/
UnifyUI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
#region Copyright and License
// -----------------------------------------------------------------------------------------------------------------
//
// UnifyUI.cs
//
// Copyright © 2020 Nivloc Enterprises Ltd. All rights reserved.
//
// -----------------------------------------------------------------------------------------------------------------
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
//
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.CrestronXml;
using Crestron.SimplSharp.CrestronXmlLinq;
using Stream = Crestron.SimplSharp.CrestronIO.Stream;
namespace Crestron.SimplSharpPro.Helpers
{
public delegate void UnifiedSigEventHandler (UnifiedUIDevice uiDevice, UnifiedSigEventArgs args);
public class UnifiedUIDevice
{
private readonly object m_device;
private readonly CrestronDeviceWithEvents m_cde;
private readonly SmartObject m_so;
private readonly BasicTriList m_btl;
private readonly Dictionary<string, uint> dictBoolSigMap;
private readonly Dictionary<string, uint> dictUShortSigMap;
private readonly Dictionary<string, uint> dictStringSigMap;
private DeviceBooleanInputCollection m_booleanInput;
private DeviceBooleanOutputCollection m_booleanOutput;
private DeviceUShortInputCollection m_ushortInput;
private DeviceUShortOutputCollection m_ushortOutput;
private DeviceStringInputCollection m_stringInput;
private DeviceStringOutputCollection m_stringOutput;
public DeviceBooleanInputCollection BooleanInput
{
get
{
if (m_booleanInput == null)
{
if (m_cde != null)
m_booleanInput = m_cde.BooleanInput;
else if (m_so != null)
m_booleanInput = m_so.BooleanInput;
else if (m_btl != null)
m_booleanInput = m_btl.BooleanInput;
}
return m_booleanInput;
}
}
public DeviceBooleanOutputCollection BooleanOutput
{
get
{
if (m_booleanOutput == null)
{
if (m_cde != null)
m_booleanOutput = m_cde.BooleanOutput;
else if (m_so != null)
m_booleanOutput = m_so.BooleanOutput;
else if (m_btl != null)
m_booleanOutput = m_btl.BooleanOutput;
}
return m_booleanOutput;
}
}
public DeviceUShortInputCollection UShortInput
{
get
{
if (m_ushortInput == null)
{
if (m_cde != null)
m_ushortInput = m_cde.UShortInput;
else if (m_so != null)
m_ushortInput = m_so.UShortInput;
else if (m_btl != null)
m_ushortInput = m_btl.UShortInput;
}
return m_ushortInput;
}
}
public DeviceUShortOutputCollection UShortOutput
{
get
{
if (m_ushortOutput == null)
{
if (m_cde != null)
m_ushortOutput = m_cde.UShortOutput;
else if (m_so != null)
m_ushortOutput = m_so.UShortOutput;
else if (m_btl != null)
m_ushortOutput = m_btl.UShortOutput;
}
return m_ushortOutput;
}
}
public DeviceStringInputCollection StringInput
{
get
{
if (m_stringInput == null)
{
if (m_cde != null)
m_stringInput = m_cde.StringInput;
else if (m_so != null)
m_stringInput = m_so.StringInput;
else if (m_btl != null)
m_stringInput = m_btl.StringInput;
}
return m_stringInput;
}
}
public DeviceStringOutputCollection StringOutput
{
get
{
if (m_stringOutput == null)
{
if (m_cde != null)
m_stringOutput = m_cde.StringOutput;
else if (m_so != null)
m_stringOutput = m_so.StringOutput;
else if (m_btl != null)
m_stringOutput = m_btl.StringOutput;
}
return m_stringOutput;
}
}
public object Device
{
get { return m_device; }
}
public CrestronDeviceWithEvents CrestronDeviceWithEvents
{
get { return m_cde; }
}
public SmartObject SmartObject
{
get { return m_so; }
}
public BasicTriList BasicTriList
{
get { return m_btl; }
}
public event UnifiedSigEventHandler SigChange;
public UnifiedUIDevice (object baseDevice)
: this (baseDevice, null, null)
{
}
private static char[] NumChars = { ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
public UnifiedUIDevice (object baseDevice, Stream streamMap, string deviceId)
{
m_device = baseDevice;
m_cde = m_device as CrestronDeviceWithEvents;
if (m_cde != null)
{
m_cde.SigChange += cde_SigChange;
}
else
{
m_so = m_device as SmartObject;
if (m_so != null)
{
m_so.SigChange += so_SigChange;
}
else
{
m_btl = m_device as BasicTriList;
if (m_btl != null)
{
m_btl.SigChange += btl_SigChange;
}
else
throw new NotSupportedException (String.Format ("Base device of type {0} not supported", baseDevice.GetType ().Name));
}
}
if (streamMap == null)
return;
XDocument xd;
using (var xr = new XmlReader (streamMap))
{
try
{
xd = XDocument.Load (xr);
}
catch (Exception ex)
{
ErrorLog.Exception ("Exception while loading device map stream", ex);
return;
}
}
XElement xe = xd.Elements ().SingleOrDefault (xet => xet.Name == "device" && xet.Attribute ("name") != null && xet.Attribute ("name").Value == deviceId);
if (xe == null)
return;
dictBoolSigMap = GetSigMap (xe.Element ("bool"));
dictUShortSigMap = GetSigMap (xe.Element ("ushort"));
dictStringSigMap = GetSigMap (xe.Element ("string"));
}
private Dictionary<string, uint> GetSigMap (XElement xeType)
{
var q = from e in xeType.Descendants () where e.Name == "map" && e.Attribute ("join") != null && e.Attribute ("name") != null && e.Attribute ("join").Value.Trim (NumChars).Length != 0 select e;
return q.ToDictionary (e => e.Attribute ("name").Value, e => UInt32.Parse (e.Attribute ("join").Value));
}
void btl_SigChange (GenericBase currentDevice, SigEventArgs args)
{
if (SigChange != null)
SigChange (this, new UnifiedSigEventArgs (args));
OnSigChange (args);
}
void so_SigChange (GenericBase currentDevice, SmartObjectEventArgs args)
{
if (SigChange != null)
SigChange (this, new UnifiedSigEventArgs (args));
OnSigChange (args);
}
void cde_SigChange (CrestronDeviceWithEvents currentDevice, SigEventArgs args)
{
if (SigChange != null)
SigChange (this, new UnifiedSigEventArgs (args));
OnSigChange (args);
}
private void OnSigChange (SigEventArgs args)
{
UnifiedSigEventArgs usea = new UnifiedSigEventArgs (args);
switch (args.Event)
{
case eSigEvent.BoolOutputSigsCleared:
BooleanOutput.Where (bo => bo.UserObject is UnifiedSigUserObject && ((UnifiedSigUserObject)bo.UserObject).UnifiedSigEvents != null).Select (bo => ((UnifiedSigUserObject)bo.UserObject).UnifiedSigEvents).ToList ().ForEach (lc => lc.FindAll (u => u.SigChange != null && (u.eSigEvent == eSigEvent.NA || u.eSigEvent == eSigEvent.BoolChange)).ForEach (u => u.SigChange (this, usea)));
break;
case eSigEvent.UShortOutputSigsCleared:
UShortOutput.Where (uo => uo.UserObject is UnifiedSigUserObject && ((UnifiedSigUserObject)uo.UserObject).UnifiedSigEvents != null).Select (uo => ((UnifiedSigUserObject)uo.UserObject).UnifiedSigEvents).ToList ().ForEach (lc => lc.FindAll (u => u.SigChange != null && (u.eSigEvent == eSigEvent.NA || u.eSigEvent == eSigEvent.UShortChange)).ForEach (u => u.SigChange (this, usea)));
break;
case eSigEvent.StringOutputSigsCleared:
StringOutput.Where (so => so.UserObject is UnifiedSigUserObject && ((UnifiedSigUserObject)so.UserObject).UnifiedSigEvents != null).Select (so => ((UnifiedSigUserObject)so.UserObject).UnifiedSigEvents).ToList ().ForEach (lc => lc.FindAll (u => u.SigChange != null && (u.eSigEvent == eSigEvent.NA || u.eSigEvent == eSigEvent.StringChange)).ForEach (u => u.SigChange (this, usea)));
break;
default:
var uuo = args.Sig.UserObject as UnifiedSigUserObject;
if (uuo == null)
return;
if (uuo.UnifiedSigEvents == null || uuo.UnifiedSigEvents.Count == 0)
{
args.Sig.UserObject = uuo.UserObject;
return;
}
switch (args.Sig.Type)
{
case eSigType.Bool:
usea.BoolValue = args.Sig.BoolValue;
break;
case eSigType.UShort:
usea.UShortValue = args.Sig.UShortValue;
break;
case eSigType.String:
usea.StringValue = args.Sig.StringValue;
break;
}
uuo.UnifiedSigEvents.FindAll (u => u.SigChange != null && (u.eSigEvent == eSigEvent.NA || u.eSigEvent == args.Event)).ForEach (u => u.SigChange (this, usea));
break;
}
}
public void DetachAllSigEventHandlers ()
{
BooleanOutput.Where (bo => bo.UserObject is UnifiedSigUserObject).ToList ().ForEach (bo => bo.UserObject = ((UnifiedSigUserObject)bo.UserObject).UserObject);
UShortOutput.Where (uo => uo.UserObject is UnifiedSigUserObject).ToList ().ForEach (uo => uo.UserObject = ((UnifiedSigUserObject)uo.UserObject).UserObject);
StringOutput.Where (so => so.UserObject is UnifiedSigUserObject).ToList ().ForEach (so => so.UserObject = ((UnifiedSigUserObject)so.UserObject).UserObject);
UShortInput.Where (ui => ui.UserObject is UnifiedSigUserObject).ToList ().ForEach (ui => ui.UserObject = ((UnifiedSigUserObject)ui.UserObject).UserObject);
}
public void AttachBooleanEventHandler (uint index, UnifiedSigEventHandler handler)
{
AttachBooleanEventHandler (index, handler, eSigEvent.BoolChange);
}
public void AttachBooleanEventHandler (uint index, UnifiedSigEventHandler handler, eSigEvent eventType)
{
BooleanOutput[index].AttachSigEventHandler (handler, eventType);
}
public void AttachBooleanEventHandler (string name, UnifiedSigEventHandler handler)
{
AttachBooleanEventHandler (name, handler, eSigEvent.BoolChange);
}
public void AttachBooleanEventHandler (string name, UnifiedSigEventHandler handler, eSigEvent eventType)
{
BooleanOutput[name].AttachSigEventHandler (handler, eventType);
}
public void AttachUShortEventHandler (uint index, UnifiedSigEventHandler handler)
{
AttachUShortEventHandler (index, handler, eSigEvent.UShortChange);
}
public void AttachUShortEventHandler (uint index, UnifiedSigEventHandler handler, eSigEvent eventType)
{
UShortOutput[index].AttachSigEventHandler (handler, eventType);
}
public void AttachUShortEventHandler (string name, UnifiedSigEventHandler handler)
{
AttachBooleanEventHandler (name, handler, eSigEvent.UShortChange);
}
public void AttachUShortEventHandler (string name, UnifiedSigEventHandler handler, eSigEvent eventType)
{
UShortOutput[name].AttachSigEventHandler (handler, eventType);
}
public void AttachUShortRampEventHandler (uint index, UnifiedSigEventHandler handler)
{
AttachUShortRampEventHandler (index, handler, eSigEvent.UShortInputRamping);
}
public void AttachUShortRampEventHandler (uint index, UnifiedSigEventHandler handler, eSigEvent eventType)
{
UShortInput[index].AttachSigEventHandler (handler, eventType);
}
public void AttachUShortRampEventHandler (string name, UnifiedSigEventHandler handler)
{
AttachUShortRampEventHandler (name, handler, eSigEvent.UShortInputRamping);
}
public void AttachUShortRampEventHandler (string name, UnifiedSigEventHandler handler, eSigEvent eventType)
{
UShortInput[name].AttachSigEventHandler (handler, eventType);
}
public void AttachStringEventHandler (uint index, UnifiedSigEventHandler handler)
{
AttachStringEventHandler (index, handler, eSigEvent.StringChange);
}
public void AttachStringEventHandler (uint index, UnifiedSigEventHandler handler, eSigEvent eventType)
{
StringOutput[index].AttachSigEventHandler (handler, eventType);
}
public void AttachStringEventHandler (string name, UnifiedSigEventHandler handler)
{
AttachStringEventHandler (name, handler, eSigEvent.StringChange);
}
public void AttachStringEventHandler (string name, UnifiedSigEventHandler handler, eSigEvent eventType)
{
StringOutput[name].AttachSigEventHandler (handler, eventType);
}
public void SetValue (uint index, string value)
{
SetStringValue (index, value);
}
public void SetValue (uint index, string format, params object[] args)
{
SetStringValue (index, format);
}
public void SetValue (string name, string value)
{
SetStringValue (name, value);
}
public void SetValue (string name, string format, params object[] args)
{
SetStringValue (name, format, args);
}
public void SetValue (uint index, ushort value)
{
SetUShortValue (index, value);
}
public void SetValue (string name, ushort value)
{
SetUShortValue (name, value);
}
public void SetValue (uint index, bool value)
{
SetBoolValue (index, value);
}
public void SetValue (string name, bool value)
{
SetBoolValue (name, value);
}
public void SetStringValue (uint index, string value)
{
StringInput.SetValue (index, value);
}
public void SetStringValue (uint index, bool propagate, string value)
{
StringInput.SetValue (index, propagate, value);
}
public void SetStringValue (string name, string value)
{
StringInput.SetValue (name, value);
}
public void SetStringValue (string name, bool propagate, string value)
{
StringInput.SetValue (name, value, propagate);
}
public void SetStringValue (uint index, string format, params object[] args)
{
StringInput.SetValue (index, format, args);
}
public void SetStringValue (uint index, bool propagate, string format, params object[] args)
{
StringInput.SetValue (index, propagate, format, args);
}
public void SetStringValue (string name, string format, params object[] args)
{
StringInput.SetValue (name, format, args);
}
public void SetStringValue (string name, bool propagate, string format, params object[] args)
{
StringInput.SetValue (name, propagate, format, args);
}
public void SetUShortValue (uint index, ushort value)
{
UShortInput.SetValue (index, value);
}
public void SetUShortValue (uint index, ushort value, bool propagate)
{
UShortInput.SetValue (index, value, propagate);
}
public void SetUShortValue (string name, ushort value)
{
UShortInput.SetValue (name, value);
}
public void SetUShortValue (string name, ushort value, bool propagate)
{
UShortInput.SetValue (name, value, propagate);
}
public void SetBoolValue (uint index, bool value)
{
BooleanInput[index].BoolValue = value;
}
public void SetBoolValue (string name, bool value)
{
BooleanInput[name].BoolValue = value;
}
public void SetTrue (uint index)
{
BooleanInput[index].BoolValue = true;
}
public void SetTrue (string name)
{
BooleanInput[name].BoolValue = true;
}
public void SetFalse (uint index)
{
BooleanInput[index].BoolValue = false;
}
public void SetFalse (string name)
{
BooleanInput[name].BoolValue = false;
}
public void Pulse (uint index)
{
BooleanInput[index].Pulse ();
}
public void Pulse (string name)
{
BooleanInput[name].Pulse ();
}
public void Pulse (uint index, int msTimeBetweenTransition)
{
BooleanInput[index].Pulse (msTimeBetweenTransition);
}
public void Pulse (string name, int msTimeBetweenTransition)
{
BooleanInput[name].Pulse (msTimeBetweenTransition);
}
public void SetStringValues (IEnumerable<KeyValuePair<uint, string>> values)
{
var si = StringInput;
foreach (var v in values)
si.SetValue (v.Key, v.Value);
}
public void SetStringValues (IEnumerable<KeyValuePair<uint, string>> values, bool repropagate)
{
var si = StringInput;
foreach (var v in values)
si.SetValue (v.Key, repropagate, v.Value);
}
public void SetStringValues (IEnumerable<KeyValuePair<string, string>> values)
{
var si = StringInput;
foreach (var v in values)
si.SetValue (v.Key, v.Value);
}
public void SetStringValues (IEnumerable<KeyValuePair<string, string>> values, bool repropagate)
{
var si = StringInput;
foreach (var v in values)
si.SetValue (v.Key, v.Value, repropagate);
}
public void SetUShortValues (IEnumerable<KeyValuePair<uint, ushort>> values)
{
var ii = UShortInput;
foreach (var v in values)
ii.SetValue (v.Key, v.Value);
}
public void SetUShortValues (IEnumerable<KeyValuePair<uint, ushort>> values, bool repropagate)
{
var ii = UShortInput;
foreach (var v in values)
ii.SetValue (v.Key, v.Value, repropagate);
}
public void SetUShortValues (IEnumerable<KeyValuePair<string, ushort>> values)
{
var ii = UShortInput;
foreach (var v in values)
ii.SetValue (v.Key, v.Value);
}
public void SetUShortValues (IEnumerable<KeyValuePair<string, ushort>> values, bool repropagate)
{
var ii = UShortInput;
foreach (var v in values)
ii.SetValue (v.Key, v.Value, repropagate);
}
public bool GetBooleanInputValue (uint index)
{
return BooleanInput[index].BoolValue;
}
public bool GetBooleanInputValue (string name)
{
return BooleanInput[name].BoolValue;
}
public bool GetBooleanOutputValue (uint index)
{
return BooleanOutput[index].BoolValue;
}
public bool GetBooleanOutputValue (string name)
{
return BooleanOutput[name].BoolValue;
}
public ushort GetUShortInputValue (uint index)
{
return UShortInput[index].UShortValue;
}
public ushort GetUShortInputValue (string name)
{
return UShortInput[name].UShortValue;
}
public ushort GetUShortOutputValue (uint index)
{
return UShortOutput[index].UShortValue;
}
public ushort GetUShortOutputValue (string name)
{
return UShortOutput[name].UShortValue;
}
public string GetStringInputValue (uint index)
{
return StringInput[index].StringValue;
}
public string GetStringInputValue (string name)
{
return StringInput[name].StringValue;
}
public string GetStringOutputValue (uint index)
{
return StringOutput[index].StringValue;
}
public string GetStringOutputValue (string name)
{
return StringOutput[name].StringValue;
}
public void CreateRamp (uint index, ushort finalRampValue, uint timeToRampIn10msIntervals)
{
UShortInput[index].CreateRamp (finalRampValue, timeToRampIn10msIntervals);
}
public void CreateRamp (string name, ushort finalRampValue, uint timeToRampIn10msIntervals)
{
UShortInput[name].CreateRamp (finalRampValue, timeToRampIn10msIntervals);
}
public void StopRamp (uint index)
{
UShortInput[index].StopRamp ();
}
public void StopRamp (string name)
{
UShortInput[name].StopRamp ();
}
public void CreateRampWithEvent (uint index, ushort finalRampValue, uint timeToRampIn10msIntervals, RampChangeHandler changeHandler)
{
UShortInput.CreateRampWithEvent (index, finalRampValue, timeToRampIn10msIntervals, changeHandler);
}
public void CreateRampWithEvent (string name, ushort finalRampValue, uint timeToRampIn10msIntervals, RampChangeHandler changeHandler)
{
UShortInput.CreateRampWithEvent (name, finalRampValue, timeToRampIn10msIntervals, changeHandler);
}
}
internal class UnifiedSigEventInfo : IEquatable<UnifiedSigEventInfo>
{
public UnifiedSigEventHandler SigChange;
public eSigEvent eSigEvent;
#region IEquatable<UnifiedCueEventInfo> Members
public bool Equals (UnifiedSigEventInfo other)
{
return eSigEvent == other.eSigEvent && SigChange == other.SigChange;
}
#endregion
}
internal class UnifiedSigUserObject
{
public object UserObject;
public List<UnifiedSigEventInfo> UnifiedSigEvents;
}
public static class SigExtensions
{
public static object GetUserObject (this Sig cue)
{
var uuo = cue.UserObject as UnifiedSigUserObject;
return uuo == null ? cue.UserObject : uuo.UserObject;
}
public static object GetUserObject<T> (this SigCollectionBase<T> coll, uint index) where T : Sig
{
return coll[index].GetUserObject ();
}
public static object GetUserObject<T> (this SigCollectionBase<T> coll, string name) where T : Sig
{
return coll[name].GetUserObject ();
}
public static void SetUserObject (this Sig cue, object value)
{
var uuo = cue.UserObject as UnifiedSigUserObject;
if (uuo == null)
cue.UserObject = value;
else
uuo.UserObject = value;
}
public static void SetUserObject<T> (this SigCollectionBase<T> coll, uint index, object value) where T : Sig
{
coll[index].SetUserObject (value);
}
public static void SetUserObject<T> (this SigCollectionBase<T> coll, string name, object value) where T : Sig
{
coll[name].SetUserObject (value);
}
public static void AttachSigEventHandler (this Sig cue, UnifiedSigEventHandler handler)
{
eSigEvent eventType;
switch (cue.Type)
{
case eSigType.Bool:
eventType = eSigEvent.BoolChange;
break;
case eSigType.UShort:
eventType = cue.IsInput ? eSigEvent.UShortInputRamping : eSigEvent.UShortChange;
break;
case eSigType.String:
eventType = eSigEvent.StringChange;
break;
default:
eventType = eSigEvent.NA;
break;
}
cue.AttachSigEventHandler (handler, eventType);
}
public static void AttachSigEventHandler (this BoolOutputSig cue, UnifiedSigEventHandler handler)
{
cue.AttachSigEventHandler (handler, eSigEvent.BoolChange);
}
public static void AttachSigEventHandler (this UShortOutputSig cue, UnifiedSigEventHandler handler)
{
cue.AttachSigEventHandler (handler, eSigEvent.UShortChange);
}
public static void AttachSigEventHandler (this StringOutputSig cue, UnifiedSigEventHandler handler)
{
cue.AttachSigEventHandler (handler, eSigEvent.StringChange);
}
public static void AttachSigEventHandler (this UShortInputSig cue, UnifiedSigEventHandler handler)
{
cue.AttachSigEventHandler (handler, eSigEvent.UShortInputRamping);
}
public static void AttachSigEventHandler (this Sig cue, UnifiedSigEventHandler handler, eSigEvent eventType)
{
var uuo = cue.UserObject as UnifiedSigUserObject;
if (uuo == null)
{
uuo = new UnifiedSigUserObject { UserObject = cue.UserObject };
cue.UserObject = uuo;
}
if (uuo.UnifiedSigEvents == null)
uuo.UnifiedSigEvents = new List<UnifiedSigEventInfo> ();
var ucei = new UnifiedSigEventInfo { eSigEvent = eventType, SigChange = handler };
uuo.UnifiedSigEvents.Add (ucei);
}
public static void AttachSigEventHandler<T> (this SigCollectionBase<T> coll, uint index, UnifiedSigEventHandler handler) where T : Sig
{
coll[index].AttachSigEventHandler (handler);
}
public static void AttachSigEventHandler<T> (this SigCollectionBase<T> coll, uint index, UnifiedSigEventHandler handler, eSigEvent eventType) where T : Sig
{
coll[index].AttachSigEventHandler (handler, eventType);
}
public static void AttachSigEventHandler<T> (this SigCollectionBase<T> coll, string name, UnifiedSigEventHandler handler) where T : Sig
{
coll[name].AttachSigEventHandler (handler);
}
public static void AttachSigEventHandler<T> (this SigCollectionBase<T> coll, string name, UnifiedSigEventHandler handler, eSigEvent eventType) where T : Sig
{
coll[name].AttachSigEventHandler (handler, eventType);
}
public static void DetachSigEventHandler (this Sig cue, UnifiedSigEventHandler handler)
{
eSigEvent eventType;
switch (cue.Type)
{
case eSigType.Bool:
eventType = eSigEvent.BoolChange;
break;
case eSigType.UShort:
eventType = cue.IsInput ? eSigEvent.UShortInputRamping : eSigEvent.UShortChange;
break;
case eSigType.String:
eventType = eSigEvent.StringChange;
break;
default:
eventType = eSigEvent.NA;
break;
}
cue.DetachSigEventHandler (handler, eventType);
}
public static void DetachSigEventHandler (this BoolOutputSig cue, UnifiedSigEventHandler handler)
{
cue.DetachSigEventHandler (handler, eSigEvent.BoolChange);
}
public static void DetachSigEventHandler (this UShortOutputSig cue, UnifiedSigEventHandler handler)
{
cue.DetachSigEventHandler (handler, eSigEvent.UShortChange);
}
public static void DetachSigEventHandler (this StringOutputSig cue, UnifiedSigEventHandler handler)
{
cue.DetachSigEventHandler (handler, eSigEvent.StringChange);
}
public static void DetachSigEventHandler (this UShortInputSig cue, UnifiedSigEventHandler handler)
{
cue.DetachSigEventHandler (handler, eSigEvent.UShortInputRamping);
}
public static void DetachSigEventHandler (this Sig cue, UnifiedSigEventHandler handler, eSigEvent eventType)
{
var uuo = cue.UserObject as UnifiedSigUserObject;
if (uuo == null || uuo.UnifiedSigEvents == null)
return;
var ucei = uuo.UnifiedSigEvents.FirstOrDefault (u => u.eSigEvent == eventType && u.SigChange == handler);
if (ucei == null)
return;
uuo.UnifiedSigEvents.Remove (ucei);
if (uuo.UnifiedSigEvents.Count == 0)
cue.UserObject = uuo.UserObject;
}
public static void DetachSigEventHandler<T> (this SigCollectionBase<T> coll, uint index, UnifiedSigEventHandler handler) where T : Sig
{
coll[index].DetachSigEventHandler (handler);
}
public static void DetachSigEventHandler<T> (this SigCollectionBase<T> coll, uint index, UnifiedSigEventHandler handler, eSigEvent eventType) where T : Sig
{
coll[index].DetachSigEventHandler (handler, eventType);
}
public static void DetachSigEventHandler<T> (this SigCollectionBase<T> coll, string name, UnifiedSigEventHandler handler) where T : Sig
{
coll[name].DetachSigEventHandler (handler);
}
public static void DetachSigEventHandler<T> (this SigCollectionBase<T> coll, string name, UnifiedSigEventHandler handler, eSigEvent eventType) where T : Sig
{
coll[name].DetachSigEventHandler (handler, eventType);
}
public static void DetachAllSigEventHandlers (this Sig cue)
{
var uuo = cue.UserObject as UnifiedSigUserObject;
if (uuo == null)
return;
cue.UserObject = uuo.UserObject;
}
public static void DetachAllSigEventHandlers<T> (this SigCollectionBase<T> coll, uint index) where T : Sig
{
coll[index].DetachAllSigEventHandlers ();
}
public static void DetachAllSigEventHandlers<T> (this SigCollectionBase<T> coll, string name) where T : Sig
{
coll[name].DetachAllSigEventHandlers ();
}
}
public class UnifiedSigEventArgs : EventArgs
{
public eSigEvent Event { get; private set; }
public Sig Sig { get; private set; }
public bool BoolValue { get; internal set; }
public ushort UShortValue { get; internal set; }
public string StringValue { get; internal set; }
public UnifiedSigEventArgs (eSigEvent eSigEvent, Sig sig)
{
Event = eSigEvent;
Sig = sig;
}
public UnifiedSigEventArgs (eSigEvent eSigEvent, Sig sig, bool value)
: this (eSigEvent, sig)
{
BoolValue = value;
}
public UnifiedSigEventArgs (eSigEvent eSigEvent, Sig sig, ushort value)
: this (eSigEvent, sig)
{
UShortValue = value;
}
public UnifiedSigEventArgs (eSigEvent eSigEvent, Sig sig, string value)
: this (eSigEvent, sig)
{
StringValue = value;
}
public UnifiedSigEventArgs (SigEventArgs args)
: this (args.Event, args.Sig)
{
}
}
}