/// <summary>
 /// Initializes a new instance of the <see cref="NotificationsCarrierService"/> class.
 /// </summary>
 /// <param name="services">The instance for <see cref="IServiceProvider"/>.</param>
 /// <param name="logger">The logger.</param>
 /// <exception cref="ArgumentNullException">
 /// services
 /// or
 /// logger.
 /// </exception>
 public NotificationsCarrierService(IServiceProvider services, ILogger <NotificationsCarrierService> logger)
 {
     this.serviceProvider         = services ?? throw new ArgumentNullException(nameof(services));
     this.webNotificationsCarrier = services.GetRequiredService <IWebNotificationsCarrier>();
     this.notificationsChannel    = services.GetRequiredService <INotificationsChannel>();
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Beispiel #2
0
        public NotificationListenerSubscription(
            INotificationsChannel notificationsChannel,
            INotificationListener listener)
        {
            Require.NotNull(notificationsChannel, "notificationsChannel");
            Require.NotNull(listener, "listener");

            m_notificationsChannel = notificationsChannel;
            m_listener             = listener;
            m_processingCountdown  = new CountdownEvent(0);
        }
Beispiel #3
0
        public NotificationHub(
            IPollingJob pollingJob,
            INotificationsChannel channel,
            IReceivedNotificationProcessor notificationProcessor)
        {
            Require.NotNull(pollingJob, "pollingJob");
            Require.NotNull(channel, "channel");
            Require.NotNull(notificationProcessor, "notificationProcessor");

            m_pollingJob            = pollingJob;
            m_channel               = channel;
            m_notificationProcessor = notificationProcessor;
        }
Beispiel #4
0
        public NotificationsChannelTests()
        {
            var storage = new StorageFactory();

            var queues = Enumerable
                         .Range(0, 16)
                         .Select(index => storage.CreateQueue("UseDevelopmentStorage=true", "notifications-channel-tests-" + index.ToString("D1")))
                         .ToArray();

            m_channel = new NotificationsChannel(queues, new NotificationFormatter());

            m_fixture             = new Fixture().Customize(new AutoConfiguredMoqCustomization());
            m_fixture.RepeatCount = 16 * 2;
        }
Beispiel #5
0
        public async Task <IActionResult> PostNotifications(string applicationName, [FromBody] WebNotificationRequestItemsContainer webNotificationRequestsContainer, [FromServices] INotificationsChannel notificationsChannel)
        {
            IActionResult result = null;

            using (this.logger.BeginScope($"RootActivityId: {this.RootActivityId}"))
            {
                this.logger.LogInformation($"Started {nameof(this.PostNotifications)} method of {nameof(NotificationsController)}.");
                if (string.IsNullOrWhiteSpace(applicationName))
                {
                    throw new ArgumentException("Application name is mandatory.", nameof(applicationName));
                }

                if (webNotificationRequestsContainer is null)
                {
                    throw new ArgumentNullException(nameof(webNotificationRequestsContainer));
                }

                if (notificationsChannel == null)
                {
                    throw new ArgumentNullException(nameof(notificationsChannel));
                }

                IEnumerable <WebNotification> notifications = await this.notificationsManager.ProcessNotificationsAsync(applicationName, webNotificationRequestsContainer.Notifications).ConfigureAwait(false);

                foreach (var notification in notifications.ToList())
                {
                    _ = notificationsChannel.AddNotificationAsync(notification);
                }

                result = this.Accepted();
                this.logger.LogInformation($"Finished {nameof(this.PostNotifications)} method of {nameof(NotificationsController)}.");
            }

            return(result);
        }