WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
TableConfigColumn.cs
Go to the documentation of this file.
1 using System;
2 using System.Linq;
3 using System.Collections.Generic;
4 
5 namespace DirectOutput.LedControl.Loader
6 {
7 
12  public class TableConfigColumn : List<TableConfigSetting>
13  {
20  public int Number { get; set; }
21 
22 
23  private int _FirstOutputNumber;
24 
31  public int FirstOutputNumber
32  {
33  get { return _FirstOutputNumber; }
34  set { _FirstOutputNumber = value; }
35  }
36 
37 
44  //public bool AnalogOutputRequired
45  //{
46  // get
47  // {
48  // foreach (TableConfigSetting TCS in this)
49  // {
50  // if (TCS.Intensity != 0 && TCS.Intensity != 48 && TCS.OutputType != OutputTypeEnum.RGBOutput)
51  // {
52  // return true;
53 
54  // }
55 
56  // };
57  // return false;
58  // }
59  //}
60 
61 
62 
69  public int RequiredOutputCount
70  {
71  get
72  {
73  return (this.Any(S => S.OutputType == OutputTypeEnum.RGBOutput) ? 3 : 1);
74  }
75  }
76 
77 
84  public bool IsArea
85  {
86  get
87  {
88  return this.Any(S => S.IsArea);
89  }
90 
91  }
92 
93 
94  #region Parser
95 
103  public bool ParseColumnData(string ColumnData, bool ThrowExceptions = false)
104  {
105  bool ExceptionOccured = false;
106  List<string> ColumnConfigs = new List<string>(SplitSettings(ColumnData));
107 
108  foreach (string CC in ColumnConfigs)
109  {
110  if (!CC.IsNullOrWhiteSpace())
111  {
112  try
113  {
115  if (TCS.OutputControl != OutputControlEnum.FixedOff)
116  {
117  Add(TCS);
118  }
119  }
120  catch (Exception E)
121  {
122  ExceptionOccured = true;
123  Log.Exception("Could not parse setting {0} in column data {1}.".Build(CC, ColumnData), E);
124  if (ThrowExceptions)
125  {
126  throw new Exception("Could not parse setting {0} in column data {1}.".Build(CC, ColumnData), E);
127  }
128  }
129  }
130  }
131  return !ExceptionOccured;
132  }
133 
134 
135  private string[] SplitSettings(string ConfigData)
136  {
137  List<string> L = new List<string>();
138 
139  int BracketCount = 0;
140 
141  int LP = 0;
142 
143  for (int P = 0; P < ConfigData.Length; P++)
144  {
145  if (ConfigData[P] == '(')
146  {
147  BracketCount++;
148  }
149  else if (ConfigData[P] == ')')
150  {
151  BracketCount--;
152  } if (ConfigData[P] == '/' && BracketCount <= 0)
153  {
154  L.Add(ConfigData.Substring(LP, P - LP));
155  LP = P + 1;
156  BracketCount = 0;
157  }
158 
159  }
160 
161  if (LP < ConfigData.Length)
162  {
163  L.Add(ConfigData.Substring(LP));
164  }
165 
166  return L.ToArray();
167  }
168 
169 
170  #endregion
171 
172 
173  #region Constructor
174  public TableConfigColumn(int ColumnNumber, string ColumnData, bool ThrowExceptions = false)
181  {
182  this.Number = ColumnNumber;
183  ParseColumnData(ColumnData, ThrowExceptions);
184 
185  }
186 
190  public TableConfigColumn() { }
191  #endregion
192 
193 
194  }
195 }
A single setting from a LedControl.ini file.
OutputControlEnum
Used the specify how the output for a setting is controled.
Column in a LedControl.ini file. Is a list of TableConfigSettingObjects for that column...
A simple logger used to record important events and exceptions.
Definition: Log.cs:14
OutputTypeEnum
The output types for the ini file loader.
bool ParseColumnData(string ColumnData, bool ThrowExceptions=false)
Parses data for a column from a LedControl.ini file.
TableConfigColumn()
Initializes a new instance of the TableConfigColumn class.
static void Exception(string Message, Exception E=null)
Writes a exception message to the log.
Definition: Log.cs:144
OutputControlEnum OutputControl
Defines the control mode for a output. It can be constantly on, off or it can be controlled by a elem...