public async Task <string> ForEachContinueAsync(string cursor, Action <FileItem> action) { Action <Metadata> handleEntry = (entry) => { var item = FileItem.Create(entry); if (item.Path != this.context.RemotePath) { action(item); } }; while (true) { var result = await this.Client.Files.ListFolderContinueAsync(new ListFolderContinueArg(cursor)); foreach (var entry in result.Entries) { handleEntry(entry); } if (!result.HasMore) { return(result.Cursor); } else { cursor = result.Cursor; } } }
public async Task <FileItem> FileSelectAsync(string path) { try { var result = await this.Client.Files.GetMetadataAsync(new GetMetadataArg(path)); return(FileItem.Create(result)); } catch { return(null); } }
public async Task <string> ForEachAsync(string path, bool recursive, bool deleted, Action <FileItem> action) { const string logstem = "ForEachAsync():{0}"; Action <Metadata> handleEntry = (entry) => { var item = FileItem.Create(entry); if (item.Path != this.context.RemotePath) { action(item); } }; var args0 = new ListFolderArg(path, recursive, false, deleted); ListFolderResult result = await this.Client.Files .ListFolderAsync(args0) .WithTimeout(TimeSpan.FromSeconds(this.context.HttpReadTimeoutInSeconds)); // These logging calls are very expensive so check we're enabled first if (log.IsDebugEnabled) { log.DebugFormat(logstem, "Request:" + Json.ToString(args0)); log.DebugFormat(logstem, "Result:" + Json.ToString(result)); } foreach (var entry in result.Entries) { handleEntry(entry); } while (result.HasMore) { var args1 = new ListFolderContinueArg(result.Cursor); result = await this.Client.Files .ListFolderContinueAsync(args1) .WithTimeout(TimeSpan.FromSeconds(this.context.HttpReadTimeoutInSeconds)); if (log.IsDebugEnabled) { log.DebugFormat(logstem, "Request:" + Json.ToString(args1)); log.DebugFormat(logstem, "Result:" + Json.ToString(result)); } foreach (var entry in result.Entries) { handleEntry(entry); } } return(result.Cursor); }
public async Task <string> ForEachAsync(string path, bool recursive, bool deleted, Action <FileItem> action) { this.context.LocalStorage.ScanDelete(); Action <FileItem> internalAction = (fileItem) => { log.DebugFormat("ForEachAsync():{0}", fileItem.Path); this.FileItemMergeFromIndex(fileItem); // Store in scan this.context.LocalStorage.ScanInsert(fileItem); action(fileItem); }; // This improves performance so much it's unreal // see: http://stackoverflow.com/questions/1711631/improve-insert-per-second-performance-of-sqlite this.context.LocalStorage.BeginTransaction(); await Task.Run(() => { DirectoryInfo root = new DirectoryInfo(path); if (!root.Exists) { return; } SearchOption option = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; foreach (var f in root.EnumerateFiles("*", option)) { var item = FileItem.Create(f, this.HashProvider); internalAction(item); } foreach (var d in root.EnumerateDirectories("*", option)) { var item = FileItem.Create(d); internalAction(item); } }); this.context.LocalStorage.EndTransaction(); return(new Cursor { Path = path, Recursive = recursive, Deleted = deleted }.ToString()); }
public FileItem ToFileItem(string path) { var fsi = this.ToFileSystemInfo(path); if (!fsi.Exists) { return(null); } if (fsi is FileInfo) { return(FileItem.Create(fsi as FileInfo, this.HashProvider)); } return(FileItem.Create(fsi as DirectoryInfo)); }
public static FileItem Create(Metadata e) { if (e is FileMetadata) { return(FileItem.Create(e as FileMetadata)); } else if (e is FolderMetadata) { return(FileItem.Create(e as FolderMetadata)); } else if (e is DeletedMetadata) { return(FileItem.Create(e as DeletedMetadata)); } throw new InvalidOperationException("Unknown Metadata type"); }