private void UpsertRule(IRule rule, ref int handle) { CompiledCode compilation = null; ScriptScope sharedScope = null; ScriptEngine engine = _sharedRuntime .GetEngineByFileExtension( rule.ContentType); sharedScope = engine.CreateScope(); ScriptSource source = engine .CreateScriptSourceFromString( rule.Body); compilation = source.Compile(); if (_rulesContexts.ContainsKey(handle)) { DeleteRule(handle); } else { handle = System.Threading .Interlocked.Increment( ref _nextHandle); } _rulesContexts[handle] = new RuleContext() { Rule = rule, Code = compilation, SharedScope = sharedScope, }; }
public void GetRegisteredIdentifiers_LangWithNoIDs_Test() { ScriptRuntime runtime = ScriptRuntimeTest.CreatePythonOnlyRuntime(new string[] { }, new string[] { ".py" }); ScriptEngine engine = runtime.GetEngineByFileExtension("py"); Assert.IsTrue(0 == engine.Setup.Names.Count); }
public DynamicCommand(ScriptRuntime scriptRuntime, IScriptSource source) { Source = source; Name = source.Name; var scriptEngine = scriptRuntime.GetEngineByFileExtension(source.LanguageExtension); var scriptScope = scriptEngine.CreateScope(); var scriptSource = scriptEngine.CreateScriptSourceFromString(source.GetScriptCode(), SourceCodeKind.File); var compiledCode = scriptSource.Compile(); compiledCode.Execute(scriptScope); Action <TAppSession, TRequestInfo> dynamicMethod; if (!scriptScope.TryGetVariable <Action <TAppSession, TRequestInfo> >("execute", out dynamicMethod)) { throw new Exception("Failed to find a command execution method in source: " + source.Tag); } CompiledTime = DateTime.Now; m_DynamicExecuteCommand = dynamicMethod; }
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!'"); }
public void Run() { ScriptEngine engine = scriptRuntime.GetEngineByFileExtension(Path.GetExtension(scriptPath)); try { engine.ExecuteFile(scriptPath); } catch (Exception ex) { ExceptionMessage = engine.GetService <ExceptionOperations>().FormatException(ex); } }
private void UpsertRule(IRule rule, ref int handle, IsolationMode runtimeMode) { if (rule == null) { throw new ArgumentNullException("rule"); } lock (_rulesContexts) { CompiledCode compilation = null; ScriptScope sharedScope = null; ScriptRuntime runtime = (runtimeMode == IsolationMode.Private) ? (_remoteAppDomain != null) ? ScriptRuntime.CreateRemote( _remoteAppDomain, _runtimeSetup) : new ScriptRuntime(_runtimeSetup) : _sharedRuntime; ScriptEngine engine = runtime .GetEngineByFileExtension( rule.ContentType); sharedScope = engine.CreateScope(); ScriptSource source = engine .CreateScriptSourceFromString( rule.Body); compilation = source.Compile(); if (_rulesContexts.ContainsKey(handle)) { DeleteRule(handle); } else { handle = System.Threading .Interlocked.Increment( ref _nextHandle); } _rulesContexts[handle] = new RuleContext() { Rule = rule, Code = compilation, SharedScope = sharedScope, IsIsolatedRuntime = (runtimeMode == IsolationMode.Private) }; } }
/// <summary> /// Initializes a new instance of the <see cref="DlrTask"/> class. /// </summary> /// <param name="factory">The Factory</param> /// <param name="xmlElement">The XElement</param> /// <param name="taskFactoryLoggingHost">The taskFactoryLoggingHost</param> internal DlrTask(DlrTaskFactory factory, XElement xmlElement, IBuildEngine taskFactoryLoggingHost) { this.xelement = xmlElement; this.language = GetLanguage(xmlElement); var srs = new ScriptRuntimeSetup(); srs.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup()); srs.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null)); var runtime = new ScriptRuntime(srs); this.engine = runtime.GetEngineByFileExtension(this.language); this.scope = this.engine.CreateScope(); this.scope.log = this.Log; }
public DynamicCommand(ScriptRuntime scriptRuntime, string filePath, DateTime lastUpdatedTime) { FilePath = filePath; LastUpdatedTime = lastUpdatedTime; Name = Path.GetFileNameWithoutExtension(filePath); var scriptEngine = scriptRuntime.GetEngineByFileExtension(Path.GetExtension(filePath)); var scriptScope = scriptEngine.CreateScope(); var scriptSource = scriptEngine.CreateScriptSourceFromFile(filePath); var compiledCode = scriptSource.Compile(); compiledCode.Execute(scriptScope); Action <TAppSession, TRequestInfo> dynamicMethod; if (!scriptScope.TryGetVariable <Action <TAppSession, TRequestInfo> >("execute", out dynamicMethod)) { throw new Exception("Failed to find a command execution method in file: " + filePath); } m_DynamicExecuteCommand = dynamicMethod; }
private void Initialize() { if (!IsInitialized && !IsInitializing) { lock (_sync) { if (!IsInitialized && !IsInitializing) { IsInitializing = true; var setup = new ScriptRuntimeSetup(); var languageSetup = new LanguageSetup( "IronRuby.Runtime.RubyContext, IronRuby, Version=1.0.0.1, Culture=neutral, PublicKeyToken=baeaf26a6e0611a7", IronConstant.IronRubyLanguageName, new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" }); setup.LanguageSetups.Add(languageSetup); setup.HostType = typeof(IronHive); setup.DebugMode = IronConstant.IronEnv == IronEnvironment.Debug; _scriptRuntime = new ScriptRuntime(setup); (_scriptRuntime.Host as IronHive).Id = _hiveId; _scriptRuntime.LoadAssembly(typeof(IronRuntime).Assembly); // IronSharePoint _scriptRuntime.LoadAssembly(typeof(SPSite).Assembly); // Microsoft.SharePoint _scriptRuntime.LoadAssembly(typeof(IHttpHandler).Assembly); // System.Web using (new SPMonitoredScope("Creating IronEngine(s)")) { string ironRubyRoot = Path.Combine(IronHive.FeatureFolderPath, "IronSP_IronRuby10\\"); SPSecurity.RunWithElevatedPrivileges(() => PrivilegedInitialize(ironRubyRoot)); ScriptEngine rubyEngine = _scriptRuntime.GetEngineByFileExtension(".rb"); rubyEngine.SetSearchPaths(new List <String> { Path.Combine(ironRubyRoot, @"Lib\IronRuby"), Path.Combine(ironRubyRoot, @"Lib\ruby\site_ruby\1.8"), Path.Combine(ironRubyRoot, @"Lib\ruby\1.8"), IronHive.CurrentDir }); var ironRubyEngine = new IronEngine(this, rubyEngine); Engines[".rb"] = ironRubyEngine; ScriptScope scope = rubyEngine.CreateScope(); scope.SetVariable("iron_runtime", this); scope.SetVariable("ruby_engine", ironRubyEngine); scope.SetVariable("rails_root", IronHive.CurrentDir); scope.SetVariable("rails_env", IronConstant.IronEnv == IronEnvironment.Debug ? "development" : IronConstant.IronEnv.ToString().ToLower()); rubyEngine.Execute("$RUNTIME = iron_runtime; $RUBY_ENGINE = ruby_engine; RAILS_ROOT = rails_root; RAILS_ENV = rails_env", scope); IronConsole.Execute(@" Dir.chdir RAILS_ROOT require 'rubygems' begin load_assembly 'Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' require './iron_sharepoint' require 'application' rescue Exception => ex IRON_DEFAULT_LOGGER.error ex ensure $RUBY_ENGINE.is_initialized = true end", ".rb", false); IsInitializing = false; IsInitialized = true; } } } } }
internal static ScriptEngine GetScriptEngineByExtension(string extension) { return(s_scriptEnvironment.GetEngineByFileExtension(extension)); }