protected override void Execute(NativeActivityContext context) { if (Delegate == null || Delegate.Handler == null) { if (this.Default != null) { context.ScheduleActivity(this.Default); } return; } Dictionary <string, object> inputParameters = new Dictionary <string, object>(); if (DelegateArguments.Count > 0) { foreach (KeyValuePair <string, Argument> entry in DelegateArguments) { if (ArgumentDirectionHelper.IsIn(entry.Value.Direction)) { inputParameters.Add(entry.Key, entry.Value.Get(context)); } } } context.ScheduleDelegate(Delegate, inputParameters, new DelegateCompletionCallback(OnHandlerComplete), null); }
protected override void GatherOutputs(ActivityInstance completedInstance) { if (completedInstance.Activity.HandlerOf != null) { IList <RuntimeDelegateArgument> runtimeArguments = completedInstance.Activity.HandlerOf.RuntimeDelegateArguments; LocationEnvironment environment = completedInstance.Environment; for (int i = 0; i < runtimeArguments.Count; i++) { RuntimeDelegateArgument runtimeArgument = runtimeArguments[i]; if (runtimeArgument.BoundArgument != null) { if (ArgumentDirectionHelper.IsOut(runtimeArgument.Direction)) { Location parameterLocation = environment.GetSpecificLocation(runtimeArgument.BoundArgument.Id); if (parameterLocation != null) { if (_results == null) { _results = new Dictionary <string, object>(); } _results.Add(runtimeArgument.Name, parameterLocation.Value); } } } } } }
internal static void ValidateRootInputs(Activity rootActivity, IDictionary <string, object> inputs) { IList <ValidationError> validationErrors = null; ValidationHelper.ValidateArguments(rootActivity, rootActivity.EquivalenceInfo, rootActivity.OverloadGroups, rootActivity.RequiredArgumentsNotInOverloadGroups, inputs, ref validationErrors); if (inputs != null) { List <string> c = null; IEnumerable <RuntimeArgument> enumerable = from a in rootActivity.RuntimeArguments where ArgumentDirectionHelper.IsIn(a.Direction) select a; foreach (string str in inputs.Keys) { bool flag = false; foreach (RuntimeArgument argument in enumerable) { if (argument.Name == str) { flag = true; object obj2 = null; if (inputs.TryGetValue(str, out obj2) && !TypeHelper.AreTypesCompatible(obj2, argument.Type)) { ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.InputParametersTypeMismatch(argument.Type, argument.Name), rootActivity)); } break; } } if (!flag) { if (c == null) { c = new List <string>(); } c.Add(str); } } if (c != null) { ActivityUtilities.Add <ValidationError>(ref validationErrors, new ValidationError(System.Activities.SR.UnusedInputArguments(c.AsCommaSeparatedValues()), rootActivity)); } } if ((validationErrors != null) && (validationErrors.Count > 0)) { string paramName = "rootArgumentValues"; ExceptionReason invalidNonNullInputs = ExceptionReason.InvalidNonNullInputs; if (inputs == null) { paramName = "program"; invalidNonNullInputs = ExceptionReason.InvalidNullInputs; } string message = GenerateExceptionString(validationErrors, invalidNonNullInputs); if (message != null) { throw FxTrace.Exception.Argument(paramName, message); } } }
protected override void CacheMetadata(NativeActivityMetadata metadata) { Collection <RuntimeArgument> arguments = new Collection <RuntimeArgument>(); foreach (KeyValuePair <string, Argument> pair in this.DelegateArguments) { RuntimeArgument argument = new RuntimeArgument(pair.Key, pair.Value.ArgumentType, pair.Value.Direction); metadata.Bind(pair.Value, argument); arguments.Add(argument); } metadata.SetArgumentsCollection(arguments); metadata.AddDelegate(this.Delegate); if (this.Delegate != null) { IList <RuntimeDelegateArgument> runtimeDelegateArguments = this.Delegate.RuntimeDelegateArguments; if (this.DelegateArguments.Count != runtimeDelegateArguments.Count) { metadata.AddValidationError(System.Activities.SR.WrongNumberOfArgumentsForActivityDelegate); } for (int i = 0; i < runtimeDelegateArguments.Count; i++) { RuntimeDelegateArgument argument2 = runtimeDelegateArguments[i]; Argument argument3 = null; string name = argument2.Name; if (this.DelegateArguments.TryGetValue(name, out argument3)) { if (argument3.Direction != argument2.Direction) { metadata.AddValidationError(System.Activities.SR.DelegateParameterDirectionalityMismatch(name, argument3.Direction, argument2.Direction)); } if (argument2.Direction == ArgumentDirection.In) { if (!TypeHelper.AreTypesCompatible(argument3.ArgumentType, argument2.Type)) { metadata.AddValidationError(System.Activities.SR.DelegateInArgumentTypeMismatch(name, argument2.Type, argument3.ArgumentType)); } } else if (!TypeHelper.AreTypesCompatible(argument2.Type, argument3.ArgumentType)) { metadata.AddValidationError(System.Activities.SR.DelegateOutArgumentTypeMismatch(name, argument2.Type, argument3.ArgumentType)); } } else { metadata.AddValidationError(System.Activities.SR.InputParametersMissing(argument2.Name)); } if (!this.hasOutputArguments && ArgumentDirectionHelper.IsOut(argument2.Direction)) { this.hasOutputArguments = true; } } } }
private static bool CheckIfArgumentIsNotBound(RuntimeArgument argument, IDictionary <string, object> inputs) { if (((argument.Owner != null) && (argument.Owner.Parent == null)) && ArgumentDirectionHelper.IsOut(argument.Direction)) { return(false); } if ((argument.BoundArgument != null) && (argument.BoundArgument.Expression != null)) { return(false); } if ((inputs != null) && inputs.ContainsKey(argument.Name)) { return(false); } return(true); }
protected override void Execute(NativeActivityContext context) { if ((this.Delegate != null) && (this.Delegate.Handler != null)) { Dictionary <string, object> inputParameters = new Dictionary <string, object>(); if (this.DelegateArguments.Count > 0) { foreach (KeyValuePair <string, Argument> pair in this.DelegateArguments) { if (ArgumentDirectionHelper.IsIn(pair.Value.Direction)) { inputParameters.Add(pair.Key, pair.Value.Get(context)); } } } context.ScheduleDelegate(this.Delegate, inputParameters, new DelegateCompletionCallback(this.OnHandlerComplete), null); } }
private void OnHandlerComplete(NativeActivityContext context, ActivityInstance completedInstance, IDictionary <string, object> outArguments) { if (this.hasOutputArguments) { foreach (KeyValuePair <string, object> entry in outArguments) { if (DelegateArguments.TryGetValue(entry.Key, out Argument argument)) { if (ArgumentDirectionHelper.IsOut(argument.Direction)) { DelegateArguments[entry.Key].Set(context, entry.Value); } else { Fx.Assert(string.Format(CultureInfo.InvariantCulture, "Expected argument named '{0}' in the DelegateArguments collection to be an out argument.", entry.Key)); } } } } }
static bool CheckIfArgumentIsNotBound(RuntimeArgument argument, IDictionary <string, object> inputs) { if (argument.Owner != null && argument.Owner.Parent == null && ArgumentDirectionHelper.IsOut(argument.Direction)) { // Skip the validation for root node's out argument // as it will be added to the output dictionary return(false); } if (argument.BoundArgument != null && argument.BoundArgument.Expression != null) { return(false); } if (inputs != null) { if (inputs.ContainsKey(argument.Name)) { return(false); } } return(true); }
protected override void GatherOutputs(System.Activities.ActivityInstance completedInstance) { if (completedInstance.Activity.HandlerOf != null) { IList <RuntimeDelegateArgument> runtimeDelegateArguments = completedInstance.Activity.HandlerOf.RuntimeDelegateArguments; LocationEnvironment environment = completedInstance.Environment; for (int i = 0; i < runtimeDelegateArguments.Count; i++) { RuntimeDelegateArgument argument = runtimeDelegateArguments[i]; if ((argument.BoundArgument != null) && ArgumentDirectionHelper.IsOut(argument.Direction)) { Location specificLocation = environment.GetSpecificLocation(argument.BoundArgument.Id); if (specificLocation != null) { if (this.results == null) { this.results = new Dictionary <string, object>(); } this.results.Add(argument.Name, specificLocation.Value); } } } } }
internal static void ValidateRootInputs(Activity rootActivity, IDictionary <string, object> inputs) { IList <ValidationError> validationErrors = null; ValidationHelper.ValidateArguments(rootActivity, rootActivity.EquivalenceInfo, rootActivity.OverloadGroups, rootActivity.RequiredArgumentsNotInOverloadGroups, inputs, ref validationErrors); // Validate if there are any extra arguments passed in the input dictionary if (inputs != null) { List <string> unusedArguments = null; IEnumerable <RuntimeArgument> arguments = rootActivity.RuntimeArguments.Where((a) => ArgumentDirectionHelper.IsIn(a.Direction)); foreach (string key in inputs.Keys) { bool found = false; foreach (RuntimeArgument argument in arguments) { if (argument.Name == key) { found = true; // Validate if the input argument type matches the expected argument type. if (inputs.TryGetValue(key, out object inputArgumentValue)) { if (!TypeHelper.AreTypesCompatible(inputArgumentValue, argument.Type)) { ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.InputParametersTypeMismatch(argument.Type, argument.Name), rootActivity)); } } // The ValidateArguments will validate Required in-args and hence not duplicating that validation if the key is not found. break; } } if (!found) { if (unusedArguments == null) { unusedArguments = new List <string>(); } unusedArguments.Add(key); } } if (unusedArguments != null) { ActivityUtilities.Add(ref validationErrors, new ValidationError(SR.UnusedInputArguments(unusedArguments.AsCommaSeparatedValues()), rootActivity)); } } if (validationErrors != null && validationErrors.Count > 0) { string parameterName = "rootArgumentValues"; ExceptionReason reason = ExceptionReason.InvalidNonNullInputs; if (inputs == null) { parameterName = "program"; reason = ExceptionReason.InvalidNullInputs; } string exceptionString = GenerateExceptionString(validationErrors, reason); if (exceptionString != null) { throw FxTrace.Exception.Argument(parameterName, exceptionString); } } }
protected override void CacheMetadata(NativeActivityMetadata metadata) { Collection <RuntimeArgument> arguments = new Collection <RuntimeArgument>(); foreach (KeyValuePair <string, Argument> entry in this.DelegateArguments) { RuntimeArgument argument = new RuntimeArgument(entry.Key, entry.Value.ArgumentType, entry.Value.Direction); metadata.Bind(entry.Value, argument); arguments.Add(argument); } metadata.SetArgumentsCollection(arguments); metadata.AddDelegate(this.Delegate); if (this.Delegate != null) { IList <RuntimeDelegateArgument> targetDelegateArguments = this.Delegate.RuntimeDelegateArguments; if (this.DelegateArguments.Count != targetDelegateArguments.Count) { metadata.AddValidationError(SR.WrongNumberOfArgumentsForActivityDelegate); } // Validate that the names and directionality of arguments in DelegateArguments dictionary // match the names and directionality of arguments returned by the ActivityDelegate.GetDelegateParameters // call above. for (int i = 0; i < targetDelegateArguments.Count; i++) { RuntimeDelegateArgument expectedParameter = targetDelegateArguments[i]; string parameterName = expectedParameter.Name; if (this.DelegateArguments.TryGetValue(parameterName, out Argument delegateArgument)) { if (delegateArgument.Direction != expectedParameter.Direction) { metadata.AddValidationError(SR.DelegateParameterDirectionalityMismatch(parameterName, delegateArgument.Direction, expectedParameter.Direction)); } if (expectedParameter.Direction == ArgumentDirection.In) { if (!TypeHelper.AreTypesCompatible(delegateArgument.ArgumentType, expectedParameter.Type)) { metadata.AddValidationError(SR.DelegateInArgumentTypeMismatch(parameterName, expectedParameter.Type, delegateArgument.ArgumentType)); } } else { if (!TypeHelper.AreTypesCompatible(expectedParameter.Type, delegateArgument.ArgumentType)) { metadata.AddValidationError(SR.DelegateOutArgumentTypeMismatch(parameterName, expectedParameter.Type, delegateArgument.ArgumentType)); } } } else { metadata.AddValidationError(SR.InputParametersMissing(expectedParameter.Name)); } if (!this.hasOutputArguments && ArgumentDirectionHelper.IsOut(expectedParameter.Direction)) { this.hasOutputArguments = true; } } } metadata.AddChild(this.Default); }
private void OnHandlerComplete(NativeActivityContext context, System.Activities.ActivityInstance completedInstance, IDictionary <string, object> outArguments) { if (this.hasOutputArguments) { foreach (KeyValuePair <string, object> pair in outArguments) { Argument argument = null; if (this.DelegateArguments.TryGetValue(pair.Key, out argument) && ArgumentDirectionHelper.IsOut(argument.Direction)) { this.DelegateArguments[pair.Key].Set(context, pair.Value); } } } }