Beispiel #1
0
 void ExecuteAfterHooks(ScriptEngine scriptEngine, IronConsoleResult ironConsoleResult)
 {
     foreach (var hook in _hooks)
     {
         hook.AfterExecute(scriptEngine, ironConsoleResult);
     }
 }
Beispiel #2
0
        public void Execute()
        {
            IronConsoleResult = new IronConsoleResult();
            try
            {
                _engine = _runtime.GetEngineByExtension(_extension, false);
                var scriptEngine = _engine.ScriptEngine;

                ExecuteBeforeHooks(scriptEngine, IronConsoleResult);

                var expressionResult = scriptEngine.Execute(_expression, _runtime.ScriptRuntime.Globals);
                IronConsoleResult.Result = expressionResult != null?expressionResult.ToString() : null;

                ExecuteAfterHooks(scriptEngine, IronConsoleResult);
            }
            catch (Exception ex)
            {
                IronConsoleResult.Error      = ex.Message;
                IronConsoleResult.StackTrace = ex.StackTrace;

                if (_engine != null)
                {
                    try
                    {
                        var eo = _engine.ScriptEngine.GetService <ExceptionOperations>();
                        IronConsoleResult.StackTrace = eo.FormatException(ex);
                    }
                    catch { }
                }
            }
            finally
            {
                _waitHandle.Set();
            }
        }
Beispiel #3
0
 void ExecuteBeforeHooks(ScriptEngine scriptEngine, IronConsoleResult ironConsoleResult)
 {
     foreach (var hook in _hooks)
     {
         hook.BeforeExecute(scriptEngine, ironConsoleResult);
     }
 }
        public void ProcessRequest(HttpContext context)
        {
            var response = new IronConsoleResult();
            var jsonResponse = string.Empty;

            try
            {
                var site = SPContext.Current.Site;
                var web = SPContext.Current.Web;
                if (!web.CurrentUser.IsSiteAdmin)
                {
                    context.Response.Write("Only Site Admins are allowed to use the Console");
                    return;
                }

                IronHiveRegistry.Local.EnsureTrustedHive(site.ID);

                //var ironRuntime = IronRuntime.GetIronRuntime(site, site.ID);
                var ironRuntime = IronRuntime.GetDefaultIronRuntime(site);
                var extension = HttpContext.Current.Request["ext"];
                var expression = HttpContext.Current.Request["expression"];

                if (expression == "_ = (kill);_.inspect")
                {
                    ironRuntime.Dispose();
                    response.Output = "Runtime disposed.";
                }
                else if(expression == "_ = (sp_status);_.inspect")
                {

                }
                else
                {
                    response = ironRuntime.IronConsole.Execute(expression, extension);
                }
            }
            catch (Exception ex)
            {
                response.Error = ex.Message;
                response.StackTrace = ex.StackTrace;
            }
            finally
            {
                if (response == null)
                {
                    response = new IronConsoleResult();
                    response.Error = "Request timed out";
                }

                jsonResponse = response.ToJson();
            }

            context.Response.Write(jsonResponse);
        }