예제 #1
0
        private void SendMessage(IStoreV1CommunicationData message, int retryCount)
        {
            var       count     = 0;
            Exception exception = null;

            while (count < retryCount)
            {
                EnsureChannelIsAvailable();
                exception = null;

                try
                {
                    var service = m_Service;
                    if (!m_IsDisposed)
                    {
                        var confirmation = service.AcceptMessage(message);
                        if ((m_Channel.State == CommunicationState.Opened) && (confirmation != null) && confirmation.WasDataReceived)
                        {
                            return;
                        }
                    }
                }
                catch (FaultException e)
                {
                    m_Diagnostics.Log(
                        LevelToLog.Error,
                        CommunicationConstants.DefaultLogTextPrefix,
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Exception occurred during the sending of message of type {0}. Exception was: {1}",
                            message.GetType(),
                            e));

                    // If there is no inner exception then there is no point in keeping the original call stack.
                    // The originalexception orginates on the other side of the channel which means that there is no
                    // useful stack trace to keep!
                    m_WasFaulted = true;
                    exception    = e.InnerException != null
                        ? new FailedToSendMessageException(Resources.Exceptions_Messages_FailedToSendMessage, e.InnerException)
                        : new FailedToSendMessageException();
                }
                catch (CommunicationException e)
                {
                    // Either the connection was aborted or faulted (although it shouldn't be)
                    // or something else nasty went wrong.
                    m_WasFaulted = true;
                    exception    = new FailedToSendMessageException(Resources.Exceptions_Messages_FailedToSendMessage, e);
                }

                count++;
            }

            if ((m_Channel.State != CommunicationState.Opened) && (exception == null))
            {
                exception = new FailedToSendMessageException();
            }

            if (exception != null)
            {
                throw exception;
            }
        }
예제 #2
0
        private void SendMessage(StreamData message, int retryCount)
        {
            var       initialStreamPosition = message.Data.Position;
            var       count     = 0;
            Exception exception = null;

            while (count < retryCount)
            {
                EnsureChannelIsAvailable();
                exception = null;

                try
                {
                    var service = m_Service;
                    if (!m_IsDisposed)
                    {
                        var confirmation = service.AcceptStream(message);
                        if ((m_Channel.State == CommunicationState.Opened) && (confirmation != null) && confirmation.WasDataReceived)
                        {
                            return;
                        }
                    }
                }
                catch (FaultException e)
                {
                    m_Diagnostics.Log(
                        LevelToLog.Error,
                        CommunicationConstants.DefaultLogTextPrefix,
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Exception occurred during the sending of data. Exception was: {0}",
                            e));

                    // If there is no inner exception then there is no point in keeping the original call stack.
                    // The originalexception orginates on the other side of the channel which means that there is no
                    // useful stack trace to keep!
                    m_WasFaulted = true;
                    exception    = e.InnerException != null
                        ? new FailedToSendMessageException(Resources.Exceptions_Messages_FailedToSendMessage, e.InnerException)
                        : new FailedToSendMessageException();
                }
                catch (CommunicationException e)
                {
                    // Either the connection was aborted or faulted (although it shouldn't be)
                    // or something else nasty went wrong.
                    //
                    // Abort the channel because it is useless now ..
                    m_WasFaulted = true;
                    exception    = new FailedToSendMessageException(Resources.Exceptions_Messages_FailedToSendMessage, e);
                }

                // After the first try the position of the stream will have changed because
                // the WCF connection read from it. In order to retry the message send we'll need
                // to reset it to the original position. If we can't do that, then we just pretend
                // we tried enough times.
                if ((message.Data.Position != initialStreamPosition) && !message.Data.CanSeek)
                {
                    count     = retryCount;
                    exception = exception ?? new FailedToSendMessageException();
                }

                message.Data.Position = initialStreamPosition;

                count++;
            }

            if ((m_Channel.State != CommunicationState.Opened) && (exception == null))
            {
                exception = new FailedToSendMessageException();
            }

            if (exception != null)
            {
                throw exception;
            }
        }