-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
1462 lines (1110 loc) · 61 KB
/
Program.cs
File metadata and controls
1462 lines (1110 loc) · 61 KB
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
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Remoting.Channels;
using System.Security.AccessControl;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml;
using System.Xml.Serialization;
using ConvertXmlToCSharpClasses;
using File = ConvertXmlToCSharpClasses.File;
using ExtensionMethods;
/** Program Summary ***********************************************************
* Neil Silver www.lightingcontrol.co.uk
* 07767888871
*
* 25.04.17
*
* SUMMARY:
* Class Crestor for Simpl# tounchpanels
*
* Converts panel.xml to Class files for use in a Simpl# Pro Project
*
* NOTES:
* See "program_readme.txt
*
*
*
*****************************************************************************/
namespace TP_XML_CSharp
{
internal class Program
{
#region constants and variables
public const byte indentation = 4;
public static IDictionary<String, String> typeXMLtoSharp = new Dictionary<string, string>()
{
{"addsliders","Gauges"},
{"addsubpages","Pages"},
{"addbuttons","Buttons"},
{"addtextentry","Text"},
{"addformattedtext","Text"}
};
public static readonly IList<String> unsupportedSmartObjects = new ReadOnlyCollection<string>
(new List<String> {
"Background Selector Horizontal",
"Spinner List",
"Checkbox List Vertical" });
// NAMESPACE
public const string system_namespace = "myNamespace";
//XML PANEL FILE
// Template Filenames
public const string panel_xml = @"Panel_xml\panel.xml";
// Template Filenames
public const string template_pages = @"Templates\Panel_vtpro.template";
public const string template_objects = @"Templates\Object_vtpro.template";
//Method templates
public const string template_button_methods = @"Templates\button_method_vtpro.template";
public const string template_smartobject_methods = @"Templates\smartobject_methods_vtpro.template";
public const string template_text_methods = @"Templates\text_methods_vtpro.template";
public const string template_slider_methods = @"Templates\slider_methods_vtpro.template";
// Output Filenames
public const string output_pages = @"\OUTPUT\panel.cs";
public const string output_objects = @"\OUTPUT\Constants\VTSObjects.cs";
// Output Filenames Methods
public const string output_buttons = @"\OUTPUT\Callbacks\{0}\VTButtons.cs";
public const string output_methods = @"\OUTPUT\Callbacks\{0}\VTSMethods.cs";
public const string output_texts = @"\OUTPUT\Callbacks\{0}\VTTextEntryBoxes.cs";
public const string output_sliders = @"\OUTPUT\Callbacks\{0}\VTSliders.cs";
public const string output_errors = @"\OUTPUT\Errorlog\Log.txt";
public const string program_readme = @"\\readme.txt";
#endregion
private static void Main(string[] args)
{
ConsoleApplicationHeader("Crestron TP 2 Class Convertor v1.0");
Console.WriteLine("Type Y key to read the readme in the consle");
Console.WriteLine(".");
Console.WriteLine("Alternatively open the program.readme.txt in a text editor");
if (Console.ReadKey().Key == ConsoleKey.Y)
{
ConsoleReadMe(@"\program_readme_brief.txt");
}
Console.WriteLine("When you are ready ...");
WaitForKey();
//Delete the output folder if it exsists!
if (Directory.Exists("Output"))
{
try
{
//DeleteDirectoriesRecursive("Output");
SafeDeleteTestDirectory("Output");
}
catch (Exception)
{
Console.Clear();
Console.WriteLine(
"Error Deleting Output Directory Please ensure no files in the BIN/Output Directory are open.");
Console.WriteLine("Application will now exit please close all explorer windows and restart.");
Thread.Sleep(1000);
System.Environment.Exit(1);
}
}
File TPFILESTRUCTURE = new File();
Console.Clear();
// Import XML and Create Object
TPFILESTRUCTURE = TpImport(panel_xml);
checkforUnsupportedItems(TPFILESTRUCTURE,unsupportedSmartObjects);
Console.Clear();
Console.WriteLine("Type your Namespace Name - Invalid characters will be removed!");
var system_namespace = checkText(Console.ReadLine());
// if blank then set to mynamespace
if (system_namespace == "")
{
Console.WriteLine("Setting Default Namespace as blank entered.");
system_namespace = "myNamespace";
}
CreateConstants(TPFILESTRUCTURE, system_namespace);
Console.Clear();
addLine(8);
Console.WriteLine("########################");
Console.WriteLine("Class Creation Completed");
Console.WriteLine("########################");
ConsoleReadMe(output_errors);
#region TESTING
// Used for local testing copy to Local Folder.
//Console.WriteLine("Type CONFIRM key to copy to specified Local folder files... NB: This will delete exsisting files in that location");
// Console.WriteLine("Press any other key to exit program");
//if (Console.ReadLine() == "CONFIRM")
//{
// CopyOutputToSimplSharp();
//}
#endregion
Console.WriteLine("Press enter to exit the application...");
Console.ReadLine();
}
private static void checkforUnsupportedItems(File tpfilestructure,IList<String> unsupportedcontrols )
{
var unupportedfound = false;
StringBuilder unsupportedControlList = new StringBuilder();
// Build List of all controls
var query = from page in tpfilestructure.Page
from control in page.Control
select control;
foreach (var control in query)
{
if (unsupportedcontrols.Contains(control.Name))
{
unupportedfound = true;
unsupportedControlList.Append(string.Format("Unsupported Control Found:{0}",control.Name));
unsupportedControlList.AppendLine();
}
if (unupportedfound)
{
Console.Clear();
Console.Write(unsupportedControlList);
Console.WriteLine("Application will now exit .. remove unsupported items and re-run.");
WaitForKey();
System.Environment.Exit(1);
}
}
}
#region MAIN Process Methods
// XML File Import
public static File TpImport(string filename)
{
var serializer = new XmlSerializer(typeof(File));
FileStream fs = new FileStream(filename, FileMode.Open);
XmlReader reader = XmlReader.Create(fs);
var PanelFile = (File)serializer.Deserialize(reader);
fs.Close();
// Initial verification to console
foreach(var page in PanelFile.Page)
{
Console.WriteLine("PageName:{0}", checkText(page.Name));
if (page.DigitalJoin.IsNotNullOrWhiteSpace())
{
Console.WriteLine("Join:{0}", page.DigitalJoin.Visibility_Digital_Join.EmptyIfNull());
}
foreach (var controls in page.Control)
{
Console.WriteLine("Controls:{0}", checkText(controls.Name));
}
foreach (var so in page.Smart_Object_ID)
{
Console.WriteLine("Smart Object:{0}", so);
}
Console.WriteLine("/////////////////////////");
}
return PanelFile;
}
// MAIN Process
private static void CreateConstants(File panel,string system_namespace)
{
var sep = "_";
StringBuilder addnamespace = new StringBuilder();
addnamespace.Append(system_namespace);
StringBuilder addpages = new StringBuilder();
StringBuilder addsubpages = new StringBuilder();
StringBuilder addbuttons = new StringBuilder();
StringBuilder addsliders = new StringBuilder();
StringBuilder addtextentry = new StringBuilder();
StringBuilder addformattedtext = new StringBuilder();
StringBuilder addsmartobjects = new StringBuilder();
// String to build the VTS Objects file that holds the SmartObject Join Numbers.
StringBuilder addsmartobjectconstants = new StringBuilder();
StringBuilder addsmartobjectcallbacks = new StringBuilder();
StringBuilder addclassdeclarations = new StringBuilder();
StringBuilder addclassinitializations = new StringBuilder();
// Add any Build errors to a log file - not implemented
StringBuilder buildFile = new StringBuilder();
buildFile.AppendLine();
buildFile.AppendLine(string.Format("System Built:{0},Namespace = {1}",DateTime.Now.ToShortDateString(),system_namespace));
buildFile.AppendLine();
buildFile.AppendLine("Build File Error List:");
buildFile.AppendLine();
buildFile.AppendLine();
// Dictionary of files that will be created dynamically depending on the page contents.
Dictionary<String,String> filesDictionary = new Dictionary<string, string>();
Dictionary<String,String> filesOutputDictionary = new Dictionary<string, string>();
Dictionary<String,String> filesTemplateDictionary = new Dictionary<string, string>();
Dictionary<String,StringBuilder> MethodsStringBuilderDictionary = new Dictionary<string, StringBuilder>();
Dictionary<String, StringBuilder> MethodNameStringBuilderDictionary = new Dictionary<string, StringBuilder>();
Dictionary<String, String> MethodClassDeclarationStringBuilderDictionary = new Dictionary<string, String>();
// Dictionary of Stringbulders used for filtering and then for file creation
Dictionary<String, StringBuilder> stringBuilders = new Dictionary<string, StringBuilder>();
stringBuilders.Add("addsubpages", addsubpages);
stringBuilders.Add("addbuttons", addbuttons);
stringBuilders.Add("addsliders", addsliders);
stringBuilders.Add("addtextentry", addtextentry);
stringBuilders.Add("addformattedtext", addformattedtext);
addpages.AppendLine();
// counters
int countpages = 0; // count pages
int countsmartobjects = 0; // count smart
foreach (var page in panel.Page)
{
// Reset the SmartObject counter for the start of each page
countsmartobjects = 0;
// Create Element for the Page if it has an associated join number
if (page.DigitalJoin.IsNotNullOrWhiteSpace()) // Only create a page element if there is a join!
{
if (page.DigitalJoin.Visibility_Digital_Join.IsNotNullOrWhiteSpace())
{
addpages.Append(String.Format("Pages.AddElement({0},\"{1}\");",
page.DigitalJoin.Visibility_Digital_Join, page.Name));
addpages.AppendLineAndIndent(indentation);
}
}
// Build File Section
// for each page we need a folder and three files /Output/Template/Callbacks/Classname/
foreach (var variable in stringBuilders)
{
// Queries if we have any of the type of controls
var query = from control in page.Control
where control.Type == typeXMLtoSharp[variable.Key]
&&
(control.DigitalJoin.IsNotNullOrWhiteSpace() || control.SerialJoin.IsNotNullOrWhiteSpace() ||
control.AnalogJoin.IsNotNullOrWhiteSpace())
select control;
// If we have any of this type then
if (query.Any())
{
// Add a file build to the dictionary
switch (variable.Key)
{
case "addbuttons":
{
//filesDictionary.Add(string.Format(output_buttons, checkText(page.Name),template_button_methods);
filesOutputDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key],
string.Format(output_buttons, checkText(page.Name)));
filesTemplateDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key], template_button_methods);
MethodNameStringBuilderDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key], new StringBuilder(checkText(page.Name)));
MethodsStringBuilderDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key], new StringBuilder());
break;
}
case "addtextentry":
{
filesOutputDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key],
string.Format(output_texts, checkText(page.Name)));
filesTemplateDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key], template_text_methods);
MethodNameStringBuilderDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key],
new StringBuilder(checkText(page.Name)));
MethodsStringBuilderDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key], new StringBuilder());
break;
}
case "addsliders":
{
filesOutputDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key],string.Format(output_sliders, checkText(page.Name)));
filesTemplateDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key], template_slider_methods);
MethodNameStringBuilderDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key], new StringBuilder(checkText(page.Name)));
MethodsStringBuilderDictionary.Add(checkText(page.Name) + sep + typeXMLtoSharp[variable.Key], new StringBuilder());
break;
}
}
}
}
if (page.Smart_Object_ID.Count > 0) // Create a Methods Callback File
{
filesOutputDictionary.Add(checkText(page.Name) + sep + "Lists",string.Format(output_methods, checkText(page.Name)));
filesTemplateDictionary.Add(checkText(page.Name) + sep + "Lists", template_smartobject_methods);
MethodNameStringBuilderDictionary.Add(checkText(page.Name) + sep + "Lists", new StringBuilder(checkText(page.Name)));
MethodsStringBuilderDictionary.Add(checkText(page.Name) + sep + "Lists", new StringBuilder( ));
}
// Add a start Region to the relevant section if there are more than one controls in the section.
foreach (var variable in stringBuilders)
{
var query = from control in page.Control
where control.Type == typeXMLtoSharp[variable.Key]
&& (control.DigitalJoin.IsNotNullOrWhiteSpace() || control.SerialJoin.IsNotNullOrWhiteSpace() || control.AnalogJoin.IsNotNullOrWhiteSpace())
select control;
if(query.Any())
startPageSection(variable.Value,checkText(page.Name));
}
/*
private void AddPages()
{
Pages.AddElement(1, "Display Page");
Pages.AddElement(2, "Source Page");
Pages.AddElement(3, "VideoServer Page");
Pages.AddElement(12, "BlurayPlayer Page");
}
*/
// Buttons and SmartObjects
foreach (var controls in page.Control)
{
if(controls.Type != null)
{
// Work out what joins are available
List<String> joinsList = new List<String>();
if (controls.DigitalJoin.IsNotNullOrWhiteSpace())
{
if (controls.DigitalJoin.Press_Digital_Join.IsNotNullOrWhiteSpace())
joinsList.Add("{ VTBJoin.Press," + controls.DigitalJoin.Press_Digital_Join + "}");
if (controls.DigitalJoin.Visibility_Digital_Join.IsNotNullOrWhiteSpace())
{
//joinsList.Add("{ VTBJoin.Visibility,"+controls.DigitalJoin.Visibility_Digital_Join+"}");
//There is a typo in VTPro.dll VTB Join ENUM should be as the line above!!
joinsList.Add("{ VTBJoin.Visbility," + controls.DigitalJoin.Visibility_Digital_Join + "}");
}
if (controls.DigitalJoin.Enable_Digital_Join.IsNotNullOrWhiteSpace())
joinsList.Add("{ VTBJoin.Enable,"+controls.DigitalJoin.Enable_Digital_Join+"}");
}
if (controls.SerialJoin.IsNotNullOrWhiteSpace())
{
if (controls.SerialJoin.Indirect_Text_Serial_Join.IsNotNullOrWhiteSpace())
joinsList.Add("{ VTBJoin.IndirectText,"+ controls.SerialJoin.Indirect_Text_Serial_Join+"}");
if (controls.SerialJoin.Output_Text_Serial_Join.IsNotNullOrWhiteSpace())
joinsList.Add("{ VTBJoin.OutputText,"+ controls.SerialJoin.Output_Text_Serial_Join+"}");
}
if (controls.AnalogJoin.IsNotNullOrWhiteSpace())
{
if (controls.AnalogJoin.Touch_Feedback_Analog_Join.IsNotNullOrWhiteSpace())
joinsList.Add("{ VTBJoin.Analog,"+ controls.AnalogJoin.Touch_Feedback_Analog_Join+"}");
}
var joins = String.Join(",", joinsList.ToArray());
switch (controls.Type)
{
case "Buttons":
{
if (controls.DigitalJoin.IsNotNullOrWhiteSpace())
{
var callback = checkText(page.Name) + "_Buttons." + checkText(controls.Name);
// Dont add Interlocks at all!!
addbuttons.Append(
"ButtonCollection.AddElement(new VTButton(this, new Dictionary<VTBJoin, uint> {" +
joins + "}, \"" + checkText(controls.Name) + "\", " + callback + "));");
addbuttons.AppendLineAndIndent(indentation);
//Add method to the Methods file
MethodsStringBuilderDictionary[checkText(page.Name) + sep + controls.Type].Append(
buttonmethod(checkText(controls.Name)));
}
break;
}
case "Text": // Formatted Text or a simple label need to test for the Name
{
if(controls.SerialJoin.IsNotNullOrWhiteSpace())
{
if (controls.SerialJoin.Output_Text_Serial_Join.IsNotNullOrWhiteSpace())
{
var callback = checkText(page.Name) + "_TextEntryBoxes." +
checkText(controls.Name);
addtextentry.Append("TextEntryCollection.AddElement( new VTTextEntry("+callback+", this, new Dictionary<VTBJoin, uint> { " + joins + " }, \"" + checkText(controls.Name) + "\"));");
addtextentry.AppendLineAndIndent(indentation);
//Add method to the Methods file
MethodsStringBuilderDictionary[checkText(page.Name) + sep + controls.Type].Append(
textentrymethod(checkText(controls.Name)));
}
else
{
addformattedtext.Append("FormattedTextCollection.AddElement( new VTFormattedText(this, new Dictionary<VTBJoin, uint> { " + joins + " }, \"" + checkText(controls.Name) + "\"));");
addformattedtext.AppendLineAndIndent(indentation);
}
}
break;
}
case "Page": // Subpage Reference
{
// If the page has a visibility join then add as a subpage element
if (controls.DigitalJoin.IsNotNullOrWhiteSpace())
{
// Note the name is not very friendly!
if (controls.DigitalJoin.Visibility_Digital_Join.IsNotNullOrWhiteSpace())
{
addsubpages.Append(String.Format("Subpages.AddElement({0},\"{1}\");",
controls.DigitalJoin.Visibility_Digital_Join,
checkText(page.Name) + sep + checkText(controls.Name)));
addsubpages.AppendLineAndIndent(indentation);
}
}
break;
}
case "Gauges": // Sliders
{
if (controls.AnalogJoin.IsNotNullOrWhiteSpace())
{
var callback = checkText(page.Name) + "_Sliders." + checkText(controls.Name);
addsliders.Append("SliderCollection.AddElement(new VTSlider(this, new Dictionary<VTBJoin, uint> { "+joins+" }, \""+checkText(controls.Name)+"\", "+callback+"));");
addsliders.AppendLineAndIndent(indentation);
//Add method to the Methods file
MethodsStringBuilderDictionary[checkText(page.Name) + sep + controls.Type].Append(
sliderobjectmethod(checkText(controls.Name)));
}
break;
}
case "Images": // Images
{
break;
}
case "Keypad": // Note Dpads and Keypads are Type Keypad
case "Lists": // Lists of all sorts are ty[e Lists
// Smart Objects
{
var smartobjectcallback = "VTS" + checkText(page.Name) + "_Methods." + checkText(controls.Name);
var smartobjectcallbackroot = "VTS" + checkText(page.Name) + "_Methods";
var smartobjectconstanttext = checkText(page.Name) + sep + checkText(controls.Name);
// no firm way of tying the smat object to the ID!
// Except the order that they appear in the XML
// The SmartObject ID appears just after the Control but not in the same element
//if (page.Smart_Object_ID.Count == 0)
// Error handling Skip Control if there is no Smartobject ID Set!
if (panel.Page[countpages].Smart_Object_ID.ElementAtOrDefault(countsmartobjects) !=
null)
{
var ID = panel.Page[countpages].Smart_Object_ID[countsmartobjects];
// Add the smartobject Constant
addsmartobjectconstants.AppendLine();
addsmartobjectconstants.AppendLineWithIndent(
"public const uint " + smartobjectconstanttext + "= " + ID + ";", 4);
// Add the smartobject Element callback
addsmartobjectcallbacks.Append("public " + smartobjectcallbackroot + " " +
smartobjectcallback + " { get; private set; }");
}
else
{
buildFile = addtobuildfile(string.Format("Error No smartObject ID found Page:{0} Control:{1} ",page.Name,controls.Name), buildFile);
break;
}
//if(panel.Page.)
//increment smartobject counter
countsmartobjects++;
//VTSVideoServerMethods.SubpageSelection checkText(controls.Name);
switch (controls.Type)
{
case "Keypad":
{
if (controls.Name.Contains("DPad"))
{
addsmartobjects.AppendLine();
addsmartobjects.AppendLineWithIndent(
"SmartObjectCollection.AddElement(new VTDPad(this, null, ExtendedInterface.SmartObjects[VTSObjects." +
smartobjectconstanttext + "],\"" + checkText(controls.Name) + "\", " +
smartobjectcallback + "));");
//Add method to the Methods file
MethodsStringBuilderDictionary[checkText(page.Name) + sep + "Lists"].Append(
dpadobjectmethod(checkText(controls.Name)));
break;
}
if (controls.Name.Contains("Keypad"))
{
addsmartobjects.AppendLine();
addsmartobjects.AppendLineWithIndent(
"SmartObjectCollection.AddElement(new VTKeypad(this, null, ExtendedInterface.SmartObjects[VTSObjects." +
smartobjectconstanttext + "],\"" + checkText(controls.Name) + "\", " +
smartobjectcallback + "));");
//Add method to the Methods file
MethodsStringBuilderDictionary[checkText(page.Name) + sep + "Lists"].Append(
keypadobjectmethod(checkText(controls.Name)));
}
break;
}
case "Lists": // No way to ascertain if it is a Button List or a Dynamic Button List
{
if (controls.Name.Contains("Dynamic Button List"))
{
// VTDynamicButton
addsmartobjects.AppendLine();
addsmartobjects.AppendLineWithIndent(
"SmartObjectCollection.AddElement(new VTDynamicButtonList(this, null, ExtendedInterface.SmartObjects[VTSObjects." +
smartobjectconstanttext + "],\"" + checkText(controls.Name) +
"\", TempList, " + smartobjectcallback + ", true));");
//Add method to the Methods file
MethodsStringBuilderDictionary[checkText(page.Name) + sep + controls.Type]
.Append(
smartobjectmethod(checkText(controls.Name)));
break;
}
if (controls.Name.Contains("Button List") && !controls.Name.Contains("Dynamic"))
{
// VTButtonList ( Not Dynamic!)
addsmartobjects.AppendLine();
addsmartobjects.AppendLineWithIndent("// Set Number of Items in ButtonList");
addsmartobjects.AppendLine();
addsmartobjects.AppendLineWithIndent(
"SmartObjectCollection.AddElement(new VTButtonList(this, null, ExtendedInterface.SmartObjects[VTSObjects." +
smartobjectconstanttext + "],\"" + checkText(controls.Name) +
"\", 10, " + smartobjectcallback + ", true));");
//Add method to the Methods file
MethodsStringBuilderDictionary[checkText(page.Name) + sep + controls.Type]
.Append(
smartobjectmethod(checkText(controls.Name)));
break;
}
if (controls.Name.Contains("Dynamic Icon List"))
{
// VTDynamicButton
addsmartobjects.AppendLine();
// Icon Lists need a List of type Icon
addsmartobjects.AppendLineWithIndent(
"List<DynamicIconButton> IconList_" + checkText(controls.Name) +
" = new List<DynamicIconButton>();");
addsmartobjects.AppendLine();
addsmartobjects.AppendLineWithIndent(
"SmartObjectCollection.AddElement(new VTDynamicIconList(this, null, ExtendedInterface.SmartObjects[VTSObjects." +
smartobjectconstanttext + "], IconList_"+checkText(controls.Name)+", " + smartobjectcallback + ",\"" + checkText(controls.Name) + "\", true));");
//Add method to the Methods file
MethodsStringBuilderDictionary[checkText(page.Name) + sep + controls.Type]
.Append(
smartobjectmethod(checkText(controls.Name)));
}
break;
}
}
break;
}
} // switch
}
}
// Add a end Region to the section
foreach (var variable in stringBuilders)
{
// Queries if we have any of the type of controls
var query = from control in page.Control
where control.Type == typeXMLtoSharp[variable.Key]
&& ( control.DigitalJoin.IsNotNullOrWhiteSpace() || control.SerialJoin.IsNotNullOrWhiteSpace() || control.AnalogJoin.IsNotNullOrWhiteSpace())
select control;
// If we have any of this type then
if (query.Any())
{
// Add an #endregion complier directive
completePageSection(variable.Value);
}
}
// increment page counter
countpages++;
}
// End Pages
//Create the Class Declarations for the panels file and initialisations for the objects
addclassinitializations.AppendLine(); // Add a newline to straighten things up!
foreach (KeyValuePair<string, StringBuilder> entry in MethodNameStringBuilderDictionary)
{
if (entry.Key.Contains("_Lists"))
{
addclassdeclarations.AppendLine();
addclassdeclarations.AppendLineWithIndent("//Smart Object",2);
addclassdeclarations.AppendLineWithIndent(String.Format("public VTS{0}Methods VTS{0}_Methods {{ get; private set; }}",entry.Value),2);
addclassinitializations.AppendLineWithIndent(String.Format("VTS{0}_Methods = new VTS{0}Methods(ControlSystem, this);",entry.Value),2);
}
if ( entry.Key.Contains("_Buttons") || entry.Key.Contains("_Gauges")|| entry.Key.Contains("_Text"))
{
addclassdeclarations.AppendLineWithIndent("//Element callbacks",2);
}
if (entry.Key.Contains("_Buttons"))
{
addclassdeclarations.AppendLineWithIndent(
String.Format("public {0}VTButtons {0}_Buttons {{ get; private set; }}", entry.Value), 2);
addclassinitializations.AppendLineWithIndent(
String.Format("{0}_Buttons = new {0}VTButtons(this);", entry.Value), 2);
}
if (entry.Key.Contains("_Gauges"))
{
addclassdeclarations.AppendLineWithIndent(String.Format("public {0}VTSliders {0}_Sliders {{ get; private set; }}",entry.Value),2);
addclassinitializations.AppendLineWithIndent(String.Format("{0}_Sliders = new {0}VTSliders(this);",entry.Value),2);
}
if (entry.Key.Contains("_Text"))
{
addclassdeclarations.AppendLineWithIndent(String.Format( "public {0}VTTextEntryBoxes {0}_TextEntryBoxes {{ get; private set; }}",entry.Value),2);
addclassinitializations.AppendLineWithIndent(String.Format( "{0}_TextEntryBoxes = new {0}VTTextEntryBoxes(this);",entry.Value),2);
}
}
// Add the remaining elements to the Dict which is used in the Main files string replace
stringBuilders.Add("addnamespace", addnamespace);
stringBuilders.Add("addsmartobjects",addsmartobjects);
stringBuilders.Add("addsmartobjectconstants",addsmartobjectconstants);
stringBuilders.Add("addsmartobjectcallbacks",addsmartobjectcallbacks);
stringBuilders.Add("addclassdeclarations",addclassdeclarations);
stringBuilders.Add("addclassinitializations",addclassinitializations);
stringBuilders.Add("addpages", addpages);
// build the main two files
ProcessTemplate(template_pages, stringBuilders, output_pages);
ProcessTemplate(template_objects, stringBuilders, output_objects);
// Now Build the remaining files based on the Dictionaries
foreach (KeyValuePair<string, string> entry in filesOutputDictionary)
{
stringBuilders.Clear();
// Add the namespace every time
stringBuilders.Add("addnamespace", addnamespace);
// add the relevant strings and search terms
stringBuilders.Add("addmethodname",MethodNameStringBuilderDictionary[entry.Key]);
stringBuilders.Add("addmethods", MethodsStringBuilderDictionary[entry.Key]);
// do something with entry.Value template or entry.Key filename
ProcessTemplate(filesTemplateDictionary[entry.Key],stringBuilders,entry.Value);
}
// Save the Buildfile
savefile(buildFile.ToString(),output_errors);
}
// Templating and File Saving
private static void ProcessTemplate(string templatefilename,Dictionary<String,StringBuilder> args,string savefilename)
{
// Progress
//drawTextProgressBarHeader("Processing Templates");
FileStream fs = new FileStream(templatefilename, FileMode.Open);
StreamReader myReader = new StreamReader(fs);
while (!myReader.EndOfStream)
{
Thread.Sleep(100);
drawTextProgressBar((int)myReader.BaseStream.Position, (int)myReader.BaseStream.Length, templatefilename);
string contents = myReader.ReadToEnd();
// Build file from Templates
var i = 0;
foreach (var arg in args)
{
//contents = stringtemplate("$$" + MemberInfoGetting.GetMemberName(() => arg) + "$$", arg.ToString(), contents);
contents = stringtemplate("$$"+arg.Key+"$$", arg.Value.ToString(), contents);
i++;
}
// Save Files
savefile(contents,savefilename);
}
fs.Close();
}
// replaces each instance of serch in the template with the replce string!
private static string stringtemplate(string search, string replace, string template)
{
string result = template;
while (result.Contains(search))
{
int Place = result.IndexOf(search);
if (Place > 1)
{
result = result.Remove(Place, search.Length).Insert(Place, replace);
}
}
return result;
}
#endregion
#region string_methods
private static string checkText(string str)
{
string name = str;
return Regex.Replace(name, @"^[^A-Za-z_]+|\W+", "_");
//return Regex.Replace(temp, @"/-/","_");
}
private static StringBuilder addtobuildfile(string note, StringBuilder buildFile)
{
buildFile.AppendLine("Build Note:" + note);
return buildFile;
}
public static string keypadobjectmethod(string name)
{
StringBuilder sb = new StringBuilder();
sb.AppendLineAndIndent();
sb.Append(@"public void ");
sb.Append(name);
sb.Append(@"(VTSmartObject SmartObject, KeypadButton Button)
{
switch (Button)
{
case KeypadButton.Misc_1:
throw new NotImplementedException();
break;
case KeypadButton.Num_0:
//ControlSystem._videoServer.KeypadNumber(0);
break;
case KeypadButton.Num_1:
//ControlSystem._videoServer.KeypadNumber(1);
break;
case KeypadButton.Num_2:
//ControlSystem._videoServer.KeypadNumber(2);
break;
case KeypadButton.Num_3:
//ControlSystem._videoServer.KeypadNumber(3);
break;
case KeypadButton.Num_4:
//ControlSystem._videoServer.KeypadNumber(4);
break;
case KeypadButton.Num_5:
//ControlSystem._videoServer.KeypadNumber(5);
break;
case KeypadButton.Num_6:
//ControlSystem._videoServer.KeypadNumber(6);
break;
case KeypadButton.Num_7:
//ControlSystem._videoServer.KeypadNumber(7);
break;
case KeypadButton.Num_8:
//ControlSystem._videoServer.KeypadNumber(8);
break;
case KeypadButton.Num_9: