public Message Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
        {
            if (!this.ValidateOutputOperation(message, timeout, maskingMode))
            {
                return(null);
            }

            bool autoAborted = false;

            try
            {
                TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
                TChannel      channel;

                if (!this.Synchronizer.TryGetChannelForOutput(timeoutHelper.RemainingTime(), maskingMode,
                                                              out channel))
                {
                    if (!ReliableChannelBinderHelper.MaskHandled(maskingMode))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                  new TimeoutException(SR.GetString(SR.TimeoutOnRequest, timeout)));
                    }

                    return(null);
                }

                if (channel == null)
                {
                    return(null);
                }

                try
                {
                    return(this.OnRequest(channel, message, timeoutHelper.RemainingTime(),
                                          maskingMode));
                }
                finally
                {
                    autoAborted = this.Synchronizer.Aborting;
                    this.Synchronizer.ReturnChannel();
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                if (!this.HandleException(e, maskingMode, autoAborted))
                {
                    throw;
                }
                else
                {
                    return(null);
                }
            }
        }
        public async Task <Message> RequestAsync(Message message, TimeSpan timeout, MaskingMode maskingMode)
        {
            if (!ValidateOutputOperation(message, timeout, maskingMode))
            {
                return(null);
            }

            bool autoAborted = false;

            try
            {
                TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
                (bool success, TChannel channel) = await Synchronizer.TryGetChannelForOutputAsync(timeoutHelper.RemainingTime(), maskingMode);

                if (!success)
                {
                    if (!ReliableChannelBinderHelper.MaskHandled(maskingMode))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                  new TimeoutException(SR.Format(SR.TimeoutOnRequest, timeout)));
                    }

                    return(null);
                }

                if (channel == null)
                {
                    return(null);
                }

                try
                {
                    return(await OnRequestAsync(channel, message, timeoutHelper.RemainingTime(),
                                                maskingMode));
                }
                finally
                {
                    autoAborted = Synchronizer.Aborting;
                    Synchronizer.ReturnChannel();
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                if (!HandleException(e, maskingMode, autoAborted))
                {
                    throw;
                }
                else
                {
                    return(null);
                }
            }
        }
        public Message Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
        {
            Message message2;

            if (!base.ValidateOutputOperation(message, timeout, maskingMode))
            {
                return(null);
            }
            bool autoAborted = false;

            try
            {
                TChannel      local;
                TimeoutHelper helper = new TimeoutHelper(timeout);
                if (!base.Synchronizer.TryGetChannelForOutput(helper.RemainingTime(), maskingMode, out local))
                {
                    if (!ReliableChannelBinderHelper.MaskHandled(maskingMode))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TimeoutException(System.ServiceModel.SR.GetString("TimeoutOnRequest", new object[] { timeout })));
                    }
                    return(null);
                }
                if (local == null)
                {
                    message2 = null;
                }
                else
                {
                    try
                    {
                        message2 = this.OnRequest(local, message, helper.RemainingTime(), maskingMode);
                    }
                    finally
                    {
                        autoAborted = base.Synchronizer.Aborting;
                        base.Synchronizer.ReturnChannel();
                    }
                }
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                if (!base.HandleException(exception, maskingMode, autoAborted))
                {
                    throw;
                }
                message2 = null;
            }
            return(message2);
        }
            private bool WaitForEof()
            {
                TimeSpan remainingTime = this.RemainingTime;

                this.lastReceive = remainingTime == TimeSpan.Zero;
                while (true)
                {
                    IAsyncResult result = null;
                    try
                    {
                        result = this.BeginTryInput(remainingTime, ReliableChannelBinderHelper.CloseInputSessionChannelAsyncResult <TChannel, TItem> .onInputCompleteStatic, this);
                    }
                    catch (Exception exception)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        if (!ReliableChannelBinderHelper.MaskHandled(this.binder.DefaultMaskingMode) || !this.binder.IsHandleable(exception))
                        {
                            throw;
                        }
                    }
                    if (result != null)
                    {
                        bool flag;
                        if (!result.CompletedSynchronously)
                        {
                            return(false);
                        }
                        bool flag2 = this.HandleInputComplete(result, out flag);
                        if (flag2 || flag)
                        {
                            return(flag2);
                        }
                    }
                    if (this.lastReceive || (this.channel.State != CommunicationState.Opened))
                    {
                        this.channel.Abort();
                        return(true);
                    }
                    remainingTime    = this.RemainingTime;
                    this.lastReceive = remainingTime == TimeSpan.Zero;
                }
            }
 protected override Task CloseChannelAsync(IDuplexSessionChannel channel, TimeSpan timeout)
 {
     return(ReliableChannelBinderHelper.CloseDuplexSessionChannelAsync(this, channel, timeout));
 }
Exemple #6
0
        internal static void CloseReplySessionChannel(ReliableChannelBinder <IReplySessionChannel> binder, IReplySessionChannel channel, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            binder.WaitForPendingOperations(timeoutHelper.RemainingTime());
            TimeSpan timeout1 = timeoutHelper.RemainingTime();
            bool     flag1    = timeout1 == TimeSpan.Zero;

            while (true)
            {
                RequestContext context = (RequestContext)null;
                bool           flag2   = true;
                try
                {
                    bool request = channel.TryReceiveRequest(timeout1, out context);
                    flag2 = false;
                    if (request)
                    {
                        if (context == null)
                        {
                            channel.Close(timeoutHelper.RemainingTime());
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }
                    else if (flag2)
                    {
                        if (!ReliableChannelBinderHelper.MaskHandled(binder.DefaultMaskingMode) || !binder.IsHandleable(ex))
                        {
                            throw;
                        }
                        else
                        {
                            flag2 = false;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                finally
                {
                    if (context != null)
                    {
                        context.RequestMessage.Close();
                        context.Close();
                    }
                    if (flag2)
                    {
                        channel.Abort();
                    }
                }
                if (!flag1 && channel.State == CommunicationState.Opened)
                {
                    timeout1 = timeoutHelper.RemainingTime();
                    flag1    = timeout1 == TimeSpan.Zero;
                }
                else
                {
                    break;
                }
            }
            channel.Abort();
        }
Exemple #7
0
            private bool WaitForEof()
            {
                TimeSpan remainingTime = this.RemainingTime;

                this.lastReceive = remainingTime == TimeSpan.Zero;
                bool flag;

                while (true)
                {
                    IAsyncResult result = (IAsyncResult)null;
                    try
                    {
                        result = this.BeginTryInput(remainingTime, ReliableChannelBinderHelper.CloseInputSessionChannelAsyncResult <TChannel, TItem> .onInputCompleteStatic, (object)this);
                    }
                    catch (Exception ex)
                    {
                        if (Fx.IsFatal(ex))
                        {
                            throw;
                        }
                        else
                        {
                            if (ReliableChannelBinderHelper.MaskHandled(this.binder.DefaultMaskingMode))
                            {
                                if (this.binder.IsHandleable(ex))
                                {
                                    goto label_8;
                                }
                            }
                            throw;
                        }
                    }
label_8:
                    if (result != null)
                    {
                        if (result.CompletedSynchronously)
                        {
                            bool gotEof;
                            flag = this.HandleInputComplete(result, out gotEof);
                            if (flag | gotEof)
                            {
                                break;
                            }
                        }
                        else
                        {
                            goto label_12;
                        }
                    }
                    if (!this.lastReceive && this.channel.State == CommunicationState.Opened)
                    {
                        remainingTime    = this.RemainingTime;
                        this.lastReceive = remainingTime == TimeSpan.Zero;
                    }
                    else
                    {
                        goto label_14;
                    }
                }
                return(flag);

label_12:
                return(false);

label_14:
                this.channel.Abort();
                return(true);
            }
Exemple #8
0
            private bool HandleInputComplete(IAsyncResult result, out bool gotEof)
            {
                TItem obj   = default(TItem);
                bool  flag1 = true;

                gotEof = false;
                try
                {
                    bool flag2 = this.EndTryInput(result, out obj);
                    flag1 = false;
                    if (!flag2 || (object)obj != null)
                    {
                        if (!this.lastReceive && this.channel.State == CommunicationState.Opened)
                        {
                            return(false);
                        }
                        this.channel.Abort();
                        return(true);
                    }
                    gotEof = true;
                    result = this.channel.BeginClose(this.RemainingTime, ReliableChannelBinderHelper.CloseInputSessionChannelAsyncResult <TChannel, TItem> .onChannelCloseCompleteStatic, (object)this);
                    if (!result.CompletedSynchronously)
                    {
                        return(false);
                    }
                    this.HandleChannelCloseComplete(result);
                    return(true);
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }
                    else if (flag1)
                    {
                        if (!ReliableChannelBinderHelper.MaskHandled(this.binder.DefaultMaskingMode) || !this.binder.IsHandleable(ex))
                        {
                            throw;
                        }
                        else
                        {
                            if (!this.lastReceive && this.channel.State == CommunicationState.Opened)
                            {
                                return(false);
                            }
                            this.channel.Abort();
                            return(true);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                finally
                {
                    if ((object)obj != null)
                    {
                        this.DisposeItem(obj);
                    }
                    if (flag1)
                    {
                        this.channel.Abort();
                    }
                }
            }
Exemple #9
0
        internal static void CloseDuplexSessionChannel(ReliableChannelBinder <IDuplexSessionChannel> binder, IDuplexSessionChannel channel, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            channel.Session.CloseOutputSession(timeoutHelper.RemainingTime());
            binder.WaitForPendingOperations(timeoutHelper.RemainingTime());
            TimeSpan timeout1 = timeoutHelper.RemainingTime();
            bool     flag1    = timeout1 == TimeSpan.Zero;

            while (true)
            {
                Message message = (Message)null;
                bool    flag2   = true;
                try
                {
                    bool flag3 = channel.TryReceive(timeout1, out message);
                    flag2 = false;
                    if (flag3)
                    {
                        if (message == null)
                        {
                            channel.Close(timeoutHelper.RemainingTime());
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }
                    else if (flag2)
                    {
                        if (!ReliableChannelBinderHelper.MaskHandled(binder.DefaultMaskingMode) || !binder.IsHandleable(ex))
                        {
                            throw;
                        }
                        else
                        {
                            flag2 = false;
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                finally
                {
                    if (message != null)
                    {
                        message.Close();
                    }
                    if (flag2)
                    {
                        channel.Abort();
                    }
                }
                if (!flag1 && channel.State == CommunicationState.Opened)
                {
                    timeout1 = timeoutHelper.RemainingTime();
                    flag1    = timeout1 == TimeSpan.Zero;
                }
                else
                {
                    break;
                }
            }
            channel.Abort();
        }
 protected override void EndCloseChannel(IDuplexSessionChannel channel,
                                         IAsyncResult result)
 {
     ReliableChannelBinderHelper.EndCloseDuplexSessionChannel(channel, result);
 }
 protected override void CloseChannel(IDuplexSessionChannel channel, TimeSpan timeout)
 {
     ReliableChannelBinderHelper.CloseDuplexSessionChannel(this, channel, timeout);
 }
 protected override IAsyncResult BeginCloseChannel(IDuplexSessionChannel channel,
                                                   TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(ReliableChannelBinderHelper.BeginCloseDuplexSessionChannel(this, channel,
                                                                       timeout, callback, state));
 }
            private bool HandleInputComplete(IAsyncResult result, out bool gotEof)
            {
                bool  flag3;
                TItem item = default(TItem);
                bool  flag = true;

                gotEof = false;
                try
                {
                    bool flag2 = false;
                    flag2 = this.EndTryInput(result, out item);
                    flag  = false;
                    if (!flag2 || (item != null))
                    {
                        if (this.lastReceive || (this.channel.State != CommunicationState.Opened))
                        {
                            this.channel.Abort();
                            return(true);
                        }
                        return(false);
                    }
                    gotEof = true;
                    result = this.channel.BeginClose(this.RemainingTime, ReliableChannelBinderHelper.CloseInputSessionChannelAsyncResult <TChannel, TItem> .onChannelCloseCompleteStatic, this);
                    if (result.CompletedSynchronously)
                    {
                        this.HandleChannelCloseComplete(result);
                        return(true);
                    }
                    flag3 = false;
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    if (!flag)
                    {
                        throw;
                    }
                    if (!ReliableChannelBinderHelper.MaskHandled(this.binder.DefaultMaskingMode) || !this.binder.IsHandleable(exception))
                    {
                        throw;
                    }
                    if (this.lastReceive || (this.channel.State != CommunicationState.Opened))
                    {
                        this.channel.Abort();
                        return(true);
                    }
                    flag3 = false;
                }
                finally
                {
                    if (item != null)
                    {
                        this.DisposeItem(item);
                    }
                    if (flag)
                    {
                        this.channel.Abort();
                    }
                }
                return(flag3);
            }