Fixing decision activity

There was no way to return an outcome
This commit is contained in:
Sebastien Ros 2013-08-20 18:09:21 -07:00
parent 9ca4349218
commit 2a00ecdcfb
3 changed files with 15 additions and 7 deletions

View File

@ -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) {

View File

@ -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" }
)
);

View File

@ -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() {