コード例 #1
0
        public override Task OnConnected()
        {
            var userId = AccountUtils.GetUserId(Context.User.Identity);

            Groups.Add(Context.ConnectionId, KeyUtils.IntToKey(userId));
            return(base.OnConnected());
        }
コード例 #2
0
        public async Task RegisterWatcher(int exerciseId)
        {
            var          userId       = AccountUtils.GetUserId(Context.User.Identity);
            const string sql          = @"select UserId from dbo.exeExercises where Id = @ExerciseId;";
            var          authorUserId = (await DapperHelper.QueryResilientlyAsync <int>(sql, new { ExerciseId = exerciseId, })).Single();

            if (userId == authorUserId)
            {
                var groupName = KeyUtils.IntToKey(exerciseId); // Corresponds to PieceTypes.PartitionKey
                await Groups.Add(Context.ConnectionId, groupName);
            }
            /* You should not manually remove the connection from the group when the user disconnects. This action is automatically performed by the SignalR framework. */
        }