当前位置: 首页>>代码示例>>C#>>正文


C# ScriptEngine.CreateScriptSourceFromString方法代码示例

本文整理汇总了C#中ScriptEngine.CreateScriptSourceFromString方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.CreateScriptSourceFromString方法的具体用法?C# ScriptEngine.CreateScriptSourceFromString怎么用?C# ScriptEngine.CreateScriptSourceFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptEngine的用法示例。


在下文中一共展示了ScriptEngine.CreateScriptSourceFromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PyMovingAverage

        public PyMovingAverage()
        {
            HandlePythonExceptions(() =>
            {
                _engine = Python.CreateEngine();

                var runtime = _engine.Runtime;
                foreach (var reference in GetReferences())
                    runtime.LoadAssembly(reference);

                string code = @"
            import sys
            sys.path.append(r'{0}')
            from MovingAverage import MovingAverage
            expert = MovingAverage()
            ";
                code = string.Format(code, GetBasePath());

                _scope = _engine.CreateScope();
                var source = _engine.CreateScriptSourceFromString(code, SourceCodeKind.Statements);
                source.Execute(_scope);
                _expert = _scope.GetVariable("expert");
                return 0;
            });
        }
开发者ID:sxbailey,项目名称:MQL4,代码行数:25,代码来源:PyMovingAverage.cs

示例2: Create

        public ICondition Create()
        {
            _engine = Ruby.CreateEngine();

            string rubyRuleTemplate;
            using (var stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream(_dslFileName))
            {
                using (var reader = new StreamReader(stream))
                {
                    rubyRuleTemplate = reader.ReadToEnd();
                }
            }
            rubyRuleTemplate = rubyRuleTemplate.Replace("$ruleAssembly$", _contextType.Namespace.Replace(".", "::"));
            rubyRuleTemplate = rubyRuleTemplate.Replace("$contextType$", _contextType.Name);
            rubyRuleTemplate = rubyRuleTemplate.Replace("$condition$", _condition);
            _source = _engine.CreateScriptSourceFromString(rubyRuleTemplate);

            var scope = _engine.CreateScope();
            _assemblies.ForEach(a => _engine.Runtime.LoadAssembly(a));

            _engine.Execute(_source.GetCode(), scope);
            var @class = _engine.Runtime.Globals.GetVariable("RubyRuleFactory");

            var installer = _engine.Operations.CreateInstance(@class);
            var rule = installer.Create();

            return (ICondition)rule;
        }
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:28,代码来源:RubyEngine.cs

示例3: IronRubyTemplateFactory

        public IronRubyTemplateFactory( ScriptEngine scriptEngine, string className )
        {
            ScriptEngine = scriptEngine;

            var format = string.Format("{0}.new.method(:render)", className);
            var scriptSource = scriptEngine.CreateScriptSourceFromString(format);
            RenderAction = scriptSource.Execute();
        }
开发者ID:Jeff-Lewis,项目名称:nhaml,代码行数:8,代码来源:IronRubyTemplateFactory.cs

示例4: Py

 public Py(Func<String> script)
 {
     _engine = ScriptRuntime.CreateFromConfiguration().GetEngine("python");
     string pythonScript = script();
     ScriptSource scriptSource = _engine.CreateScriptSourceFromString(pythonScript, SourceCodeKind.Statements);
     _scope = _engine.CreateScope();
     scriptSource.Execute(_scope);
 }
开发者ID:serakrin,项目名称:presentations,代码行数:8,代码来源:Program.cs

示例5: IronPython

            static IronPython()
            {
                pythonEngine = Python.CreateEngine();
                pythonScope = pythonEngine.CreateScope();

                var src = pythonEngine.CreateScriptSourceFromString(listisizeCode, SourceCodeKind.Statements);
                src.Execute(pythonScope);

                Listisize = pythonScope.GetVariable<Func<List<List<string>>, List<List<string>>>>("listisize");
            }
开发者ID:tomrittervg,项目名称:Sprocket,代码行数:10,代码来源:TestContext.cs

示例6: PythonLoader

        public PythonLoader(string code, string className = "PyClass")
        {
            //creating engine and stuff
            engine = Python.CreateEngine();
            scope = engine.CreateScope();

            //loading and compiling code
            source = engine.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements);
            compiled = source.Compile();
        }
开发者ID:hrkrx,项目名称:InsertNameHere,代码行数:10,代码来源:PythonLoader.cs

示例7: ScriptFilter

        public ScriptFilter(string scriptText)
        {
            Validation.CheckObject("scriptText", scriptText);

            //initialize python
            runtime = Python.CreateRuntime();
            engine = Python.GetEngine(runtime);
            //load the script
            source = engine.CreateScriptSourceFromString(scriptText);
            script = source.Compile();
        }
开发者ID:davidpet,项目名称:photography,代码行数:11,代码来源:ScriptFilter.cs

示例8: ReplWindow

        public ReplWindow()
        {
            InitializeComponent();

            _engine = Ruby.CreateEngine();
            _scope = Ruby.CreateRuntime().CreateScope();

            _scope.SetVariable("pi", Math.PI);
            _scope.SetVariable("e", Math.E);
            _scope.SetVariable("_", new Extension());

            var source = _engine.CreateScriptSourceFromString("require 'RubyInt.exe'\nrequire 'Mathos.dll'\nrequire '" + Settings.DataDirectory + "Std.rb'", SourceCodeKind.Statements);

            source.Execute(_scope);
        }
开发者ID:rodriada000,项目名称:Mathos-Project,代码行数:15,代码来源:ReplWindow.xaml.cs

示例9: PythonInstance

        public PythonInstance(string code, string className = "PyClass")
        {
            //creating engine and stuff
            engine = Python.CreateEngine();
            scope = engine.CreateScope();

            //loading and compiling codes
            source = engine.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements);
            compiled = source.Compile();

            //now executing this code (the code should contain a class)
            compiled.Execute(scope);

            //now creating an object that could be used to access the stuff inside a python script
            pythonClass = engine.Operations.Invoke(scope.GetVariable(className));
        }
开发者ID:inessadl,项目名称:kinect-2-libras,代码行数:16,代码来源:PythonInstance.cs

示例10: Engine

        public Engine(string source)
        {
            _engine = Python.CreateEngine();
            _runtime = _engine.Runtime;

            AddAssemblies();
            PublishModule();
            _scope = _engine.CreateScope();
            _scope.SetVariable("__name__", "__main__");

            Scope _main = HostingHelpers.GetScope(_scope);
            _runtime.Globals.SetVariable("__main__", _main);

            ScriptSource _script = _engine.CreateScriptSourceFromString(source, SourceCodeKind.Statements);
            _code = _script.Compile();
        }
开发者ID:rachmatg,项目名称:ironpython,代码行数:16,代码来源:Engine.cs

示例11: ExecuteRuby

        private void ExecuteRuby(string line, ScriptEngine engine, ScriptScope scope)
        {
            object result = null;

            try
            {
                ScriptSource s = engine.CreateScriptSourceFromString(line, SourceCodeKind.AutoDetect);
                result = s.Execute(scope);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            if (result != null)
                Console.WriteLine("Result from IronRuby: " + result);
            else
                Console.WriteLine("Method returned nil");
        }
开发者ID:BenHall,项目名称:EmbeddedIronRuby,代码行数:19,代码来源:DlrHost.cs

示例12: PythonInstance

        public PythonInstance(string className = "PyClass")
        {
            string code = @"
            import sys
            sys.path.append(r'C:\Program Files\IronPython 2.7\Lib')
            import os
            import hashlib
            import urllib2
            class PyClass:
            def __init__(self):
            pass

            def somemethod(self):
            print 'in some method'

            def isodd(self, n):
            return 1 == n % 2

            def get_hash(self,name):
            readsize = 64 * 1024
            with open(name, 'rb') as f:
            size = os.path.getsize(name)
            data = f.read(readsize)
            f.seek(-readsize, os.SEEK_END)
            data += f.read(readsize)
            return hashlib.md5(data).hexdigest()
            ";
            //creating engine and stuff
            engine = Python.CreateEngine();
            scope = engine.CreateScope();

            //loading and compiling code
            source = engine.CreateScriptSourceFromString(code, Microsoft.Scripting.SourceCodeKind.Statements);
            compiled = source.Compile();

            //now executing this code (the code should contain a class)
            compiled.Execute(scope);

            //now creating an object that could be used to access the stuff inside a python script
            pythonClass = engine.Operations.Invoke(scope.GetVariable(className));
        }
开发者ID:nalawade41,项目名称:movie-subtitles,代码行数:41,代码来源:movie-sbtitles.cs

示例13: Create

        public ICondition Create()
        {
            this.engine = Ruby.CreateEngine();
            var rubyRuleTemplate = String.Empty;
            using(var stream = new StreamReader(this.dslFileName))
            {
                rubyRuleTemplate = stream.ReadToEnd();
            }
            rubyRuleTemplate = rubyRuleTemplate.Replace("$ruleAssembly$", this.contextType.Namespace.Replace(".", "::"));
            rubyRuleTemplate = rubyRuleTemplate.Replace("$contextType$", this.contextType.Name);
            rubyRuleTemplate = rubyRuleTemplate.Replace("$condition$", this.condition);
            this.source = engine.CreateScriptSourceFromString(rubyRuleTemplate);
            
            var scope = engine.CreateScope();
            assemblies.ForEach(a => engine.Runtime.LoadAssembly(a));

            engine.Execute(source.GetCode(), scope);
            var @class = engine.Runtime.Globals.GetVariable("RuleRuleFactory");

            var installer = engine.Operations.CreateInstance(@class);
            var rule = installer.Create();

            return (ICondition) rule;
        }
开发者ID:JackWangCUMT,项目名称:RulesEngine,代码行数:24,代码来源:RubyEngine.cs

示例14: TestCategorizer

        public void TestCategorizer(ScriptEngine engine, string src, int charCount, params TokenInfo[] expected) {
            if (charCount == -1) charCount = src.Length;

            TokenCategorizer categorizer = engine.GetService<TokenCategorizer>();

            categorizer.Initialize(null, engine.CreateScriptSourceFromString(src), SourceLocation.MinValue);
            IEnumerable<TokenInfo> actual = categorizer.ReadTokens(charCount);

            int i = 0;
            foreach (TokenInfo info in actual) {
                Assert(i < expected.Length);
                if (!info.Equals(expected[i])) {
                    Assert(false);
                }
                i++;
            }
            Assert(i == expected.Length);
        }
开发者ID:toddb,项目名称:ironruby,代码行数:18,代码来源:ParserTests.cs

示例15: SetScriptedSend

        internal static string SetScriptedSend(ScriptEngine Engine, string Code)
        {
            try
            {
                ScriptRuntime Runtime = Engine.Runtime;
                Assembly MainAssembly = Assembly.GetExecutingAssembly();
                string RootDir = Directory.GetParent(MainAssembly.Location).FullName;
                Runtime.LoadAssembly(MainAssembly);
                Runtime.LoadAssembly(typeof(String).Assembly);
                Runtime.LoadAssembly(typeof(Uri).Assembly);

                if (Engine.Setup.DisplayName.Contains("IronPython"))
                {
                    string[] Results = PluginEditor.CheckPythonIndentation(Code);
                    if (Results[1].Length > 0)
                    {
                        throw new Exception(Results[1]);
                    }
                }

                ScriptSource Source = Engine.CreateScriptSourceFromString(Code);
                Source.ExecuteProgram();
                return "";
            }
            catch (Exception Exp)
            {
                return Exp.Message;
            }
        }
开发者ID:herotheo,项目名称:IronWASP,代码行数:29,代码来源:IronProxy.cs


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