public object Evaluate(string expression, IEnumerable <IGlobalMethodProvider> providers)
        {
            object  execContextType = _cacheManager.Get("---", ctx => (object)_scriptingManager.ExecuteExpression(@"
class ExecBlock
    def initialize(callbacks)
        @callbacks = callbacks
    end
    def method_missing(name, *args, &block)
        @callbacks.send(name, args, &block);
    end
end
class ExecContext
    class << self
        def alloc(thing)
            instance_eval 'self.new {' + thing + '}'
        end
    end
    def initialize(&block)
        @block = block
    end
    def evaluate(callbacks)
      ExecBlock.new(callbacks).instance_eval(&@block)
    end
end
ExecContext
                                        "));
            var     ops             = _cacheManager.Get("----", ctx => (ObjectOperations)_scriptingManager.ExecuteOperation(x => x));
            object  execContext     = _cacheManager.Get(expression, ctx => (object)ops.InvokeMember(execContextType, "alloc", expression));
            dynamic result          = ops.InvokeMember(execContext, "evaluate", new CallbackApi(this, providers));

            return(ConvertRubyValue(result));
        }
Example #2
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));
        }