コード例 #1
0
        /// <summary>
        /// Loads the notifications with ids asynchronously.
        /// </summary>
        /// <param name="ids">The notification related ids.</param>
        /// <param name="applicationName">Name of the application.</param>
        /// <param name="isTrackingIds"><c>true</c> if the specified Ids are tracking identifiers.</param>
        /// <returns>The instance of <see cref="Task{TResult}"/>.</returns>
        private async Task <EntityCollection <WebNotificationItemEntity> > LoadNotificationsWithIdsInternalAsync(IEnumerable <string> ids, string applicationName = null, bool isTrackingIds = false)
        {
            Debug.Assert(ids?.Any() ?? false, "Missing ids");
            Expression <Func <WebNotificationItemEntity, bool> > filterExpression       = NotificationsExpressionProvider.PrepareNotificationsFilter(ids, applicationName, isTrackingIds);
            EntityCollection <WebNotificationItemEntity>         notificationCollection =
                await this.notificationsRepository.ReadAsync(
                    filterExpression,
                    NotificationsExpressionProvider.NotificationsSortOrderExpression,
                    nextPageId : null,
                    numOfEntities : ids.Count())
                .ConfigureAwait(false);

            return(notificationCollection);
        }
コード例 #2
0
        /// <inheritdoc cref="INotificationsManager"/>
        public async Task <WebNotificationResponse> DeliverNotificationsAsync(string applicationName, string userObjectId)
        {
            if (string.IsNullOrWhiteSpace(applicationName))
            {
                throw new ArgumentException("The application name is not specified.", nameof(applicationName));
            }

            if (string.IsNullOrWhiteSpace(userObjectId))
            {
                throw new ArgumentException("The user object identifier is not specified.", nameof(userObjectId));
            }

            WebNotificationResponse webNotificationResponse = new WebNotificationResponse();

            this.logger.TraceInformation($"Started {nameof(this.DeliverNotificationsAsync)} method of {nameof(NotificationsManager)}.");
            Expression <Func <WebNotificationItemEntity, bool> > filterExpression       = NotificationsExpressionProvider.PrepareNotificationsFilter(applicationName, notificationReadStatus: null, userObjectId: userObjectId);
            EntityCollection <WebNotificationItemEntity>         notificationCollection =
                await this.notificationsRepository.ReadAsync(
                    filterExpression,
                    NotificationsExpressionProvider.NotificationsSortOrderExpression,
                    nextPageId : null,
                    numOfEntities : BusinessConstants.PageSize).ConfigureAwait(false);

            webNotificationResponse.Notifications.AddRange(notificationCollection.Items.Select(wbn => wbn.ToWebNotification()));
            if (webNotificationResponse.Notifications.Any())
            {
                await this.MarkNotificationsDeliveredInternalAsync(NotificationDeliveryChannel.Web, notificationCollection.Items).ConfigureAwait(false);
            }

            this.logger.TraceInformation($"Finished {nameof(this.DeliverNotificationsAsync)} method of {nameof(NotificationsManager)}.");
            return(webNotificationResponse);
        }
コード例 #3
0
        /// <summary>
        /// Processes the notifications internally.
        /// </summary>
        /// <param name="applicationName">Name of the application.</param>
        /// <param name="webNotificationRequestItems">The instance for <see cref="IEnumerable{WebNotificationRequestItem}"/>.</param>
        /// <returns>The instance of <see cref="Task{WebNotification}"/> representing an asynchronous operation.</returns>
        private async Task <IEnumerable <WebNotification> > ProcessNotificationsInternalAsync(string applicationName, IEnumerable <WebNotificationRequestItem> webNotificationRequestItems)
        {
            Debug.Assert(!string.IsNullOrWhiteSpace(applicationName), "Missing application name.");
            Debug.Assert(webNotificationRequestItems?.Any() ?? false, "Missing web notification request items.");
            IEnumerable <WebNotificationItemEntity> notificationEntities = webNotificationRequestItems.Select(wbr => wbr.ToEntity(applicationName)).ToList();

            await this.UpdateNotificationEntitiesWithExitingIdsAsync(notificationEntities).ConfigureAwait(false);

            notificationEntities = await this.notificationsRepository.UpsertAsync(notificationEntities).ConfigureAwait(false);

            IOrderedQueryable <WebNotificationItemEntity> queryableNotifications = notificationEntities.AsQueryable().Where(NotificationsExpressionProvider.PrepareNotificationsFilter(applicationName, NotificationReadStatus.New)).OrderBy(NotificationsExpressionProvider.NotificationsSortOrderExpression);
            IEnumerable <WebNotification> notifications = queryableNotifications.Select(we => we.ToWebNotification()).ToList();

            return(notifications);
        }