DirectOuput Framework R2
DirectOutput framework R2 for virtual pinball cabinets
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
LedControlFileTestWizard.cs
Go to the documentation of this file.
1 using System;
2 using System.IO;
3 using System.Windows.Forms;
4 using DirectOutput.LedControl.Loader;
5 using System.Threading;
6 
7 namespace LedControlFileTester
8 {
13  public partial class LedControlFileTestWizard : Form
14  {
19  {
20  InitializeComponent();
21  }
22 
23 
24  public LedControlFileTestWizard(string Filename):this()
25  {
26  if (CheckLedControlFile(Filename))
27  {
28  Console.WriteLine("LedControl file {0} seems to be ok.", Filename);
29  this.Refresh();
30 
31  Thread.Sleep(1500);
32  this.Close();
33  }
34  else
35  {
36  Console.WriteLine("WARNING: Found some issues in ledcontrol file: {0}", Filename);
37  }
38  }
39 
40 
41 
42  private void SelectLedControlFile_Click(object sender, EventArgs e)
43  {
44  string Filename = "";
45  if (OpenLedControlFile.ShowDialog() == DialogResult.OK)
46  {
47  Filename = OpenLedControlFile.FileName;
48  CheckLedControlFile(Filename);
49 
50 
51 
52  }
53  }
54 
55  private bool CheckLedControlFile(string Filename)
56  {
57  try
58  {
59  bool OK = true;
60  LedControlFileName.Text = Filename;
61 
62  ParsingResults.Rows.Clear();
63 
64  string TempLogFile = Path.GetTempFileName();
65  DirectOutput.Log.Filename = TempLogFile;
66  DirectOutput.Log.Init();
67 
68  LedControlConfig L = new LedControlConfig(Filename, 1);
69 
70  DirectOutput.Log.Finish();
71 
72  string LedControlLoadingLog = DirectOutput.General.FileReader.ReadFileToString(TempLogFile);
73 
74 
75  File.Delete(TempLogFile);
76 
77  foreach (string LogLine in LedControlLoadingLog.Split(new[] { '\r', '\n' }))
78  {
79  string[] Parts = LogLine.Split('\t');
80  if (Parts.Length > 1)
81  {
82  if (Parts[1].ToLowerInvariant().Contains("exception") || Parts[1].ToLowerInvariant().Contains("warning") || Parts[1].ToLowerInvariant().Contains("error"))
83  {
84  OK = false;
85  }
86 
87  int RowIndex = ParsingResults.Rows.Add();
88  ParsingResults[0, RowIndex].Value = Parts[0];
89  ParsingResults[1, RowIndex].Value = Parts[1];
90  }
91  }
92  return OK;
93 
94  }
95  catch (Exception E)
96  {
97  ParsingResults.Rows.Clear();
98  MessageBox.Show("A error has occured when trying to load and parse the ledcontrol file: \n{0}\n\nException:\n{1}".Build(Filename, E.Message));
99  return false;
100  }
101  }
102 
103 
104  }
105 }