public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
        {
            var script = activityContext.GetState <string>("Script");

            if (!String.IsNullOrWhiteSpace(script))
            {
                var submission = (FormSubmissionTokenContext)workflowContext.Tokens["FormSubmission"];

                // Start the script with the new token syntax.
                script = "// #{ }" + System.Environment.NewLine + script;

                if (workflowContext.Content != null)
                {
                    _csharpService.SetParameter("ContentItem", (dynamic)workflowContext.Content.ContentItem);
                }

                _csharpService.SetParameter("Services", _orchardServices);
                _csharpService.SetParameter("WorkContext", _workContextAccessor.GetContext());
                _csharpService.SetParameter("Workflow", workflowContext);
                _csharpService.SetFunction("T", (Func <string, string>)(x => T(x).Text));
                _csharpService.SetFunction("AddModelError", (Action <string, LocalizedString>)((key, message) => submission.ModelState.AddModelError(key, message.Text)));

                _csharpService.Run(script);
            }

            return(base.Execute(workflowContext, activityContext));
        }
Exemple #2
0
        public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
        {
            var    script  = activityContext.GetState <string>("Script");
            object outcome = null;

            _csharpService.SetParameter("Services", _orchardServices);
            _csharpService.SetParameter("ContentItem", (dynamic)workflowContext.Content.ContentItem);
            _csharpService.SetParameter("WorkContext", _workContextAccessor.GetContext());
            _csharpService.SetFunction("T", (Func <string, string>)(x => T(x).Text));
            _csharpService.SetFunction("SetOutcome", (Action <object>)(x => outcome = x));

            _csharpService.Run(script);

            yield return(T(Convert.ToString(outcome)));
        }
        protected override DriverResult Editor(ScriptValidationPart part, Orchard.ContentManagement.IUpdateModel updater, dynamic shapeHelper)
        {
            var script = part.Settings.GetModel <ScriptValidationPartSettings>().Script;

            if (!String.IsNullOrWhiteSpace(script))
            {
                _csharpService.SetParameter("Services", _orchardServices);
                _csharpService.SetParameter("ContentItem", (dynamic)part.ContentItem);
                _csharpService.SetParameter("WorkContext", _workContextAccessor.GetContext());
                _csharpService.SetFunction("T", (Func <string, string>)(x => T(x).Text));
                _csharpService.SetFunction("AddModelError", (Action <string>)(x => updater.AddModelError("Script", T(x))));

                _csharpService.Run(script);
            }

            return(Editor(part, shapeHelper));
        }
Exemple #4
0
        public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
        {
            var    script  = activityContext.GetState <string>("Script");
            object outcome = null;

            // Start the script with the new token syntax.
            script = "// #{ }" + System.Environment.NewLine + script;

            if (workflowContext.Content != null)
            {
                _csharpService.SetParameter("ContentItem", (dynamic)workflowContext.Content.ContentItem);
            }

            _csharpService.SetParameter("Services", _orchardServices);
            _csharpService.SetParameter("WorkContext", _workContextAccessor.GetContext());
            _csharpService.SetParameter("Workflow", workflowContext);
            _csharpService.SetFunction("T", (Func <string, string>)(x => T(x).Text));
            _csharpService.SetFunction("SetOutcome", (Action <object>)(x => outcome = x));

            _csharpService.Run(script);

            yield return(T(Convert.ToString(outcome)));
        }