Beispiel #1
0
        public async Task PublishAsync(IEventSource eventSource,
                                       CancellationToken cancellationToken = default,
                                       IntegrationTypes integrationType    = IntegrationTypes.All)
        {
            if (eventSource == null)
            {
                throw new ArgumentNullException(nameof(eventSource),
                                                "Event source cannot be null.");
            }

            if (cancellationToken == null)
            {
                throw new ArgumentNullException(nameof(cancellationToken),
                                                "Cancellation token cannot be null.");
            }

            var publisherErrors = new List <PublisherException>();

            foreach (IDomainEvent domainEvent in eventSource.DomainEvents)
            {
                try
                {
                    await PublishMessage(domainEvent, integrationType, cancellationToken).ConfigureAwait(false);
                }
                catch (PublisherException ex)
                {
                    publisherErrors.Add(ex);
                }
            }

            if (publisherErrors.Any())
            {
                throw new PublisherException("Exception dispatching event source.", eventSource, publisherErrors);
            }
        }
Beispiel #2
0
        private async Task InvokePublishers(IMessage message, CancellationToken cancellationToken,
                                            IntegrationTypes integrationType)
        {
            TaskListItem <IMessagePublisher>[] taskList = null;

            var publishers = integrationType == IntegrationTypes.All ? _messagePublishers.ToArray()
                : _messagePublishers.Where(p => p.IntegrationType == integrationType).ToArray();

            try
            {
                taskList = publishers.Invoke(message,
                                             (pub, msg) => pub.PublishMessageAsync(msg, cancellationToken));

                await taskList.WhenAll();
            }
            catch (Exception ex)
            {
                if (taskList != null)
                {
                    var publisherErrors = taskList.GetExceptions(ti => new PublisherException(ti));
                    if (publisherErrors.Any())
                    {
                        throw new PublisherException("Exception when invoking message publishers.",
                                                     message,
                                                     publisherErrors);
                    }
                }

                throw new PublisherException("Exception when invoking message publishers.", message, ex);
            }
        }
Beispiel #3
0
 public static string GetAPIURL(IntegrationTypes _intType, Boolean SandBox = false)
 {
     if (_intType == IntegrationTypes.Redirect)
     {
         if (SandBox == true)
         {
             return("https://sbcheckout.payfort.com/FortAPI/paymentPage");
         }
         else
         {
             return("https://checkout.payfort.com/FortAPI/paymentPage");
         }
     }
     else
     {
         if (SandBox == true)
         {
             return("https://sbpaymentservices.payfort.com/FortAPI/paymentApi");
         }
         else
         {
             return("https://paymentservices.payfort.com/FortAPI/paymentApi");
         }
     }
 }
        public async Task <TResult> PublishAsync <TResult>(ICommand <TResult> command, CancellationToken cancellationToken = default(CancellationToken),
                                                           IntegrationTypes integrationType = IntegrationTypes.All)
        {
            Check.NotNull(command, nameof(command), "command not specified");
            await PublishMessageAsync(command, integrationType, cancellationToken);

            return(command.Result);
        }
        public Task <TResult> SendAsync <TResult>(ICommand <TResult> command,
                                                  CancellationToken cancellationToken = default(CancellationToken),
                                                  IntegrationTypes integrationType    = IntegrationTypes.All)
        {
            var result = (TResult)_mockCommandResponses[command.GetType()];

            _receivedMessages.Add(command);
            return(Task.FromResult(result));
        }
        Task IMessagingService.PublishAsync(IEventSource eventSource,
                                            CancellationToken cancellationToken,
                                            IntegrationTypes integrationType)
        {
            if (eventSource == null)
            {
                throw new ArgumentNullException(nameof(eventSource));
            }

            _receivedRequests.Add(eventSource.DomainEvents);
            return(Task.CompletedTask);
        }
Beispiel #7
0
        public async Task SendAsync(ICommand command,
                                    CancellationToken cancellationToken = default,
                                    IntegrationTypes integrationType    = IntegrationTypes.All)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command),
                                                "Command cannot be null.");
            }

            await PublishMessage(command, integrationType, cancellationToken).ConfigureAwait(false);
        }
Beispiel #8
0
        public async Task PublishAsync(IDomainEvent domainEvent,
                                       CancellationToken cancellationToken = default,
                                       IntegrationTypes integrationType    = IntegrationTypes.All)
        {
            if (domainEvent == null)
            {
                throw new ArgumentNullException(nameof(domainEvent),
                                                "Domain event cannot be null.");
            }

            await PublishMessage(domainEvent, integrationType, cancellationToken).ConfigureAwait(false);
        }
 // Private method to which all other publish methods delegate to asynchronously apply
 // the enrichers and to invoke all registered message publishers.
 private async Task PublishMessageAsync(IMessage message, IntegrationTypes integrationType, CancellationToken cancellationToken)
 {
     try
     {
         await ApplyMessageEnrichers(message);
         await InvokePublishers(message, cancellationToken, integrationType);
     }
     catch (PublisherException ex)
     {
         // Log the details of the publish exception and throw a generic error messages.
         _logger.LogError(MessagingLogEvents.MESSAGING_EXCEPTION, ex, "Exception publishing message.");
         throw new PublisherException("Exception publishing message.  See log for details.");
     }
 }
        Task <TResult> IMessagingService.SendAsync <TResult>(ICommand <TResult> command,
                                                             CancellationToken cancellationToken,
                                                             IntegrationTypes integrationType)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            _receivedRequests.Add(command);

            object response = GetCommandResponse(command);

            return(Task.FromResult((TResult)response));
        }
Beispiel #11
0
        // Private method to which all other publish methods delegate to asynchronously apply
        // the enrichers and to invoke all registered message publishers.
        private async Task PublishMessage(IMessage message, IntegrationTypes integrationType,
                                          CancellationToken cancellationToken)
        {
            if (cancellationToken == null)
            {
                throw new ArgumentNullException(nameof(cancellationToken),
                                                "Cancellation token cannot be null.");
            }

            try
            {
                await ApplyMessageEnrichers(message);
                await InvokePublishers(message, cancellationToken, integrationType);
            }
            catch (PublisherException ex)
            {
                // Log the details of the publish exception and rethrow.
                _logger.LogErrorDetails(MessagingLogEvents.MessagingException, ex, "Exception publishing message.");
                throw;
            }
        }
        public async Task PublishAsync(IEventSource eventSource, CancellationToken cancellationToken = default(CancellationToken),
                                       IntegrationTypes integrationType = IntegrationTypes.All)
        {
            Check.NotNull(eventSource, nameof(eventSource), "event source not specified");
            var publisherErrors = new List <PublisherException>();

            foreach (IDomainEvent domainEvent in eventSource.DomainEvents)
            {
                try
                {
                    await PublishMessageAsync(domainEvent, integrationType, cancellationToken);
                }
                catch (PublisherException ex)
                {
                    publisherErrors.Add(ex);
                }
            }

            if (publisherErrors.Any())
            {
                throw new PublisherException("Exception dispatching event source.",
                                             eventSource, publisherErrors);
            }
        }
        private async Task InvokePublishers(IMessage message, CancellationToken cancellationToken, IntegrationTypes integrationType)
        {
            FutureResult <IMessagePublisher>[] futureResults = null;

            var publishers = integrationType == IntegrationTypes.All ? _messagePublishers.ToArray()
                : _messagePublishers.Where(p => p.IntegrationType == integrationType).ToArray();

            try
            {
                futureResults = publishers.Invoke(message,
                                                  (pub, msg) => pub.PublishMessageAsync(msg, cancellationToken));

                await futureResults.WhenAll();
            }
            catch (Exception ex)
            {
                if (futureResults != null)
                {
                    var publisherErrors = futureResults.GetExceptions(fr => new PublisherException(fr));
                    if (publisherErrors.Any())
                    {
                        throw new PublisherException("Exception when invoking message publishers.",
                                                     message,
                                                     publisherErrors);
                    }

                    throw new PublisherException("Exception when invoking message publishers.",
                                                 message, ex);
                }

                throw new PublisherException("Exception when invoking message publishers.",
                                             message, ex);
            }
        }
 public Task SendAsync(ICommand command, CancellationToken cancellationToken = default(CancellationToken), IntegrationTypes integrationType = IntegrationTypes.All)
 {
     throw new NotImplementedException();
 }
 public Task PublishAsync(IEventSource eventSource, CancellationToken cancellationToken = default(CancellationToken), IntegrationTypes integrationType = IntegrationTypes.All)
 {
     throw new NotImplementedException();
 }
Beispiel #16
0
 public Task PublishAsync(IDomainEvent domainEvent,
                          CancellationToken cancellationToken = default,
                          IntegrationTypes integrationType    = IntegrationTypes.All)
 {
     return(_messageDispatcher.PublishAsync(domainEvent, cancellationToken, integrationType));
 }
Beispiel #17
0
 public Task PublishAsync(IEventSource eventSource,
                          CancellationToken cancellationToken = default,
                          IntegrationTypes integrationType    = IntegrationTypes.All)
 {
     return(_messageDispatcher.PublishAsync(eventSource, cancellationToken, integrationType));
 }
Beispiel #18
0
 public Task <TResult> SendAsync <TResult>(ICommand <TResult> command,
                                           CancellationToken cancellationToken = default,
                                           IntegrationTypes integrationType    = IntegrationTypes.All)
 {
     return(_messageDispatcher.SendAsync(command, cancellationToken, integrationType));
 }
 public Task PublishAsync(ICommand command, CancellationToken cancellationToken = default(CancellationToken),
                          IntegrationTypes integrationType = IntegrationTypes.All)
 {
     Check.NotNull(command, nameof(command), "command not specified");
     return(PublishMessageAsync(command, integrationType, cancellationToken));
 }
 public Task PublishAsync(IDomainEvent domainEvent, CancellationToken cancellationToken = default(CancellationToken),
                          IntegrationTypes integrationType = IntegrationTypes.All)
 {
     Check.NotNull(domainEvent, nameof(domainEvent), "domain event not specified");
     return(PublishMessageAsync(domainEvent, integrationType, cancellationToken));
 }