Пример #1
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>());
        }