public AddAsyncResult(Message message, bool isLast, TimeSpan timeout, object state,
                                  ReliableOutputConnection connection, AsyncCallback callback, object asyncState)
                : base(callback, asyncState)
            {
                this.connection    = connection;
                this.timeoutHelper = new TimeoutHelper(timeout);
                this.isLast        = isLast;

                bool         complete = false;
                IAsyncResult result;

                try
                {
                    if (isLast)
                    {
                        if (state != null)
                        {
                            throw Fx.AssertAndThrow("The isLast overload does not take a state.");
                        }

                        result = this.connection.strategy.BeginAddLast(message, this.timeoutHelper.RemainingTime(), state, addCompleteStatic, this);
                    }
                    else
                    {
                        result = this.connection.strategy.BeginAdd(message, this.timeoutHelper.RemainingTime(), state, addCompleteStatic, this);
                    }
                }
                catch (TimeoutException)
                {
                    if (isLast)
                    {
                        this.connection.RaiseFault(null, SequenceTerminatedFault.CreateCommunicationFault(this.connection.id, SR.GetString(SR.SequenceTerminatedAddLastToWindowTimedOut), null));
                    }
                    // else - RM does not fault the channel based on a timeout exception trying to add a sequenced message to the window.

                    throw;
                }
                catch (Exception e)
                {
                    if (!Fx.IsFatal(e))
                    {
                        this.connection.RaiseFault(null, SequenceTerminatedFault.CreateCommunicationFault(this.connection.id, SR.GetString(SR.SequenceTerminatedUnknownAddToWindowError), null));
                    }

                    throw;
                }

                if (result.CompletedSynchronously)
                {
                    complete = this.CompleteAdd(result);
                }

                if (complete)
                {
                    this.Complete(true);
                }
            }
 protected override void OnOpened()
 {
     base.OnOpened();
     Connection = new ReliableOutputConnection(_session.OutputID, Settings.MaxTransferWindowSize,
                                               Settings.MessageVersion, Settings.ReliableMessagingVersion, _session.InitiationTime,
                                               RequestAcks, DefaultSendTimeout);
     Connection.Faulted                     += OnComponentFaulted;
     Connection.OnException                 += OnComponentException;
     Connection.SendAsyncHandler             = OnConnectionSendAsyncHandler;
     Connection.SendAckRequestedAsyncHandler = OnConnectionSendAckRequestedAsyncHandler;
 }
 protected override void OnOpened()
 {
     base.OnOpened();
     this.connection                              = new ReliableOutputConnection(this.session.OutputID, this.settings.MaxTransferWindowSize, this.settings.MessageVersion, this.settings.ReliableMessagingVersion, this.session.InitiationTime, false, base.DefaultSendTimeout);
     this.connection.Faulted                      = (ComponentFaultedHandler)Delegate.Combine(this.connection.Faulted, new ComponentFaultedHandler(this.OnComponentFaulted));
     this.connection.OnException                  = (ComponentExceptionHandler)Delegate.Combine(this.connection.OnException, new ComponentExceptionHandler(this.OnComponentException));
     this.connection.BeginSendHandler             = new BeginSendHandler(this.OnConnectionBeginSend);
     this.connection.EndSendHandler               = new EndSendHandler(this.OnConnectionEndSend);
     this.connection.SendHandler                  = new SendHandler(this.OnConnectionSend);
     this.connection.BeginSendAckRequestedHandler = new OperationWithTimeoutBeginCallback(this.OnConnectionBeginSendAckRequested);
     this.connection.EndSendAckRequestedHandler   = new OperationEndCallback(this.OnConnectionEndSendAckRequested);
     this.connection.SendAckRequestedHandler      = new OperationWithTimeoutCallback(this.OnConnectionSendAckRequested);
 }
            public AddAsyncResult(Message message, bool isLast, TimeSpan timeout, object state, ReliableOutputConnection connection, AsyncCallback callback, object asyncState) : base(callback, asyncState)
            {
                IAsyncResult result;

                this.connection    = connection;
                this.timeoutHelper = new TimeoutHelper(timeout);
                this.isLast        = isLast;
                bool flag = false;

                try
                {
                    if (isLast)
                    {
                        if (state != null)
                        {
                            throw Fx.AssertAndThrow("The isLast overload does not take a state.");
                        }
                        result = this.connection.strategy.BeginAddLast(message, this.timeoutHelper.RemainingTime(), state, addCompleteStatic, this);
                    }
                    else
                    {
                        result = this.connection.strategy.BeginAdd(message, this.timeoutHelper.RemainingTime(), state, addCompleteStatic, this);
                    }
                }
                catch (TimeoutException)
                {
                    if (isLast)
                    {
                        this.connection.RaiseFault(null, SequenceTerminatedFault.CreateCommunicationFault(this.connection.id, System.ServiceModel.SR.GetString("SequenceTerminatedAddLastToWindowTimedOut"), null));
                    }
                    throw;
                }
                catch (Exception exception)
                {
                    if (!Fx.IsFatal(exception))
                    {
                        this.connection.RaiseFault(null, SequenceTerminatedFault.CreateCommunicationFault(this.connection.id, System.ServiceModel.SR.GetString("SequenceTerminatedUnknownAddToWindowError"), null));
                    }
                    throw;
                }
                if (result.CompletedSynchronously)
                {
                    flag = this.CompleteAdd(result);
                }
                if (flag)
                {
                    base.Complete(true);
                }
            }
 protected override void OnOpened()
 {
     base.OnOpened();
     this.connection = new ReliableOutputConnection(this.session.OutputID, this.settings.MaxTransferWindowSize,
                                                    this.settings.MessageVersion, this.settings.ReliableMessagingVersion, this.session.InitiationTime,
                                                    false, this.DefaultSendTimeout);
     this.connection.Faulted                     += OnComponentFaulted;
     this.connection.OnException                 += OnComponentException;
     this.connection.BeginSendHandler             = OnConnectionBeginSend;
     this.connection.EndSendHandler               = OnConnectionEndSend;
     this.connection.SendHandler                  = OnConnectionSend;
     this.connection.BeginSendAckRequestedHandler = OnConnectionBeginSendAckRequested;
     this.connection.EndSendAckRequestedHandler   = OnConnectionEndSendAckRequested;
     this.connection.SendAckRequestedHandler      = OnConnectionSendAckRequested;
 }
        private static void SendRetries(object state)
        {
            ReliableOutputConnection connection = (ReliableOutputConnection)state;

            try
            {
                connection.SendRetries();
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                connection.RaiseOnException(exception);
            }
        }
 private static void OnSendRetryComplete(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         ReliableOutputConnection asyncState = (ReliableOutputConnection)result.AsyncState;
         try
         {
             asyncState.CompleteSendRetry(result);
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             asyncState.RaiseOnException(exception);
         }
     }
 }
        static void SendRetries(object state)
        {
            ReliableOutputConnection outputConnection = (ReliableOutputConnection)state;

            try
            {
                outputConnection.SendRetries();
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                outputConnection.RaiseOnException(e);
            }
        }
        static void OnSendRetriesComplete(IAsyncResult result)
        {
            if (!result.CompletedSynchronously)
            {
                ReliableOutputConnection outputConnection = (ReliableOutputConnection)result.AsyncState;

                try
                {
                    outputConnection.CompleteSendRetries(result);
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    outputConnection.RaiseOnException(e);
                }
            }
        }
            public AddAsyncResult(Message message, bool isLast, TimeSpan timeout, object state,
                ReliableOutputConnection connection, AsyncCallback callback, object asyncState)
                : base(callback, asyncState)
            {
                this.connection = connection;
                this.timeoutHelper = new TimeoutHelper(timeout);
                this.isLast = isLast;

                bool complete = false;
                IAsyncResult result;

                try
                {
                    if (isLast)
                    {
                        if (state != null)
                        {
                            throw Fx.AssertAndThrow("The isLast overload does not take a state.");
                        }

                        result = this.connection.strategy.BeginAddLast(message, this.timeoutHelper.RemainingTime(), state, addCompleteStatic, this);
                    }
                    else
                    {
                        result = this.connection.strategy.BeginAdd(message, this.timeoutHelper.RemainingTime(), state, addCompleteStatic, this);
                    }
                }
                catch (TimeoutException)
                {
                    if (isLast)
                        this.connection.RaiseFault(null, SequenceTerminatedFault.CreateCommunicationFault(this.connection.id, SR.GetString(SR.SequenceTerminatedAddLastToWindowTimedOut), null));
                    // else - RM does not fault the channel based on a timeout exception trying to add a sequenced message to the window.

                    throw;
                }
                catch (Exception e)
                {
                    if (!Fx.IsFatal(e))
                        this.connection.RaiseFault(null, SequenceTerminatedFault.CreateCommunicationFault(this.connection.id, SR.GetString(SR.SequenceTerminatedUnknownAddToWindowError), null));

                    throw;
                }

                if (result.CompletedSynchronously)
                    complete = this.CompleteAdd(result);

                if (complete)
                    this.Complete(true);
            }
 public AddAsyncResult(Message message, bool isLast, TimeSpan timeout, object state, ReliableOutputConnection connection, AsyncCallback callback, object asyncState) : base(callback, asyncState)
 {
     IAsyncResult result;
     this.connection = connection;
     this.timeoutHelper = new TimeoutHelper(timeout);
     this.isLast = isLast;
     bool flag = false;
     try
     {
         if (isLast)
         {
             if (state != null)
             {
                 throw Fx.AssertAndThrow("The isLast overload does not take a state.");
             }
             result = this.connection.strategy.BeginAddLast(message, this.timeoutHelper.RemainingTime(), state, addCompleteStatic, this);
         }
         else
         {
             result = this.connection.strategy.BeginAdd(message, this.timeoutHelper.RemainingTime(), state, addCompleteStatic, this);
         }
     }
     catch (TimeoutException)
     {
         if (isLast)
         {
             this.connection.RaiseFault(null, SequenceTerminatedFault.CreateCommunicationFault(this.connection.id, System.ServiceModel.SR.GetString("SequenceTerminatedAddLastToWindowTimedOut"), null));
         }
         throw;
     }
     catch (Exception exception)
     {
         if (!Fx.IsFatal(exception))
         {
             this.connection.RaiseFault(null, SequenceTerminatedFault.CreateCommunicationFault(this.connection.id, System.ServiceModel.SR.GetString("SequenceTerminatedUnknownAddToWindowError"), null));
         }
         throw;
     }
     if (result.CompletedSynchronously)
     {
         flag = this.CompleteAdd(result);
     }
     if (flag)
     {
         base.Complete(true);
     }
 }