private static IEnumerable <Type> GetBrainSimUIExtensionTypes() { var ret = new List <Type>(); foreach (FileInfo assemblyFile in MyConfiguration.ListModules()) { try { Assembly assembly = Assembly.LoadFrom(assemblyFile.FullName); string xml; if (MyResources.TryGetTextFromAssembly(assembly, MyModuleConfig.MODULE_CONFIG_FILE, out xml)) { continue; } MyLog.INFO.WriteLine("UI module loaded: " + assemblyFile.Name); ret.AddRange(assembly.GetTypes().Where(IsUIExtension)); } catch (Exception ex) { MyLog.DEBUG.WriteLine("Error when looking for UI modules: " + ex.Message); } } return(ret); }
private IEnumerable <string> FindTestAssemblies() { List <string> fileList = FindBrainTestAssemblies().ToList(); fileList.AddRange(MyConfiguration.ListModules().Select(fileInfo => fileInfo.FullName)); return(fileList); }
public void Compile(string script, MyValidator validator) { if (m_node.Language != this.Language) { throw new ArgumentException("Language is not supported (" + this.Language + " only): " + m_node.Language); } m_methods.Clear(); CSharpCodeProvider codeProvider = new CSharpCodeProvider(); CompilerParameters parameters = new CompilerParameters() { GenerateInMemory = false, GenerateExecutable = false, }; parameters.ReferencedAssemblies.Add("GoodAI.Platform.Core.dll"); parameters.ReferencedAssemblies.Add("System.Core.dll"); //for LINQ support // add all loaded dll modules to be accessible also from the C# node script foreach (FileInfo assemblyFile in MyConfiguration.ListModules()) { parameters.ReferencedAssemblies.Add(assemblyFile.FullName); } parameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location); Assembly[] loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies(); IEnumerable <Assembly> openTKAssemblies = loadedAssemblies.Where(x => x.ManifestModule.Name == "OpenTK.dll").ToList(); if (openTKAssemblies.Any()) { parameters.ReferencedAssemblies.Add(openTKAssemblies.First().Location); } CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, script); Assembly compiledAssembly = null; if (results.Errors.HasErrors) { string message = ""; foreach (CompilerError error in results.Errors) { message += "\nLine " + error.Line + ": " + error.ErrorText; } validator.AddError(m_node, "Errors in compiled script:" + message); } else { compiledAssembly = results.CompiledAssembly; } if (compiledAssembly != null) { try { Type enclosingType = compiledAssembly.GetType("Runtime.Script"); Type methodEnum = typeof(TMethodEnum); foreach (string methodName in methodEnum.GetEnumNames()) { MethodInfo method = enclosingType.GetMethod(methodName); if (method != null) { m_methods[methodName] = method; } else { validator.AddError(m_node, methodName + "() method not found in compiled script"); } } } catch (Exception e) { validator.AddError(m_node, "Script analysis failed: " + e.GetType().Name + ": " + e.Message); } } }