public List<CloudItem> Dir(CloudFolder parentFolder = null) { string path = string.Empty; if (parentFolder != null) { path = parentFolder.FullName(); } List<CloudItem> couldItems = List(path); List<CloudItem> result = null; if (couldItems != null && couldItems.Count > 0) { result = new List<CloudItem>(); Dictionary<string, CloudFile> filesWithHistory = new Dictionary<string, CloudFile>(); foreach (var cloudItem in couldItems) { #region dir sub folder if (cloudItem is CloudFolder) { if (parentFolder != null) { parentFolder.AddChild(cloudItem); } var cloudFolder = cloudItem as CloudFolder; var grandChildren = Dir(cloudFolder); cloudFolder.Timestamp = DateTime.MinValue; if (grandChildren != null) { foreach (var grandChild in grandChildren) { cloudFolder.AddChild(grandChild); if (grandChild.Timestamp > cloudFolder.Timestamp) { cloudFolder.Timestamp = grandChild.Timestamp; } } } result.Add(cloudFolder); } #endregion } result.AddRange(filesWithHistory.Values); } return result; }
public override List<CloudItem> RealList(string path) { path = Path.Combine(this.rootPath, path); if (Directory.Exists(path)) { var fileSystemInfos = new DirectoryInfo(path).GetFileSystemInfos(); if (fileSystemInfos != null && fileSystemInfos.Length > 0) { var result = new List<CloudItem>(); foreach (var item in fileSystemInfos) { if ((item.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } if (item is DirectoryInfo ) { var cloudFolder = new CloudFolder(); cloudFolder.Name = Path.GetFileName(item.Name); result.Add(cloudFolder); } else if (item is FileInfo) { var fileInfo = item as FileInfo; if (fileInfo.Length > 0) { var cloudFile = new CloudFile(); cloudFile.UniqueName = item.Name; cloudFile.CloudSize = fileInfo.Length; result.Add(cloudFile); } } } return result; } } return null; }
public static CloudFolder MkDir(this CloudFolder cloudFolder, string path) { if (string.IsNullOrEmpty(path)) { return cloudFolder; } var index = path.IndexOf("/"); string subPath = string.Empty; if (index >= 0) { subPath = path.Substring(index + 1); path = path.Substring(0, index); } var cloudItem = cloudFolder.GetChild(path); if (cloudItem != null && cloudItem is CloudFile) { var msg = string.Format("MkDir failed, path=[{0}] conflicted with exist file", path); throw new Exception(msg); } var directoryItem = cloudItem as CloudFolder; if (directoryItem == null) { directoryItem = new CloudFolder(); directoryItem.Name = path; directoryItem.Parent = cloudFolder; if (cloudFolder.Children == null) { cloudFolder.Children = new List<CloudItem>(); } cloudFolder.Children.Add(directoryItem); } if (string.IsNullOrEmpty(subPath)) { return directoryItem; } else { return directoryItem.MkDir(subPath); } }
public override List<CloudItem> RealList(string path) { BaiduListResult listResult = null; try { listResult = connector.List(path); } catch (WebException ex) { throw new CloudProviderOperationFailedException("Baidu list failed, path = " + path, ex); } if (listResult.list != null && listResult.list.Count > 0) { var result = new List<CloudItem>(); foreach (var item in listResult.list) { if (item.isdir == 1) { var cloudFolder = new CloudFolder(); cloudFolder.Name = Path.GetFileName(item.path); result.Add(cloudFolder); } else { var cloudFile = new CloudFile(); cloudFile.UniqueName = item.path; cloudFile.CloudSize = item.size; result.Add(cloudFile); } } return result; } return null; }
private CloudFolder EnsureFolder(string path) { var matchedItem = cache.GetItemByPath(path); if (matchedItem != null) { if (matchedItem is CloudFile) { throw new Exception("Cannot ensure a folder with same name of an exist file."); } return matchedItem as CloudFolder; } var index = path.LastIndexOf('/'); if (index > 0) path = path.Substring(0, index-1); var parentFolder = EnsureFolder(path); var name = path.Substring(index); CloudFolder newFolder = new CloudFolder(); newFolder.Name = name; parentFolder.AddChild(newFolder); connector.MkDir(newFolder.FullName()); return newFolder; }
public List<CloudItem> List(string path) { path = Path.Combine(this.rootPath, path.TrimStart('/')); if (!Directory.Exists(path)) { return null; //throw new FileNotFoundException(string.Format("LocalHDProvider path does not exist, path = {0}", path)); } var fileSystemInfos = new DirectoryInfo(path).GetFileSystemInfos(); if (fileSystemInfos != null && fileSystemInfos.Length > 0) { var result = new List<CloudItem>(); foreach (var item in fileSystemInfos) { if ((item.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } if (item is DirectoryInfo) { var cloudFolder = new CloudFolder(); cloudFolder.Name = Path.GetFileName(item.Name); result.Add(cloudFolder); } else if (item is FileInfo) { var fileInfo = item as FileInfo; if (fileInfo.Length > 0) { var cloudFile = new CloudFile(); cloudFile.Name = fileInfo.Name; cloudFile.Size = fileInfo.Length; cloudFile.Timestamp = fileInfo.LastWriteTime; result.Add(cloudFile); } } } return result; } return null; }
private CloudFolder CreateFolderByPath(string path) { CloudFolder parentFolder = null; foreach (string subPath in path.Trim('/').Split('/')) { CloudFolder folder = new CloudFolder(); folder.Name = subPath; folder.Parent = parentFolder; parentFolder = folder; } return parentFolder; }
public List<CloudItem> Dir(CloudFolder cloudFile = null) { var result = provider.Dir(cloudFile); return result; }