public string CompileSass(string input, SassMode mode) { var srs = new ScriptRuntimeSetup() { HostType = typeof(ResourceAwareScriptHost) }; srs.AddRubySetup(); var runtime = Ruby.CreateRuntime(srs); var engine = runtime.GetRubyEngine(); engine.SetSearchPaths(new List <string> { @"R:\lib\ironruby", @"R:\lib\ruby\1.9.1" }); var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("SquishIt.Sass.lib.sass_in_one.rb"), SourceCodeKind.File); var scope = engine.CreateScope(); source.Execute(scope); dynamic sassMode = mode == SassMode.Sass ? engine.Execute("{:syntax => :sass}") : engine.Execute("{:syntax => :scss}"); var sassEngine = scope.Engine.Runtime.Globals.GetVariable("Sass"); return((string)sassEngine.compile(input, sassMode)); }
public static ScriptRuntimeSetup CreateSetup() { var configFile = TestHelpers.StandardConfigFile; Debug.Assert(File.Exists(configFile), configFile); return(ScriptRuntimeSetup.ReadConfiguration(configFile)); }
/// <summary> /// Creates a new script runtime configured using .NET configuration files. /// A default IronRuby configuration is added if not found anywhere in the .NET configuration files. /// </summary> /// <returns>A runtime that is capable of running IronRuby scripts and scripts of other languages specified in the .NET configuration files.</returns> public static ScriptRuntime /*!*/ CreateRuntime() { var setup = ScriptRuntimeSetup.ReadConfiguration(); setup.AddRubySetup(); return(new ScriptRuntime(setup)); }
public ConsoleHostOptionsParser(ConsoleHostOptions options, ScriptRuntimeSetup runtimeSetup) { ContractUtils.RequiresNotNull(options, "options"); ContractUtils.RequiresNotNull(runtimeSetup, "runtimeSetup"); _options = options; _runtimeSetup = runtimeSetup; }
public static ScriptRuntime CreateRuntime(params LanguageSetup[] setups) { var setup = new ScriptRuntimeSetup(); setups.ToList().ForEach(lsetup => setup.LanguageSetups.Add(lsetup)); return(new ScriptRuntime(setup)); }
public static void Scenario_RemoteEvaluationInSandbox() { // creates a sandbox: Evidence e = new Evidence(); e.AddHostEvidence(new Zone(SecurityZone.Internet)); AppDomainSetup setup = new AppDomainSetup(); setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var ps = SecurityManager.GetStandardSandbox(e); AppDomain sandbox = AppDomain.CreateDomain("Tests", null, setup, ps); // creates a remote runtime: var runtime = ScriptRuntime.CreateRemote(sandbox, ScriptRuntimeSetup.ReadConfiguration()); var engine = runtime.GetEngine("python"); ObjectHandle exception; engine.CreateScriptSourceFromString(@"raise TypeError('this is wrong')").ExecuteAndWrap(out exception); if (exception != null) { string message, typeName; engine.GetService <ExceptionOperations>().GetExceptionMessage(exception, out message, out typeName); Console.WriteLine(typeName); Console.WriteLine(message); } }
protected override ScriptRuntime /*!*/ CreateRuntime() { var setup = new ScriptRuntimeSetup(); setup.AddRubySetup(); return(_factory.CreateRuntime(setup)); }
public MainPage() { this.InitializeComponent(); var setup = new ScriptRuntimeSetup(); setup.HostType = typeof(DlrHost); setup.AddRubySetup(); var runtime = Ruby.CreateRuntime(setup); this.engine = Ruby.GetEngine(runtime); this.scope = engine.CreateScope(); this.scope.SetVariable("Main", this); runtime.LoadAssembly(typeof(object).GetTypeInfo().Assembly); runtime.LoadAssembly(typeof(TextSetOptions).GetTypeInfo().Assembly); runtime.LoadAssembly(typeof(TextAlignment).GetTypeInfo().Assembly); string outputText = @" box = main.find_name('OutputBox') p box.text_alignment box.text_alignment = Windows::UI::Xaml::TextAlignment.Right p box.text_alignment "; InputBox.IsSpellCheckEnabled = false; OutputBox.IsSpellCheckEnabled = false; InputBox.Document.SetText(TextSetOptions.None, outputText); }
private void ExploreOrRun(ITestIsolationContext testIsolationContext, TestPackage testPackage, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, string taskName) { using (progressMonitor.BeginTask(taskName, 1)) { if (progressMonitor.IsCanceled) { return; } FileInfo testDriverScriptFile = GetTestDriverScriptFile(testPackage); if (testDriverScriptFile == null) { return; } HostSetup hostSetup = CreateHostSetup(testPackage); ScriptRuntimeSetup scriptRuntimeSetup = CreateScriptRuntimeSetup(testPackage); string testDriverScriptPath = testDriverScriptFile.FullName; var remoteMessageSink = new RemoteMessageSink(messageSink); var remoteLogger = new RemoteLogger(logger); using (var remoteProgressMonitor = new RemoteProgressMonitor(progressMonitor.CreateSubProgressMonitor(1))) { testIsolationContext.RunIsolatedTask <ExploreOrRunTask>(hostSetup, (statusMessage) => progressMonitor.SetStatus(statusMessage), new object[] { testPackage, scriptRuntimeSetup, testDriverScriptPath, testExplorationOptions, testExecutionOptions, remoteMessageSink, remoteProgressMonitor, remoteLogger }); } } }
private static ScriptRuntimeSetup ReadScriptRuntimeSetupFromConfiguration() { string assemblyFile = AssemblyUtils.GetFriendlyAssemblyLocation(typeof(DLRTestDriver).Assembly); string configFile = assemblyFile + ".config"; return(ScriptRuntimeSetup.ReadConfiguration(configFile)); }
static void Main() { var setup = new ScriptRuntimeSetup(); setup.LanguageSetups.Add( new LanguageSetup( typeof(RubyContext).AssemblyQualifiedName, "IronRuby", new[] { "IronRuby" }, new[] { ".rb" } ) ); var runtime = new ScriptRuntime(setup); var engine = runtime.GetEngine("IronRuby"); var ec = Ruby.GetExecutionContext(runtime); ec.DefineGlobalVariable("bob", new Person { Name = "Bob", Age = 30, Weight = 213, FavouriteDay = "1/1/2000" }); var eval = engine.Execute <bool>( "return ($bob.Age > 3 && $bob.Weight > 50) || $bob.Age < 3" ); Console.WriteLine(eval); }
public void ReloadScripts(ScriptExecutionCallback scriptExecutionCallback) { Shutdown(); ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup(); scriptRuntimeSetup.LanguageSetups.Add(new LanguageSetup("IronPython.Runtime.PythonContext, IronPython", "IronPython 2.6", new[] { "IronPython", "Python", "py" }, new[] { ".py" })); scriptRuntimeSetup.LanguageSetups.Add(new LanguageSetup("IronRuby.Runtime.RubyContext, IronRuby", "IronRuby 1.0", new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" })); scriptRuntimeSetup.LanguageSetups[0].Options.Add("SearchPaths", @"Libraries\IronPython".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options.Add("SearchPaths", @"Libraries\IronRuby\IronRuby;Libraries\IronRuby\ruby;Libraries\IronRuby\ruby\site_ruby;Libraries\IronRuby\ruby\site_ruby\1.8;Libraries\IronRuby\ruby\1.8".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options.Add("LibraryPaths", @"Libraries\IronRuby\IronRuby;Libraries\IronRuby\ruby;Libraries\IronRuby\ruby\site_ruby;Libraries\IronRuby\ruby\site_ruby\1.8;Libraries\IronRuby\ruby\1.8".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options["KCode"] = RubyEncoding.KCodeUTF8; scriptRuntimeSetup.LanguageSetups[1].ExceptionDetail = true; _scriptRuntime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, scriptRuntimeSetup); foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { _scriptRuntime.LoadAssembly(asm); } _scriptScopes = new Dictionary <string, ScriptScope>(); PrepareScriptScopeByPath("*Eval*"); _scriptRuntime.Globals.SetVariable("Session", _sessionProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("Server", _serverProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("CurrentSession", _sessionProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("CurrentServer", _serverProxy.GetTransparentProxy()); // 共通のスクリプトを読む LoadScriptsFromDirectory(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "GlobalScripts"), scriptExecutionCallback); // ユーザごとのスクリプトを読む LoadScriptsFromDirectory(Path.Combine(CurrentSession.UserConfigDirectory, "Scripts"), scriptExecutionCallback); }
protected override ScriptRuntime /*!*/ CreateRuntime() { string root = IronRubyToolsPackage.Instance.IronRubyBinPath; string configPath = IronRubyToolsPackage.Instance.IronRubyExecutable + ".config"; LanguageSetup existingRubySetup = null; LanguageSetup rubySetup = Ruby.CreateRubySetup(); if (File.Exists(configPath)) { try { existingRubySetup = GetSetupByName(ScriptRuntimeSetup.ReadConfiguration(configPath), "IronRuby"); } catch { // TODO: report the error } } if (existingRubySetup != null) { var options = new RubyOptions(existingRubySetup.Options); rubySetup.Options["StandardLibraryPath"] = NormalizePaths(root, new[] { options.StandardLibraryPath })[0]; rubySetup.Options["RequiredPaths"] = NormalizePaths(root, options.RequirePaths); rubySetup.Options["SearchPaths"] = NormalizePaths(root, options.SearchPaths); } var runtimeSetup = new ScriptRuntimeSetup(); runtimeSetup.LanguageSetups.Add(rubySetup); return(RemoteScriptFactory.CreateRuntime(runtimeSetup)); }
static void Main(string[] args) { try { ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null); ScriptRuntime runtime = new ScriptRuntime(setup); ScriptEngine engine = Python.GetEngine(runtime); var paths = engine.GetSearchPaths(); paths.Add(@"C:\Program Files\IronPython 2.7\lib"); engine.SetSearchPaths(paths); ScriptSource source = engine.CreateScriptSourceFromFile(@"D:\VsCodeDemo\pythonfile\EagleXml.py"); ScriptScope scope = engine.CreateScope(); List <String> argv = new List <String>(); //Do some stuff and fill argv argv.Add("."); argv.Add(@"D:\VsCodeDemo\pythonfile\MEHOW-0.xml"); engine.GetSysModule().SetVariable("argv", argv); source.Execute(scope); } catch (Exception e) { Console.WriteLine(e.Message); } Console.Read(); }
public static void MultiLanguageLoad() { var runtimeSetup = new ScriptRuntimeSetup(); var pythonSetup = new LanguageSetup( typeName: "IronPython.Runtime.PythonContext, IronPython", displayName: "IronPython", names: new[] { "IronPython", "Python", "py" }, fileExtensions: new[] { ".py" }); runtimeSetup.LanguageSetups.Add(pythonSetup); var rubySetup = new LanguageSetup( typeName: "IronRuby.Runtime.RubyContext, IronRuby", displayName: "IronRuby", names: new[] { "IronRuby", "Ruby", "rb" }, fileExtensions: new[] { ".rb" }); runtimeSetup.LanguageSetups.Add(rubySetup); ScriptRuntime runtimeObject = new ScriptRuntime(runtimeSetup); ScriptEngine pythonEngine = runtimeObject.GetEngine("Python"); ScriptEngine rubyEngine = runtimeObject.GetEngineByFileExtension(".rb"); pythonEngine.Execute("print 'Hello from Python!'"); rubyEngine.Execute("puts 'Hello from Ruby!'"); }
/// <summary> /// Creates a ScriptRuntimeSetup object which includes the Python script engine with the specified options. /// /// The ScriptRuntimeSetup object can then be additional configured and used to create a ScriptRuntime. /// </summary> public static ScriptRuntimeSetup /*!*/ CreateRuntimeSetup(IDictionary <string, object> options) { ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); setup.LanguageSetups.Add(CreateLanguageSetup(options)); if (options != null) { object value; if (options.TryGetValue("Debug", out value) && value is bool && (bool)value) { setup.DebugMode = true; } if (options.TryGetValue("PrivateBinding", out value) && value is bool && (bool)value) { setup.PrivateBinding = true; } } return(setup); }
public static void PassingVariablesToCompiledCode( string question, object correctResponse) { var runtimeSetup = new ScriptRuntimeSetup(); var languageSetup = new LanguageSetup( "IronPython.Runtime.PythonContext, IronPython", "IronPython", new[] { "Python" }, new[] { ".py" }); runtimeSetup.LanguageSetups.Add(languageSetup); var runtime = new ScriptRuntime(runtimeSetup); ScriptEngine engine = runtime.GetEngine("Python"); ScriptSource source = engine.CreateScriptSourceFromString(@" import Question import CorrectResponse input(Question) == CorrectResponse "); CompiledCode AskQuestion = source.Compile(); runtime.Globals.SetVariable("Question", question); runtime.Globals.SetVariable( "CorrectResponse", correctResponse); Console.WriteLine("You chose... {0}", AskQuestion.Execute <bool>() ? "wisely." : "poorly"); }
public AspHost(AspHostConfiguration config) { _config = config; ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); if (config != null && config.Trace) { setup.Options["Trace"] = ScriptingRuntimeHelpers.True; } string qualifiedname = typeof(VBScriptContext).AssemblyQualifiedName; setup.LanguageSetups.Add(new LanguageSetup( qualifiedname, "vbscript", new[] { "vbscript" }, new[] { ".vbs" })); _runtime = new ScriptRuntime(setup); if (config != null && config.Assemblies != null) { foreach (Assembly a in config.Assemblies) { _runtime.LoadAssembly(a); } } _engine = _runtime.GetEngine("vbscript"); }
public void Cons_NoArg2() { var srs = new ScriptRuntimeSetup(); var sr = new ScriptRuntime(srs); Assert.Fail("shouldn't be able to create a runtime without any langsetups"); }
public static void Scenario_RemoteEvaluation() { ScriptRuntime runtime = ScriptRuntime.CreateRemote( AppDomain.CreateDomain("remote domain"), ScriptRuntimeSetup.ReadConfiguration() ); ScriptEngine engine = runtime.GetEngine("python"); ObjectOperations ops = engine.Operations; ObjectHandle classC = engine.ExecuteAndWrap(@" class C(object): def __init__(self, value): self.value = value def __int__(self): return self.value C "); ObjectHandle result = ops.CreateInstance(classC, 17); int intResult = ops.Unwrap <int>(result); Console.WriteLine(intResult); }
public void ReadConfiguration_Multiple() { string configFile = GetTempConfigFile(new[] { LangSetup.Python }); var srs = ScriptRuntimeSetup.ReadConfiguration(configFile); Assert.AreEqual(1, srs.LanguageSetups.Count); var sr = new ScriptRuntime(srs); Assert.AreEqual(1, sr.Setup.LanguageSetups.Count); //create a config file, srs and runtime with 2 langsetups configFile = GetTempConfigFile(new[] { LangSetup.Python, LangSetup.Ruby }); var srs2 = ScriptRuntimeSetup.ReadConfiguration(configFile); Assert.AreEqual(2, srs2.LanguageSetups.Count); var sr2 = new ScriptRuntime(srs2); Assert.AreEqual(2, sr2.Setup.LanguageSetups.Count); //older ones still have only 1 lang Assert.AreEqual(1, srs.LanguageSetups.Count); Assert.AreEqual(1, sr.Setup.LanguageSetups.Count); }
private string GetLanguageProvider(ScriptRuntimeSetup setup) { var providerType = Provider; if (providerType != null) { return(providerType.AssemblyQualifiedName); } if (Options.HasLanguageProvider) { return(Options.LanguageProvider); } if (Options.RunFile != null) { string ext = Path.GetExtension(Options.RunFile); foreach (var lang in setup.LanguageSetups) { if (lang.FileExtensions.Any(e => DlrConfiguration.FileExtensionComparer.Equals(e, ext))) { return(lang.TypeName); } } } throw new InvalidOptionException("No language specified."); }
public void RubyHosting5() { // app-domain creation: if (_driver.PartialTrust) { return; } AppDomain domain = AppDomain.CreateDomain("foo"); var rs = ScriptRuntimeSetup.ReadConfiguration(); LanguageSetup ls = rs.GetRubySetup(); Debug.Assert(ls.Names.IndexOf("IronRuby") != -1); var newSetup = new ScriptRuntimeSetup(); newSetup.AddRubySetup((s) => { s.Options["Compatibility"] = RubyCompatibility.Ruby19; s.Options["LibraryPaths"] = ls.Options["LibraryPaths"]; }); ScriptRuntime runtime = ScriptRuntime.CreateRemote(domain, newSetup); ScriptEngine engine = runtime.GetRubyEngine(); Assert(engine.RequireFile("fcntl") == true); Assert(engine.Execute <bool>("Object.constants.include?(:Fcntl)") == true); }
internal Host(LanguageSetup language, string languageName, bool enableDebug) { _output = new MemoryStream(); _error = new MemoryStream(); //var configFile = Path.GetFullPath(Uri.UnescapeDataString(new Uri(typeof(Host).Assembly.CodeBase).AbsolutePath)) + ".config"; //_runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile)); ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); if (enableDebug) { language.Options["Debug"] = Microsoft.Scripting.Runtime.ScriptingRuntimeHelpers.True; setup.DebugMode = true; } setup.LanguageSetups.Add(language); _runtime = new ScriptRuntime(setup); _engine = _runtime.GetEngine(languageName); _runtime.IO.SetOutput(_output, new StreamWriter(_output)); _runtime.IO.SetErrorOutput(_error, new StreamWriter(_error)); _theScope = _engine.CreateScope(); _theScope.SetVariable("_host", this); }
private void initRuby() { ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration(); var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup); runtimeSetup.DebugMode = false; runtimeSetup.PrivateBinding = false; runtimeSetup.HostType = typeof(RhoHost); //runtimeSetup.HostArguments = new object[] { testCase.Options }; languageSetup.Options["NoAdaptiveCompilation"] = false; languageSetup.Options["CompilationThreshold"] = 0; languageSetup.Options["Verbosity"] = 2; _runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup); _engine = IronRuby.Ruby.GetEngine(_runtime); System.Collections.ObjectModel.Collection <string> paths = new System.Collections.ObjectModel.Collection <string>(); paths.Add("lib"); paths.Add("apps/app"); _engine.SetSearchPaths(paths); //IronRuby.Runtime.Loader //context.Loader.LoadAssembly(assemblyName.ConvertToString(), initializer, true, true); //IronRuby.Libraries //IronRuby.StandardLibrary.StringScanner.StringScannerLibraryInitializer }
protected override ConsoleOptions ParseOptions(string[] args, ScriptRuntimeSetup runtimeSetup, LanguageSetup languageSetup) { var options = base.ParseOptions(args, runtimeSetup, languageSetup); _pyoptions = (PythonConsoleOptions)options; return(options); }
public void ResetEngine(bool debugmode = false) { if (_python != null) { _python.Runtime.Shutdown(); } ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); setup.DebugMode = debugmode; setup.LanguageSetups.Add(Python.CreateLanguageSetup(null)); ScriptRuntime runtime = new ScriptRuntime(setup); _python = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName); LoadAssembly(typeof(Prefab.Bitmap).Assembly); LoadAssembly(typeof(PrefabUtils.PathDescriptor).Assembly); if (_consoleOutput == null) { _consoleOutput = new MemoryStream(); } _python.Runtime.IO.SetOutput(_consoleOutput, Encoding.Default); // _python.Runtime.GetClrModule().GetVariable("AddReference")("Prefab"); //_python = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName); //Instance = new PythonScriptHost(false); }
private PythonExec() { setup = Python.CreateRuntimeSetup(null); runtime = new ScriptRuntime(setup); engine = Python.GetEngine(runtime); programs = new Dictionary <string, PythonProgram>(); }
/// <exception cref="InvalidOptionException">On error.</exception> public void Parse(string[] args, ScriptRuntimeSetup setup, LanguageSetup languageSetup, PlatformAdaptationLayer platform) { ContractUtils.RequiresNotNull(args, "args"); ContractUtils.RequiresNotNull(setup, "setup"); ContractUtils.RequiresNotNull(languageSetup, "languageSetup"); ContractUtils.RequiresNotNull(platform, "platform"); _args = args; _runtimeSetup = setup; _languageSetup = languageSetup; _platform = platform; _current = 0; try { BeforeParse(); while (_current < args.Length) { ParseArgument(args[_current++]); } AfterParse(); } finally { _args = null; _runtimeSetup = null; _languageSetup = null; _platform = null; _current = -1; } }
private static ScriptRuntime CreateRuntimeHelper(ScriptRuntimeSetup setup) { var runtime = new ScriptRuntime(setup); LoadDefaultAssemblies(runtime); return(runtime); }
public TestRuntime(Driver /*!*/ driver, TestCase /*!*/ testCase) { _driver = driver; _testName = testCase.Name; if (testCase.Options.NoRuntime) { return; } if (_driver.SaveToAssemblies) { Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName); } var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration(); var languageSetup = runtimeSetup.AddRubySetup(); runtimeSetup.DebugMode = _driver.IsDebug; runtimeSetup.PrivateBinding = testCase.Options.PrivateBinding; runtimeSetup.HostType = typeof(TestHost); runtimeSetup.HostArguments = new object[] { testCase.Options }; languageSetup.Options["NoAdaptiveCompilation"] = _driver.NoAdaptiveCompilation; languageSetup.Options["CompilationThreshold"] = _driver.CompilationThreshold; languageSetup.Options["Verbosity"] = 2; _runtime = Ruby.CreateRuntime(runtimeSetup); _engine = Ruby.GetEngine(_runtime); _context = (RubyContext)HostingHelpers.GetLanguageContext(_engine); }
protected virtual ConsoleOptions ParseOptions(string/*!*/[]/*!*/ args, ScriptRuntimeSetup/*!*/ runtimeSetup, LanguageSetup/*!*/ languageSetup) { var languageOptionsParser = CreateOptionsParser(); try { languageOptionsParser.Parse(args, runtimeSetup, languageSetup, PlatformAdaptationLayer); } catch (InvalidOptionException e) { ReportInvalidOption(e); return null; } return languageOptionsParser.CommonConsoleOptions; }
private string GetLanguageProvider(ScriptRuntimeSetup setup) { var providerType = Provider; if (providerType != null) { return providerType.AssemblyQualifiedName; } if (Options.HasLanguageProvider) { return Options.LanguageProvider; } if (Options.RunFile != null) { string ext = Path.GetExtension(Options.RunFile); foreach (var lang in setup.LanguageSetups) { if (lang.FileExtensions.Any(e => DlrConfiguration.FileExtensionComparer.Equals(e, ext))) { return lang.TypeName; } } } throw new InvalidOptionException("No language specified."); }
internal static void LoadRuntimeSetup(ScriptRuntimeSetup setup, Stream configFileStream) { Section config; if (configFileStream != null) { config = LoadFromFile(configFileStream); } else { config = System.Configuration.ConfigurationManager.GetSection(Section.SectionName) as Section; } if (config == null) { return; } if (config.DebugMode.HasValue) { setup.DebugMode = config.DebugMode.Value; } if (config.PrivateBinding.HasValue) { setup.PrivateBinding = config.PrivateBinding.Value; } foreach (var languageConfig in config.GetLanguages()) { var provider = languageConfig.Type; var names = languageConfig.GetNamesArray(); var extensions = languageConfig.GetExtensionsArray(); var displayName = languageConfig.DisplayName ?? ((names.Length > 0) ? names[0] : languageConfig.Type); // Honor the latest-wins behavior of the <languages> tag for options that were already included in the setup object; // Keep the options though. bool found = false; foreach (var language in setup.LanguageSetups) { if (language.TypeName == provider) { language.Names.Clear(); foreach (string name in names) { language.Names.Add(name); } language.FileExtensions.Clear(); foreach (string extension in extensions) { language.FileExtensions.Add(extension); } language.DisplayName = displayName; found = true; break; } } if (!found) { setup.LanguageSetups.Add(new LanguageSetup(provider, displayName, names, extensions)); } } foreach (var option in config.GetOptions()) { if (String.IsNullOrEmpty(option.Language)) { // common option: setup.Options[option.Name] = option.Value; } else { // language specific option: bool found = false; foreach (var language in setup.LanguageSetups) { if (language.Names.Any(s => DlrConfiguration.LanguageNameComparer.Equals(s, option.Language))) { language.Options[option.Name] = option.Value; found = true; break; } } if (!found) { throw new ConfigurationErrorsException(string.Format("Unknown language name: '{0}'", option.Language)); } } } }