Ejemplo n.º 1
0
        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);
                            }
                        }
                    }
                }
            }
        }
        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);
 }
 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));
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 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);
                 }
             }
         }
     }
 }
        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);
             }
         }
     }
 }