public static void CacheMetadataHelper(
            ActivityMetadata metadata, InArgument <IEnumerable> input, OutArgument <Collection <ErrorRecord> > errors, string commandText, string typeName,
            string displayName, IDictionary <string, Argument> variables, IDictionary <string, InArgument> parameters,
            IDictionary <string, Argument> childVariables, IDictionary <string, InArgument> childParameters)
        {
            childVariables.Clear();
            childParameters.Clear();
            RuntimeArgument inputArgument = new RuntimeArgument("Input", typeof(IEnumerable), ArgumentDirection.In);

            metadata.Bind(input, inputArgument);
            metadata.AddArgument(inputArgument);

            RuntimeArgument errorArgument = new RuntimeArgument("Errors", typeof(Collection <ErrorRecord>), ArgumentDirection.Out);

            metadata.Bind(errors, errorArgument);
            metadata.AddArgument(errorArgument);

            if (commandText == null || string.IsNullOrEmpty(commandText.Trim()))
            {
                metadata.AddValidationError(string.Format(ErrorMessages.PowerShellRequiresCommand, displayName));
            }

            foreach (KeyValuePair <string, Argument> variable in variables)
            {
                string          name     = variable.Key;
                Argument        argument = variable.Value;
                RuntimeArgument ra       = new RuntimeArgument(name, argument.ArgumentType, argument.Direction, true);
                metadata.Bind(argument, ra);
                metadata.AddArgument(ra);

                Argument childArgument = Argument.Create(argument.ArgumentType, argument.Direction);
                childVariables.Add(name, Argument.CreateReference(argument, name));
            }

            foreach (KeyValuePair <string, InArgument> parameter in parameters)
            {
                string          name     = parameter.Key;
                InArgument      argument = parameter.Value;
                RuntimeArgument ra;
                if (argument.ArgumentType == typeof(bool))
                {
                    ra = new RuntimeArgument(name, argument.ArgumentType, argument.Direction, false);
                }
                else
                {
                    ra = new RuntimeArgument(name, argument.ArgumentType, argument.Direction, true);
                }
                metadata.Bind(argument, ra);
                metadata.AddArgument(ra);

                Argument childArgument = Argument.Create(argument.ArgumentType, argument.Direction);
                childParameters.Add(name, Argument.CreateReference(argument, name) as InArgument);
            }
        }
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            if (this.Request == null)
            {
                metadata.AddValidationError(System.ServiceModel.Activities.SR.SendReplyRequestCannotBeNull(base.DisplayName));
            }
            MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, base.DisplayName, (this.Request != null) ? this.Request.OperationName : string.Empty);
            string operationName = (this.Request != null) ? this.Request.OperationName : null;

            this.InternalContent.CacheMetadata(metadata, this, operationName);
            if (this.correlationInitializers != null)
            {
                for (int i = 0; i < this.correlationInitializers.Count; i++)
                {
                    CorrelationInitializer initializer = this.correlationInitializers[i];
                    initializer.ArgumentName = "Parameter" + i;
                    RuntimeArgument argument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(initializer.CorrelationHandle, argument);
                    metadata.AddArgument(argument);
                }
            }
            if (!metadata.HasViolations)
            {
                this.internalSend = this.CreateInternalSend();
                this.InternalContent.ConfigureInternalSendReply(this.internalSend, out this.responseFormatter);
                InArgument <CorrelationHandle> replyHandleFromReceive = this.GetReplyHandleFromReceive();
                if (replyHandleFromReceive != null)
                {
                    InArgument <CorrelationHandle> binding = MessagingActivityHelper.CreateReplyCorrelatesWith(replyHandleFromReceive);
                    RuntimeArgument argument4 = new RuntimeArgument("InternalSendCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(binding, argument4);
                    metadata.AddArgument(argument4);
                    this.internalSend.CorrelatesWith = (InArgument <CorrelationHandle>)InArgument.CreateReference(binding, "InternalSendCorrelatesWith");
                    if (this.responseFormatter != null)
                    {
                        InArgument <CorrelationHandle> argument5 = MessagingActivityHelper.CreateReplyCorrelatesWith(replyHandleFromReceive);
                        RuntimeArgument argument6 = new RuntimeArgument("ResponseFormatterCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                        metadata.Bind(argument5, argument6);
                        metadata.AddArgument(argument6);
                        this.responseFormatter.CorrelatesWith = (InArgument <CorrelationHandle>)InArgument.CreateReference(argument5, "ResponseFormatterCorrelatesWith");
                    }
                }
            }
            else
            {
                this.internalSend      = null;
                this.responseFormatter = null;
            }
            metadata.SetImportedChildrenCollection(new Collection <Activity>());
        }
        public static void AddRuntimeArgument(Argument messageArgument, string runtimeArgumentName, System.Type runtimeArgumentType, ArgumentDirection runtimeArgumentDirection, ActivityMetadata metadata)
        {
            RuntimeArgument argument = new RuntimeArgument(runtimeArgumentName, runtimeArgumentType, runtimeArgumentDirection);

            metadata.Bind(messageArgument, argument);
            metadata.AddArgument(argument);
        }
        internal override void CacheMetadata(ActivityMetadata metadata, Activity owner, string operationName)
        {
            // force a shred for every CacheMetadata call
            ShredParameters();

            int index = 0;

            foreach (Type argumentType in this.argumentTypes)
            {
                if (argumentType == null || argumentType == TypeHelper.VoidType)
                {
                    metadata.AddValidationError(SR.ArgumentCannotHaveNullOrVoidType(owner.DisplayName, argumentNames[index]));
                }
                if (argumentType == MessageDescription.TypeOfUntypedMessage || MessageBuilder.IsMessageContract(argumentType))
                {
                    metadata.AddValidationError(SR.ReceiveParametersContentDoesNotSupportMessage(owner.DisplayName, argumentNames[index]));
                }
                index++;
            }

            if (!metadata.HasViolations)
            {
                foreach (KeyValuePair <string, OutArgument> pair in this.Parameters)
                {
                    RuntimeArgument newRuntimeArgument = new RuntimeArgument(pair.Key, pair.Value.ArgumentType, ArgumentDirection.Out);
                    metadata.Bind(pair.Value, newRuntimeArgument);
                    metadata.AddArgument(newRuntimeArgument);
                }
            }
        }
Exemple #5
0
        internal override void CacheMetadata(ActivityMetadata metadata, Activity owner, string operationName)
        {
            this.ShredParameters();
            int index = 0;

            foreach (Type type in this.argumentTypes)
            {
                if ((type == null) || (type == TypeHelper.VoidType))
                {
                    metadata.AddValidationError(System.ServiceModel.Activities.SR.ArgumentCannotHaveNullOrVoidType(owner.DisplayName, this.argumentNames[index]));
                }
                if ((type == MessageDescription.TypeOfUntypedMessage) || MessageBuilder.IsMessageContract(type))
                {
                    metadata.AddValidationError(System.ServiceModel.Activities.SR.SendParametersContentDoesNotSupportMessage(owner.DisplayName, this.argumentNames[index]));
                }
                index++;
            }
            if (!metadata.HasViolations)
            {
                foreach (KeyValuePair <string, InArgument> pair in this.Parameters)
                {
                    RuntimeArgument argument = new RuntimeArgument(pair.Key, pair.Value.ArgumentType, ArgumentDirection.In);
                    metadata.Bind(pair.Value, argument);
                    metadata.AddArgument(argument);
                }
            }
        }
 internal override void CacheMetadata(ActivityMetadata metadata, Activity owner, string operationName)
 {
     this.ShredParameters();
     int index = 0;
     foreach (Type type in this.argumentTypes)
     {
         if ((type == null) || (type == TypeHelper.VoidType))
         {
             metadata.AddValidationError(System.ServiceModel.Activities.SR.ArgumentCannotHaveNullOrVoidType(owner.DisplayName, this.argumentNames[index]));
         }
         if ((type == MessageDescription.TypeOfUntypedMessage) || MessageBuilder.IsMessageContract(type))
         {
             metadata.AddValidationError(System.ServiceModel.Activities.SR.ReceiveParametersContentDoesNotSupportMessage(owner.DisplayName, this.argumentNames[index]));
         }
         index++;
     }
     if (!metadata.HasViolations)
     {
         foreach (KeyValuePair<string, OutArgument> pair in this.Parameters)
         {
             RuntimeArgument argument = new RuntimeArgument(pair.Key, pair.Value.ArgumentType, ArgumentDirection.Out);
             metadata.Bind(pair.Value, argument);
             metadata.AddArgument(argument);
         }
     }
 }
 protected override void CacheMetadata(ActivityMetadata metadata)
 {
     if (string.IsNullOrEmpty(this.OperationName))
     {
         metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingOperationName(base.DisplayName));
     }
     MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, false, base.DisplayName, this.OperationName);
     MessagingActivityHelper.AddRuntimeArgument(this.CorrelatesWith, "CorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In, metadata);
     this.InternalContent.CacheMetadata(metadata, this, this.OperationName);
     if (this.correlationInitializers != null)
     {
         for (int i = 0; i < this.correlationInitializers.Count; i++)
         {
             CorrelationInitializer initializer = this.correlationInitializers[i];
             initializer.ArgumentName = "Parameter" + i;
             RuntimeArgument argument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
             metadata.Bind(initializer.CorrelationHandle, argument);
             metadata.AddArgument(argument);
         }
     }
     if (!metadata.HasViolations)
     {
         this.internalReceive = this.CreateInternalReceive();
         this.InternalContent.ConfigureInternalReceive(this.internalReceive, out this.requestFormatter);
     }
     else
     {
         this.internalReceive  = null;
         this.requestFormatter = null;
     }
 }
 protected override void CacheMetadata(ActivityMetadata metadata)
 {
     if (string.IsNullOrEmpty(this.OperationName))
     {
         metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingOperationName(base.DisplayName));
     }
     MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, false, base.DisplayName, this.OperationName);
     MessagingActivityHelper.AddRuntimeArgument(this.CorrelatesWith, "CorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In, metadata);
     this.InternalContent.CacheMetadata(metadata, this, this.OperationName);
     if (this.correlationInitializers != null)
     {
         for (int i = 0; i < this.correlationInitializers.Count; i++)
         {
             CorrelationInitializer initializer = this.correlationInitializers[i];
             initializer.ArgumentName = "Parameter" + i;
             RuntimeArgument argument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
             metadata.Bind(initializer.CorrelationHandle, argument);
             metadata.AddArgument(argument);
         }
     }
     if (!metadata.HasViolations)
     {
         this.internalReceive = this.CreateInternalReceive();
         this.InternalContent.ConfigureInternalReceive(this.internalReceive, out this.requestFormatter);
     }
     else
     {
         this.internalReceive = null;
         this.requestFormatter = null;
     }
 }
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            IPSHelper.CacheMetadataHelper(metadata, this.Input, this.Errors, this.CommandText, GetType().Name,
                                          this.DisplayName, this.PowerShellVariables, this.Parameters, this.childPowerShellVariables, this.childParameters);

            RuntimeArgument outputArgument = new RuntimeArgument("Output", typeof(Collection <PSObject>), ArgumentDirection.Out, false);

            metadata.Bind(this.Output, outputArgument);
            metadata.AddArgument(outputArgument);
        }
        public static void AddRuntimeArgument <T>(
            this ActivityMetadata metadata,
            OutArgument <T> argument,
            string argumentName,
            bool isRequired,
            List <string> overloadGroupNames)
        {
            RuntimeArgument runtimeArgument = new RuntimeArgument(argumentName, typeof(T), ArgumentDirection.Out, isRequired, overloadGroupNames);

            metadata.Bind((Argument)argument, runtimeArgument);
            metadata.AddArgument(runtimeArgument);
        }
        public static void AddRuntimeArgument(
            this ActivityMetadata metadata,
            Argument messageArgument,
            string runtimeArgumentName,
            Type runtimeArgumentType,
            ArgumentDirection runtimeArgumentDirection,
            bool isRequired,
            List <string> overloadGroupNames)
        {
            RuntimeArgument runtimeArgument = new RuntimeArgument(runtimeArgumentName, runtimeArgumentType, runtimeArgumentDirection, isRequired, overloadGroupNames);

            metadata.Bind(messageArgument, runtimeArgument);
            metadata.AddArgument(runtimeArgument);
        }
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            IPSHelper.CacheMetadataHelper(metadata, this.Input, this.Errors, this.CommandText, GetType().Name,
                this.DisplayName, this.PowerShellVariables, this.Parameters, this.childPowerShellVariables, this.childParameters);

            RuntimeArgument outputArgument = new RuntimeArgument("Output", typeof(Collection<PSObject>), ArgumentDirection.Out, false);
            metadata.Bind(this.Output, outputArgument);
            metadata.AddArgument(outputArgument);
        }
 protected override void CacheMetadata(ActivityMetadata metadata)
 {
     if (this.Request == null)
     {
         metadata.AddValidationError(System.ServiceModel.Activities.SR.ReceiveReplyRequestCannotBeNull(base.DisplayName));
     }
     else
     {
         if (this.Request.ServiceContractName == null)
         {
             string errorMessageOperationName = ContractValidationHelper.GetErrorMessageOperationName(this.Request.OperationName);
             metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingServiceContractName(this.Request.DisplayName, errorMessageOperationName));
         }
         if (string.IsNullOrEmpty(this.Request.OperationName))
         {
             metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingOperationName(this.Request.DisplayName));
         }
     }
     MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, base.DisplayName, (this.Request != null) ? this.Request.OperationName : string.Empty);
     string operationName = (this.Request != null) ? this.Request.OperationName : null;
     this.InternalContent.CacheMetadata(metadata, this, operationName);
     if (this.correlationInitializers != null)
     {
         for (int i = 0; i < this.correlationInitializers.Count; i++)
         {
             CorrelationInitializer initializer = this.correlationInitializers[i];
             initializer.ArgumentName = "Parameter" + i;
             RuntimeArgument argument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
             metadata.Bind(initializer.CorrelationHandle, argument);
             metadata.AddArgument(argument);
         }
     }
     if (!metadata.HasViolations)
     {
         this.internalReceive = this.CreateInternalReceive();
         InArgument<CorrelationHandle> replyHandleFromSend = this.GetReplyHandleFromSend();
         if (replyHandleFromSend != null)
         {
             InArgument<CorrelationHandle> binding = MessagingActivityHelper.CreateReplyCorrelatesWith(replyHandleFromSend);
             RuntimeArgument argument4 = new RuntimeArgument("ResultCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
             metadata.Bind(binding, argument4);
             metadata.AddArgument(argument4);
             this.internalReceive.CorrelatesWith = (InArgument<CorrelationHandle>) InArgument.CreateReference(binding, "ResultCorrelatesWith");
         }
         this.InternalContent.ConfigureInternalReceiveReply(this.internalReceive, out this.responseFormatter);
         if ((this.InternalContent is ReceiveMessageContent) && MessageBuilder.IsMessageContract(((ReceiveMessageContent) this.InternalContent).InternalDeclaredMessageType))
         {
             this.Request.OperationUsesMessageContract = true;
         }
         OperationDescription operationDescription = ContractInferenceHelper.CreateTwoWayOperationDescription(this.Request, this);
         this.Request.OperationDescription = operationDescription;
         if (this.responseFormatter != null)
         {
             IClientMessageFormatter formatterFromRuntime = ClientOperationFormatterProvider.GetFormatterFromRuntime(operationDescription);
             this.Request.SetFormatter(formatterFromRuntime);
             this.responseFormatter.Formatter = formatterFromRuntime;
             int index = 0;
             Type[] detailTypes = new Type[operationDescription.KnownTypes.Count];
             foreach (Type type in operationDescription.KnownTypes)
             {
                 detailTypes[index] = type;
                 index++;
             }
             this.responseFormatter.FaultFormatter = new FaultFormatter(detailTypes);
         }
         if ((this.correlationInitializers != null) && (this.correlationInitializers.Count > 0))
         {
             foreach (CorrelationQuery query in ContractInferenceHelper.CreateClientCorrelationQueries(null, this.correlationInitializers, this.Action, this.Request.ServiceContractName, this.Request.OperationName, true))
             {
                 this.Request.SetReplyCorrelationQuery(query);
             }
         }
     }
     else
     {
         this.internalReceive = null;
         this.responseFormatter = null;
     }
     metadata.SetImportedChildrenCollection(new Collection<Activity>());
 }
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            if (this.Request == null)
            {
                metadata.AddValidationError(SR.SendReplyRequestCannotBeNull(this.DisplayName));
            }

            // validate Correlation Initializers
            MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, this.DisplayName, (this.Request != null ? this.Request.OperationName : String.Empty));

            // Validate Content
            string operationName = this.Request != null ? this.Request.OperationName : null;
            this.InternalContent.CacheMetadata(metadata, this, operationName);

            if (this.correlationInitializers != null)
            {
                for (int i = 0; i < this.correlationInitializers.Count; i++)
                {
                    CorrelationInitializer initializer = this.correlationInitializers[i];
                    initializer.ArgumentName = Constants.Parameter + i;
                    RuntimeArgument initializerArgument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(initializer.CorrelationHandle, initializerArgument);
                    metadata.AddArgument(initializerArgument);
                }
            }

            if (!metadata.HasViolations)
            {
                this.internalSend = CreateInternalSend();
                this.InternalContent.ConfigureInternalSendReply(this.internalSend, out this.responseFormatter);

                InArgument<CorrelationHandle> requestReplyHandleFromReceive = GetReplyHandleFromReceive();
                if (requestReplyHandleFromReceive != null)
                {
                    InArgument<CorrelationHandle> internalSendCorrelatesWith = MessagingActivityHelper.CreateReplyCorrelatesWith(requestReplyHandleFromReceive);
                    
                    RuntimeArgument internalSendCorrelatesWithArgument = new RuntimeArgument("InternalSendCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(internalSendCorrelatesWith, internalSendCorrelatesWithArgument);
                    metadata.AddArgument(internalSendCorrelatesWithArgument);

                    this.internalSend.CorrelatesWith = (InArgument<CorrelationHandle>)InArgument.CreateReference(internalSendCorrelatesWith, "InternalSendCorrelatesWith");

                    if (this.responseFormatter != null)
                    {
                        InArgument<CorrelationHandle> responseFormatterCorrelatesWith = MessagingActivityHelper.CreateReplyCorrelatesWith(requestReplyHandleFromReceive);

                        RuntimeArgument responseFormatterCorrelatesWithArgument = new RuntimeArgument("ResponseFormatterCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                        metadata.Bind(responseFormatterCorrelatesWith, responseFormatterCorrelatesWithArgument);
                        metadata.AddArgument(responseFormatterCorrelatesWithArgument);

                        responseFormatter.CorrelatesWith = (InArgument<CorrelationHandle>)InArgument.CreateReference(responseFormatterCorrelatesWith, "ResponseFormatterCorrelatesWith");
                    }
                }
            }
            else
            {
                this.internalSend = null;
                this.responseFormatter = null;
            }

            // We don't have any imported children despite referencing the Request
            metadata.SetImportedChildrenCollection(new Collection<Activity>());
        }
Exemple #15
0
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            if (string.IsNullOrEmpty(this.OperationName))
            {
                metadata.AddValidationError(SR.MissingOperationName(this.DisplayName));
            }
            if (this.ServiceContractName == null)
            {
                string errorOperationName = ContractValidationHelper.GetErrorMessageOperationName(this.OperationName);
                metadata.AddValidationError(SR.MissingServiceContractName(this.DisplayName, errorOperationName));
            }

            if (this.Endpoint == null)
            {
                if (string.IsNullOrEmpty(this.EndpointConfigurationName))
                {
                    metadata.AddValidationError(SR.EndpointNotSet(this.DisplayName, this.OperationName));
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(this.EndpointConfigurationName))
                {
                    metadata.AddValidationError(SR.EndpointIncorrectlySet(this.DisplayName, this.OperationName));
                }
                if (this.Endpoint.Binding == null)
                {
                    metadata.AddValidationError(SR.MissingBindingInEndpoint(this.Endpoint.Name, this.ServiceContractName));
                }
            }

            // validate Correlation Initializers
            MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, false, this.DisplayName, this.OperationName);
            
            // Add runtime arguments
            MessagingActivityHelper.AddRuntimeArgument(this.CorrelatesWith, "CorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In, metadata);
            MessagingActivityHelper.AddRuntimeArgument(this.EndpointAddress, "EndpointAddress", Constants.UriType, ArgumentDirection.In, metadata);

            // Validate Content
            this.InternalContent.CacheMetadata(metadata, this, this.OperationName);

            if (this.correlationInitializers != null)
            {
                for (int i = 0; i < this.correlationInitializers.Count; i++)
                {
                    CorrelationInitializer initializer = this.correlationInitializers[i];
                    initializer.ArgumentName = Constants.Parameter + i;
                    RuntimeArgument initializerArgument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(initializer.CorrelationHandle, initializerArgument);
                    metadata.AddArgument(initializerArgument);
                }
            }

            if (!metadata.HasViolations)
            {
                if (this.InternalContent is SendMessageContent
                    && MessageBuilder.IsMessageContract(((SendMessageContent)this.InternalContent).InternalDeclaredMessageType))
                {
                    this.OperationUsesMessageContract = true;
                }

                this.internalSend = CreateInternalSend();
                this.InternalContent.ConfigureInternalSend(this.internalSend, out this.requestFormatter);

                if (this.requestFormatter != null && this.lazyFormatter != null)
                {
                    this.requestFormatter.Formatter = this.lazyFormatter;
                }
            }
            else
            {
                this.internalSend = null;
                this.requestFormatter = null;
            }
        }
Exemple #16
0
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            if (this.Request == null)
            {
                metadata.AddValidationError(SR.ReceiveReplyRequestCannotBeNull(this.DisplayName));
            }
            else
            {
                // Need to validate Send.ServiceContractName and Send.OperationName here so that we can proceed with contract inference
                if (this.Request.ServiceContractName == null)
                {
                    string errorOperationName = ContractValidationHelper.GetErrorMessageOperationName(this.Request.OperationName);
                    metadata.AddValidationError(SR.MissingServiceContractName(this.Request.DisplayName, errorOperationName));
                }
                if (string.IsNullOrEmpty(this.Request.OperationName))
                {
                    metadata.AddValidationError(SR.MissingOperationName(this.Request.DisplayName));
                }
            }

            // validate Correlation Initializers
            MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, this.DisplayName, (this.Request != null ? this.Request.OperationName : String.Empty));

            // Validate Content
            string operationName = this.Request != null ? this.Request.OperationName : null;

            this.InternalContent.CacheMetadata(metadata, this, operationName);

            if (this.correlationInitializers != null)
            {
                for (int i = 0; i < this.correlationInitializers.Count; i++)
                {
                    CorrelationInitializer initializer = this.correlationInitializers[i];
                    initializer.ArgumentName = Constants.Parameter + i;
                    RuntimeArgument initializerArgument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(initializer.CorrelationHandle, initializerArgument);
                    metadata.AddArgument(initializerArgument);
                }
            }

            if (!metadata.HasViolations)
            {
                this.internalReceive = CreateInternalReceive();

                InArgument <CorrelationHandle> requestReplyHandleFromSend = GetReplyHandleFromSend();
                if (requestReplyHandleFromSend != null)
                {
                    InArgument <CorrelationHandle> resultCorrelatesWith = MessagingActivityHelper.CreateReplyCorrelatesWith(requestReplyHandleFromSend);

                    RuntimeArgument resultCorrelatesWithArgument = new RuntimeArgument("ResultCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(resultCorrelatesWith, resultCorrelatesWithArgument);
                    metadata.AddArgument(resultCorrelatesWithArgument);

                    this.internalReceive.CorrelatesWith = (InArgument <CorrelationHandle>)InArgument.CreateReference(resultCorrelatesWith, "ResultCorrelatesWith");
                }

                this.InternalContent.ConfigureInternalReceiveReply(this.internalReceive, out this.responseFormatter);

                if (this.InternalContent is ReceiveMessageContent &&
                    MessageBuilder.IsMessageContract(((ReceiveMessageContent)this.InternalContent).InternalDeclaredMessageType))
                {
                    this.Request.OperationUsesMessageContract = true;
                }

                OperationDescription operation = ContractInferenceHelper.CreateTwoWayOperationDescription(this.Request, this);
                this.Request.OperationDescription = operation;

                if (this.responseFormatter != null)
                {
                    IClientMessageFormatter formatter = ClientOperationFormatterProvider.GetFormatterFromRuntime(operation);

                    this.Request.SetFormatter(formatter);
                    this.responseFormatter.Formatter = formatter;

                    //
                    int    index      = 0;
                    Type[] faultTypes = new Type[operation.KnownTypes.Count];
                    foreach (Type type in operation.KnownTypes)
                    {
                        faultTypes[index] = type;
                        index++;
                    }

                    this.responseFormatter.FaultFormatter = new FaultFormatter(faultTypes);
                }

                // Add CorrelationQuery to the Send->ReplyCorrelation, we validate that the same query is not added multiple times
                if (this.correlationInitializers != null && this.correlationInitializers.Count > 0)
                {
                    Collection <CorrelationQuery> internalCorrelationQueryCollection = ContractInferenceHelper.CreateClientCorrelationQueries(null, this.correlationInitializers,
                                                                                                                                              this.Action, this.Request.ServiceContractName, this.Request.OperationName, true);

                    foreach (CorrelationQuery query in internalCorrelationQueryCollection)
                    {
                        this.Request.SetReplyCorrelationQuery(query);
                    }
                }
            }
            else
            {
                this.internalReceive   = null;
                this.responseFormatter = null;
            }

            // We don't have any imported children despite referencing the Request
            metadata.SetImportedChildrenCollection(new Collection <Activity>());
        }
        internal override void CacheMetadata(ActivityMetadata metadata, Activity owner, string operationName)
        {
            // force a shred for every CacheMetadata call
            ShredParameters();

            int index = 0;
            foreach (Type argumentType in this.argumentTypes)
            {
                if (argumentType == null || argumentType == TypeHelper.VoidType)
                {
                    metadata.AddValidationError(SR.ArgumentCannotHaveNullOrVoidType(owner.DisplayName, argumentNames[index]));
                }
                if (argumentType == MessageDescription.TypeOfUntypedMessage || MessageBuilder.IsMessageContract(argumentType))
                {
                    metadata.AddValidationError(SR.SendParametersContentDoesNotSupportMessage(owner.DisplayName, argumentNames[index]));
                }
                index++;
            }

            if (!metadata.HasViolations)
            {
                foreach (KeyValuePair<string, InArgument> pair in this.Parameters)
                {
                    RuntimeArgument newRuntimeArgument = new RuntimeArgument(pair.Key, pair.Value.ArgumentType, ArgumentDirection.In);
                    metadata.Bind(pair.Value, newRuntimeArgument);
                    metadata.AddArgument(newRuntimeArgument);
                }
            }
        }
        public static void CacheMetadataHelper(
            ActivityMetadata metadata, InArgument<IEnumerable> input, OutArgument<Collection<ErrorRecord>> errors, string commandText, string typeName,
            string displayName, IDictionary<string, Argument> variables, IDictionary<string, InArgument> parameters,
            IDictionary<string, Argument> childVariables, IDictionary<string, InArgument> childParameters)
        {
            childVariables.Clear();
            childParameters.Clear();
            RuntimeArgument inputArgument = new RuntimeArgument("Input", typeof(IEnumerable), ArgumentDirection.In);
            metadata.Bind(input, inputArgument);
            metadata.AddArgument(inputArgument);

            RuntimeArgument errorArgument = new RuntimeArgument("Errors", typeof(Collection<ErrorRecord>), ArgumentDirection.Out);
            metadata.Bind(errors, errorArgument);
            metadata.AddArgument(errorArgument);

            if (commandText == null || string.IsNullOrEmpty(commandText.Trim()))
            {
                metadata.AddValidationError(string.Format(ErrorMessages.PowerShellRequiresCommand, displayName));
            }

            foreach (KeyValuePair<string, Argument> variable in variables)
            {
                string name = variable.Key;
                Argument argument = variable.Value;
                RuntimeArgument ra = new RuntimeArgument(name, argument.ArgumentType, argument.Direction, true);
                metadata.Bind(argument, ra);
                metadata.AddArgument(ra);

                Argument childArgument = Argument.Create(argument.ArgumentType, argument.Direction);
                childVariables.Add(name, Argument.CreateReference(argument, name));
            }

            foreach (KeyValuePair<string, InArgument> parameter in parameters)
            {
                string name = parameter.Key;
                InArgument argument = parameter.Value;
                RuntimeArgument ra;
                if (argument.ArgumentType == typeof(bool))
                {
                    ra = new RuntimeArgument(name, argument.ArgumentType, argument.Direction, false);
                }
                else
                {
                    ra = new RuntimeArgument(name, argument.ArgumentType, argument.Direction, true);
                }
                metadata.Bind(argument, ra);
                metadata.AddArgument(ra);

                Argument childArgument = Argument.Create(argument.ArgumentType, argument.Direction);
                childParameters.Add(name, Argument.CreateReference(argument, name) as InArgument);
            }
        }
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            if (this.Request == null)
            {
                metadata.AddValidationError(SR.ReceiveReplyRequestCannotBeNull(this.DisplayName));
            }
            else
            {
                // Need to validate Send.ServiceContractName and Send.OperationName here so that we can proceed with contract inference
                if (this.Request.ServiceContractName == null)
                {
                    string errorOperationName = ContractValidationHelper.GetErrorMessageOperationName(this.Request.OperationName);
                    metadata.AddValidationError(SR.MissingServiceContractName(this.Request.DisplayName, errorOperationName));
                }
                if (string.IsNullOrEmpty(this.Request.OperationName))
                {
                    metadata.AddValidationError(SR.MissingOperationName(this.Request.DisplayName));
                }
            }

            // validate Correlation Initializers
            MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, this.DisplayName, (this.Request != null ? this.Request.OperationName : String.Empty));
            
            // Validate Content
            string operationName = this.Request != null ? this.Request.OperationName : null;
            this.InternalContent.CacheMetadata(metadata, this, operationName);

            if (this.correlationInitializers != null)
            {
                for (int i = 0; i < this.correlationInitializers.Count; i++)
                {
                    CorrelationInitializer initializer = this.correlationInitializers[i];
                    initializer.ArgumentName = Constants.Parameter + i;
                    RuntimeArgument initializerArgument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(initializer.CorrelationHandle, initializerArgument);
                    metadata.AddArgument(initializerArgument);
                }
            }

            if (!metadata.HasViolations)
            {
                this.internalReceive = CreateInternalReceive();

                InArgument<CorrelationHandle> requestReplyHandleFromSend = GetReplyHandleFromSend();
                if (requestReplyHandleFromSend != null)
                {
                    InArgument<CorrelationHandle> resultCorrelatesWith = MessagingActivityHelper.CreateReplyCorrelatesWith(requestReplyHandleFromSend);

                    RuntimeArgument resultCorrelatesWithArgument = new RuntimeArgument("ResultCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(resultCorrelatesWith, resultCorrelatesWithArgument);
                    metadata.AddArgument(resultCorrelatesWithArgument);

                    this.internalReceive.CorrelatesWith = (InArgument<CorrelationHandle>)InArgument.CreateReference(resultCorrelatesWith, "ResultCorrelatesWith");
                }

                this.InternalContent.ConfigureInternalReceiveReply(this.internalReceive, out this.responseFormatter);

                if (this.InternalContent is ReceiveMessageContent
                    && MessageBuilder.IsMessageContract(((ReceiveMessageContent)this.InternalContent).InternalDeclaredMessageType))
                {
                    this.Request.OperationUsesMessageContract = true;
                }

                OperationDescription operation = ContractInferenceHelper.CreateTwoWayOperationDescription(this.Request, this);
                this.Request.OperationDescription = operation;

                if (this.responseFormatter != null)
                {
                    IClientMessageFormatter formatter = ClientOperationFormatterProvider.GetFormatterFromRuntime(operation);

                    this.Request.SetFormatter(formatter);
                    this.responseFormatter.Formatter = formatter;

                    // 
                    int index = 0;
                    Type[] faultTypes = new Type[operation.KnownTypes.Count];
                    foreach (Type type in operation.KnownTypes)
                    {
                        faultTypes[index] = type;
                        index++;
                    }

                    this.responseFormatter.FaultFormatter = new FaultFormatter(faultTypes);
                }

                // Add CorrelationQuery to the Send->ReplyCorrelation, we validate that the same query is not added multiple times
                if (this.correlationInitializers != null && this.correlationInitializers.Count > 0)
                {
                    Collection<CorrelationQuery> internalCorrelationQueryCollection = ContractInferenceHelper.CreateClientCorrelationQueries(null, this.correlationInitializers,
                        this.Action, this.Request.ServiceContractName, this.Request.OperationName, true);

                    foreach (CorrelationQuery query in internalCorrelationQueryCollection)
                    {
                        this.Request.SetReplyCorrelationQuery(query);
                    }
                    
                }
            }
            else
            {
                this.internalReceive = null;
                this.responseFormatter = null;
            }

            // We don't have any imported children despite referencing the Request
            metadata.SetImportedChildrenCollection(new Collection<Activity>());
        }
Exemple #20
0
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            if (this.Request == null)
            {
                metadata.AddValidationError(SR.SendReplyRequestCannotBeNull(this.DisplayName));
            }

            // validate Correlation Initializers
            MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, this.DisplayName, (this.Request != null ? this.Request.OperationName : String.Empty));

            // Validate Content
            string operationName = this.Request != null ? this.Request.OperationName : null;

            this.InternalContent.CacheMetadata(metadata, this, operationName);

            if (this.correlationInitializers != null)
            {
                for (int i = 0; i < this.correlationInitializers.Count; i++)
                {
                    CorrelationInitializer initializer = this.correlationInitializers[i];
                    initializer.ArgumentName = Constants.Parameter + i;
                    RuntimeArgument initializerArgument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(initializer.CorrelationHandle, initializerArgument);
                    metadata.AddArgument(initializerArgument);
                }
            }

            if (!metadata.HasViolations)
            {
                this.internalSend = CreateInternalSend();
                this.InternalContent.ConfigureInternalSendReply(this.internalSend, out this.responseFormatter);

                InArgument <CorrelationHandle> requestReplyHandleFromReceive = GetReplyHandleFromReceive();
                if (requestReplyHandleFromReceive != null)
                {
                    InArgument <CorrelationHandle> internalSendCorrelatesWith = MessagingActivityHelper.CreateReplyCorrelatesWith(requestReplyHandleFromReceive);

                    RuntimeArgument internalSendCorrelatesWithArgument = new RuntimeArgument("InternalSendCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(internalSendCorrelatesWith, internalSendCorrelatesWithArgument);
                    metadata.AddArgument(internalSendCorrelatesWithArgument);

                    this.internalSend.CorrelatesWith = (InArgument <CorrelationHandle>)InArgument.CreateReference(internalSendCorrelatesWith, "InternalSendCorrelatesWith");

                    if (this.responseFormatter != null)
                    {
                        InArgument <CorrelationHandle> responseFormatterCorrelatesWith = MessagingActivityHelper.CreateReplyCorrelatesWith(requestReplyHandleFromReceive);

                        RuntimeArgument responseFormatterCorrelatesWithArgument = new RuntimeArgument("ResponseFormatterCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                        metadata.Bind(responseFormatterCorrelatesWith, responseFormatterCorrelatesWithArgument);
                        metadata.AddArgument(responseFormatterCorrelatesWithArgument);

                        responseFormatter.CorrelatesWith = (InArgument <CorrelationHandle>)InArgument.CreateReference(responseFormatterCorrelatesWith, "ResponseFormatterCorrelatesWith");
                    }
                }
            }
            else
            {
                this.internalSend      = null;
                this.responseFormatter = null;
            }

            // We don't have any imported children despite referencing the Request
            metadata.SetImportedChildrenCollection(new Collection <Activity>());
        }
 protected override void CacheMetadata(ActivityMetadata metadata)
 {
     if (string.IsNullOrEmpty(this.OperationName))
     {
         metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingOperationName(base.DisplayName));
     }
     if (this.ServiceContractName == null)
     {
         string errorMessageOperationName = ContractValidationHelper.GetErrorMessageOperationName(this.OperationName);
         metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingServiceContractName(base.DisplayName, errorMessageOperationName));
     }
     if (this.Endpoint == null)
     {
         if (string.IsNullOrEmpty(this.EndpointConfigurationName))
         {
             metadata.AddValidationError(System.ServiceModel.Activities.SR.EndpointNotSet(base.DisplayName, this.OperationName));
         }
     }
     else
     {
         if (!string.IsNullOrEmpty(this.EndpointConfigurationName))
         {
             metadata.AddValidationError(System.ServiceModel.Activities.SR.EndpointIncorrectlySet(base.DisplayName, this.OperationName));
         }
         if (this.Endpoint.Binding == null)
         {
             metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingBindingInEndpoint(this.Endpoint.Name, this.ServiceContractName));
         }
     }
     MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, false, base.DisplayName, this.OperationName);
     MessagingActivityHelper.AddRuntimeArgument(this.CorrelatesWith, "CorrelatesWith", System.ServiceModel.Activities.Constants.CorrelationHandleType, ArgumentDirection.In, metadata);
     MessagingActivityHelper.AddRuntimeArgument(this.EndpointAddress, "EndpointAddress", System.ServiceModel.Activities.Constants.UriType, ArgumentDirection.In, metadata);
     this.InternalContent.CacheMetadata(metadata, this, this.OperationName);
     if (this.correlationInitializers != null)
     {
         for (int i = 0; i < this.correlationInitializers.Count; i++)
         {
             CorrelationInitializer initializer = this.correlationInitializers[i];
             initializer.ArgumentName = "Parameter" + i;
             RuntimeArgument argument = new RuntimeArgument(initializer.ArgumentName, System.ServiceModel.Activities.Constants.CorrelationHandleType, ArgumentDirection.In);
             metadata.Bind(initializer.CorrelationHandle, argument);
             metadata.AddArgument(argument);
         }
     }
     if (!metadata.HasViolations)
     {
         if ((this.InternalContent is SendMessageContent) && MessageBuilder.IsMessageContract(((SendMessageContent)this.InternalContent).InternalDeclaredMessageType))
         {
             this.OperationUsesMessageContract = true;
         }
         this.internalSend = this.CreateInternalSend();
         this.InternalContent.ConfigureInternalSend(this.internalSend, out this.requestFormatter);
         if ((this.requestFormatter != null) && (this.lazyFormatter != null))
         {
             this.requestFormatter.Formatter = this.lazyFormatter;
         }
     }
     else
     {
         this.internalSend     = null;
         this.requestFormatter = null;
     }
 }
Exemple #22
0
        protected override void CacheMetadata(ActivityMetadata metadata)
        {
            if (this.Request == null)
            {
                metadata.AddValidationError(System.ServiceModel.Activities.SR.ReceiveReplyRequestCannotBeNull(base.DisplayName));
            }
            else
            {
                if (this.Request.ServiceContractName == null)
                {
                    string errorMessageOperationName = ContractValidationHelper.GetErrorMessageOperationName(this.Request.OperationName);
                    metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingServiceContractName(this.Request.DisplayName, errorMessageOperationName));
                }
                if (string.IsNullOrEmpty(this.Request.OperationName))
                {
                    metadata.AddValidationError(System.ServiceModel.Activities.SR.MissingOperationName(this.Request.DisplayName));
                }
            }
            MessagingActivityHelper.ValidateCorrelationInitializer(metadata, this.correlationInitializers, true, base.DisplayName, (this.Request != null) ? this.Request.OperationName : string.Empty);
            string operationName = (this.Request != null) ? this.Request.OperationName : null;

            this.InternalContent.CacheMetadata(metadata, this, operationName);
            if (this.correlationInitializers != null)
            {
                for (int i = 0; i < this.correlationInitializers.Count; i++)
                {
                    CorrelationInitializer initializer = this.correlationInitializers[i];
                    initializer.ArgumentName = "Parameter" + i;
                    RuntimeArgument argument = new RuntimeArgument(initializer.ArgumentName, Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(initializer.CorrelationHandle, argument);
                    metadata.AddArgument(argument);
                }
            }
            if (!metadata.HasViolations)
            {
                this.internalReceive = this.CreateInternalReceive();
                InArgument <CorrelationHandle> replyHandleFromSend = this.GetReplyHandleFromSend();
                if (replyHandleFromSend != null)
                {
                    InArgument <CorrelationHandle> binding = MessagingActivityHelper.CreateReplyCorrelatesWith(replyHandleFromSend);
                    RuntimeArgument argument4 = new RuntimeArgument("ResultCorrelatesWith", Constants.CorrelationHandleType, ArgumentDirection.In);
                    metadata.Bind(binding, argument4);
                    metadata.AddArgument(argument4);
                    this.internalReceive.CorrelatesWith = (InArgument <CorrelationHandle>)InArgument.CreateReference(binding, "ResultCorrelatesWith");
                }
                this.InternalContent.ConfigureInternalReceiveReply(this.internalReceive, out this.responseFormatter);
                if ((this.InternalContent is ReceiveMessageContent) && MessageBuilder.IsMessageContract(((ReceiveMessageContent)this.InternalContent).InternalDeclaredMessageType))
                {
                    this.Request.OperationUsesMessageContract = true;
                }
                OperationDescription operationDescription = ContractInferenceHelper.CreateTwoWayOperationDescription(this.Request, this);
                this.Request.OperationDescription = operationDescription;
                if (this.responseFormatter != null)
                {
                    IClientMessageFormatter formatterFromRuntime = ClientOperationFormatterProvider.GetFormatterFromRuntime(operationDescription);
                    this.Request.SetFormatter(formatterFromRuntime);
                    this.responseFormatter.Formatter = formatterFromRuntime;
                    int    index       = 0;
                    Type[] detailTypes = new Type[operationDescription.KnownTypes.Count];
                    foreach (Type type in operationDescription.KnownTypes)
                    {
                        detailTypes[index] = type;
                        index++;
                    }
                    this.responseFormatter.FaultFormatter = new FaultFormatter(detailTypes);
                }
                if ((this.correlationInitializers != null) && (this.correlationInitializers.Count > 0))
                {
                    foreach (CorrelationQuery query in ContractInferenceHelper.CreateClientCorrelationQueries(null, this.correlationInitializers, this.Action, this.Request.ServiceContractName, this.Request.OperationName, true))
                    {
                        this.Request.SetReplyCorrelationQuery(query);
                    }
                }
            }
            else
            {
                this.internalReceive   = null;
                this.responseFormatter = null;
            }
            metadata.SetImportedChildrenCollection(new Collection <Activity>());
        }