public void AddActivity(Activity a, string Name) { var aa = new ActivityAction <UIElement>(); var da = new DelegateInArgument <UIElement>(); da.Name = Name; aa.Handler = a; ((GetElement)Activity).Body = aa; aa.Argument = da; }
Constraint <DialSipUri> MustBeInsideDialSipActivityConstraint() { var activityBeingValidated = new DelegateInArgument <DialSipUri>(); var validationContext = new DelegateInArgument <ValidationContext>(); var parent = new DelegateInArgument <Activity>(); var parentIsOuter = new Variable <bool>(); return(new Constraint <DialSipUri>() { Body = new ActivityAction <DialSipUri, ValidationContext>() { Argument1 = activityBeingValidated, Argument2 = validationContext, Handler = new Sequence() { Variables = { parentIsOuter, }, Activities = { new ForEach <Activity>() { Values = new GetParentChain() { ValidationContext = validationContext, }, Body = new ActivityAction <Activity>() { Argument = parent, Handler = new If() { Condition = new InArgument <bool>(env => parent.Get(env).GetType() == typeof(DialSip)), Then = new Assign <bool>() { To = parentIsOuter, Value = true, }, }, }, }, new AssertValidation() { Assertion = parentIsOuter, Message = "DialSipUris must be nested inside DialSip", IsWarning = false, }, }, }, }, }); }
public void ParallelForEachWithAChildThatThrowsInCancelWhileCompletionConditionIsTrue() { Variable <bool> cancelIt = new Variable <bool> { Name = "cancelIt", Default = false }; DelegateInArgument <bool> arg = new DelegateInArgument <bool>("arg"); TestParallelForEach <bool> pfeAct = new TestParallelForEach <bool> { HintIterationCount = 2, HintValues = new bool[] { true, false }, ValuesExpression = (e => new bool[] { true, false }), CurrentVariable = arg, CompletionConditionVariable = cancelIt, Body = new TestIf(HintThenOrElse.Then, HintThenOrElse.Else) { ConditionExpression = e => arg.Get(e), ThenActivity = new TestBlockingActivityWithWriteLineInCancel("writeLineInCancel", OutcomeState.Faulted) { ExpectedOutcome = Outcome.UncaughtException(typeof(TestCaseException)), }, ElseActivity = new TestSequence { Activities = { new TestDelay("d1", new TimeSpan(1)), new TestAssign <bool> { Value = true, ToVariable = cancelIt } } } } }; TestSequence root = new TestSequence { Activities = { pfeAct }, Variables = { cancelIt }, }; using (TestWorkflowRuntime testWorkflowRuntime = TestRuntime.CreateTestWorkflowRuntime(root)) { testWorkflowRuntime.ExecuteWorkflow(); Exception outException = null; testWorkflowRuntime.WaitForAborted(out outException, false); if (outException == null || outException.InnerException == null || !outException.InnerException.GetType().Equals(typeof(TestCaseException))) { throw new TestCaseException(String.Format("Workflow was suuposed to Abort with a TestCaseException, but this is the exception: {0}", outException.ToString())); } else { //Log.Info("Workflow aborted as excpected"); } } }
public Activity Create(System.Windows.DependencyObject target) { var fef = new DatabaseScope(); var aa = new ActivityAction <Connection>(); var da = new DelegateInArgument <Connection>(); da.Name = "conn"; fef.Body = aa; aa.Argument = da; return(fef); }
public Activity Create(System.Windows.DependencyObject target) { var fef = new TakeScreenshot(); var aa = new ActivityAction <ImageElement>(); var da = new DelegateInArgument <ImageElement>(); da.Name = "item"; fef.Body = aa; aa.Argument = da; return(fef); }
/// <summary> /// Creates the code for wrapping an activity. /// Returns a <see cref="System.Activities.Statements.TryCatch "/>activity that implements error handling logic /// </summary> /// <returns>The code for wrapping activity</returns> internal Activity CreateBody() { var exceptionArgument = new DelegateInArgument <Exception>(); return(new TryCatch { Try = this.CreateInternalBody(), Catches = { new Catch <FailingBuildException> { Action = new ActivityAction <FailingBuildException> { Handler = new @If { Condition = new InArgument <bool>(env => this.IgnoreExceptions.Get(env)), Else = new Rethrow() } } }, new Catch <Exception> { Action = new ActivityAction <Exception> { Argument = exceptionArgument, Handler = new Sequence { Activities = { new @If { Condition = new InArgument <bool>(env => this.LogExceptionStack.Get(env)), Then = new LogBuildError { Message = new InArgument <string>(env => FormatLogExceptionStackMessage(exceptionArgument.Get(env))) } }, new @If { Condition = new InArgument <bool>(env => this.IgnoreExceptions.Get(env)), Else = new Rethrow() } } } } } } }); }
public System.Activities.Activity Create(System.Windows.DependencyObject target) { var fef = new ForEachDataRow(); var aa = new ActivityAction <System.Data.DataRowView>(); var da = new DelegateInArgument <System.Data.DataRowView>(); da.Name = "row"; fef.Body = aa; aa.Argument = da; return(fef); }
public Activity Create(System.Windows.DependencyObject target) { var fef = new GetMails(); var aa = new ActivityAction <email>(); var da = new DelegateInArgument <email>(); da.Name = "item"; fef.Body = aa; aa.Argument = da; return(fef); }
public void ThrowWithExceptionSet() { //TestParameters.DisableXamlRoundTrip = true; DelegateInArgument <ArgumentNullException> ex = new DelegateInArgument <ArgumentNullException>(); TestSequence seq = new TestSequence("Seq") { Activities = { new TestTryCatch("Try catch finally") { Try = new TestSequence("Try") { Activities = { new TestThrow <ArgumentNullException>() { ExpectedOutcome = new CaughtExceptionOutcome(typeof(ArgumentNullException)), ExceptionExpression = (context => new ArgumentNullException("Value cannot be null.", new InvalidCastException())), } } }, Catches = { new TestCatch <InvalidCastException>() { }, new TestCatch <ArgumentNullException> { ExceptionVariable = ex, Body = new TestSequence() { Activities = { new TestWriteLine() { HintMessage = "Value cannot be null.", MessageExpression = (env) => (string)ex.Get(env).Message, }, new TestThrow <InvalidCastException>() { ExceptionExpression = (env) => (InvalidCastException)ex.Get(env).InnerException, } } }, } } } } }; TestRuntime.RunAndValidateAbortedException(seq, typeof(InvalidCastException), new Dictionary <string, string>()); }
public static Constraint VerifyParentIsReceiveRequestSendResponseScope() { DelegateInArgument <Activity> element = new DelegateInArgument <Activity>(); DelegateInArgument <ValidationContext> context = new DelegateInArgument <ValidationContext>(); DelegateInArgument <Activity> parent = new DelegateInArgument <Activity>(); Variable <bool> result = new Variable <bool>(); return(new Constraint <Activity> { Body = new ActivityAction <Activity, ValidationContext> { Argument1 = element, Argument2 = context, Handler = new Sequence { Variables = { result, }, Activities = { new ForEach <Activity> { Values = new GetParentChain { ValidationContext = context, }, Body = new ActivityAction <Activity> { Argument = parent, Handler = new If { Condition = new InArgument <bool>((env) => parent.Get(env).GetType() == typeof(ReceiveRequestSendResponseScope)), Then = new Assign <bool> { Value = true, To = result, }, }, }, }, new AssertValidation { Assertion = new InArgument <bool>((env) => result.Get(env)), Message = new InArgument <string>((env) => $"{element.Get(env).GetType().GetFriendlyName()} can only be added inside a {nameof(ReceiveRequestSendResponseScope)} activity."), PropertyName = new InArgument <string>((env) => element.Get(env).DisplayName), }, }, }, }, }); }
static Activity CreateWF() { DelegateInArgument <string> current = new DelegateInArgument <string>(); IList <string> data = new List <string>(); for (int i = 1; i < 11; i++) { data.Add(string.Format("Branch {0}", i)); } Variable <int> waitTime = new Variable <int>(); return (new Sequence { Variables = { waitTime }, Activities = { new ThrottledParallelForEach <string> { Values = new LambdaValue <IEnumerable <string> >(c => data), MaxConcurrentBranches = 3, Body = new ActivityAction <string> { Argument = current, Handler = new Sequence { Activities = { new WriteLine() { Text = new InArgument <string>(ctx => string.Format("Enter {0}", current.Get(ctx))) }, new Assign <int> { To = waitTime, Value = new InArgument <int>(ctx => new Random().Next(0, 2500)) }, new WriteLine() { Text = new InArgument <string>(ctx => string.Format("...{0} will wait for {1} millisenconds...", current.Get(ctx), waitTime.Get(ctx))) }, new Delay { Duration = new InArgument <TimeSpan>(ctx => new TimeSpan(0, 0, 0, 0, waitTime.Get(ctx))) }, new WriteLine() { Text = new InArgument <string>(ctx => string.Format("......Exit {0}", current.Get(ctx))) }, } } } } } }); }
internal static Constraint CheckThatParentsAreOfType <ActivityType, ParentType1, ParentType2>(string validationMessage) where ActivityType : Activity { var context = new DelegateInArgument <ValidationContext>(); var result = new Variable <bool>(); var element = new DelegateInArgument <ActivityType>(); var parentList = new Variable <IEnumerable <Activity> >(); var parentHasType = new InArgument <bool>( ctx => parentList.Get(ctx).Any() && (parentList.Get(ctx).ToArray().Where(t => t.GetType().Equals(typeof(ParentType1)) || t.GetType().Equals(typeof(ParentType2))).Any())); return(new Constraint <ActivityType> { Body = new ActivityAction <ActivityType, ValidationContext> { Argument1 = element, Argument2 = context, Handler = new Sequence { Variables = { result, parentList }, Activities = { new Assign <IEnumerable <Activity> > { To = parentList, Value = new GetParentChain { ValidationContext = context } }, new If { Condition = parentHasType, Then = new Assign <bool> { Value = true, To = result } }, new AssertValidation { Assertion = new InArgument <bool>(result), Message = new InArgument <string> (validationMessage), } } } } }); }
private static Constraint NoPersistInScope() { DelegateInArgument <ValidationContext> validationContext = new DelegateInArgument <ValidationContext>("validationContext"); DelegateInArgument <NoPersistScope> noPersistScope = new DelegateInArgument <NoPersistScope>("noPersistScope"); Variable <bool> isConstraintSatisfied = new Variable <bool>("isConstraintSatisfied", true); Variable <IEnumerable <Activity> > childActivities = new Variable <IEnumerable <Activity> >("childActivities"); Variable <string> constraintViolationMessage = new Variable <string>("constraintViolationMessage"); return(new Constraint <NoPersistScope> { Body = new ActivityAction <NoPersistScope, ValidationContext> { Argument1 = noPersistScope, Argument2 = validationContext, Handler = new Sequence { Variables = { isConstraintSatisfied, childActivities, constraintViolationMessage, }, Activities = { new Assign <IEnumerable <Activity> > { To = childActivities, Value = new GetChildSubtree { ValidationContext = validationContext, }, }, new Assign <bool> { To = isConstraintSatisfied, Value = new CheckNoPersistInDescendants { NoPersistScope = noPersistScope, DescendantActivities = childActivities, ConstraintViolationMessage = constraintViolationMessage, }, }, new AssertValidation { Assertion = isConstraintSatisfied, Message = constraintViolationMessage, }, } } } }); }
/// <summary> /// Validates whether the Twilio activity is contained within a CallScope activity. /// </summary> /// <returns></returns> internal static Constraint <Activity> MustBeInsideCallScopeConstraint() { var activityBeingValidated = new DelegateInArgument <Activity>(); var validationContext = new DelegateInArgument <ValidationContext>(); var parent = new DelegateInArgument <Activity>(); var parentIsCallScope = new Variable <bool>(); return(new Constraint <Activity>() { Body = new ActivityAction <Activity, ValidationContext>() { Argument1 = activityBeingValidated, Argument2 = validationContext, Handler = new Sequence() { Variables = { parentIsCallScope, }, Activities = { new ForEach <Activity>() { Values = new GetParentChain() { ValidationContext = validationContext, }, Body = new ActivityAction <Activity>() { Argument = parent, Handler = new If(env => parent.Get(env).GetType() == typeof(CallScope)) { Then = new Assign <bool>() { To = parentIsCallScope, Value = true, }, }, }, }, new AssertValidation() { Assertion = parentIsCallScope, Message = "Twilio activities must be nested inside of a CallScope", IsWarning = false, }, }, }, }, }); }
/// <summary> /// Validates whether the Dial activity contains at least one DialNoun activity. /// </summary> /// <returns></returns> Constraint <Dial> MustContainAtLeastOneNoun() { var activityBeingValidated = new DelegateInArgument <Dial>(); var validationContext = new DelegateInArgument <ValidationContext>(); var inner = new DelegateInArgument <Activity>(); var nounIsInner = new Variable <bool>(); return(new Constraint <Dial>() { Body = new ActivityAction <Dial, ValidationContext>() { Argument1 = activityBeingValidated, Argument2 = validationContext, Handler = new Sequence() { Variables = { nounIsInner, }, Activities = { new ForEach <Activity>() { Values = new GetChildSubtree() { ValidationContext = validationContext, }, Body = new ActivityAction <Activity>() { Argument = inner, Handler = new If(env => typeof(DialNoun).IsAssignableFrom(inner.Get(env).GetType())) { Then = new Assign <bool>() { To = nounIsInner, Value = true, }, }, }, }, new AssertValidation() { Assertion = nounIsInner, Message = "Dial must contain at least one DialNoun", IsWarning = false, }, }, }, }, }); }
private static Constraint SetOperationNames(TypeParameterIndex typeParameterIndex) { DelegateInArgument <Activity> element = new DelegateInArgument <Activity>(); DelegateInArgument <ValidationContext> context = new DelegateInArgument <ValidationContext>(); DelegateInArgument <Activity> child = new DelegateInArgument <Activity>(); Variable <Type> iWorkflowActivityType = new Variable <Type>(); return(new Constraint <Activity> { Body = new ActivityAction <Activity, ValidationContext> { Argument1 = element, Argument2 = context, Handler = new Sequence { Variables = { iWorkflowActivityType }, Activities = { new ForEach <Activity> { Values = new GetParentChain { ValidationContext = context, }, Body = new ActivityAction <Activity> { Argument = child, Handler = new If { Condition = new InArgument <bool>((env) => child.Get(env).IsWorkflowActivity()), Then = new Assign <Type> { Value = new InArgument <Type>((env) => child.Get(env).GetWorkflowActivityType()), To = iWorkflowActivityType, }, }, }, }, new OperationNamesSetter(typeParameterIndex) { Activity = new InArgument <Activity>((env) => element.Get(env)), IWorkflowActivityType = new InArgument <Type>((env) => iWorkflowActivityType.Get(env)), }, }, }, }, }); }
//[HostWorkflowAsWebService] public void DelayDoesNotBlockOtherExecution() { // In this scenario, I use "delayed" variable to make sure the Delay activity was not a blocking one // This is verified, by setting the "delayed" variable after Delay activity is done. DelegateInArgument <string> currentVariable = new DelegateInArgument <string>() { Name = "currentVariable" }; Variable <bool> delayed = VariableHelper.CreateInitialized <bool>("delayed", false); TimeSpan sec = new TimeSpan(0, 0, 0, 0, 1); TestParallelForEach <string> parallelForEach = new TestParallelForEach <string>("PFE") { CurrentVariable = currentVariable, Body = new TestSequence("BodyOfParallel") { Variables = { delayed }, Activities = { new TestIf("If condition", HintThenOrElse.Then, HintThenOrElse.Then) { ConditionExpression = ((env) => !delayed.Get(env)), ThenActivity = new TestSequence("Body of If") { Activities = { new TestDelay() { Duration = sec }, new TestAssign <bool> { Value = true, ToVariable = delayed } }, }, }, } }, HintValues = new string[] { "a", "b" }, ValuesExpression = (context => new string[] { "a", "b" }), HintIterationCount = 2 }; ExpectedTrace trace = parallelForEach.GetExpectedTrace(); TestRuntime.RunAndValidateWorkflow(parallelForEach, trace); }
public static Constraint CheckParent <ParentType>() { DelegateInArgument <Activity> element = new DelegateInArgument <Activity>(); DelegateInArgument <ValidationContext> context = new DelegateInArgument <ValidationContext>(); Variable <bool> result = new Variable <bool>(); DelegateInArgument <Activity> parent = new DelegateInArgument <Activity>(); return(new Constraint <Activity> { Body = new ActivityAction <Activity, ValidationContext> { Argument1 = element, Argument2 = context, Handler = new Sequence { Variables = { result }, Activities = { new ForEach <Activity> { Values = new GetParentChain { ValidationContext = context }, Body = new ActivityAction <Activity> { Argument = parent, Handler = new If() { Condition = new InArgument <bool>((env) => object.Equals(parent.Get(env).GetType(), typeof(ParentType))), Then = new Assign <bool> { Value = true, To = result } } } }, new AssertValidation { Assertion = new InArgument <bool>(result), Message = new InArgument <string> (string.Format("This activity has to be inside a {0} activity", typeof(ParentType).Name.ToString())), } } } } }); }
/// <summary> /// Validates whether the Leave activity is contained inside of an Enqueue activity. /// </summary> /// <returns></returns> Constraint <Leave> MustBeContainedInEnqueue() { var activityBeingValidated = new DelegateInArgument <Leave>(); var validationContext = new DelegateInArgument <ValidationContext>(); var outer = new DelegateInArgument <Activity>(); var enqueueIsOuter = new Variable <bool>(); return(new Constraint <Leave>() { Body = new ActivityAction <Leave, ValidationContext>() { Argument1 = activityBeingValidated, Argument2 = validationContext, Handler = new Sequence() { Variables = { enqueueIsOuter, }, Activities = { new ForEach <Activity>() { Values = new GetParentChain() { ValidationContext = validationContext, }, Body = new ActivityAction <Activity>() { Argument = outer, Handler = new If(env => typeof(Enqueue).IsAssignableFrom(outer.Get(env).GetType())) { Then = new Assign <bool>() { To = enqueueIsOuter, Value = true, }, }, }, }, new AssertValidation() { Assertion = enqueueIsOuter, Message = "Leave must be contained inside of an Enqueue.", IsWarning = false, }, }, }, }, }); }
// Create a validation to verify that there are no Persist activites inside of a NoPersistScope static Constraint VerifiyNoChildPersistActivity() { DelegateInArgument <NoPersistScope> element = new DelegateInArgument <NoPersistScope>(); DelegateInArgument <ValidationContext> context = new DelegateInArgument <ValidationContext>(); DelegateInArgument <Activity> child = new DelegateInArgument <Activity>(); Variable <bool> result = new Variable <bool>(); return(new Constraint <NoPersistScope> { Body = new ActivityAction <NoPersistScope, ValidationContext> { Argument1 = element, Argument2 = context, Handler = new Sequence { Variables = { result }, Activities = { new ForEach <Activity> { Values = new GetChildSubtree { ValidationContext = context }, Body = new ActivityAction <Activity> { Argument = child, Handler = new If() { Condition = new InArgument <bool>((env) => object.Equals(child.Get(env).GetType(), typeof(Persist))), Then = new Assign <bool> { Value = true, To = result } } } }, new AssertValidation { Assertion = new InArgument <bool>(env => !result.Get(env)), Message = new InArgument <string> ("NoPersistScope activity can't contain a Persist activity"), PropertyName = new InArgument <string>((env) => element.Get(env).DisplayName) } } } } }); }
public static Constraint HasParent <TActivity>(Func <Activity, bool> condition, string validationMessage) where TActivity : Activity { var element = new DelegateInArgument <TActivity>(); DelegateInArgument <ValidationContext> context = new DelegateInArgument <ValidationContext>(); Variable <bool> result = new Variable <bool>(); DelegateInArgument <Activity> parent = new DelegateInArgument <Activity>(); return(new Constraint <TActivity> { Body = new ActivityAction <TActivity, ValidationContext>() { Argument1 = element, Argument2 = context, Handler = new Sequence() { Variables = { result }, Activities = { new ForEach <Activity>() { Values = new GetParentChain { ValidationContext = context }, Body = new ActivityAction <Activity>() { Argument = parent, Handler = new If() { Condition = new InArgument <bool>(ctx => condition(parent.Get(ctx))), Then = new Assign <bool> { Value = true, To = result } } } }, new AssertValidation() { Assertion = new InArgument <bool>(result), Message = new InArgument <string> (validationMessage), } } } } }); }
/// <summary> /// Throws a <typeparam name="Exception"/>. /// </summary> /// <param name="exception"></param> /// <param name="displayName"></param> /// <returns></returns> public static Throw Throw(DelegateInArgument <Exception> exception, string displayName = null) { if (exception == null) { throw new ArgumentNullException(nameof(exception)); } return(new Throw() { DisplayName = displayName, Exception = exception, }); }
/// <summary> /// Executes <paramref name="body"/> for each element in <paramref name="values"/>. /// </summary> /// <typeparam name="TElement"></typeparam> /// <param name="values"></param> /// <param name="body"></param> /// <param name="displayName"></param> /// <returns></returns> public static ParallelForEach <TElement> ParallelForEach <TElement>(DelegateInArgument <IEnumerable <TElement> > values, Func <DelegateInArgument <TElement>, Activity> body, string displayName = null) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (body == null) { throw new ArgumentNullException(nameof(body)); } return(ParallelForEach(values, Delegate(body), displayName)); }
/// <summary> /// Executes <paramref name="body"/> for each element in <paramref name="values"/>. /// </summary> /// <typeparam name="TElement"></typeparam> /// <param name="values"></param> /// <param name="body"></param> /// <param name="displayName"></param> /// <returns></returns> public static ParallelForEach <TElement> ParallelForEach <TElement>(DelegateInArgument <IEnumerable <TElement> > values, Func <TElement, Task> body, string displayName = null) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (body == null) { throw new ArgumentNullException(nameof(body)); } return(ParallelForEach(values, Delegate <TElement>(arg => Invoke <TElement>(body, arg, displayName)), displayName)); }
public Activity Create(System.Windows.DependencyObject target) { Type t = typeof(GetElement); var wfdesigner = Plugin.client.Window.LastDesigner; WFHelper.DynamicAssemblyMonitor(wfdesigner.WorkflowDesigner, t.Assembly.GetName().Name, t.Assembly, true); var fef = new GetElement(); var aa = new ActivityAction<NMElement>(); var da = new DelegateInArgument<NMElement>(); da.Name = "item"; fef.Body = aa; aa.Argument = da; return fef; }
public static ActivityAction <Task> CreateActivityDelegate() { var resultTask = new DelegateInArgument <Task>(); return(new ActivityAction <Task>() { Argument = resultTask, Handler = new TaskWaiter() { ResultTask = resultTask, }, }); }
public static ActivityAction <Func <Task> > CreateActivityDelegate() { var resultTaskFunc = new DelegateInArgument <Func <Task> >(); return(new ActivityAction <Func <Task> >() { Argument = resultTaskFunc, Handler = new TaskFuncEvaluator() { ResultTaskFunc = resultTaskFunc, }, }); }
/// <summary> /// Method that handles the use of the R activities outside the R Scope, which should not be accepted. /// </summary> private static Constraint ActivityNotInRScopeWarning() { DelegateInArgument <RActivity> element = new DelegateInArgument <RActivity>(); DelegateInArgument <ValidationContext> context = new DelegateInArgument <ValidationContext>(); Variable <bool> result = new Variable <bool>(); DelegateInArgument <Activity> parent = new DelegateInArgument <Activity>(); return(new Constraint <RActivity> { Body = new ActivityAction <RActivity, ValidationContext> { Argument1 = element, Argument2 = context, Handler = new Sequence { Variables = { result }, Activities = { new ForEach <Activity> { Values = new GetParentChain { ValidationContext = context }, Body = new ActivityAction <Activity> { Argument = parent, Handler = new If() { Condition = new InArgument <bool>((env) => object.Equals(parent.Get(env).GetType(), typeof(RScope))), Then = new Assign <bool> { Value = true, To = result } } } }, new AssertValidation { Assertion = new InArgument <bool>(result), Message = new InArgument <string> ("R activities should be used only inside R scope."), } } } } }); }
static Constraint CheckParent() { DelegateInArgument <ExcelSheetExtensionCodeActivity> element = new DelegateInArgument <ExcelSheetExtensionCodeActivity>(); DelegateInArgument <ValidationContext> context = new DelegateInArgument <ValidationContext>(); Variable <bool> result = new Variable <bool>(); DelegateInArgument <Activity> parent = new DelegateInArgument <Activity>(); return(new Constraint <ExcelSheetExtensionCodeActivity> { Body = new ActivityAction <ExcelSheetExtensionCodeActivity, ValidationContext> { Argument1 = element, Argument2 = context, Handler = new Sequence { Variables = { result }, Activities = { new ForEach <Activity> { Values = new GetParentChain { ValidationContext = context }, Body = new ActivityAction <Activity> { Argument = parent, Handler = new If() { Condition = new InArgument <bool>((env) => object.Equals(parent.Get(env).GetType(), typeof(XLExcelApplicationScope))), Then = new Assign <bool> { Value = true, To = result } } } }, new AssertValidation { Assertion = new InArgument <bool>(result), Message = new InArgument <string> ("CreateState has to be inside a XL Excel Application Scope activity"), } } } } }); }
private static Constraint CheckParent() { DelegateInArgument <WhileContinue> element = new DelegateInArgument <WhileContinue>(); DelegateInArgument <ValidationContext> context = new DelegateInArgument <ValidationContext>(); Variable <bool> result = new Variable <bool>(); DelegateInArgument <Activity> parent = new DelegateInArgument <Activity>(); return(new Constraint <WhileContinue> { Body = new ActivityAction <WhileContinue, ValidationContext> { Argument1 = element, Argument2 = context, Handler = new Sequence { Variables = { result }, Activities = { new ForEach <Activity> { Values = new GetParentChain { ValidationContext = context }, Body = new ActivityAction <Activity> { Argument = parent, Handler = new If() { Condition = new InArgument <bool>((env) => (object.Equals(parent.Get(env).GetType(), typeof(DoWhileLoop)) || object.Equals(parent.Get(env).GetType(), typeof(WhileLoop)))), Then = new Assign <bool> { Value = true, To = result } } } }, new AssertValidation { Assertion = new InArgument <bool>(result), Message = new InArgument <string> ("WhileContinue has to be inside a DoWhileLoop or WhileLoop activity"), } } } } }); }
private Constraint CreateCheckDelegateRule(EditingContext editingContext) { DelegateInArgument<InvokeDelegate> invokeDelegate = new DelegateInArgument<InvokeDelegate>(); DelegateInArgument<ValidationContext> context = new DelegateInArgument<ValidationContext>(); return new Constraint<InvokeDelegate> { Body = new ActivityAction<InvokeDelegate, ValidationContext> { Argument1 = invokeDelegate, Argument2 = context, Handler = new CheckDelegateRule { Activity = invokeDelegate, EditingContext = editingContext, } } }; }
static Constraint CompensateWithNoTarget() { DelegateInArgument<Compensate> element = new DelegateInArgument<Compensate> { Name = "element" }; DelegateInArgument<ValidationContext> validationContext = new DelegateInArgument<ValidationContext> { Name = "validationContext" }; Variable<bool> assertFlag = new Variable<bool> { Name = "assertFlag" }; Variable<IEnumerable<Activity>> elements = new Variable<IEnumerable<Activity>>() { Name = "elements" }; Variable<int> index = new Variable<int>() { Name = "index" }; return new Constraint<Compensate> { Body = new ActivityAction<Compensate, ValidationContext> { Argument1 = element, Argument2 = validationContext, Handler = new Sequence { Variables = { assertFlag, elements, index }, Activities = { new If { Condition = new InArgument<bool>((env) => element.Get(env).Target != null), Then = new Assign<bool> { To = assertFlag, Value = true }, Else = new Sequence { Activities = { new Assign<IEnumerable<Activity>> { To = elements, Value = new GetParentChain { ValidationContext = validationContext, }, }, new While(env => (assertFlag.Get(env) != true) && index.Get(env) < elements.Get(env).Count()) { Body = new Sequence { Activities = { new If(env => (elements.Get(env).ElementAt(index.Get(env))).GetType() == typeof(CompensationParticipant)) { Then = new Assign<bool> { To = assertFlag, Value = true }, }, new Assign<int> { To = index, Value = new InArgument<int>(env => index.Get(env) + 1) }, } } } } } }, new AssertValidation { Assertion = new InArgument<bool>(assertFlag), Message = new InArgument<string>(SR.CompensateWithNoTargetConstraint) } } } } }; }