/// <summary>
        /// Runs the registered script tags against the DynamicEngine.
        /// </summary>
        public void Run(DynamicEngine engine)
        {
            var inlineScope = engine.CreateScope();

            foreach (var sc in Code)
            {
                engine.Engine = _LangConfig.GetEngine(sc.Language);
                if (engine.Engine != null && !sc.Defer)
                {
                    ScriptSource sourceCode = null;
                    ScriptScope  scope      = null;
                    if (sc.External != null)
                    {
                        var code = BrowserPAL.PAL.VirtualFilesystem.GetFileContents(sc.External);
                        if (code == null)
                        {
                            continue;
                        }
                        sourceCode =
                            engine.Engine.CreateScriptSourceFromString(
                                code,
                                DynamicApplication.BaseUri.MakeRelativeUri(sc.External).ToString(),
                                SourceCodeKind.File
                                );
                        scope = engine.CreateScope();
                    }
                    else if (sc.Inline != null)
                    {
                        Assert.NotNull(DynamicApplication.HtmlPageUri);
                        var page = BrowserPAL.PAL.VirtualFilesystem.GetFileContents(DynamicApplication.HtmlPageUri);
                        var code = AlignSourceLines(sc.Inline, page);
                        sourceCode =
                            engine.Engine.CreateScriptSourceFromString(
                                RemoveMargin(code),
                                DynamicApplication.HtmlPageUri.ToString(),
                                SourceCodeKind.File
                                );
                        scope = inlineScope;
                    }
                    if (sourceCode != null && scope != null)
                    {
                        RunningScriptTags = true;
                        sourceCode.Compile(new ErrorFormatter.Sink()).Execute(scope);
                        RunningScriptTags = false;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Runs the registered script tags against the DynamicEngine.
        /// </summary>
        public void Run(DynamicEngine engine)
        {
            var inlineScope = engine.CreateScope();

            foreach (var sc in Code)
            {
                engine.Engine = _LangConfig.GetEngine(sc.Language);
                if (engine.Engine != null && !sc.Defer)
                {
                    ScriptSource sourceCode = null;
                    ScriptScope  scope      = null;
                    if (sc.External != null)
                    {
                        var code = BrowserPAL.PAL.VirtualFilesystem.GetFileContents(sc.External);
                        if (code == null)
                        {
                            continue;
                        }
                        sourceCode =
                            engine.Engine.CreateScriptSourceFromString(
                                code,
                                sc.External.AbsoluteUri,
                                SourceCodeKind.File
                                );
                        scope = engine.CreateScope();
                    }
                    else if (sc.Inline != null)
                    {
                        sourceCode =
                            engine.Engine.CreateScriptSourceFromString(
                                sc.Inline,
                                "main" + engine.LangConfig.GetLanguageByName(sc.Language).Extensions[0],
                                SourceCodeKind.File
                                );
                        scope = inlineScope;
                    }
                    if (sourceCode != null && scope != null)
                    {
                        RunningScriptTags = true;
                        sourceCode.Compile(new ErrorFormatter.Sink()).Execute(scope);
                        RunningScriptTags = false;
                    }
                }
            }
        }