• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Hosting.ScriptRuntime类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.Scripting.Hosting.ScriptRuntime的典型用法代码示例。如果您正苦于以下问题:C# ScriptRuntime类的具体用法?C# ScriptRuntime怎么用?C# ScriptRuntime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ScriptRuntime类属于Microsoft.Scripting.Hosting命名空间,在下文中一共展示了ScriptRuntime类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestRuntime

        public TestRuntime(Driver/*!*/ driver, TestCase/*!*/ testCase) {
            _driver = driver;
            _testName = testCase.Name;

            if (_driver.SaveToAssemblies) {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            LanguageSetup languageSetup = null;
            foreach (var language in runtimeSetup.LanguageSetups) {
                if (language.TypeName == typeof(RubyContext).AssemblyQualifiedName) {
                    languageSetup = language;
                    break;
                }
            }

            runtimeSetup.DebugMode = _driver.IsDebug;
            languageSetup.Options["InterpretedMode"] = _driver.Interpret;
            languageSetup.Options["Verbosity"] = 2;
            languageSetup.Options["Compatibility"] = testCase.Compatibility;

            _env = Ruby.CreateRuntime(runtimeSetup);
            _engine = Ruby.GetEngine(_env);
            _context = Ruby.GetExecutionContext(_engine);
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:26,代码来源:Driver.cs


示例2: Start

        public void Start()
        {
            try
            {
                _runtime = ScriptRuntime.CreateFromConfiguration();
                    // this reads from app.config for configured Dynamic Language Runtime libraries

                // now get all the file extensions of scripting types, as creatted from the Configuration
                foreach (LanguageSetup ls in _runtime.Setup.LanguageSetups)
                {
                    foreach (string fext in ls.FileExtensions)
                    {
                        _scriptingManager.RegisterLanguageExtensions(this, fext);
                    }
                }

                IEnumerable<string> lg = from setup in _runtime.Setup.LanguageSetups
                                         select setup.Names[0];
                foreach (string ln in lg)
                    _scriptingManager.RegisterLanguageNames(this, ln);

                _scopevariables = new ScopeVariables();
                    // setup the initial scopevariables that are shared by all scopes
                _librarypaths = new List<string>();
                    // list of Lib directories, or others that contain standard libraries for this script collection
            }
            catch (Exception ex)
            {
                _scriptingManager.IsScriptEngineActive = false;
                CompositionManager.Get<IExceptionReporter>().ReportHandledException(ex);
            }
        }
开发者ID:nickhodge,项目名称:MahTweets.LawrenceHargrave,代码行数:32,代码来源:DynamicLanguagesScriptEngine.cs


示例3: Page

        public Page()
        {
            InitializeComponent();
            string code = @"
            def function(string):
            return string.upper()";

            ScriptRuntimeSetup setup = Python.CreateRuntimeSetup(null);
            setup.HostType = typeof(Microsoft.Scripting.Silverlight.BrowserScriptHost);
            setup.Options["SearchPaths"] = new string[] { string.Empty };

            ScriptRuntime runtime = new ScriptRuntime(setup);
            ScriptEngine pe = Python.GetEngine(runtime);

            // load platform assemblies so you don't need to call LoadAssembly in script code.
            foreach (string name in new string[] { "mscorlib", "System", "System.Windows", "System.Windows.Browser", "System.Net" })
            {
                runtime.LoadAssembly(runtime.Host.PlatformAdaptationLayer.LoadAssembly(name));
            }

            ScriptScope scope = pe.CreateScope();
            ScriptSource source = pe.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
            source.Execute(scope);

            Func<string, string> func = scope.GetVariable<Func<string, string>>("function");

            string result = func("hello world!");
            textblock.Text = result;
        }
开发者ID:rachmatg,项目名称:ironpython,代码行数:29,代码来源:Page.xaml.cs


示例4: LoadReferencedAssembliesIntoEnvironment

        private static void LoadReferencedAssembliesIntoEnvironment(ScriptRuntime environment)
        {
            // Make sure we're running with a System.Web.dll that has the new API's we need
            UI.NoCompileCodePageParserFilter.CheckCorrectSystemWebSupport();

            // Call BuildManager.GetReferencedAssemblies(), either the one that returns an array or an ICollection,
            // depending on what's available.
            // TODO: this is a temporary workaround for bug VSWhidbey 607089.  Once fix, we should always call
            // the one that returns an ICollection.
            ICollection referencedAssemblies = null;
            GetReferencedAssembliesReturnCollection getReferencedAssembliesCollection =
                (GetReferencedAssembliesReturnCollection)GetGetReferencedAssembliesDelegate(
                    typeof(GetReferencedAssembliesReturnCollection));
            if (getReferencedAssembliesCollection != null) {
                referencedAssemblies = getReferencedAssembliesCollection();
            } else {
                GetReferencedAssembliesReturnArray getReferencedAssembliesArray =
                    (GetReferencedAssembliesReturnArray)GetGetReferencedAssembliesDelegate(
                        typeof(GetReferencedAssembliesReturnArray));
                Debug.Assert(getReferencedAssembliesArray != null);
                if (getReferencedAssembliesArray != null) {
                    referencedAssemblies = getReferencedAssembliesArray();
                }
            }

            if (referencedAssemblies != null) {
                // Load all the BuildManager assemblies into the engine
                foreach (Assembly a in referencedAssemblies) {
                    environment.LoadAssembly(a);
                }
            }
        }
开发者ID:TerabyteX,项目名称:main,代码行数:32,代码来源:WebScriptHost.cs


示例5: PythonConverser

 internal PythonConverser(Socket socket, IEnumerable<NameBinding> nameBindings)
     : base(socket)
 {
     _ScriptRuntime = IronPython.Hosting.Python.CreateRuntime();
     InitialiseScriptRuntime(socket);
     BindScriptScopeNames(nameBindings);
 }
开发者ID:thelimberlambda,项目名称:ScriptServer,代码行数:7,代码来源:PythonConverser.cs


示例6: GetEngine

        public ScriptEngine GetEngine()
        {
            if (_engine != null)
                return _engine;
            _engine = Python.CreateEngine();

            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.DebugMode = true;
            setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
            ScriptRuntime runtime = new ScriptRuntime(setup);
            _engine = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);

            _engine.Runtime.IO.SetOutput(_stream, Encoding.UTF8);
            _engine.Runtime.IO.SetErrorOutput(_stream, Encoding.UTF8);
            string path = Environment.CurrentDirectory;
            string ironPythonLibPath = string.Format(@"{0}\IronPythonLib.zip", path);
            var paths = _engine.GetSearchPaths() as List<string> ?? new List<string>();
            paths.Add(path);
            paths.Add(ironPythonLibPath);
            path = Environment.GetEnvironmentVariable("IRONPYTHONPATH");
            if (!string.IsNullOrEmpty(path))
            {
                var pathStrings = path.Split(';');
                paths.AddRange(pathStrings.Where(p => p.Length > 0));
            }
            _engine.SetSearchPaths(paths.ToArray());
            return _engine;
        }
开发者ID:heyxEvget,项目名称:IronPython-Debugger,代码行数:28,代码来源:MainWindow.xaml.cs


示例7: Main

        static void Main(string[] args)
        {
            try {

                ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
                ScriptRuntime runtime = new ScriptRuntime(setup);
                runtime.GetEngine("Python").Execute("print \"Hello, Hosted Script World!\"");
                //runtime.ExecuteFile(PYTHON_FILE);

                //ScriptScope scope = runtime.GetEngine("Python").CreateScope();
                //scope.SetVariable("name", "John Zablocki");
                #region func
                //Func<string, string> reverse = (s) => {
                //        string reversed = "";
                //        for (int i = s.Length - 1; i >= 0; i--) {
                //            reversed += s[i];
                //        }
                //        return reversed;
                //    };
                //scope.SetVariable("reverse", reverse);
                #endregion
                //runtime.GetEngine("Python").ExecuteFile(PYTHON_FILE, scope);

            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:27,代码来源:Program.cs


示例8: initRuby

        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType = typeof(RhoHost);

            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"] = 0;
            languageSetup.Options["Verbosity"] = 2;

            m_runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            m_engine = IronRuby.Ruby.GetEngine(m_runtime);
            m_context = (RubyContext)Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_engine);

            m_context.ObjectClass.SetConstant("RHO_WP7", 1);
            m_context.Loader.LoadAssembly("RhoRubyLib", "rho.rubyext.rubyextLibraryInitializer", true, true);

            System.Collections.ObjectModel.Collection<string> paths = new System.Collections.ObjectModel.Collection<string>();
            paths.Add("lib");
            paths.Add("apps/app");
            m_engine.SetSearchPaths(paths);
        }
开发者ID:artemk,项目名称:rhodes,代码行数:25,代码来源:RhoRuby.cs


示例9: TestRuntime

        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;
            languageSetup.Options["NoAdaptiveCompilation"] = _driver.NoAdaptiveCompilation;
            languageSetup.Options["Verbosity"] = 2;
            languageSetup.Options["Compatibility"] = testCase.Options.Compatibility;

            _runtime = Ruby.CreateRuntime(runtimeSetup);
            _engine = Ruby.GetEngine(_runtime);
            _context = Ruby.GetExecutionContext(_engine);
        }
开发者ID:aceptra,项目名称:ironruby,代码行数:25,代码来源:Driver.cs


示例10: RubyScriptingRuntime

        public RubyScriptingRuntime() {
            _defaultLanguageSetup = Ruby.CreateRubySetup();

            var setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(_defaultLanguageSetup);
            _scriptingRuntime = new ScriptRuntime(setup);
        }
开发者ID:anycall,项目名称:Orchard,代码行数:7,代码来源:RubyScriptingRuntime.cs


示例11: Cons_NoArg1

        public void Cons_NoArg1()
        {
            var srs = new ScriptRuntimeSetup();
            Assert.AreEqual(0, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
        }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:ScriptRuntimeSetupTest.cs


示例12: DlrContext

 public DlrContext(ScriptRuntime runtime, IPathProvider pathProvider, string routesPath)
 {
     //_routesPath = routesPath;
     Runtime = runtime;
     PathProvider = pathProvider;
     //Initialize();
 }
开发者ID:jdhardy,项目名称:ironrubymvc,代码行数:7,代码来源:DlrContext.cs


示例13: Ruby

        public Ruby()
        {
            //Setup the script engine runtime
            var setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(
                new LanguageSetup(
                    "IronRuby.Runtime.RubyContext, IronRuby",
                    "IronRuby 1.0",
                    new[] { "IronRuby", "Ruby", "rb" },
                    new[] { ".rb" }));
            setup.DebugMode = true;
            
            //Create the runtime, engine, and scope
            runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, setup);
            engine = runtime.GetEngine("Ruby");
            scope = engine.CreateScope();

            try
            {
                engine.Execute(@"$RGSS_VERSION = " + Program.GetRuntime().GetRGSSVersion(), scope);
                engine.Execute(@"$GAME_DIRECTORY = '" + Program.GetRuntime().GetResourcePaths()[0].Replace(@"\", @"\\") + @"'", scope);
                engine.Execute(@"$GAME_OS_WIN = " + Program.GetRuntime().IsWindowsOS().ToString().ToLower(), scope);
            }
            catch (Exception e)
            {
                Program.Error(e.Message);
            }

            //Load system internals and our Ruby internals
            Console.WriteLine("Loading system");
            //engine.Execute(System.Text.Encoding.UTF8.GetString(Properties.Resources.System), scope);
            string script = System.Text.Encoding.UTF8.GetString(Properties.Resources.System);
            script = script.Substring(1);  //fix for a weird character that shouldn't be there o.O
            Eval(script);

            //Load the adaptable RPG datatypes
            script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG);
            script = script.Substring(1);
            Eval(script);

            //Load the version appropriate RPG datatypes
            if (Program.GetRuntime().GetRGSSVersion() == 1)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG1);
                script = script.Substring(1);
                Eval(script);
            }
            if (Program.GetRuntime().GetRGSSVersion() == 2)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG2);
                script = script.Substring(1);
                Eval(script);
            }
            if (Program.GetRuntime().GetRGSSVersion() == 3)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG3);
                script = script.Substring(1);
                Eval(script);
            }
        }
开发者ID:mattiascibien,项目名称:OpenGame.exe,代码行数:60,代码来源:Ruby.cs


示例14: Cons_NoArg2

        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");
        }
开发者ID:TerabyteX,项目名称:main,代码行数:7,代码来源:ScriptRuntimeSetupTest.cs


示例15: initRuby

        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType = typeof(RhoHost);

            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"] = 0;
            languageSetup.Options["Verbosity"] = 2;

            m_runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            m_engine = IronRuby.Ruby.GetEngine(m_runtime);
            m_context = (RubyContext)Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_engine);

            m_context.ObjectClass.SetConstant("RHO_WP7", 1);
            m_context.ObjectClass.AddMethod(m_context, "__rhoGetCallbackObject", new RubyLibraryMethodInfo(
                new[] { LibraryOverload.Create(new Func<System.Object, System.Int32, System.Object>(RhoKernelOps.__rhoGetCallbackObject), false, 0, 0) },
                RubyMethodVisibility.Public,
                m_context.ObjectClass
            ));
            m_context.Loader.LoadAssembly("RhoRubyLib", "rho.rubyext.rubyextLibraryInitializer", true, true);

            System.Collections.ObjectModel.Collection<string> paths = new System.Collections.ObjectModel.Collection<string>();
            paths.Add("lib");
            paths.Add("apps/app");
            m_engine.SetSearchPaths(paths);
        }
开发者ID:douglaslise,项目名称:rhodes,代码行数:30,代码来源:RhoRuby.cs


示例16: Main

    static void Main(string[] args)
    {
        // set path for dynamic assembly loading
        AppDomain.CurrentDomain.AssemblyResolve +=
            new ResolveEventHandler(ResolveAssembly);

        string path = System.IO.Path.Combine(exe_path, py_path);
        pyscript = System.IO.Path.Combine(path, pyscript);
        pyscript = System.IO.Path.GetFullPath(pyscript); // normalize

        // get runtime
        ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();

        LanguageSetup language = Python.CreateLanguageSetup(null);
        language.Options["Debug"] = true;
        scriptRuntimeSetup.LanguageSetups.Add(language);

        ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);

        // set sys.argv
        SetPyEnv(runtime, pyscript, args);

        // get engine
        ScriptScope scope = runtime.CreateScope();
        ScriptEngine engine = runtime.GetEngine("python");

        ScriptSource source = engine.CreateScriptSourceFromFile(pyscript);
        source.Compile();

        try {
            source.Execute(scope);
        } catch (IronPython.Runtime.Exceptions.SystemExitException e) {
            Console.WriteLine(e.StackTrace);
        }
    }
开发者ID:numerodix,项目名称:nametrans,代码行数:35,代码来源:launcher.cs


示例17: CompileModule

 public static Action<HappyRuntimeContext> CompileModule(string filename)
 {
     ScriptRuntime runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration());
     Microsoft.Scripting.Hosting.ScriptEngine engine = runtime.GetEngine("ht");
     ScriptScope globals = engine.CreateScope();
     var scriptSource = engine.CreateScriptSourceFromString(readFile(filename), filename, SourceCodeKind.File);
     return scriptSource.Execute(globals);
 }
开发者ID:dlurton,项目名称:Happy,代码行数:8,代码来源:HappyCompiler.cs


示例18: InitializeRuntime

        private void InitializeRuntime(bool debugMode) {
            RuntimeSetup = CreateRuntimeSetup();
            RuntimeSetup.DebugMode = debugMode;
            RuntimeSetup.Options["SearchPaths"] = new string[] { String.Empty };

            Runtime = new ScriptRuntime(RuntimeSetup);
            LoadDefaultAssemblies();
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:8,代码来源:DynamicEngine.cs


示例19: Configuration_MutateAndCheck

        public void Configuration_MutateAndCheck()
        {
            string configFile = GetTempConfigFile(new[] { LangSetup.Python });

            var sr = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile));
            var config1 = sr.Setup;
            config1 = null;

            Assert.IsNotNull(sr.Setup);
        }
开发者ID:TerabyteX,项目名称:main,代码行数:10,代码来源:ScriptRuntimeSetupTest.cs


示例20: Create

        public void Create()
        {
            LogTo.Debug("PythonPacketParser created");
            _runtime = Python.CreateRuntime();

            var scriptDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            if (scriptDirectory == null)
                throw new NullReferenceException("ScriptDirectory should not be null");

            LogTo.Debug("Looking for python decoder in {0}", scriptDirectory);
            watcher = new FileSystemWatcher(scriptDirectory, "*.py");

            watcher.Changed += (sender, args) => UpdateScript(args.FullPath);
            watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
            watcher.EnableRaisingEvents = true;
            UpdateScript("interpreter.py");

            try
            {
                LogTo.Debug(InterpretPacket((new UTF8Encoding()).GetBytes("Hello from Python")));
            }
            catch (Exception e)
            {
                LogTo.WarnException("Interpreting python script threw an error", e);
            }
        }
开发者ID:GeorgeHahn,项目名称:Hypertoken,代码行数:26,代码来源:PythonPacketParser.cs



注:本文中的Microsoft.Scripting.Hosting.ScriptRuntime类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Hosting.ScriptRuntimeSetup类代码示例发布时间:2022-05-26
下一篇:
C# Ast.Expression类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap