public override IAsyncResult BeginSecureOutgoingMessage(Message message, TimeSpan timeout, SecurityProtocolCorrelationState correlationState, AsyncCallback callback, object state)
 {
     IAsyncResult result;
     if (message == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("message");
     }
     base.CommunicationObject.ThrowIfClosedOrNotOpen();
     string actor = string.Empty;
     try
     {
         if (base.SecurityProtocolFactory.ActAsInitiator)
         {
             return this.BeginSecureOutgoingMessageAtInitiatorCore(message, actor, timeout, callback, state);
         }
         this.SecureOutgoingMessageAtResponder(ref message, actor);
         result = new CompletedAsyncResult<Message>(message, callback, state);
     }
     catch (Exception exception)
     {
         if (Fx.IsFatal(exception))
         {
             throw;
         }
         base.OnSecureOutgoingMessageFailure(message);
         throw;
     }
     return result;
 }
Beispiel #2
0
        public bool EndDequeue(IAsyncResult result, out T value)
        {
            CompletedAsyncResult <T> typedResult = result as CompletedAsyncResult <T>;

            if (typedResult != null)
            {
                value = CompletedAsyncResult <T> .End(result);

                return(true);
            }

            return(AsyncQueueReader.End(result, out value));
        }
Beispiel #3
0
        public bool EndWaitForItem(IAsyncResult result)
        {
            CompletedAsyncResult <bool> completedAsyncResult = result as CompletedAsyncResult <bool>;

            if (completedAsyncResult == null)
            {
                return(InputQueue <T> .AsyncQueueWaiter.End(result));
            }
            else
            {
                return(CompletedAsyncResult <bool> .End(result));
            }
        }
Beispiel #4
0
        public bool EndDequeue(IAsyncResult result, out T value)
        {
            CompletedAsyncResult <T> completedAsyncResult = result as CompletedAsyncResult <T>;

            if (completedAsyncResult == null)
            {
                return(InputQueue <T> .AsyncQueueReader.End(result, out value));
            }
            else
            {
                value = CompletedAsyncResult <T> .End(result);

                return(true);
            }
        }
        public IAsyncResult BeginSend(object registrant, Message message, Uri via,
            ITransportFactorySettings settings, TimeSpan timeout, AsyncCallback callback, object state, SecurityProtocol securityProtocol)
        {
            PeerFlooder localFlooder;
            int factoryMaxReceivedMessageSize;
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            MessageBuffer messageBuffer = null;
            Message securedMessage = null;
            ulong hopcount = PeerTransportConstants.MaxHopCount;
            PeerMessagePropagation propagateFlags = PeerMessagePropagation.LocalAndRemote;
            int messageSize = (int)-1;
            byte[] id;
            SendAsyncResult result = new SendAsyncResult(callback, state);
            AsyncCallback onFloodComplete = Fx.ThunkCallback(new AsyncCallback(result.OnFloodComplete));

            try
            {
                lock (ThisLock)
                {
                    ThrowIfNotOpen();
                    localFlooder = flooder;
                }

                // we know this will fit in an int because of our MaxReceivedMessageSize restrictions
                factoryMaxReceivedMessageSize = (int)Math.Min(maxReceivedMessageSize, settings.MaxReceivedMessageSize);
                Guid guid = ProcessOutgoingMessage(message, via);
                SecureOutgoingMessage(ref message, via, timeout, securityProtocol);
                if ((message is SecurityAppliedMessage))
                {
                    ArraySegment<byte> buffer = encoder.WriteMessage(message, int.MaxValue, bufferManager);
                    securedMessage = encoder.ReadMessage(buffer, bufferManager);
                    id = (message as SecurityAppliedMessage).PrimarySignatureValue;
                    messageSize = (int)buffer.Count;
                }
                else
                {
                    securedMessage = message;
                    id = guid.ToByteArray();
                }

                messageBuffer = securedMessage.CreateBufferedCopy(factoryMaxReceivedMessageSize);
                string contentType = settings.MessageEncoderFactory.Encoder.ContentType;
                if (this.messagePropagationFilter != null)
                {
                    using (Message filterMessage = messageBuffer.CreateMessage())
                    {
                        propagateFlags = ((IPeerNodeMessageHandling)this).DetermineMessagePropagation(filterMessage, PeerMessageOrigination.Local);
                    }
                }

                if ((propagateFlags & PeerMessagePropagation.Remote) != PeerMessagePropagation.None)
                {
                    if (hopcount == 0)
                        propagateFlags &= ~PeerMessagePropagation.Remote;
                }

                // flood it out
                IAsyncResult ar = null;
                if ((propagateFlags & PeerMessagePropagation.Remote) != 0)
                {
                    ar = localFlooder.BeginFloodEncodedMessage(id, messageBuffer, timeoutHelper.RemainingTime(), onFloodComplete, null);
                    if (DiagnosticUtility.ShouldTraceVerbose)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.PeerChannelMessageSent, SR.GetString(SR.TraceCodePeerChannelMessageSent), this, message);
                    }
                }
                else
                {
                    ar = new CompletedAsyncResult(onFloodComplete, null);
                }
                if (ar == null)
                {
                    Fx.Assert("SendAsyncResult must have an Async Result for onFloodComplete");
                }

                // queue up the pre-encoded message for local channels
                if ((propagateFlags & PeerMessagePropagation.Local) != 0)
                {
                    using (Message msg = messageBuffer.CreateMessage())
                    {
                        int i = msg.Headers.FindHeader(SecurityJan2004Strings.Security, SecurityJan2004Strings.Namespace);
                        if (i >= 0)
                        {
                            msg.Headers.AddUnderstood(i);
                        }
                        using (MessageBuffer clientBuffer = msg.CreateBufferedCopy(factoryMaxReceivedMessageSize))
                        {
                            DeliverMessageToClientChannels(registrant, clientBuffer, via, message.Headers.To, contentType, messageSize, -1, null);
                        }
                    }
                }
                result.OnLocalDispatchComplete(result);
            }
            finally
            {
                message.Close();
                if (securedMessage != null)
                    securedMessage.Close();
                if (messageBuffer != null)
                    messageBuffer.Close();
            }

            return result;
        }
 public override void EndWrite(IAsyncResult result)
 {
     CompletedAsyncResult.End(result);
 }
            bool PerformOperation()
            {
                IAsyncResult result = null;
                bool completed = false;

                if (this.invoker.isControlOperation)
                {
                    //Mode 1: Dispatch directly to WorkflowServiceInstance method.
                    switch (this.invoker.operationName)
                    {
                        case XD2.WorkflowInstanceManagementService.Suspend:
                        case XD2.WorkflowInstanceManagementService.TransactedSuspend:
                            result = this.workflowServiceInstance.BeginSuspend(false, (string)this.inputs[1] ?? SR.DefaultSuspendReason,
                                this.transaction, this.timeoutHelper.RemainingTime(),
                                this.PrepareAsyncCompletion(handleEndOperation), this);
                            break;
                        case XD2.WorkflowInstanceManagementService.Unsuspend:
                        case XD2.WorkflowInstanceManagementService.TransactedUnsuspend:
                            result = this.workflowServiceInstance.BeginUnsuspend(this.transaction, this.timeoutHelper.RemainingTime(),
                                this.PrepareAsyncCompletion(handleEndOperation), this);
                            break;
                        case XD2.WorkflowInstanceManagementService.Terminate:
                        case XD2.WorkflowInstanceManagementService.TransactedTerminate:
                            result = this.workflowServiceInstance.BeginTerminate((string)this.inputs[1] ?? SR.DefaultTerminationReason,
                                this.transaction, this.timeoutHelper.RemainingTime(),
                                this.PrepareAsyncCompletion(handleEndOperation), this);
                            break;
                        case XD2.WorkflowInstanceManagementService.Run:
                        case XD2.WorkflowInstanceManagementService.TransactedRun:
                            result = this.workflowServiceInstance.BeginRun(this.transaction, this.timeoutHelper.RemainingTime(),
                                this.PrepareAsyncCompletion(handleEndOperation), this);
                            break;
                        case XD2.WorkflowInstanceManagementService.Cancel:
                        case XD2.WorkflowInstanceManagementService.TransactedCancel:
                            result = this.workflowServiceInstance.BeginCancel(this.transaction,
                                this.timeoutHelper.RemainingTime(), this.PrepareAsyncCompletion(handleEndOperation), this);
                            break;
                        case XD2.WorkflowInstanceManagementService.Abandon:
                            string reason = (string)this.inputs[1];
                            result = this.workflowServiceInstance.BeginAbandon(
                                new WorkflowApplicationAbortedException(!String.IsNullOrEmpty(reason) ? reason : SR.DefaultAbortReason),
                                this.timeoutHelper.RemainingTime(), this.PrepareAsyncCompletion(handleEndOperation), this);
                            break;
                        case XD2.WorkflowInstanceManagementService.Update:
                        case XD2.WorkflowInstanceManagementService.TransactedUpdate:
                            WorkflowIdentity identity = (WorkflowIdentity)this.inputs[1];
                            if (!object.Equals(identity, this.workflowServiceInstance.DefinitionIdentity))
                            {
                                throw FxTrace.Exception.AsError(new FaultException(
                                    OperationExecutionFault.CreateUpdateFailedFault(SR.CannotUpdateLoadedInstance(this.workflowServiceInstance.Id))));
                            }
                            if (this.workflowServiceInstance.IsActive)
                            {
                                result = this.workflowServiceInstance.BeginRun(this.transaction, this.invoker.operationName, this.timeoutHelper.RemainingTime(),
                                    this.PrepareAsyncCompletion(handleEndOperation), this);
                            }
                            else
                            {
                                result = new CompletedAsyncResult(this.PrepareAsyncCompletion(handleEndOperation), this);
                            }
                            break;
                        default:
                            throw Fx.AssertAndThrow("Unreachable code");

                    }
                    if (this.notification != null)
                    {
                        this.notification.NotifyInvokeReceived();
                    }
                }
                else if (this.getInstanceContext.WorkflowCreationContext != null)
                {
                    result = BeginRunAndGetResponse(timeoutHelper, this.PrepareAsyncCompletion(handleEndOperation), this);
                    if (this.notification != null)
                    {
                        this.notification.NotifyInvokeReceived();
                    }
                }
                else
                {
                    try
                    {
                        //User Endpoint operation.
                        result = this.invoker.OnBeginServiceOperation(this.workflowServiceInstance, this.operationContext,
                            this.inputs, this.transaction, this.notification, this.timeoutHelper.RemainingTime(),
                            this.PrepareAsyncCompletion(handleEndOperation), this);
                    }
                    catch (FaultException)
                    {
                        throw; // ReceiveContext was handled appropriately by WorkflowOperationContext
                    }
                    catch (Exception exception)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        if (!ShouldAbandonReceiveContext())
                        {
                            throw;
                        }
                        return AbandonReceiveContext(exception);
                    }
                }

                if (result != null && result.CompletedSynchronously)
                {
                    completed = HandleEndOperation(result);
                }

                return completed;
            }
 public IAsyncResult BeginSend(object registrant, Message message, Uri via, ITransportFactorySettings settings, TimeSpan timeout, AsyncCallback callback, object state, SecurityProtocol securityProtocol)
 {
     TimeoutHelper helper = new TimeoutHelper(timeout);
     MessageBuffer encodedMessage = null;
     Message message2 = null;
     ulong maxValue = ulong.MaxValue;
     PeerMessagePropagation localAndRemote = PeerMessagePropagation.LocalAndRemote;
     int messageSize = -1;
     SendAsyncResult result = new SendAsyncResult(callback, state);
     AsyncCallback callback2 = Fx.ThunkCallback(new AsyncCallback(result.OnFloodComplete));
     try
     {
         PeerFlooder flooder;
         byte[] primarySignatureValue;
         lock (this.ThisLock)
         {
             this.ThrowIfNotOpen();
             flooder = this.flooder;
         }
         int maxBufferSize = (int) Math.Min(this.maxReceivedMessageSize, settings.MaxReceivedMessageSize);
         Guid guid = this.ProcessOutgoingMessage(message, via);
         this.SecureOutgoingMessage(ref message, via, timeout, securityProtocol);
         if (message is SecurityAppliedMessage)
         {
             ArraySegment<byte> buffer = this.encoder.WriteMessage(message, 0x7fffffff, this.bufferManager);
             message2 = this.encoder.ReadMessage(buffer, this.bufferManager);
             primarySignatureValue = (message as SecurityAppliedMessage).PrimarySignatureValue;
             messageSize = buffer.Count;
         }
         else
         {
             message2 = message;
             primarySignatureValue = guid.ToByteArray();
         }
         encodedMessage = message2.CreateBufferedCopy(maxBufferSize);
         string contentType = settings.MessageEncoderFactory.Encoder.ContentType;
         if (this.messagePropagationFilter != null)
         {
             using (Message message3 = encodedMessage.CreateMessage())
             {
                 localAndRemote = ((IPeerNodeMessageHandling) this).DetermineMessagePropagation(message3, PeerMessageOrigination.Local);
             }
         }
         if (((localAndRemote & PeerMessagePropagation.Remote) != PeerMessagePropagation.None) && (maxValue == 0L))
         {
             localAndRemote &= ~PeerMessagePropagation.Remote;
         }
         IAsyncResult result2 = null;
         if ((localAndRemote & PeerMessagePropagation.Remote) != PeerMessagePropagation.None)
         {
             result2 = flooder.BeginFloodEncodedMessage(primarySignatureValue, encodedMessage, helper.RemainingTime(), callback2, null);
             if (System.ServiceModel.DiagnosticUtility.ShouldTraceVerbose)
             {
                 TraceUtility.TraceEvent(TraceEventType.Verbose, 0x4003e, System.ServiceModel.SR.GetString("TraceCodePeerChannelMessageSent"), this, message);
             }
         }
         else
         {
             result2 = new CompletedAsyncResult(callback2, null);
         }
         if ((localAndRemote & PeerMessagePropagation.Local) != PeerMessagePropagation.None)
         {
             using (Message message4 = encodedMessage.CreateMessage())
             {
                 int i = message4.Headers.FindHeader("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
                 if (i >= 0)
                 {
                     message4.Headers.AddUnderstood(i);
                 }
                 using (MessageBuffer buffer3 = message4.CreateBufferedCopy(maxBufferSize))
                 {
                     this.DeliverMessageToClientChannels(registrant, buffer3, via, message.Headers.To, contentType, messageSize, -1, null);
                 }
             }
         }
         result.OnLocalDispatchComplete(result);
     }
     finally
     {
         message.Close();
         if (message2 != null)
         {
             message2.Close();
         }
         if (encodedMessage != null)
         {
             encodedMessage.Close();
         }
     }
     return result;
 }
Beispiel #9
0
 public virtual void EndWrite(IAsyncResult result)
 {
     CompletedAsyncResult.End(result);
 }