DirectOutputR1
DirectOutput framework R1 for virtual pinball cabinets.
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
ScriptList.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 
5 namespace DirectOutput.Scripting
6 {
10  public class ScriptList : IEnumerable<Script>
11  {
12  private List<Script> InternalList = new List<Script>();
13 
14 
21  public IEnumerator<Script> GetEnumerator()
22  {
23  return InternalList.GetEnumerator();
24  }
25 
32  System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
33  {
34  return GetEnumerator();
35  }
36 
37 
46  public Script this[string Filename]
47  {
48  get
49  {
50  FileInfo FI = new FileInfo(Filename);
51  foreach (Script S in InternalList)
52  {
53  if (S.File.FullName == FI.FullName) return S;
54  }
55  return null;
56  }
57  }
58 
59 
60 
61 
70  public Script this[int Index]
71  {
72  get
73  {
74  return InternalList[Index];
75  }
76  }
77 
84  public int Count
85  {
86  get { return InternalList.Count; }
87  }
88 
95  public void LoadAndAddScripts(string ScriptDirectory, string FilePattern = "*.cs", bool ThrowExceptions = false)
96  {
97  LoadAndAddScripts(new DirectoryInfo(ScriptDirectory), FilePattern, ThrowExceptions);
98  }
99 
106  public void LoadAndAddScripts(DirectoryInfo ScriptDirectory, string FilePattern = "*.cs", bool ThrowExceptions = false)
107  {
108  LoadAndAddScripts(ScriptDirectory.GetFiles(FilePattern), ThrowExceptions);
109  }
110 
116  public void LoadAndAddScripts(IEnumerable<FileInfo> ScriptFiles, bool ThrowExceptions = false)
117  {
118  foreach (FileInfo F in ScriptFiles)
119  {
120  LoadAndAddScript(F, ThrowExceptions);
121  }
122  }
123 
124 
130  public void LoadAndAddScript(FileInfo ScriptFile, bool ThrowExceptions = false)
131  {
132 
133  foreach (Script S in InternalList)
134  {
135  if (S.File.FullName == ScriptFile.FullName)
136  {
137 
138  Log.Warning("Script file has already been loaded. Will skip: {0}".Build(ScriptFile.FullName));
139 
140  return;
141  }
142  }
143 
144 
145  InternalList.Add(new Script(ScriptFile, ThrowExceptions));
146  }
147 
148 
149  }
150 }