Example #1
0
        public async Task NotifyDataChangedAsync(string dataType, string dataObjectId, DataModificationType modificationType)
        {
            if (dataType == null)
            {
                throw new ArgumentNullException(nameof(dataType));
            }
            if (dataObjectId == null)
            {
                throw new ArgumentNullException(nameof(dataObjectId));
            }

            using var cursor = await subscriptionCollection
                               .Find(x => x.DataType == dataType || x.DataType == null)
                               .ToCursorAsync();

            var subscribedUsers = new HashSet <string>();

            while (await cursor.MoveNextAsync())
            {
                foreach (var subscription in cursor.Current)
                {
                    if (subscribedUsers.Contains(subscription.Username))
                    {
                        continue;
                    }
                    if (!await MatchesFilterAsync(dataType, dataObjectId, subscription.Filter))
                    {
                        continue;
                    }
                    subscribedUsers.Add(subscription.Username);
                }
            }
            foreach (var subscribedUser in subscribedUsers)
            {
                var notification = new DataNotification(
                    subscribedUser,
                    dataType,
                    dataObjectId,
                    modificationType);
                await dataNotificationCollection.InsertOneAsync(notification);
            }
        }
Example #2
0
 public async Task NotifyUserAboutNewDataAsync(string username, string dataType, string dataObjectId)
 {
     var notification = new DataNotification(username, dataType, dataObjectId, DataModificationType.Created);
     await dataNotificationCollection.InsertOneAsync(notification);
 }