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


C# ScriptEngine.GetService方法代码示例

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


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

示例1: Parse

        private void Parse(ScriptEngine engine, Exception exc)
        {
            var service = engine.GetService<Microsoft.Scripting.Hosting.ExceptionOperations>();
            string briefMessage;
            string errorTypeName;
            service.GetExceptionMessage(exc, out briefMessage, out errorTypeName);
            var formattedMessage = service.FormatException(exc);
            /*
            var stackFrames = service.GetStackFrames(exc);
            var ctxt = Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(engine);
            var sink = ctxt.GetCompilerErrorSink();
            var rubyContext = (IronRuby.Runtime.RubyContext)ctxt;
            RubyExceptionData data = RubyExceptionData.GetInstance(exc);
            IronRuby.Builtins.RubyArray backtrace = data.Backtrace;
            var s = 12;
            */

            switch (errorTypeName)
            {
                case "TypeInitializationException":
                    MessageType = "Sorry - Iron7 is unable to use dynamic ruby delegates";
                    break;
                default:
                    MessageType = errorTypeName;
                    break;
            }
            MessageBrief = briefMessage;

            var lines = formattedMessage.Replace("\r","").Split('\n');
            AttemptParseLineNumber(lines);
            CaptureRelevantStack(lines);
        }
开发者ID:slodge,项目名称:main,代码行数:32,代码来源:RubyExceptionHelper.cs

示例2: Main

        /// <summary>
        /// Main method
        /// </summary>
        /// <param name="args">Command line args.</param>
        public static void Main(string[] args)
        {
            engine = Python.CreateEngine();
            scope = engine.CreateScope();

            engine.Runtime.LoadAssembly(typeof(TurntableBot).Assembly);
            engine.Runtime.LoadAssembly(typeof(JObject).Assembly);
            engine.Runtime.IO.RedirectToConsole();

            ScriptSource source = null;

            if (File.Exists(Script))
            {
                source = engine.CreateScriptSourceFromFile(Script);
            }
            else
            {
                Console.WriteLine("File not found");
            }

            if (source != null)
            {
                try
                {
                    source.Execute(scope);
                }
                catch (Exception e)
                {
                    ExceptionOperations ops = engine.GetService<ExceptionOperations>();
                    Console.WriteLine(ops.FormatException(e));
                }
            }

            Console.ReadLine();
        }
开发者ID:nmalaguti,项目名称:Turntable-API-sharp,代码行数:39,代码来源:Program.cs

示例3: DlrClassifier

        internal DlrClassifier(DlrClassifierProvider provider, ScriptEngine engine, ITextBuffer buffer)
        {
            buffer.Changed += BufferChanged;
            buffer.ContentTypeChanged += BufferContentTypeChanged;

            _tokenCache = new TokenCache();
            _categorizer = engine.GetService<TokenCategorizer>();
            _engine = engine;
            _provider = provider;
            _buffer = buffer;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:11,代码来源:DlrClassifier.cs

示例4: RunRawCode

        public void RunRawCode(InputImage[] images, string rawCode)
        {
            string pythonCode = this.GetFunctionCode(rawCode);

            dynamic scope = engine.CreateScope();

            try
            {
                engine.Execute(pythonCode, scope);
            }
            catch (SyntaxErrorException ex)
            {
                engine = null;
                scope = null;

                ExceptionOperations eo = engine.GetService<ExceptionOperations>();
                MessageBox.Show(eo.FormatException(ex));
            }

            if (engine == null || scope == null)
            {
                throw new Exception("Cannot create Python engine!");
            }

            ImageExtensions.SaveAction = saveCallback;

            foreach (var inputImage in images)
            {
                Image imageCopy = new Image(inputImage.SourceImage);

                try
                {
                    scope.ProcessImage(imageCopy);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error processing " + inputImage.SourceImage.Filename + ": " + ex.Message);
                }
            }
        }
开发者ID:karamanolev,项目名称:MusicDatabase,代码行数:40,代码来源:PythonExecutioner.cs

示例5: Execute

        private string Execute(ScriptEngine engine, ScriptScope scope, string script)
        {
            stdout = new MemoryStream();
            stdoutwriter = new StreamWriter(stdout);
            stdoutreader = new StreamReader(stdout);

            engine.Runtime.IO.SetOutput(stdout, stdoutwriter);

            try
            {
                m_Core.Renderer.SetExceptionCatching(true);
                dynamic ret = engine.CreateScriptSourceFromString(script).Execute(scope);
                m_Core.Renderer.SetExceptionCatching(false);
                if (ret != null)
                {
                    stdoutwriter.Write(ret.ToString() + Environment.NewLine);
                    stdoutwriter.Flush();
                }
            }
            catch (Exception ex)
            {
                m_Core.Renderer.SetExceptionCatching(false);

                // IronPython throws so many exceptions, we don't want to kill the application
                // so we just swallow Exception to cover all the bases
                string exstr = engine.GetService<ExceptionOperations>().FormatException(ex);
                stdoutwriter.Write(exstr);
                stdoutwriter.Write(Environment.NewLine);
                stdoutwriter.Flush();
            }

            stdout.Seek(0, SeekOrigin.Begin);

            string output = stdoutreader.ReadToEnd();

            stdoutreader.Dispose();

            stdout = null;
            stdoutreader = null;
            stdoutwriter = null;

            return output;
        }
开发者ID:Clever-Boy,项目名称:renderdoc,代码行数:43,代码来源:PythonShell.cs

示例6: UnhandledException

        protected virtual void UnhandledException(ScriptEngine engine, Exception e) {
            Console.Error.Write("Unhandled exception");
            Console.Error.WriteLine(':');

            ExceptionOperations es = engine.GetService<ExceptionOperations>();
            Console.Error.WriteLine(es.FormatException(e));
        }
开发者ID:jschementi,项目名称:iron,代码行数:7,代码来源:ConsoleHost.cs

示例7: 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

示例8: MacroScriptEngine

 internal MacroScriptEngine(string scriptType)
 {
     loadRunTime();
     m_engine = m_runTime.GetEngine(scriptType);
     m_exceptionOperations = m_engine.GetService<ExceptionOperations>();
 }
开发者ID:elrute,项目名称:Triphulcas,代码行数:6,代码来源:ScriptEngine.cs

示例9: GetPythonService

 private static PythonService/*!*/ GetPythonService(ScriptEngine/*!*/ engine) {
     return engine.GetService<PythonService>(engine);
 }
开发者ID:atczyc,项目名称:ironruby,代码行数:3,代码来源:Python.cs

示例10: ProcessRuntimeException

        internal static bool ProcessRuntimeException(ScriptEngine engine, Exception e, string defaultVirtualPath, int lineOffset)
        {
            var frames = engine.GetService<ExceptionOperations>().GetStackFrames(e);
            if (frames.Count == 0)
                return false;

            DynamicStackFrame frame = frames[0];
            int line = frame.GetFileLineNumber();

            // Get the physical path of the file where the exception occured, and attempt to get a
            // virtual path from it
            string physicalPath = frame.GetFileName();
            string virtualPath = Misc.GetVirtualPathFromPhysicalPath(physicalPath);

            // If we couldn't get one, use the passed in one, and adjust the line number
            if (virtualPath == null) {
                virtualPath = defaultVirtualPath;
                line += lineOffset;
            }

            Misc.ThrowException(e.Message, e, virtualPath, line);
            return true;
        }
开发者ID:TerabyteX,项目名称:main,代码行数:23,代码来源:EngineHelper.cs


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