Ejemplo n.º 1
0
        private bool Run(dynamic context)
        {
            using (var scope = _scriptingManager.CreateScope(context.Properties["ScriptExecutionDescription"] + " ActionScript"))
            {
                scope.SetVariable("Tokens", context.Tokens);
                var script = ((ContentItem)_contentManager.Get(int.Parse(context.Properties["ScriptExecutionScriptId"]), VersionOptions.Published)).As <IScriptAspect>();
                _scriptingManager.ExecuteExpression(script.Engine, script.Expression, scope);
            }

            return(true);
        }
        protected override DriverResult Editor(ScriptingAdminTestbedPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);

            ContentItem script;

            if (part.ScriptId != 0)
            {
                script           = part.Script = _contentManager.Get(part.ScriptId, VersionOptions.Latest);
                part.EditorShape = _contentManager.UpdateEditor(_contentManager.New("Script"), updater);
            }
            else
            {
                script           = _contentManager.New("Script");
                part.EditorShape = _contentManager.UpdateEditor(script, updater);
            }


            var scriptPart = script.As <IScriptAspect>();

            if (scriptPart == null)
            {
                throw new InvalidOperationException("The Script content type should have a part implementing IScriptAspect attached.");
            }

            if (!String.IsNullOrEmpty(scriptPart.Expression))
            {
                try
                {
                    using (var scope = _scriptingManager.CreateScope("testbed"))
                    {
                        part.Output = _scriptingManager.ExecuteExpression(scriptPart.Engine, scriptPart.Expression, scope);
                    }
                }
                catch (ScriptRuntimeException ex)
                {
                    var builder = new StringBuilder();
                    for (Exception current = ex; current != null; current = current.InnerException)
                    {
                        builder.Append(Environment.NewLine + current.Message);
                    }

                    _notifier.Error(T("There was a glitch with your code: {0}", builder.ToString()));
                }
            }

            return(Display(part, "Detail", shapeHelper));
        }