public Task GivenIHaveCreatedAndStoredNotificationsWithTimestampsAtSecondIntervalsForTheUserWithId(int notificationCount, int interval, string userId)
        {
            IUserNotificationStore store = this.serviceProvider.GetRequiredService <IUserNotificationStore>();
            IPropertyBagFactory    propertyBagFactory = this.serviceProvider.GetRequiredService <IPropertyBagFactory>();

            DateTimeOffset timestamp = DateTimeOffset.UtcNow;
            var            offset    = TimeSpan.FromSeconds(interval);

            var tasks = new List <Task>();
            var propertiesDictionary = new Dictionary <string, object>
            {
                { "prop1", "val1" },
                { "prop2", 2 },
                { "prop3", DateTime.Now },
            };

            IPropertyBag properties = propertyBagFactory.Create(propertiesDictionary);

            for (int i = 0; i < notificationCount; i++)
            {
                string[] correlationIds = Enumerable.Range(0, 3).Select(_ => Guid.NewGuid().ToString()).ToArray();
                var      metadata       = new UserNotificationMetadata(correlationIds, null);
                tasks.Add(store.StoreAsync(new UserNotification(null, "marain.usernotifications.test", userId, timestamp, properties, metadata)));
                timestamp -= offset;
            }

            return(Task.WhenAll(tasks));
        }
Esempio n. 2
0
        public async Task <UserNotification?> ExecuteAsync(
            [ActivityTrigger] IDurableActivityContext context,
            ILogger logger)
        {
            TenantedFunctionData <UserNotification> request = context.GetInput <TenantedFunctionData <UserNotification> >();

            ITenant tenant = await this.tenantProvider.GetTenantAsync(request.TenantId).ConfigureAwait(false);

            logger.LogInformation(
                "Executing CreateNotificationActivity for notification of type {notificationType} for user {userId}",
                request.Payload.NotificationType,
                request.Payload.UserId);

            IUserNotificationStore store = await this.notificationStoreFactory.GetUserNotificationStoreForTenantAsync(tenant).ConfigureAwait(false);

            try
            {
                return(await store.StoreAsync(request.Payload).ConfigureAwait(false));
            }
            catch (UserNotificationStoreConcurrencyException)
            {
                // We will ignore concurrency exceptions; these suggest that the notification has already been created,
                // which normally means that we've received the request to create it twice for reasons outside our
                // control.
                logger.LogInformation(
                    "Received a concurrency exception when attempting to store notification for user '{userId}'.",
                    request.Payload.UserId);
            }

            return(null);
        }
        public async Task WhenITellTheUserNotificationStoreToStoreTheUserNotificationCalled(string notificationName, string resultName)
        {
            IUserNotificationStore store        = this.serviceProvider.GetRequiredService <IUserNotificationStore>();
            UserNotification       notification = this.scenarioContext.Get <UserNotification>(notificationName);
            UserNotification       result       = await store.StoreAsync(notification).ConfigureAwait(false);

            this.scenarioContext.Set(result, resultName);
        }
        public async Task GivenIHaveCreatedAndStoredANotificationInTheCurrentTransientTenantAndCalledTheResult(string resultName, Table table)
        {
            ITenantedUserNotificationStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedUserNotificationStoreFactory>();
            IJsonSerializerSettingsProvider       serializerSettingsProvider = this.serviceProvider.GetRequiredService <IJsonSerializerSettingsProvider>();
            UserNotification       notification = BuildNotificationFrom(table.Rows[0], serializerSettingsProvider.Instance);
            IUserNotificationStore store        = await storeFactory.GetUserNotificationStoreForTenantAsync(this.featureContext.GetTransientTenant()).ConfigureAwait(false);

            UserNotification result = await store.StoreAsync(notification).ConfigureAwait(false);

            this.scenarioContext.Set(result, resultName);
        }
Esempio n. 5
0
        private async Task UpdateNotificationDeliveryStatusAsync(string deliveryChannelId, string notificationId, UserNotificationDeliveryStatus deliveryStatus, ITenant tenant, string?failureMessage = null)
        {
            IUserNotificationStore store = await this.notificationStoreFactory.GetUserNotificationStoreForTenantAsync(tenant).ConfigureAwait(false);

            UserNotification originalNotification = await store.GetByIdAsync(notificationId).ConfigureAwait(false);

            UserNotification modifiedNotification = originalNotification.WithChannelDeliveryStatus(
                deliveryChannelId,
                deliveryStatus,
                DateTimeOffset.UtcNow,
                failureMessage);

            await store.StoreAsync(modifiedNotification).ConfigureAwait(false);
        }
        public async Task WhenITellTheUserNotificationStoreToStoreTheUserNotificationCalledAndCallTheResult(string notificationName, string resultName)
        {
            IUserNotificationStore store        = this.serviceProvider.GetRequiredService <IUserNotificationStore>();
            UserNotification       notification = this.scenarioContext.Get <UserNotification>(notificationName);

            try
            {
                UserNotification result = await store.StoreAsync(notification).ConfigureAwait(false);

                this.scenarioContext.Set(result, resultName);
            }
            catch (Exception ex)
            {
                ExceptionSteps.StoreLastExceptionInScenarioContext(ex, this.scenarioContext);
            }
        }
        public async Task GivenIHaveCreatedAndStoredNotificationsInTheCurrentTransientTenantWithTimestampsAtSecondIntervalsForTheUserWithId(int notificationCount, int interval, string userId)
        {
            ITenantedUserNotificationStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedUserNotificationStoreFactory>();
            IUserNotificationStore store = await storeFactory.GetUserNotificationStoreForTenantAsync(this.featureContext.GetTransientTenant()).ConfigureAwait(false);

            IPropertyBagFactory propertyBagFactory = this.serviceProvider.GetRequiredService <IPropertyBagFactory>();

            var            offset    = TimeSpan.FromSeconds(interval);
            DateTimeOffset timestamp = DateTimeOffset.UtcNow - offset;

            var tasks = new List <Task <UserNotification> >();
            var propertiesDictionary = new Dictionary <string, object>
            {
                { "prop1", "val1" },
                { "prop2", 2 },
                { "prop3", DateTime.Now },
            };

            IPropertyBag properties = propertyBagFactory.Create(propertiesDictionary);

            for (int i = 0; i < notificationCount; i++)
            {
                string[] correlationIds = Enumerable.Range(0, 3).Select(_ => Guid.NewGuid().ToString()).ToArray();
                var      metadata       = new UserNotificationMetadata(correlationIds, null);
                tasks.Add(store.StoreAsync(new UserNotification(null, "marain.usernotifications.test", userId, timestamp, properties, metadata)));
                timestamp -= offset;
            }

            UserNotification[] newlyCreatedNotifications = await Task.WhenAll(tasks).ConfigureAwait(false);

            // Store the notifications in session state
            if (!this.scenarioContext.TryGetValue(CreatedNotificationsKey, out List <UserNotification> createdNotifications))
            {
                createdNotifications = new List <UserNotification>();
                this.scenarioContext.Set(createdNotifications, CreatedNotificationsKey);
            }

            createdNotifications.AddRange(newlyCreatedNotifications);
        }
Esempio n. 8
0
        public async Task ExecuteAsync(
            [ActivityTrigger] IDurableActivityContext context,
            ILogger logger)
        {
            TenantedFunctionData <BatchReadStatusUpdateRequestItem> request = context.GetInput <TenantedFunctionData <BatchReadStatusUpdateRequestItem> >();

            ITenant tenant = await this.tenantProvider.GetTenantAsync(request.TenantId).ConfigureAwait(false);

            logger.LogInformation(
                "Executing UpdateNotificationReadStatusActivity for notification with Id {notificationId}",
                request.Payload.NotificationId);

            IUserNotificationStore store = await this.notificationStoreFactory.GetUserNotificationStoreForTenantAsync(tenant).ConfigureAwait(false);

            UserNotification originalNotification = await store.GetByIdAsync(request.Payload.NotificationId).ConfigureAwait(false);

            UserNotification modifiedNotification = originalNotification.WithChannelReadStatus(
                request.Payload.DeliveryChannelId,
                request.Payload.NewStatus,
                request.Payload.UpdateTimestamp);

            await store.StoreAsync(modifiedNotification).ConfigureAwait(false);
        }