Ejemplo n.º 1
0
        public async Task <IEntry> FolderInfo(RemotePath path, int offset = 0, int limit = int.MaxValue, int depth = 1)
        {
            if (path.IsLink)
            {
                throw new NotImplementedException(nameof(FolderInfo));
            }

            var req = new ListRequest(HttpSettings, Authent, _metaServer.Value.Url, path.Path, _listDepth);
            var res = await req.MakeRequestAsync();

            switch (res.Item)
            {
            case FsFolder fsFolder:
            {
                var f = new Folder(fsFolder.Size == null ? 0 : (long)fsFolder.Size.Value, fsFolder.FullPath);
                foreach (var fsi in fsFolder.Items)
                {
                    if (fsi is FsFile fsfi)
                    {
                        var fi = new File(fsfi.FullPath, (long)fsfi.Size, new FileHashMrc(fsfi.Sha1))
                        {
                            CreationTimeUtc  = fsfi.ModifDate,
                            LastWriteTimeUtc = fsfi.ModifDate
                        };
                        f.Files.Add(fi);
                    }
                    else if (fsi is FsFolder fsfo)
                    {
                        var fo = new Folder(fsfo.Size == null ? 0 : (long)fsfo.Size.Value, fsfo.FullPath);
                        f.Folders.Add(fo);
                    }
                    else
                    {
                        throw new Exception($"Unknown item type {fsi.GetType()}");
                    }
                }
                return(f);
            }

            case FsFile fsFile:
            {
                var fi = new File(fsFile.FullPath, (long)fsFile.Size, new FileHashMrc(fsFile.Sha1))
                {
                    CreationTimeUtc  = fsFile.ModifDate,
                    LastWriteTimeUtc = fsFile.ModifDate
                };

                return(fi);
            }

            default:
                return(null);
            }
        }
        public async Task <IEntry> FolderInfo(string path, Link ulink, int offset = 0, int limit = Int32.MaxValue)
        {
            var req = new ListRequest(HttpSettings, Authent, _metaServer.Value.Url, path)
            {
                Depth = 1
            };
            var res = await req.MakeRequestAsync();

            if (res.Item is FsFolder fsf)
            {
                var f = new Folder(fsf.Size == null ? 0 : (long)fsf.Size.Value, fsf.FullPath);
                foreach (var fsi in fsf.Items)
                {
                    if (fsi is FsFile fsfi)
                    {
                        var fi = new File(fsfi.FullPath, (long)fsfi.Size, fsfi.Sha1.ToHexString())
                        {
                            CreationTimeUtc  = fsfi.ModifDate,
                            LastWriteTimeUtc = fsfi.ModifDate,
                        };
                        f.Files.Add(fi);
                    }
                    else if (fsi is FsFolder fsfo)
                    {
                        var fo = new Folder(fsfo.Size == null ? 0 : (long)fsfo.Size.Value, fsfo.FullPath);
                        f.Folders.Add(fo);
                    }
                    else
                    {
                        throw new Exception($"Unknown item type {fsi.GetType()}");
                    }
                }
                return(f);
            }

            if (res.Item is FsFile fsfi1)
            {
                var fi = new File(fsfi1.FullPath, (long)fsfi1.Size, fsfi1.Sha1.ToHexString())
                {
                    CreationTimeUtc  = fsfi1.ModifDate,
                    LastWriteTimeUtc = fsfi1.ModifDate,
                };

                return(fi);
            }

            return(null);
        }