public async Task <WsFolder> FindFolder(WsFolderPath folderPath) { if (folderPath.FullPath == "/") { return(folderPath.IsPrivate ? PrivateRootFolder : PublicRootFolder); } using (WsItemsReaderEngine itemsResult = await GetItems(folderPath.Parent, false, false)) { foreach (WsItem item in itemsResult.GetItems()) { if (item is WsFolder folder) { if (folder.PathInfo.Equals(folderPath)) { return(folder); } } else { break; } } }; return(null); }
public async Task <WsFile> FindFile(WsFilePath filePath) { using (WsItemsReaderEngine filesResult = await GetItem(filePath, true)) { return(filesResult.GetItems().OfType <WsFile>().Where(f => f.PathInfo.Equals(filePath)).SingleOrDefault()); }; }
private IEnumerable <WsFile> GetAllFilesRecursive(WsItemsReaderEngine engine, int depth, int currentDepth) { List <WsFolderPath> folderPaths = new List <WsFolderPath>(); foreach (WsItem item in engine.GetItems()) { if (item is WsFile file) { yield return(file); } else if (item is WsFolder folder) { folderPaths.Add(folder.PathInfo); } } currentDepth++; if (currentDepth <= depth) { foreach (WsFolderPath folderPath in folderPaths) { using (WsItemsReaderEngine childEngine = _apiClient.GetItems(folderPath, false, true).Result) { _childEngine = childEngine; foreach (WsFile file in GetAllFilesRecursive(childEngine, depth, currentDepth)) { yield return(file); } _childEngine = null; } } } }
private async Task ContinuosResolve(CancellationToken cancellationToken) { int delay = 1000; bool firstCall = true; while (cancellationToken.IsCancellationRequested == false && (_dic.Count > 0 || firstCall)) { firstCall = false; try { await Task.Delay(delay, cancellationToken); WsFile[] maxFiveWaitingFilesOrNull = _dic.Count > 5 ? new WsFile[] { null } : _dic.Values.ToArray(); string[] allWaitingFilesIdents = _dic.Values.Select(f => f.Ident).ToArray(); foreach (WsFile waitingFileOrNull in maxFiveWaitingFilesOrNull) { if (cancellationToken.IsCancellationRequested) { return; } using (WsItemsReaderEngine reader = await _apiClient.GetFolderItemsWithoutCreatedFilesInProgress(_folderPath, waitingFileOrNull?.PathInfo.Name ?? "")) { if (cancellationToken.IsCancellationRequested) { return; } foreach (WsFile foundedFile in reader.GetItems().OfType <WsFile>().Where(f => f.Ident == waitingFileOrNull?.Ident || allWaitingFilesIdents.Contains(f.Ident))) { if (cancellationToken.IsCancellationRequested) { return; } if (RemoveFileAndFolderIfEmpty(foundedFile)) { CleanContinuosResolve(); return; } } } } } catch (Exception) { } if (delay < (1000 * 2 * 2)) { delay *= 2; } } }
public virtual IEnumerator <WsItem> GetEnumerator() { return(_readerEngine.GetItems().GetEnumerator()); }