示例#1
0
 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;
 }
示例#4
0
        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));
        }
示例#5
0
 public void ChangeFolderPath(WsFolderPath newFolderPath)
 {
     _folderPath = newFolderPath;
     foreach (WsFile file in _dic.Values)
     {
         file.ChangeFolderPathInInstance(newFolderPath.FullPath, newFolderPath.IsPrivate);
     }
 }
示例#6
0
 public IEnumerable <WsFile> GetCreatedFilesInProgress(WsFolderPath folderPath)
 {
     if (_dic.TryGetValue(folderPath, out FolderItemsResolver folderItemsResolver))
     {
         return(folderItemsResolver.GetCreatedFilesInProgress());
     }
     return(_empty);
 }
示例#7
0
 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);
        }
示例#9
0
 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);
             }
         }
     }
 }
示例#10
0
 public IFolderItemsResolver FindFolderItemsResolver(WsFolderPath folderPath)
 {
     _dic.TryGetValue(folderPath, out FolderItemsResolver folderItemsResolver);
     return(folderItemsResolver);
 }
示例#11
0
 private void RemoveFolder(WsFolderPath folderPath)
 {
     RemoveFolder(folderPath, out _);
 }
示例#12
0
 internal Task <WsItemsReaderEngine> GetItems(WsFolderPath folderPath, bool onlyOne, bool useCreatedFileResolver)
 {
     return(GetItemsOrItem(folderPath, onlyOne, useCreatedFileResolver));
 }
示例#13
0
 internal Task <WsItemsReaderEngine> GetFolderItemsWithoutCreatedFilesInProgress(WsFolderPath folderPath, string fileName = "")
 {
     if (string.IsNullOrEmpty(fileName))
     {
         return(GetItems(folderPath, false, false));
     }
     return(GetItem(new WsFilePath(folderPath, fileName), false));
 }
示例#14
0
        public async Task <WsFilesReader> GetFolderAllFilesRecursive(WsFolderPath folderPath, int depth)
        {
            WsItemsReaderEngine filesResult = await GetItems(folderPath, false, true);

            return(new WsFilesReader(filesResult, depth));
        }
示例#15
0
        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);
        }