예제 #1
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();
            }
        }
예제 #2
0
        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;
        }
예제 #3
0
        private void CompileScript(SPItemEventProperties properties)
        {
            if (!properties.ListItem.ContentTypeId.IsChildOf(new SPContentTypeId(IronContentTypeId.IronScript)))
            {
                return;
            }

            IronRuntime runtime = null;


            try
            {
                runtime = IronRuntime.GetDefaultIronRuntime(properties.Web.Site);
                engine  = runtime.GetEngineByExtension(Path.GetExtension(properties.ListItem.File.Name));

                EventFiringEnabled = false;
                properties.ListItem[IronField.IronOutput]    = engine.ExcecuteScriptFile(properties.ListItem.File);
                properties.ListItem[IronField.IronErrorFlag] = false;
                properties.ListItem.SystemUpdate(false);

                //cause compile bug??
                // runtime.IronHive.ReloadFiles();
            }
            catch (Exception ex)
            {
                var    eo    = engine.ScriptEngine.GetService <ExceptionOperations>();
                string error = eo.FormatException(ex);

                properties.ListItem[IronField.IronOutput]    = error;
                properties.ListItem[IronField.IronErrorFlag] = true;
                properties.ListItem.SystemUpdate(false);
            }
            finally
            {
                EventFiringEnabled = true;

                if (runtime != null)
                {
                    runtime.IronHive.Dispose();
                }
            }
        }
        private void CompileScript(SPItemEventProperties properties)
        {
            
            if (!properties.ListItem.ContentTypeId.IsChildOf(new SPContentTypeId(IronContentTypeId.IronScript)))
                return;

            IronRuntime runtime = null;


            try
            {
                runtime = IronRuntime.GetDefaultIronRuntime(properties.Web.Site);
                engine =  runtime.GetEngineByExtension(Path.GetExtension(properties.ListItem.File.Name));

                EventFiringEnabled = false;
                properties.ListItem[IronField.IronOutput] = engine.ExcecuteScriptFile(properties.ListItem.File);
                properties.ListItem[IronField.IronErrorFlag] = false; 
                properties.ListItem.SystemUpdate(false);

                //cause compile bug??
               // runtime.IronHive.ReloadFiles();

            }
            catch (Exception ex)
            {
                var eo = engine.ScriptEngine.GetService<ExceptionOperations>();
                string error = eo.FormatException(ex);

                properties.ListItem[IronField.IronOutput] = error;
                properties.ListItem[IronField.IronErrorFlag] = true; 
                properties.ListItem.SystemUpdate(false);
            }
            finally
            {
                EventFiringEnabled = true;

                if (runtime != null)
                {
                    runtime.IronHive.Dispose();
                }
            }
        }
        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);
        }