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); }
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); }
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(); }
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); }
public static string GetUsername(this ClaimsPrincipal user) { NullHelper.ThrowIfNull(user.Identity?.Name); return(user.Identity.Name); }
public IEnumerable <UploadedFile> GetAllFiles() { NullHelper.ThrowIfNull(Context.User); return(_uploadSvc.GetFileList(Context.User)); }