コード例 #1
0
        public BsonValue CreateResponseMessageBackup(object command, MediatrActions action = MediatrActions.Sent,
                                                     bool increaseRetryCounter             = false, string additionalData = null, string errorData = null)
        {
            try
            {
                var backUp = new MediatRBackup
                {
                    Id             = Guid.NewGuid(),
                    Retries        = increaseRetryCounter ? 1 : 0,
                    AdditionalData = string.IsNullOrEmpty(additionalData) ? string.Empty : additionalData,
                    IsError        = false,
                    MessageContent = GetSerializedContent(command), //System.Text.Json.JsonSerializer.Serialize(command),
                    TimeStampUTC   = DateTime.UtcNow.ToUniversalTime(),
                    Action         = action.ToString(),
                    Error          = string.IsNullOrEmpty(errorData) ? string.Empty : errorData
                };

                return(MediatRBackupLiteDbRepository.Create(backUp));
            }
            catch (Exception ex)
            {
                Devon4NetLogger.Error(ex);
                throw;
            }
        }
コード例 #2
0
        public BsonValue CreateMessageBackup <T>(ActionBase <T> command, MediatrActions action = MediatrActions.Sent,
                                                 bool increaseRetryCounter = false, string additionalData = null, string errorData = null) where T : class
        {
            try
            {
                if (command?.InternalMessageIdentifier == null || command.InternalMessageIdentifier.IsNullOrEmptyGuid())
                {
                    throw new ArgumentException($"The provided command  and the command identifier cannot be null ");
                }

                var backUp = new MediatRBackup
                {
                    Id = Guid.NewGuid(),
                    InternalMessageIdentifier = command.InternalMessageIdentifier,
                    Retries        = increaseRetryCounter ? 1 : 0,
                    AdditionalData = string.IsNullOrEmpty(additionalData) ? string.Empty : additionalData,
                    IsError        = false,
                    MessageContent = GetSerializedContent(command), //System.Text.Json.JsonSerializer.Serialize(command),
                    MessageType    = command.MessageType,
                    TimeStampUTC   = command.Timestamp.ToUniversalTime(),
                    Action         = action.ToString(),
                    Error          = string.IsNullOrEmpty(errorData) ? string.Empty : errorData
                };

                return(MediatRBackupLiteDbRepository.Create(backUp));
            }
            catch (Exception ex)
            {
                Devon4NetLogger.Error(ex);
                throw;
            }
        }
コード例 #3
0
        private async Task BackUpMessage(TRequest request, MediatrActions queueAction = MediatrActions.Sent, bool increaseRetryCounter = false, string additionalData = null, string errorData = null)
        {
            MediatRBackupLiteDbService?.CreateResponseMessageBackup(request, queueAction, increaseRetryCounter, additionalData, errorData);

            if (MediatRBackupService != null && MediatRBackupService.UseExternalDatabase)
            {
                await MediatRBackupService.CreateResponseMessageBackup(request, queueAction, increaseRetryCounter, additionalData, errorData).ConfigureAwait(false);
            }
        }
コード例 #4
0
        private async Task BackUpMessage <TResult>(ActionBase <TResult> command, MediatrActions queueAction = MediatrActions.Sent, bool increaseRetryCounter = false, string additionalData = null, string errorData = null) where TResult : class
        {
            try
            {
                MediatRBackupLiteDbService?.CreateMessageBackup(command, queueAction, increaseRetryCounter, additionalData, errorData);

                if (MediatRBackupService?.UseExternalDatabase == true)
                {
                    await MediatRBackupService.CreateMessageBackup(command, queueAction, increaseRetryCounter, additionalData, errorData).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                Devon4NetLogger.Error($"Error making the backup of the MediatR action base. {ex.Message} {ex.InnerException}");
                Devon4NetLogger.Error(ex);
                throw;
            }
        }
コード例 #5
0
        public async Task <MediatRBackup> CreateResponseMessageBackup(object command, MediatrActions action = MediatrActions.Sent,
                                                                      bool increaseRetryCounter             = false, string additionalData = null, string errorData = null)
        {
            try
            {
                var ctx = CreateContext();

                var backUp = new MediatRBackup
                {
                    Id             = Guid.NewGuid(),
                    Retries        = increaseRetryCounter ? 1 : 0,
                    AdditionalData = string.IsNullOrEmpty(additionalData) ? string.Empty : additionalData,
                    IsError        = false,
                    MessageContent = GetSerializedContent(command), //System.Text.Json.JsonSerializer.Serialize(command),
                    TimeStampUTC   = DateTime.UtcNow.ToUniversalTime(),
                    Action         = action.ToString(),
                    Error          = string.IsNullOrEmpty(errorData) ? string.Empty : errorData
                };

                var result = await ctx.MediatRBackup.AddAsync(backUp).ConfigureAwait(false);

                await ctx.SaveChangesAsync().ConfigureAwait(false);

                await ctx.DisposeAsync().ConfigureAwait(false);

                return(result.Entity);
            }
            catch (Exception ex)
            {
                Devon4NetLogger.Error(ex);
                throw;
            }
        }
コード例 #6
0
        public async Task <MediatRBackup> CreateMessageBackup <T>(ActionBase <T> command, MediatrActions action = MediatrActions.Sent, bool increaseRetryCounter = false, string additionalData = null, string errorData = null) where T : class
        {
            MediatRBackupContext ctx = null;

            try
            {
                ctx = CreateContext();

                CheckCommandContext(command, ctx);

                var backUp = new MediatRBackup
                {
                    Id = Guid.NewGuid(),
                    InternalMessageIdentifier = command.InternalMessageIdentifier,
                    Retries        = increaseRetryCounter ? 1 : 0,
                    AdditionalData = string.IsNullOrEmpty(additionalData) ? string.Empty : additionalData,
                    IsError        = false,
                    MessageContent = GetSerializedContent(command),
                    MessageType    = command.MessageType,
                    TimeStampUTC   = command.Timestamp.ToUniversalTime(),
                    Action         = action.ToString(),
                    Error          = string.IsNullOrEmpty(errorData) ? string.Empty : errorData
                };

                var result = await ctx.MediatRBackup.AddAsync(backUp).ConfigureAwait(false);

                await ctx.SaveChangesAsync().ConfigureAwait(false);

                await ctx.DisposeAsync().ConfigureAwait(false);

                return(result.Entity);
            }
            catch (Exception ex)
            {
                Devon4NetLogger.Error(ex);
                throw;
            }
            finally
            {
                if (ctx != null)
                {
                    await ctx.DisposeAsync().ConfigureAwait(false);
                }
            }
        }