public async Task <AsyncTaskResult> AddRecordAsync(TwoMessageHandleRecord record)
        {
            try
            {
                using (var connection = GetConnection())
                {
                    await connection.InsertToMySqlAsync(record, _twoMessageTableName);

                    return(AsyncTaskResult.Success);
                }
            }
            catch (DbException ex)
            {
                //if (ex.Number == 2627 && ex.Message.Contains(_twoMessageTablePrimaryKeyName))
                //{
                //    return AsyncTaskResult.Success;
                //}
                _logger.Error("Insert two-message handle record has sql exception.", ex);
                return(new AsyncTaskResult(AsyncTaskStatus.IOException, ex.Message));
            }
            catch (Exception ex)
            {
                _logger.Error("Insert two-message handle record has unknown exception.", ex);
                return(new AsyncTaskResult(AsyncTaskStatus.Failed, ex.Message));
            }
        }
 public async Task<AsyncTaskResult> AddRecordAsync(TwoMessageHandleRecord record)
 {
     try
     {
         using (var connection = GetConnection())
         {
             await connection.InsertAsync(record, _twoMessageTableName);
             return AsyncTaskResult.Success;
         }
     }
     catch (SqlException ex)
     {
         if (ex.Number == 2627 && ex.Message.Contains(_twoMessageTablePrimaryKeyName))
         {
             return AsyncTaskResult.Success;
         }
         _logger.Error("Insert two-message handle record has sql exception.", ex);
         return new AsyncTaskResult(AsyncTaskStatus.IOException, ex.Message);
     }
     catch (Exception ex)
     {
         _logger.Error("Insert two-message handle record has unknown exception.", ex);
         return new AsyncTaskResult(AsyncTaskStatus.Failed, ex.Message);
     }
 }
        private void HandleTwoMessageAsync(MultiMessageDisptaching multiMessageDispatching, IMessageHandlerProxy2 handlerProxy, string handlerTypeName, QueuedHandler <IMessageHandlerProxy2> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;
            var message1 = messages[0];
            var message2 = messages[1];

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("HandleTwoMessageAsync",
                                                                  () => handlerProxy.HandleAsync(message1, message2),
                                                                  currentRetryTimes => HandleTwoMessageAsync(multiMessageDispatching, handlerProxy, handlerTypeName, queueHandler, currentRetryTimes),
                                                                  result =>
            {
                var message1TypeName    = _typeNameProvider.GetTypeName(message1.GetType());
                var message2TypeName    = _typeNameProvider.GetTypeName(message2.GetType());
                var messageHandleRecord = new TwoMessageHandleRecord
                {
                    MessageId1       = message1.Id,
                    MessageId2       = message2.Id,
                    Message1TypeName = message1TypeName,
                    Message2TypeName = message2TypeName,
                    HandlerTypeName  = handlerTypeName,
                    CreatedOn        = DateTime.Now
                };
                var sequenceMessage = message1 as ISequenceMessage;
                if (sequenceMessage != null)
                {
                    messageHandleRecord.AggregateRootTypeName = sequenceMessage.AggregateRootTypeName;
                    messageHandleRecord.AggregateRootId       = sequenceMessage.AggregateRootStringId;
                    messageHandleRecord.Version = sequenceMessage.Version;
                }

                AddTwoMessageHandledRecordAsync(multiMessageDispatching, messageHandleRecord, handlerTypeName, handlerProxy, queueHandler, 0);
            },
                                                                  () => string.Format("[messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name),
                                                                  null,
                                                                  retryTimes,
                                                                  true);
        }
 public Task<AsyncTaskResult> AddRecordAsync(TwoMessageHandleRecord record)
 {
     _dict.TryAdd(record.MessageId1 + record.MessageId2 + record.HandlerTypeCode.ToString(), 0);
     return _successTask;
 }
        private void AddTwoMessageHandledRecordAsync(MultiMessageDisptaching multiMessageDispatching, TwoMessageHandleRecord messageHandleRecord, string handlerTypeName, IMessageHandlerProxy2 handlerProxy, QueuedHandler <IMessageHandlerProxy2> queueHandler, int retryTimes)
        {
            var messages = multiMessageDispatching.Messages;

            _ioHelper.TryAsyncActionRecursively <AsyncTaskResult>("AddTwoMessageHandledRecordAsync",
                                                                  () => _messageHandleRecordStore.AddRecordAsync(messageHandleRecord),
                                                                  currentRetryTimes => AddTwoMessageHandledRecordAsync(multiMessageDispatching, messageHandleRecord, handlerTypeName, handlerProxy, queueHandler, currentRetryTimes),
                                                                  result =>
            {
                multiMessageDispatching.RemoveHandledHandler(handlerTypeName);
                if (queueHandler != null)
                {
                    queueHandler.OnHandlerFinished(handlerProxy);
                }
                if (_logger.IsDebugEnabled)
                {
                    _logger.DebugFormat("TwoMessage handled success, [messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name);
                }
            },
                                                                  () => string.Format("[messages:[{0}], handlerType:{1}]", string.Join("|", messages.Select(x => string.Format("id:{0},type:{1}", x.Id, x.GetType().Name))), handlerProxy.GetInnerObject().GetType().Name),
                                                                  null,
                                                                  retryTimes,
                                                                  true);
        }
 public Task <AsyncTaskResult> AddRecordAsync(TwoMessageHandleRecord record)
 {
     _dict.TryAdd(record.MessageId1 + record.MessageId2 + record.HandlerTypeCode.ToString(), 0);
     return(_successTask);
 }