예제 #1
0
        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;
        }
예제 #2
0
        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;
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
 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;
 }
예제 #5
0
        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;
        }
예제 #6
0
        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;
        }
예제 #7
0
파일: Pipeline.cs 프로젝트: xfm84/test
 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;
 }
예제 #8
0
 public List<CloudItem> Dir(CloudFolder cloudFile = null)
 {
     var result = provider.Dir(cloudFile);
     return result;
 }