public FolderItemsResolver(WsFolderPath folderPath, WsApiClient apiClient, Action <WsFolderPath> removeFromParent) { _folderPath = folderPath; _apiClient = apiClient; _removeFromParent = removeFromParent; Log("Add folder", folderPath); }
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); }
private WsItemsReaderEngine(WsApiClient apiClient, HttpResponseMessage responseMessage, WsFolderPath folderPath, bool useCreatedFileResolver) { _apiClient = apiClient; _responseMessage = responseMessage; _folderPath = folderPath; _useCreatedFileResolver = useCreatedFileResolver; }
public WsFile Add(WsFolderPath folderPath, string fileName, string fileIdent, long fileSize) { FolderItemsResolver folderItemsResolver = _dic.GetOrAdd( folderPath, x => new FolderItemsResolver(folderPath, _apiClient, RemoveFolder)); return(folderItemsResolver.Add(fileName, fileIdent, fileSize, folderPath.IsPrivate)); }
public void ChangeFolderPath(WsFolderPath newFolderPath) { _folderPath = newFolderPath; foreach (WsFile file in _dic.Values) { file.ChangeFolderPathInInstance(newFolderPath.FullPath, newFolderPath.IsPrivate); } }
public IEnumerable <WsFile> GetCreatedFilesInProgress(WsFolderPath folderPath) { if (_dic.TryGetValue(folderPath, out FolderItemsResolver folderItemsResolver)) { return(folderItemsResolver.GetCreatedFilesInProgress()); } return(_empty); }
private bool RemoveFolder(WsFolderPath folderPath, out FolderItemsResolver folderItemsResolver) { if (_dic.TryRemove(folderPath, out folderItemsResolver)) { Log("Remove folder", folderPath); return(true); } return(false); }
public async Task <WsFolder> GetFolder(WsFolderPath folderPath) { WsFolder folder = await FindFolder(folderPath); if (folder == null) { throw new DirectoryNotFoundException($"Required folder {folderPath} not found on server."); } return(folder); }
private void MoveFolder(WsFolderPath baseFolder, WsFolderPath baseNewFolder) { KeyValuePair <WsFolderPath, FolderItemsResolver>[] renamingFolders = _dic.Where(e => e.Key.IsPrivate == baseFolder.IsPrivate && e.Key.FullPath.StartsWith(baseFolder.FullPath)).ToArray(); foreach (KeyValuePair <WsFolderPath, FolderItemsResolver> renamingFolder in renamingFolders) { if (RemoveFolder(renamingFolder.Key, out FolderItemsResolver folderItemsResolver)) { WsFolderPath newFolderPath = new WsFolderPath(baseNewFolder.FullPath + renamingFolder.Key.FullPath.Substring(baseNewFolder.FullPath.Length), baseNewFolder.IsPrivate); folderItemsResolver.ChangeFolderPath(newFolderPath); if (_dic.TryAdd(newFolderPath, folderItemsResolver)) { Log($"Rename/move folder {newFolderPath}", renamingFolder.Key); } } } }
public IFolderItemsResolver FindFolderItemsResolver(WsFolderPath folderPath) { _dic.TryGetValue(folderPath, out FolderItemsResolver folderItemsResolver); return(folderItemsResolver); }
private void RemoveFolder(WsFolderPath folderPath) { RemoveFolder(folderPath, out _); }
internal Task <WsItemsReaderEngine> GetItems(WsFolderPath folderPath, bool onlyOne, bool useCreatedFileResolver) { return(GetItemsOrItem(folderPath, onlyOne, useCreatedFileResolver)); }
internal Task <WsItemsReaderEngine> GetFolderItemsWithoutCreatedFilesInProgress(WsFolderPath folderPath, string fileName = "") { if (string.IsNullOrEmpty(fileName)) { return(GetItems(folderPath, false, false)); } return(GetItem(new WsFilePath(folderPath, fileName), false)); }
public async Task <WsFilesReader> GetFolderAllFilesRecursive(WsFolderPath folderPath, int depth) { WsItemsReaderEngine filesResult = await GetItems(folderPath, false, true); return(new WsFilesReader(filesResult, depth)); }
public async Task <WsItemsReader> GetFolderItems(WsFolderPath folderPath) { WsItemsReaderEngine filesResult = await GetItems(folderPath, false, true); return(new WsItemsReader(filesResult)); }
public static async Task <WsItemsReaderEngine> Create(WsApiClient apiClient, HttpResponseMessage responseMessage, WsFolderPath folderPath, bool useCreatedFileResolver) { WsItemsReaderEngine engine = new WsItemsReaderEngine(apiClient, responseMessage, folderPath, useCreatedFileResolver); XmlDocument xml = new XmlDocument(); xml.Load(await engine._responseMessage.Content.ReadAsStreamAsync()); engine._xmlReader = new XmlNodeReader(xml.DocumentElement); if (engine._xmlReader.Read() && engine._xmlReader.Name == ROOT_ELEMENT_NAME && engine._xmlReader.Read() && engine._xmlReader.Name == "status") { engine.Status = engine._xmlReader.ReadElementContentAsString(); if (engine.Status != ResultStatus.OK) { if (engine._xmlReader.Name == "code") { engine.ErrorCode = engine._xmlReader.ReadElementContentAsString(); } engine.Dispose(); } } else { engine.Status = "Xml format error."; engine.Dispose(); } return(engine); }