示例#1
0
        private async Task <SizeResponseModel> DirectorySizeAndCount(string dir)
        {
            var response = new SizeResponseModel();

            // Get all files and directories
            var items = await AzureStorageAPI.ListFilesAndDirectoriesAsync(dir);

            foreach (var file in items.Where(i => i is CloudFile))
            {
                var cloudFile = file as CloudFile;
                response.FileCount++;
                await cloudFile.FetchAttributesAsync();

                response.Size += cloudFile.Properties.Length;
            }

            // Add subdirectory sizes.
            foreach (var directory in items.Where(i => i is CloudFileDirectory))
            {
                response.DirectoryCount++;

                var subdir = await DirectorySizeAndCount(directory.Uri.LocalPath.Substring(1)); // Get path without leading '/'

                response.DirectoryCount += subdir.DirectoryCount;
                response.FileCount      += subdir.FileCount;
                response.Size           += subdir.Size;
            }

            return(response);
        }
示例#2
0
        public async Task <JsonResult> SizeAsync(IEnumerable <FullPath> paths)
        {
            var response = new SizeResponseModel();

            foreach (var path in paths)
            {
                if (path.IsDirectory)
                {
                    response.DirectoryCount++; // API counts the current directory in the total

                    var sizeAndCount = await DirectorySizeAndCount(path.Directory.FullName);

                    response.DirectoryCount += sizeAndCount.DirectoryCount;
                    response.FileCount      += sizeAndCount.FileCount;
                    response.Size           += sizeAndCount.Size;
                }
                else
                {
                    response.FileCount++;
                    response.Size += await path.File.LengthAsync;
                }
            }

            return(await Json(response));
        }
示例#3
0
        private async Task <SizeResponseModel> DirectorySizeAndCount(IDirectory d)
        {
            var response = new SizeResponseModel();

            // Add file sizes.
            foreach (var file in await d.GetFilesAsync())
            {
                response.FileCount++;
                response.Size += await file.LengthAsync;
            }

            // Add subdirectory sizes.
            foreach (var directory in await d.GetDirectoriesAsync())
            {
                response.DirectoryCount++;

                var subdir = await DirectorySizeAndCount(directory);

                response.DirectoryCount += subdir.DirectoryCount;
                response.FileCount      += subdir.FileCount;
                response.Size           += subdir.Size;
            }

            return(response);
        }
示例#4
0
        private static async Task <SizeResponseModel> DirectorySizeAndCount(IDirectory d)
        {
            var response = new SizeResponseModel();

            // Add file sizes.
            // todo: add mimetypes instead of null as GetFilesAsync parameter
            foreach (var file in await d.GetFilesAsync(null))
            {
                response.FileCount++;
                response.Size += await file.LengthAsync;
            }

            // Add subdirectory sizes.
            foreach (var directory in await d.GetDirectoriesAsync())
            {
                response.DirectoryCount++;

                var subdir = await DirectorySizeAndCount(directory);

                response.DirectoryCount += subdir.DirectoryCount;
                response.FileCount      += subdir.FileCount;
                response.Size           += subdir.Size;
            }

            return(response);
        }
示例#5
0
        private SizeResponseModel DirectorySizeAndCount(DirectoryInfo d)
        {
            var response = new SizeResponseModel();

            // Add file sizes.
            foreach (var file in d.GetFiles())
            {
                response.FileCount++;
                response.Size += file.Length;
            }

            // Add subdirectory sizes.
            foreach (var directory in d.GetDirectories())
            {
                response.DirectoryCount++;

                var subdir = DirectorySizeAndCount(directory);
                response.DirectoryCount += subdir.DirectoryCount;
                response.FileCount      += subdir.FileCount;
                response.Size           += subdir.Size;
            }

            return(response);
        }