Changeset 10358 for branches/HLScript/HeuristicLab.HLScript
- Timestamp:
- 01/20/14 17:33:22 (11 years ago)
- Location:
- branches/HLScript
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HLScript
- Property svn:mergeinfo changed
/trunk/sources (added) merged: 10346,10348,10355
- Property svn:mergeinfo changed
-
branches/HLScript/HeuristicLab.HLScript/3.3/HLScript.cs
r10332 r10358 17 17 18 18 namespace HeuristicLab.HLScript { 19 [Item("HL Script", "A HeuristicLab script.")]19 [Item("HL Script", "A HeuristicLab script.")] 20 20 [Creatable("Scripts")] 21 21 [StorableClass] … … 84 84 : base(original, cloner) { 85 85 code = original.code; 86 // variableStore = cloner.Clone(original.variableStore); 87 // compiledHLScript = cloner.Clone(original.compiledHLScript) 86 variableStore = new VariableStore(); 88 87 compilationUnitCode = original.compilationUnitCode; 89 88 if (original.compileErrors != null) … … 92 91 93 92 public HLScript() 94 : base("HL S") {93 : base("HL Script", "A HeuristicLab script.") { 95 94 code = CodeTemplate; 96 variableStore = new VariableStore();97 }98 99 [StorableHook(HookType.AfterDeserialization)]100 private void AfterDeserialization() {101 compiledHLScript = null;102 95 variableStore = new VariableStore(); 103 96 } … … 172 165 } 173 166 167 public IEnumerable<Assembly> GetAssemblies() { 168 var assemblies = new List<Assembly>(); 169 foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) { 170 try { 171 if (File.Exists(a.Location)) assemblies.Add(a); 172 } catch (NotSupportedException) { 173 // NotSupportedException is thrown while accessing 174 // the Location property of the anonymously hosted 175 // dynamic methods assembly, which is related to 176 // LINQ queries 177 } 178 } 179 assemblies.Add(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly); // for dlr functionality 180 return assemblies; 181 } 182 174 183 private readonly Regex LineSplitter = new Regex(@"\r\n|\r|\n"); 175 184 private readonly Regex SafeTypeNameCharRegex = new Regex("[_a-zA-Z0-9]+"); … … 177 186 private readonly Regex NamespaceDeclarationRegex = new Regex(@"using\s+(@?[a-z_A-Z]\w+(?:\s*\.\s*@?[a-z_A-Z]\w*)*)\s*;"); 178 187 private readonly Regex NamespaceRegex = new Regex(@"(@?[a-z_A-Z]\w+(?:\s*\.\s*@?[a-z_A-Z]\w*)*)"); 188 private readonly Regex CommentRegex = new Regex(@"((/\*)[^/]+(\*/))|(//.*)"); 179 189 180 190 private CodeCompileUnit CreateCompilationUnit() { … … 191 201 192 202 private IEnumerable<string> GetNamespaces() { 193 var strings = NamespaceDeclarationRegex.Matches( code)203 var strings = NamespaceDeclarationRegex.Matches(CommentRegex.Replace(code, string.Empty)) 194 204 .Cast<Match>() 195 205 .Select(m => m.Value); … … 207 217 yield return trimmedLine; 208 218 } 209 }210 211 private IEnumerable<Assembly> GetAssemblies() {212 var assemblies = new List<Assembly>();213 foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) {214 try {215 if (File.Exists(a.Location)) assemblies.Add(a);216 } catch (NotSupportedException) {217 // NotSupportedException is thrown while accessing218 // the Location property of the anonymously hosted219 // dynamic methods assembly, which is related to220 // LINQ queries221 }222 }223 assemblies.Add(typeof(Microsoft.CSharp.RuntimeBinder.Binder).Assembly); // for dlr functionality224 return assemblies;225 219 } 226 220 -
branches/HLScript/HeuristicLab.HLScript/3.3/HLScriptGeneration.cs
r10332 r10358 8 8 namespace HeuristicLab.HLScript { 9 9 public abstract class HLScriptGeneration { 10 protected static dynamic vars; 10 protected dynamic vars; 11 12 private readonly EventWriter console; 13 protected EventWriter Console { 14 get { return console; } 15 } 16 17 protected HLScriptGeneration() { 18 console = new EventWriter(this); 19 } 11 20 12 21 public abstract void Main(); … … 14 23 private void Execute(VariableStore variableStore) { 15 24 vars = new Variables(variableStore); 16 using (new EventWriter(this)) { 17 try { 18 Main(); 19 } catch (ThreadAbortException) { 20 } catch (Exception e) { 21 Console.WriteLine("---"); 22 Console.WriteLine(e); 23 } 25 try { 26 Main(); 27 } catch (ThreadAbortException) { 28 } catch (Exception e) { 29 Console.WriteLine("---"); 30 Console.WriteLine(e); 24 31 } 25 32 } … … 48 55 } 49 56 50 private class EventWriter : TextWriter { 51 private readonly TextWriter consoleOut; 57 protected class EventWriter : TextWriter { 52 58 private readonly HLScriptGeneration hlsg; 53 private bool disposed;54 59 55 60 public EventWriter(HLScriptGeneration hlsg) { 56 61 this.hlsg = hlsg; 57 consoleOut = Console.Out;58 Console.SetOut(this);59 disposed = false;60 62 } 61 63 … … 106 108 #endregion 107 109 #endregion 108 109 protected override void Dispose(bool disposing) {110 if (!disposed && disposing)111 Console.SetOut(consoleOut);112 disposed = true;113 }114 110 } 115 111 }
Note: See TracChangeset
for help on using the changeset viewer.