コード例 #1
0
        public bool UpdateForNextAttempt()
        {
            _resultDto = null;

            var correlationId = Guid.NewGuid();

            Attempt += 1;
            var package = new TcpPackage(SentPackage.Command, correlationId, SentPackage.Data);

            SentPackage = package;

            return(true);
        }
コード例 #2
0
        public ProcessResult Process(TcpPackage package)
        {
            try
            {
                if (package.Command != TcpCommand.DeleteStreamCompleted)
                {
                    return(new ProcessResult(ProcessResultStatus.NotifyError,
                                             new Exception(string.Format("Not expected command, expected {0}, received {1}",
                                                                         TcpCommand.DeleteStreamCompleted, package.Command))));
                }

                var data = package.Data;
                var dto  = data.Deserialize <ClientMessages.DeleteStreamCompleted>();
                _resultDto = dto;

                switch ((OperationErrorCode)dto.ErrorCode)
                {
                case OperationErrorCode.Success:
                    return(new ProcessResult(ProcessResultStatus.Success));

                case OperationErrorCode.PrepareTimeout:
                case OperationErrorCode.CommitTimeout:
                case OperationErrorCode.ForwardTimeout:
                    if (Attempt < MaxRetriesCount)
                    {
                        return(new ProcessResult(ProcessResultStatus.Retry));
                    }
                    else
                    {
                        return(new ProcessResult(ProcessResultStatus.NotifyError,
                                                 new Exception(string.Format("Max retries count reached, last error: {0}",
                                                                             (OperationErrorCode)dto.ErrorCode))));
                    }

                case OperationErrorCode.WrongExpectedVersion:
                case OperationErrorCode.StreamDeleted:
                case OperationErrorCode.InvalidTransaction:
                    return(new ProcessResult(ProcessResultStatus.NotifyError,
                                             new Exception(string.Format("{0}", (OperationErrorCode)dto.ErrorCode))));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception ex)
            {
                return(new ProcessResult(ProcessResultStatus.NotifyError, ex));
            }
        }
コード例 #3
0
        public InspectionResult InspectPackage(TcpPackage package)
        {
            try
            {
                if (package.Command != TcpCommand.DeleteStreamCompleted)
                {
                    return(new InspectionResult(InspectionDecision.NotifyError,
                                                new CommandNotExpectedException(TcpCommand.DeleteStreamCompleted.ToString(),
                                                                                package.Command.ToString())));
                }

                var data = package.Data;
                var dto  = data.Deserialize <ClientMessages.DeleteStreamCompleted>();
                _result = dto;

                switch ((OperationErrorCode)dto.ErrorCode)
                {
                case OperationErrorCode.Success:
                    return(new InspectionResult(InspectionDecision.Succeed));

                case OperationErrorCode.PrepareTimeout:
                case OperationErrorCode.CommitTimeout:
                case OperationErrorCode.ForwardTimeout:
                    return(new InspectionResult(InspectionDecision.Retry));

                case OperationErrorCode.WrongExpectedVersion:
                    var err = string.Format("Delete stream failed due to WrongExpectedVersion. Stream: {0}, Expected version: {1}, CorrID: {2}.",
                                            _stream,
                                            _expectedVersion,
                                            CorrelationId);
                    return(new InspectionResult(InspectionDecision.NotifyError, new WrongExpectedVersionException(err)));

                case OperationErrorCode.StreamDeleted:
                    return(new InspectionResult(InspectionDecision.NotifyError, new StreamDeletedException(_stream)));

                case OperationErrorCode.InvalidTransaction:
                    return(new InspectionResult(InspectionDecision.NotifyError, new InvalidTransactionException()));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                return(new InspectionResult(InspectionDecision.NotifyError, e));
            }
        }
コード例 #4
0
        public ProcessResult Process(TcpPackage package)
        {
            try
            {
                if (package.Command != TcpCommand.DeleteStreamCompleted)
                {
                    return new ProcessResult(ProcessResultStatus.NotifyError,
                                             new Exception(string.Format("Not expected command, expected {0}, received {1}",
                                                                         TcpCommand.DeleteStreamCompleted, package.Command)));
                }

                var data = package.Data;
                var dto = data.Deserialize<ClientMessages.DeleteStreamCompleted>();
                _resultDto = dto;

                switch ((OperationErrorCode)dto.ErrorCode)
                {
                    case OperationErrorCode.Success:
                        return new ProcessResult(ProcessResultStatus.Success);

                    case OperationErrorCode.PrepareTimeout:
                    case OperationErrorCode.CommitTimeout:
                    case OperationErrorCode.ForwardTimeout:
                        if (Attempt < MaxRetriesCount)
                        {
                            return new ProcessResult(ProcessResultStatus.Retry);
                        }
                        else
                        {
                            return new ProcessResult(ProcessResultStatus.NotifyError,
                                                     new Exception(string.Format("Max retries count reached, last error: {0}",
                                                                  (OperationErrorCode)dto.ErrorCode)));
                        }
                    case OperationErrorCode.WrongExpectedVersion:
                    case OperationErrorCode.StreamDeleted:
                    case OperationErrorCode.InvalidTransaction:
                        return new ProcessResult(ProcessResultStatus.NotifyError,
                                                 new Exception(string.Format("{0}", (OperationErrorCode)dto.ErrorCode)));
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception ex)
            {
                return new ProcessResult(ProcessResultStatus.NotifyError, ex);
            }
        }
コード例 #5
0
        public bool UpdateForNextAttempt()
        {
            _resultDto = null;

            var correlationId = Guid.NewGuid();
            Attempt += 1;
            var package = new TcpPackage(SentPackage.Command, correlationId, SentPackage.Data);
            SentPackage = package;

            return true;
        }