WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
TableVariablesDictionary.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 
6 namespace DirectOutput.LedControl.Loader
7 {
8  public class TableVariablesDictionary : Dictionary<string, VariablesDictionary>
9  {
10 
12 
13  public TableVariablesDictionary(List<string> DataToParse)
14  {
15  foreach (string D in DataToParse)
16  {
17  int TP = D.IndexOf(",");
18  if (TP > 0)
19  {
20  string TableName = D.Substring(0, TP).Trim();
21  if (!ContainsKey(TableName))
22  {
23  Add(TableName, new VariablesDictionary());
24  }
25  string VD = D.Substring(TP + 1).Trim();
26 
27  int Pos = 0;
28  int LastPos = 0;
29  while (Pos < VD.Length)
30  {
31  Pos = VD.IndexOf('=', LastPos);
32  if (Pos < 0) break;
33  if (Pos - LastPos < 1)
34  {
35  Log.Warning("Will skip some variable definitions due to missing variable name before = in line {0}".Build(D));
36  break;
37  }
38  string VarName = VD.Substring(LastPos, Pos - LastPos).Trim();
39  string Value = "";
40 
41  Pos++;
42  if (Pos < VD.Length)
43  {
44  LastPos = Pos;
45 
46  if (VD[Pos] == '{')
47  {
48  Pos = VD.IndexOf('}', LastPos);
49  if (Pos < 0)
50  {
51  Log.Warning("Will skip some variable definitions due to missing closing } bracket in line {0}".Build(D));
52  break;
53  }
54  Value = VD.Substring(LastPos + 1, Pos - LastPos - 1);
55 
56  Pos++;
57  while (Pos < VD.Length && VD[Pos] == ' ')
58  {
59  Pos++;
60  }
61  if (Pos < VD.Length)
62  {
63  if (VD[Pos] != '/')
64  {
65 
66  Log.Warning("Will skip some variable definitions due to missing / after } in line {0}".Build(D));
67  break;
68  }
69 
70  }
71  }
72  else
73  {
74  Pos = VD.IndexOf('/', LastPos);
75  if (Pos < 0)
76  {
77  Pos = VD.Length ;
78  }
79  Value = VD.Substring(LastPos, Pos - LastPos).Trim();
80 
81  }
82  }
83  if (!this[TableName].ContainsKey(VarName))
84  {
85  this[TableName].Add(VarName, Value);
86 
87  }
88  else
89  {
90  Log.Warning("Variable {0} has been defined more than once in line {1}.".Build(VarName, D));
91  }
92 
93  LastPos = Pos + 1;
94 
95  };
96 
97 
98 
99  }
100  else
101  {
102  Log.Warning("Could not find comma in TableVariables section line {0}.".Build(D));
103  }
104  }
105 
106 
107  }
108 
109 
110  }
111 }
static void Warning(string Message)
Writes a warning message to the log.
Definition: Log.cs:134
A simple logger used to record important events and exceptions.
Definition: Log.cs:14