Exemplo n.º 1
0
        public static async Task <SharedFile[]> GetSharedFilesRecursiveAsync(this Project project, string directory = "", SharedFileQuery query = null, ErrorHandler onError = null)
        {
            query = query ?? new SharedFileQuery();

            var typeNames = query.TypeNames;

            query.Count(SharedFileQuery.MaxCount);
            query.FileType(SharedFileType.Directory | SharedFileType.File);

            var files = new List <SharedFile>();

            var directories = new Queue <string>();

            directories.Enqueue(directory);

            var success = true;

            while (success && directories.Any())
            {
                var tmpFiles   = new List <SharedFile>();
                var currentDir = directories.Dequeue();

                while (true)
                {
                    query.Offset(tmpFiles.Count);
                    var fileResponse = await project.GetSharedFilesAsync(currentDir, query).ConfigureAwait(false);

                    if (!fileResponse.CanContinueBatchJobs(onError))
                    {
                        success = false;
                        break;
                    }

                    tmpFiles.AddRange(fileResponse.Content);

                    foreach (var file in fileResponse.Content)
                    {
                        if (file.Type == SharedFileType.Directory)
                        {
                            directories.Enqueue(currentDir + file.Name);
                        }
                    }

                    if (fileResponse.Content.Length < SharedFileQuery.MaxCount)
                    {
                        break;
                    }
                }

                files.AddRange(tmpFiles.Where(x => typeNames.Contains(x.TypeName)));
            }

            return(files.ToArray());
        }
Exemplo n.º 2
0
        public async Task <BacklogResponse <SharedFile[]> > GetSharedFilesAsync(string directory = "", SharedFileQuery query = null)
        {
            query = query ?? new SharedFileQuery();

            var response = await Client.GetAsync($"/api/v2/projects/{Id}/files/metadata/{directory}", query.Build()).ConfigureAwait(false);

            var result = await Client.CreateResponseAsync <SharedFile[], List <_SharedFile> >(
                response,
                HttpStatusCode.OK,
                data => data.Select(x => Client.ItemsCache.Update(x.id, () => new SharedFile(x, this))).ToArray()
                ).ConfigureAwait(false);

            if (result.Errors != null)
            {
                return(result);
            }

            var content = result.Content.Where(x => query.TypeNames.Contains(x.TypeName)).ToArray();

            if (content.Length == result.Content.Length)
            {
                return(result);
            }

            return(new BacklogResponse <SharedFile[]>(result.StatusCode, content));
        }