Exemple #1
0
        //private void OnPreRequest(object sender, EventArgs e)
        //{
        //    var application = sender as HttpApplication;
        //    var context = application.Context;

        //    if (SPContext.Current != null)
        //    {
        //        var runtime = IronRuntime.GetDefaultIronRuntime(SPContext.Current.Site);
        //        context.Items[IronHelper.GetPrefixedKey("Runtime")] = runtime;
        //    }
        //}

        void Error(object sender, EventArgs e)
        {
            var application = sender as HttpApplication;

            if (SPContext.Current != null)
            {
                var runtime = IronRuntime.GetDefaultIronRuntime(SPContext.Current.Site);

                var logger = new IronLogger(runtime);

                var exception = application.Server.GetLastError();

                logger.Log(String.Format("Error: {0} at {1}!", exception.Message, exception.StackTrace), LogLevel.Fatal);

                //hack: ruby engine hard coded
                var engine = runtime.GetEngineByExtension(".rb");

                if (engine != null)
                {
                    var    eo    = engine.ScriptEngine.GetService <ExceptionOperations>();
                    string error = eo.FormatException(exception);

                    logger.Log(String.Format("Ruby Error: {0} at {1}", exception.Message, error), LogLevel.Fatal);
                }
            }
        }
Exemple #2
0
        public override void Execute(Guid targetInstanceId)
        {
            using (SPSite site = new SPSite(HiveId))
            {
                var runtime = IronRuntime.GetDefaultIronRuntime(site);

                if (String.IsNullOrEmpty(Script))
                {
                    runtime.IronConsole.Execute(Script, ".rb", true);
                }
            }
        }
        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);
        }
        public override object EvaluateExpression(object target, System.Web.UI.BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
        {
            string value      = String.Empty;
            string scriptName = entry.Expression;

            try
            {
                string functionName = null;

                if (scriptName.Contains("@"))
                {
                    var tmp = scriptName.Split('@');
                    functionName = tmp[0].Trim();
                    scriptName   = tmp[1].Trim();
                }
                else
                {
                    throw new ArgumentException("Invalid expression! Use <%$Iron:My.sayHello@my/functions.rb");
                }

                engine = IronRuntime.GetDefaultIronRuntime(SPContext.Current.Site).GetEngineByExtension(Path.GetExtension(scriptName));
                value  = engine.InvokeDynamicFunction(functionName, scriptName, target, entry).ToString();
            }
            catch (Exception ex)
            {
                IronRuntime.LogError("Error", ex);

                if (SPContext.Current.Web.UserIsSiteAdmin && engine.IronRuntime.IronHive.Web.CurrentUser.IsSiteAdmin)
                {
                    var    eo    = engine.ScriptEngine.GetService <ExceptionOperations>();
                    string error = eo.FormatException(ex);

                    IronRuntime.LogError(String.Format("Error executing script {0}: {1}", scriptName, error), ex);

                    value = error;

                    if (engine != null)
                    {
                        new IronLogger(engine.IronRuntime).Log(String.Format("Ruby Error: {0} at {1}", ex.Message, error));
                    }
                }
                else
                {
                    value = "Error occured";
                }
            }

            return(value);
        }
Exemple #5
0
        protected override void OnInit(EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(ScriptName))
                {
                    Exception = new InvalidEnumArgumentException("Property ScriptName is empty!");
                }
                else if (String.IsNullOrEmpty(ScriptClass))
                {
                    Exception = new InvalidEnumArgumentException("Property ScriptClass is empty!");
                }

                if (Exception != null)
                {
                    return;
                }

                //Guid hiveId = String.IsNullOrEmpty(ScriptHiveId) ? Guid.Empty : new Guid(ScriptHiveId);
                //IronRuntime ironRuntime = IronRuntime.GetIronRuntime(SPContext.Current.Site, hiveId);

                IronRuntime ironRuntime = IronRuntime.GetDefaultIronRuntime(SPContext.Current.Site);
                engine = ironRuntime.GetEngineByExtension(Path.GetExtension(ScriptName));

                if (engine != null)
                {
                    ctrl = engine.CreateDynamicInstance(ScriptClass, ScriptName) as Control;

                    var dynamicControl = ctrl as IIronControl;
                    if (dynamicControl != null)
                    {
                        dynamicControl.WebPart = null;
                        dynamicControl.Data    = null;
                        dynamicControl.Config  = Config;
                    }

                    this.Controls.Add(ctrl);
                }
            }
            catch (Exception ex)
            {
                Exception = ex;
            }

            base.OnInit(e);
        }
        protected override void OnInit(EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(ScriptName))
                {
                    _exception = new InvalidEnumArgumentException("Property ScripName is empty!");
                }
                else if (String.IsNullOrEmpty(ScriptClass))
                {
                    _exception = new InvalidEnumArgumentException("Property ScripClass is empty!");
                }

                if (_exception != null)
                {
                    return;
                }

                Guid hiveId = String.IsNullOrEmpty(ScriptHiveId) ? Guid.Empty : new Guid(ScriptHiveId);

                //IronRuntime ironRuntime = IronRuntime.GetIronRuntime(SPContext.Current.Site, hiveId);
                IronRuntime ironRuntime = IronRuntime.GetDefaultIronRuntime(SPContext.Current.Site);
                engine = ironRuntime.GetEngineByExtension(Path.GetExtension(ScriptName));

                if (engine != null)
                {
                    ctrl = engine.CreateDynamicInstance(ScriptClass, ScriptName) as Control;

                    var dynamicControl = ctrl as IIronControl;
                    if (dynamicControl != null)
                    {
                        dynamicControl.WebPart = null;
                        dynamicControl.Data    = null;
                        dynamicControl.Config  = Config;
                    }

                    if (Template != null)
                    {
                        Template.InstantiateIn(ctrl);
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(TemplatePath))
                        {
                            var path = TemplatePath.Replace("~site", SPContext.Current.Site.ServerRelativeUrl)
                                       .Replace("~web", SPContext.Current.Web.ServerRelativeUrl)
                                       .Replace("~hiveSite", engine.IronRuntime.IronHive.Site.ServerRelativeUrl)
                                       .Replace("~hiveWeb", engine.IronRuntime.IronHive.Web.ServerRelativeUrl)
                                       .Replace("~hiveFolder", engine.IronRuntime.IronHive.Folder.ServerRelativeUrl);

                            Template = this.LoadTemplate(path);
                            Template.InstantiateIn(ctrl);
                        }
                    }

                    this.Controls.Add(ctrl);
                }
            }
            catch (Exception ex)
            {
                IronDiagnosticsService.Local.WriteTrace(1, IronDiagnosticsService.Local[IronCategoryDiagnosticsId.Controls], TraceSeverity.Unexpected, String.Format("Error: {0}; Stack: {1}", ex.Message, ex.StackTrace));
                _exception = ex;
            }

            base.OnInit(e);
        }