コード例 #1
0
        public async Task <IEntry> FolderInfo(RemotePath path, int offset = 0, int limit = Int32.MaxValue, int depth = 1)
        {
            if (Credentials.IsAnonymous)
            {
                return(await AnonymousRepo.FolderInfo(path, offset, limit));
            }

            if (!path.IsLink && depth > 1)
            {
                return(await FolderInfo(path, depth));
            }

            FolderInfoResult datares;

            try
            {
                datares = await new FolderInfoRequest(HttpSettings, Authent, path, offset, limit)
                          .MakeRequestAsync();
            }
            catch (WebException e) when((e.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            Cloud.ItemType itemType;

            //TODO: subject to refact, bad-bad-bad
            if (null == path.Link || path.Link.ItemType == Cloud.ItemType.Unknown)
            {
                itemType = datares.Body.Home == path.Path ||
                           WebDavPath.PathEquals("/" + datares.Body.Weblink, path.Path)
                    ? Cloud.ItemType.Folder
                    : Cloud.ItemType.File;
            }
            else
            {
                itemType = path.Link.ItemType;
            }


            var entry = itemType == Cloud.ItemType.File
                ? (IEntry)datares.ToFile(
                PublicBaseUrlDefault,
                home: WebDavPath.Parent(path.Path ?? string.Empty),
                ulink: path.Link,
                filename: path.Link == null ? WebDavPath.Name(path.Path) : path.Link.OriginalName,
                nameReplacement: path.Link?.IsLinkedToFileSystem ?? true ? WebDavPath.Name(path.Path) : null)
                : datares.ToFolder(PublicBaseUrlDefault, path.Path, path.Link);

            return(entry);
        }
コード例 #2
0
        public async Task <IEntry> FolderInfo(string path, Link ulink, int offset = 0, int limit = Int32.MaxValue, int depth = 1)
        {
            if (_creds.IsAnonymous)
            {
                return(await AnonymousRepo.FolderInfo(path, ulink, offset, limit));
            }

            if (null == ulink && depth > 1)
            {
                return(await FolderInfo(path, depth));
            }

            FolderInfoResult datares;

            try
            {
                datares = await new FolderInfoRequest(HttpSettings, Authent, ulink != null ? ulink.Href : path, ulink != null, offset, limit)
                          .MakeRequestAsync();
            }
            catch (WebException e) when((e.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            MailRuCloud.ItemType itemType;

            //TODO: subject to refact, bad-bad-bad
            if (null == ulink || ulink.ItemType == MailRuCloud.ItemType.Unknown)
            {
                itemType = datares.body.home == path ||
                           WebDavPath.PathEquals("/" + datares.body.weblink, path)
                    ? MailRuCloud.ItemType.Folder
                    : MailRuCloud.ItemType.File;
            }
            else
            {
                itemType = ulink.ItemType;
            }


            var entry = itemType == MailRuCloud.ItemType.File
                ? (IEntry)datares.ToFile(
                home: WebDavPath.Parent(path),
                ulink: ulink,
                filename: ulink == null ? WebDavPath.Name(path) : ulink.OriginalName,
                nameReplacement: ulink?.IsLinkedToFileSystem ?? true ? WebDavPath.Name(path) : null)
                : datares.ToFolder(path, ulink);

            return(entry);
        }