public static void ValidateReferenceExpressionXaml <T>(TestExpression te) { Expression <Func <ActivityContext, T> > lambdaExpression = (Expression <Func <ActivityContext, T> >)te.CreateLambdaExpresson <T>(); //Log.TraceInternal("Expression: {0}", lambdaExpression.ToString()); Activity expectedActivity = te.CreateExpectedActivity() as Activity; Activity actualActivity = ExpressionServices.ConvertReference(lambdaExpression); ValidateActivity(expectedActivity, actualActivity); }
public static Activity <Location <TResult> > ConvertReference <TResult>(Expression <Func <ActivityContext, TResult> > expression, Exception expectedException) { Activity <Location <TResult> > result = null; if (expectedException != null) { ExceptionHelpers.CheckForException( expectedException.GetType(), expectedException.Message, () => { result = ExpressionServices.ConvertReference <TResult>(expression); }, true); } else { result = ExpressionServices.ConvertReference <TResult>(expression); } return(result); }
public override Sequence CreateActualWorkflow <TResult>() { Expression <Func <ActivityContext, TResult> > lambdaExpression = Expression.Lambda <Func <ActivityContext, TResult> >(this.CreateLinqExpression(), TestExpression.EnvParameter); Activity <Location <TResult> > we = ExpressionServices.ConvertReference(lambdaExpression); Sequence sequence = new Sequence() { Activities = { new Assign <TResult>() { Value = (TResult)FromValue, To = we }, new WriteLine() { Text = new InArgument <string>(ToExpression) } } }; return(sequence); }
private Activity CreateXamlSerializableCodeWorkflow() { Variable <Employee> e1 = new Variable <Employee> { Name = "Employee1", Default = ExpressionServices.Convert <Employee>(ctx => new Employee("John", "Doe", 55000.0)) }; Variable <Employee> e2 = new Variable <Employee> { Name = "Employee2", Default = ExpressionServices.Convert <Employee>(ctx => new Employee("Frank", "Kimono", 89000.0)) }; Variable <SalaryStats> stats = new Variable <SalaryStats> { Name = "SalaryStats", Default = ExpressionServices.Convert <SalaryStats>(ctx => new SalaryStats()) }; Variable <Double> v1 = new Variable <double>(); // Lambda expressions do not serialize to XAML. ExpressionServices utility class can be used to // convert them to operator activities, which do serialize to XAML. // ExpressionServices.Convert applies to r-values, which cannot be assigned to. // ExpressionServices.ConvertReference applies to l-values, which can be the target of an assignment. // Note that conversion is supported for a limited set of lambda expressions only. Sequence workflow = new Sequence() { Variables = { e1, e2, stats, v1, }, Activities = { new WriteLine() { Text = ExpressionServices.Convert <string>(ctx => e1.Get(ctx).FirstName + " " + e1.Get(ctx).LastName + " earns " + e1.Get(ctx).Salary.ToString("$0.00")), }, new WriteLine() { Text = ExpressionServices.Convert <string>(ctx => e2.Get(ctx).FirstName + " " + e2.Get(ctx).LastName + " earns " + e2.Get(ctx).Salary.ToString("$0.00")), }, new Assign <double>() { To = ExpressionServices.ConvertReference <double>(ctx => stats.Get(ctx).MinSalary), Value = ExpressionServices.Convert <double>(ctx => Math.Min(e1.Get(ctx).Salary, e2.Get(ctx).Salary)) }, new Assign <double>() { To = ExpressionServices.ConvertReference <double>(ctx => stats.Get(ctx).MaxSalary), Value = ExpressionServices.Convert <double>(ctx => Math.Max(e1.Get(ctx).Salary, e2.Get(ctx).Salary)) }, new Assign <double>() { To = ExpressionServices.ConvertReference <double>(ctx => stats.Get(ctx).AvgSalary), Value = ExpressionServices.Convert <double>(ctx => (e1.Get(ctx).Salary + e2.Get(ctx).Salary) / 2.0) }, new WriteLine() { Text = ExpressionServices.Convert <string>(ctx => String.Format( "Salary statistics: minimum salary is {0:$0.00}, maximum salary is {1:$0.00}, average salary is {2:$0.00}", stats.Get(ctx).MinSalary, stats.Get(ctx).MaxSalary, stats.Get(ctx).AvgSalary)) } }, }; return(workflow); }