public async Task Remove(FileExplorerEntry entry) { if (entry.Type == FileExplorerEntryType.File) { await FileSystemResource.DeleteFile(entry.Path, _restClient); } else { await FileSystemResource.DeleteDirectory(entry.Path, _restClient); } EntryRemoved?.Invoke(this, entry); var parentFolder = Path.GetDirectoryName(entry.Path); if (parentFolder != null && TryGetCachedDirectory(parentFolder, out var cachedDirectory)) { lock (cachedDirectory.EntriesLock) { cachedDirectory.Entries = cachedDirectory.Entries.Remove(entry); } } if (entry.Type != FileExplorerEntryType.File) { var normalizedPath = NormalizePath(entry.Path); foreach (var keyValuePair in _localCache.Where(x => x.Key.StartsWith(normalizedPath, PathStringComparison))) { _localCache.TryRemove(keyValuePair.Key, out _); } } }
public CustomFileExplorerEntry(FileExplorerEntry fee) { this.dateModified = fee.dateModified; this.hasChild = fee.hasChild; this.isFile = fee.isFile; this.name = fee.name; this.size = fee.size; this.type = fee.type; }
public void UploadCompleted(FileExplorerEntry entry) { var parentFolderPath = Path.GetDirectoryName(entry.Path); if (parentFolderPath != null && TryGetCachedDirectory(parentFolderPath, out var cachedDirectory)) { entry.Parent = cachedDirectory.Directory; cachedDirectory.Directory.HasSubFolder = true; lock (cachedDirectory.EntriesLock) { cachedDirectory.Entries = cachedDirectory.Entries.Add(entry); } } EntryAdded?.Invoke(this, entry); }
public async Task Move(FileExplorerEntry entry, string path) { path = NormalizePath(path); if (entry.Type == FileExplorerEntryType.File) { await FileSystemResource.MoveFile(entry.Path, path, _restClient); } else { await FileSystemResource.MoveDirectory(entry.Path, path, _restClient); } var oldPath = NormalizePath(entry.Path); entry.Path = path; entry.Name = Path.GetFileName(path); EntryUpdated?.Invoke(this, new EntryUpdatedEventArgs(entry, oldPath)); if (entry.Type != FileExplorerEntryType.File) { foreach (var cachedEntry in _localCache.Where(x => x.Key.StartsWith(oldPath, PathStringComparison))) { _localCache.TryRemove(cachedEntry.Key, out _); var newPath = path + cachedEntry.Key.Substring(oldPath.Length); cachedEntry.Value.Directory.Path = newPath; lock (cachedEntry.Value.EntriesLock) { foreach (var fileExplorerEntry in cachedEntry.Value.Entries) { fileExplorerEntry.Path = path + fileExplorerEntry.Path.Substring(oldPath.Length); } } _localCache[newPath] = cachedEntry.Value; } } }
public async Task <IEnumerable <FileExplorerEntry> > GetEntriesKeepOrder(DirectoryInfoEx directory, CancellationToken token) { var entries = directory.EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly).ToList(); var result = new FileExplorerEntry[entries.Count]; await TaskCombinators.ThrottledAsync(entries, (entry, _) => Task.Run(() => { var index = entries.IndexOf(entry); using (entry) { if (entry.IsFolder) { result[index] = GetDirectoryEntry((DirectoryInfoEx)entry, directory); } else { result[index] = GetFileEntry((FileInfoEx)entry); } } }), token); return(result); }
public static Task Rename(this IFileSystem fileSystem, FileExplorerEntry entry, string newName) { var directory = Path.GetDirectoryName(entry.Path); return(fileSystem.Move(entry, Path.Combine(directory, newName))); }
public EntryUpdatedEventArgs(FileExplorerEntry entry, string oldPath) { Entry = entry; OldPath = oldPath; OldParentPath = Path.GetDirectoryName(oldPath); }