Exemple #1
0
        /// <summary>
        /// Displays an error
        /// </summary>
        /// <param name="targetElementId">HTML id to put error information into</param>
        /// <param name="e">Exception to get error info out of</param>
        internal static void DisplayError(string targetElementId, Exception e)
        {
            // we only support displaying one error
            if (_displayedError)
            {
                return;
            }
            _displayedError = true;

            // keep track of the runtime if it exists
            if (DynamicApplication.Current.Engine != null)
            {
                _runtime = DynamicApplication.Current.Engine.Runtime;
            }

            // show the window in the targetElementId
            Window.Show(targetElementId);

            // show the Repl if we can get to the current engine
            if (DynamicApplication.Current.Engine != null)
            {
                Repl.Show();
            }

            // format the Exception
            string result;

            try {
                result = FormatErrorAsHtml(e);
            } catch (Exception ex) {
                result = EscapeHtml(ex.ToString());
            }

            // Create a "div" with class/id set as the _errorReportId, and put
            // formatted exception into it.
            var report = HtmlPage.Document.CreateElement("div");

            report.Id = report.CssClass = _errorReportId;
            report.SetProperty("innerHTML", result);

            // Adds a new panel to the "Window", initialize it, and force the panel to be shown.
            Window.Current.AddPanel("Error Report (" + EscapeHtml(new DynamicExceptionInfo(e).ErrorTypeName) + ")", report);
            Window.Current.Initialize();
            Window.Current.ShowPanel(report.Id);
        }
Exemple #2
0
 /// <summary>
 /// Starts the dynamic application
 /// </summary>
 void DynamicApplication_Startup(object sender, StartupEventArgs e)
 {
     Settings.Parse(InitParams = NormalizeInitParams(e.InitParams));
     ScriptTags = new DynamicScriptTags(LanguagesConfig);
     XamlScriptTags.Load();
     LanguagesConfig.DownloadLanguages(AppManifest, () => {
         ScriptTags.DownloadExternalCode(() => {
             Engine = new DynamicEngine();
             if (Settings.ConsoleEnabled && LanguagesConfig.LanguagesUsed.Count > 0)
             {
                 Console = Repl.Show();
             }
             LanguageTypeExtensions.Load(Engine.LangConfig);
             ScriptTags.Run(Engine);
             Engine.Run(Settings.EntryPoint);
         });
     });
 }
Exemple #3
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RootVisual = new MainPage();

            var runtime = Silverlight.DynamicEngine.CreateRuntime();
            _python = runtime.GetEngine("python");

            _scope = _python.CreateScope();
            _repl = Silverlight.Repl.Show(_python, _scope);
            _scope.SetVariable("app", this);

            try {
                test("Execute strings", "4", "2 + 2");
                test("Import .NET namespace", "hi", @"import System
            System.String('hi')");
                _python.Execute(@"import foo
            foo.test(app)
            foo.test_import(app)", _scope);
            } catch(Exception ex) {
                _repl.OutputBuffer.WriteLine("[FAIL]");
                _repl.OutputBuffer.Write(_python.GetService<Hosting.ExceptionOperations>().FormatException(ex));
            }
        }
Exemple #4
0
 private IReplFormatter GetReplFormatter(Repl instance)
 {
     _neutralFormatter = new LanguageNeutralFormatter(this);
     if (_engine.Setup.FileExtensions.Count > 0)
     {
         string path = string.Format("repl_formatter{0}", _engine.Setup.FileExtensions[0]);
         string code = DynamicApplication.GetResource(path);
         if (code != null)
         {
             var scope = _engine.CreateScope();
             try {
                 _engine.CreateScriptSourceFromString(code, path).Execute(scope);
                 var CreateReplFormatter = scope.GetVariable <Func <Repl, IReplFormatter, IReplFormatter> >("create_repl_formatter");
                 if (CreateReplFormatter != null)
                 {
                     return(CreateReplFormatter(this, _neutralFormatter));
                 }
             } catch (Exception e) {
                 DynamicApplication.Current.HandleException(this, e);
             }
         }
     }
     return(_neutralFormatter);
 }
Exemple #5
0
 public ReplInputBuffer(Repl console) {
     _console = console;
 }
Exemple #6
0
 public static HtmlElement Create(ScriptEngine engine, ScriptScope scope) {
     HtmlElement replDiv = null;
     if (_current == null) {
         replDiv = HtmlPage.Document.CreateElement("div");
         replDiv.Id = _sdlr;
         replDiv.SetProperty("innerHTML", _replHtmlTemplate);
         _current = new Repl(engine, scope);
     }
     return replDiv;
 }
Exemple #7
0
 public LanguageNeutralFormatter(Repl repl) {
     CurrentRepl = repl;
 }
Exemple #8
0
 private IReplFormatter GetReplFormatter(Repl instance) {
     _neutralFormatter = new LanguageNeutralFormatter(this);
     if (_engine.Setup.FileExtensions.Count > 0) {
         string path = string.Format("repl_formatter{0}", _engine.Setup.FileExtensions[0]);
         string code = DynamicApplication.GetResource(path);
         if (code != null) {
             var scope = _engine.CreateScope();
             try {
                 _engine.CreateScriptSourceFromString(code, path).Execute(scope);
                 var CreateReplFormatter = scope.GetVariable<Func<Repl, IReplFormatter, IReplFormatter>>("create_repl_formatter");
                 if (CreateReplFormatter != null) {
                     return CreateReplFormatter(this, _neutralFormatter);
                 }
             } catch (Exception e) {
                 DynamicApplication.Current.HandleException(this, e);
             }
         }
     }
     return _neutralFormatter;
 }
Exemple #9
0
 public ReplInputBuffer(Repl console)
 {
     _console = console;
 }
Exemple #10
0
 public LanguageNeutralFormatter(Repl repl)
 {
     CurrentRepl = repl;
 }