public async void UploadFile(string path) { var fileInfo = new FileInfo(path); try { if (fileInfo.Length <= MAX_FILE_SIZE) { if (fileInfo.Length + totalFilesSize <= MAX_TOTAL_FILE_SIZE) { if (fileInfo.Extension == ".zip") { if (IsCorrectArchive(path)) { int fileID = await httpService.AddFileAsync(path, userID); Files.Add(fileID, fileInfo.Name); totalFilesSize += fileInfo.Length; UpdateFilesList?.Invoke(); MessageBox.Show("File " + fileInfo.Name + " was uploaded with id = " + fileID.ToString()); } else { MessageBox.Show("Chosen archive has files with unacceptable extensions"); } } else if (!UNACCEPTABLE_EXTENSIONS.Contains(fileInfo.Extension)) { int fileID = await httpService.AddFileAsync(path, userID); Files.Add(fileID, fileInfo.Name); totalFilesSize += fileInfo.Length; UpdateFilesList?.Invoke(); MessageBox.Show("File " + fileInfo.Name + " was uploaded with id = " + fileID.ToString()); } else { MessageBox.Show("Chosen file has unacceptable extension"); } } else { MessageBox.Show("Total files size is over maximum limit"); } } else { MessageBox.Show("File's size is over maximum limit"); } } catch { MessageBox.Show("Something unexpected happened"); } }
public async void DeleteFile(int fileID) { try { var fileInfo = await httpService.GetFileAttributesAsync(fileID); if (await httpService.DeleteFileAsync(fileID)) { totalFilesSize -= fileInfo.Size; Files.Remove(fileID); UpdateFilesList?.Invoke(); MessageBox.Show("File was deleted successfully"); } else { MessageBox.Show("File with such id has been already deleted"); } } catch { MessageBox.Show("Something unexpected happened"); } }