Exemplo n.º 1
0
        public static UnpublishResult ToUnpublishResult(this YadResponseModel <YadPublishRequestData, YadPublishRequestParams> data)
        {
            var res = new UnpublishResult
            {
                IsSuccess = true
            };

            return(res);
        }
Exemplo n.º 2
0
        public static PublishResult ToPublishResult(this YadResponseModel <YadPublishRequestData, YadPublishRequestParams> data)
        {
            var res = new PublishResult
            {
                IsSuccess = !string.IsNullOrEmpty(data.Data.ShortUrl),
                Url       = data.Data.ShortUrl
            };

            return(res);
        }
Exemplo n.º 3
0
        public static RemoveResult ToRemoveResult(this YadResponseModel <YadDeleteRequestData, YadDeleteRequestParams> data)
        {
            var res = new RemoveResult
            {
                IsSuccess = true,
                DateTime  = DateTime.Now,
                Path      = data.Params.Id.Remove(0, "/disk".Length)
            };

            return(res);
        }
Exemplo n.º 4
0
        public static RenameResult ToRenameResult(this YadResponseModel <YadMoveRequestData, YadMoveRequestParams> data)
        {
            var res = new RenameResult
            {
                IsSuccess = null == data.Data.Error,
                DateTime  = DateTime.Now,
                Path      = data.Params.Src.Remove(0, "/disk".Length)
            };

            return(res);
        }
Exemplo n.º 5
0
        public static CopyResult ToMoveResult(this YadResponseModel <YadMoveRequestData, YadMoveRequestParams> data)
        {
            var res = new CopyResult
            {
                IsSuccess   = null == data.Data.Error,
                NewName     = data.Params.Dst.Remove(0, "/disk".Length),
                OldFullPath = data.Params.Src.Remove(0, "/disk".Length),
                DateTime    = DateTime.Now
            };

            return(res);
        }
Exemplo n.º 6
0
        public static AccountInfoResult ToAccountInfo(this YadResponseModel <YadAccountInfoRequestData, YadAccountInfoRequestParams> data)
        {
            var info = data.Data;
            var res  = new AccountInfoResult
            {
                FileSizeLimit = info.FilesizeLimit,

                DiskUsage = new DiskUsage
                {
                    Total     = info.Limit,
                    Used      = info.Used,
                    OverQuota = info.Used > info.Limit
                }
            };

            return(res);
        }
Exemplo n.º 7
0
        private void WaitForOperation(string operationOid)
        {
            YadResponseModel <YadOperationStatusData, YadOperationStatusParams> itemInfo = null;

            Retry.Do(
                () => TimeSpan.Zero,
                () => new YaDCommonRequest(HttpSettings, (YadWebAuth)Authent)
                .With(new YadOperationStatusPostModel(operationOid), out itemInfo)
                .MakeRequestAsync()
                .Result,
                resp =>
            {
                var doAgain = null == itemInfo.Data.Error && itemInfo.Data.State != "COMPLETED";
                //if (doAgain)
                //    Logger.Debug("Move op still not finished, let's try again");
                return(doAgain);
            },
                TimeSpan.FromMilliseconds(OperationStatusCheckIntervalMs), OperationStatusCheckRetryCount);
        }
Exemplo n.º 8
0
        public async Task <IEntry> FolderInfo(RemotePath path, int offset = 0, int limit = Int32.MaxValue, int depth = 1)
        {
            if (path.IsLink)
            {
                throw new NotImplementedException(nameof(FolderInfo));
            }

            if (path.Path.StartsWith(YadMediaPath))
            {
                return(await MediaFolderInfo(path.Path));
            }

            // YaD perform async deletion
            YadResponseModel <YadItemInfoRequestData, YadItemInfoRequestParams>           itemInfo      = null;
            YadResponseModel <YadFolderInfoRequestData, YadFolderInfoRequestParams>       folderInfo    = null;
            YadResponseModel <YadResourceStatsRequestData, YadResourceStatsRequestParams> resourceStats = null;

            bool hasRemoveOp = _lastRemoveOperation != null &&
                               WebDavPath.IsParentOrSame(path.Path, _lastRemoveOperation.Path) &&
                               (DateTime.Now - _lastRemoveOperation.DateTime).TotalMilliseconds < 1_000;

            Retry.Do(
                () =>
            {
                var doPreSleep = hasRemoveOp ? TimeSpan.FromMilliseconds(OperationStatusCheckIntervalMs) : TimeSpan.Zero;
                if (doPreSleep > TimeSpan.Zero)
                {
                    Logger.Debug("Has remove op, sleep before");
                }
                return(doPreSleep);
            },
                () => new YaDCommonRequest(HttpSettings, (YadWebAuth)Authent)
                .With(new YadItemInfoPostModel(path.Path), out itemInfo)
                .With(new YadFolderInfoPostModel(path.Path), out folderInfo)
                .With(new YadResourceStatsPostModel(path.Path), out resourceStats)
                .MakeRequestAsync()
                .Result,
                resp =>
            {
                var doAgain = hasRemoveOp &&
                              folderInfo.Data.Resources.Any(r =>
                                                            WebDavPath.PathEquals(r.Path.Remove(0, "/disk".Length), _lastRemoveOperation.Path));
                if (doAgain)
                {
                    Logger.Debug("Remove op still not finished, let's try again");
                }
                return(doAgain);
            },
                TimeSpan.FromMilliseconds(OperationStatusCheckIntervalMs), OperationStatusCheckRetryCount);


            var itdata = itemInfo?.Data;

            if (itdata?.Type == null)
            {
                return(null);
            }

            if (itdata.Type == "file")
            {
                return(itdata.ToFile(PublicBaseUrlDefault));
            }

            var entry = folderInfo.Data.ToFolder(itemInfo.Data, resourceStats.Data, path.Path, PublicBaseUrlDefault);

            return(entry);
        }