mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-08-01 18:13:08 +08:00
Fixing decision activity
There was no way to return an outcome
This commit is contained in:
parent
9ca4349218
commit
2a00ecdcfb
@ -45,18 +45,18 @@ namespace Orchard.Scripting.CSharp.Activities {
|
||||
}
|
||||
|
||||
public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {
|
||||
var properties = new Dictionary<string, string> {
|
||||
{"Script", activityContext.GetState<string>("Script")}
|
||||
};
|
||||
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));
|
||||
|
||||
var scriptResult = _csharpService.Evaluate(properties["Script"]).ToString();
|
||||
_csharpService.Run(script);
|
||||
|
||||
yield return T(scriptResult);
|
||||
yield return T(Convert.ToString(outcome));
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetOutcomes(ActivityContext context) {
|
||||
|
@ -25,7 +25,7 @@ namespace Orchard.Scripting.CSharp.Forms {
|
||||
_Script: Shape.TextArea(
|
||||
Id: "Script", Name: "Script",
|
||||
Title: T("Script"),
|
||||
Description: T("The script to run every time the Decision Activity is invoked. You can use ContentItem, Services, WorkContext, and T(). Return type must be a string."),
|
||||
Description: T("The script to run every time the Decision Activity is invoked. You can use ContentItem, Services, WorkContext, and T(). Call SetOutcome(string outcome) to define the outcome of the activity."),
|
||||
Classes: new[] { "tokenized" }
|
||||
)
|
||||
);
|
||||
|
@ -32,7 +32,15 @@ namespace Orchard.Scripting.CSharp.Services {
|
||||
public object Evaluate(string script) {
|
||||
DemandCompiler();
|
||||
|
||||
return Engine.Evaluate(script);
|
||||
object result;
|
||||
bool resultSet;
|
||||
|
||||
Engine.Evaluate(script, out result, out resultSet);
|
||||
if (resultSet) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void DemandCompiler() {
|
||||
|
Loading…
Reference in New Issue
Block a user