コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #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");
         }
     }
 }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        Task IMessagingService.PublishAsync(IEventSource eventSource,
                                            CancellationToken cancellationToken,
                                            IntegrationTypes integrationType)
        {
            if (eventSource == null)
            {
                throw new ArgumentNullException(nameof(eventSource));
            }

            _receivedRequests.Add(eventSource.DomainEvents);
            return(Task.CompletedTask);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #9
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 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.");
     }
 }
コード例 #10
0
        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));
        }
コード例 #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;
            }
        }
コード例 #12
0
        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);
            }
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
 public Task SendAsync(ICommand command, CancellationToken cancellationToken = default(CancellationToken), IntegrationTypes integrationType = IntegrationTypes.All)
 {
     throw new NotImplementedException();
 }
コード例 #15
0
 public Task PublishAsync(IEventSource eventSource, CancellationToken cancellationToken = default(CancellationToken), IntegrationTypes integrationType = IntegrationTypes.All)
 {
     throw new NotImplementedException();
 }
コード例 #16
0
 public Task PublishAsync(IDomainEvent domainEvent,
                          CancellationToken cancellationToken = default,
                          IntegrationTypes integrationType    = IntegrationTypes.All)
 {
     return(_messageDispatcher.PublishAsync(domainEvent, cancellationToken, integrationType));
 }
コード例 #17
0
 public Task PublishAsync(IEventSource eventSource,
                          CancellationToken cancellationToken = default,
                          IntegrationTypes integrationType    = IntegrationTypes.All)
 {
     return(_messageDispatcher.PublishAsync(eventSource, cancellationToken, integrationType));
 }
コード例 #18
0
 public Task <TResult> SendAsync <TResult>(ICommand <TResult> command,
                                           CancellationToken cancellationToken = default,
                                           IntegrationTypes integrationType    = IntegrationTypes.All)
 {
     return(_messageDispatcher.SendAsync(command, cancellationToken, integrationType));
 }
コード例 #19
0
 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));
 }
コード例 #20
0
 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));
 }