예제 #1
0
        private async Task OnEntityChangedAsync(EntityChanged entityChanged, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (entityChanged == null)
            {
                return;
            }

            var appEntityChanged = AppEntityChanged.Create(entityChanged);

            if (appEntityChanged.Type == typeof(User).Name)
            {
                foreach (var connectionId in await _connectionMapping.GetConnectionsAsync(appEntityChanged.Id))
                {
                    await Context.Connection.TypedSendAsync(connectionId, appEntityChanged);
                }

                return;
            }

            if (!String.IsNullOrEmpty(appEntityChanged.OrganizationId))
            {
                await GroupSendAsync(appEntityChanged.OrganizationId, appEntityChanged);
            }

            if (appEntityChanged.Type == "Organization")
            {
                await GroupSendAsync(appEntityChanged.Id, appEntityChanged);
            }
        }
예제 #2
0
        private async Task OnUserMembershipChangedAsync(UserMembershipChanged userMembershipChanged, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (String.IsNullOrEmpty(userMembershipChanged?.OrganizationId))
            {
                return;
            }

            // manage user organization group membership
            foreach (var connectionId in await _connectionMapping.GetConnectionsAsync(userMembershipChanged.UserId))
            {
                if (userMembershipChanged.ChangeType == ChangeType.Added)
                {
                    await _connectionMapping.GroupAddAsync(userMembershipChanged.OrganizationId, connectionId);
                }
                else if (userMembershipChanged.ChangeType == ChangeType.Removed)
                {
                    await _connectionMapping.GroupRemoveAsync(userMembershipChanged.OrganizationId, connectionId);
                }
            }

            await GroupSendAsync(userMembershipChanged.OrganizationId, userMembershipChanged);
        }
예제 #3
0
 public static Task <ICollection <string> > GetUserIdConnectionsAsync(this IConnectionMapping map, string userId)
 {
     return(map.GetConnectionsAsync(UserIdPrefix + userId));
 }
예제 #4
0
 public static Task <ICollection <string> > GetGroupConnectionsAsync(this IConnectionMapping map, string group)
 {
     return(map.GetConnectionsAsync(GroupPrefix + group));
 }