Exemplo n.º 1
0
        public void Run(ApiCredentials credentials, Form owner, bool debugMode)
        {
            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }
            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            _engine = new Engine(p => p
                                 .DebugMode(debugMode)
                                 .AllowClr()
                                 );

            _engine.SetValue("require", new Func <string, object>(RequireFunction));
            _engine.SetValue("console", FirebugConsole.CreateFirebugConsole(_engine, _output));

            new JavaScriptUtil(credentials).Setup(_engine, owner);

            try
            {
                RequireFunction("main.js");
            }
            catch (Exception ex)
            {
                var javaScriptException = ex as JavaScriptException;
                if (javaScriptException != null)
                {
                    ExceptionForm.Show(owner, javaScriptException);
                    return;
                }

                MessageBox.Show(
                    owner,
                    new StringBuilder()
                    .AppendLine("An exception occurred while executing the script:")
                    .AppendLine()
                    .Append(ex.Message).Append(" (").Append(ex.GetType().FullName).AppendLine(")")
                    .AppendLine()
                    .AppendLine(ex.StackTrace)
                    .ToString(),
                    owner.Text,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }
Exemplo n.º 2
0
        private static void HandleException(Exception ex)
        {
            var exceptionForm = new ExceptionForm(ex);

            exceptionForm.Show();
        }