Example #1
0
    async Task FileDeletedAsync(UploadedFile file)
    {
        NullHelper.ThrowIfNull(Context.User);

        if (!Context.User.IsAdmin())
        {
            await Clients.User(file.Location.Username).SendAsync(CALL_FILE_DELETED, file);
        }

        await Clients.Group(GROUP_ADMINS).SendAsync(CALL_FILE_DELETED, file);
    }
Example #2
0
    public override async Task OnDisconnectedAsync(Exception?exception)
    {
        NullHelper.ThrowIfNull(Context.User?.Identity);

        _log.LogDebug("User [{Username}] disconnected from {Hub}.", Context.User.Identity.Name, nameof(UploadHub));

        if (Context.User.IsAdmin())
        {
            await Groups.RemoveFromGroupAsync(Context.ConnectionId, GROUP_ADMINS);
        }

        await base.OnDisconnectedAsync(exception);
    }
Example #3
0
    public override async Task OnConnectedAsync()
    {
        NullHelper.ThrowIfNull(Context.User?.Identity);

        _log.LogDebug("User [{Username}] connected to {Hub}.", Context.User.Identity.Name, nameof(UploadHub));

        if (Context.User.IsAdmin())
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, GROUP_ADMINS);
        }

        await base.OnConnectedAsync();
    }
Example #4
0
    public async Task <IEnumerable <FileOperationResult> > DeleteFilesAsync(List <string> files)
    {
        NullHelper.ThrowIfNull(Context.User);

        var results = _uploadSvc.DeleteFiles(Context.User, files);

        foreach (var result in results)
        {
            if (result.WasSuccessful)
            {
                await FileDeletedAsync(result.UploadedFile);
            }
        }

        return(results);
    }
Example #5
0
    public static string GetUsername(this ClaimsPrincipal user)
    {
        NullHelper.ThrowIfNull(user.Identity?.Name);

        return(user.Identity.Name);
    }
Example #6
0
    public IEnumerable <UploadedFile> GetAllFiles()
    {
        NullHelper.ThrowIfNull(Context.User);

        return(_uploadSvc.GetFileList(Context.User));
    }