Пример #1
0
        public static async Task Copy(string bucket, string containerPrefix, string path, string location, String provider,
                                      string bucket2, string containerPrefix2, string path2, string location2, String provider2,
                                      int maxDegreeOfParallelism,
                                      ILogger logger)
        {
            logger.LogInformation($"source {provider}@{bucket}-{location}, {containerPrefix}/{path}");
            logger.LogInformation($"destination {provider2}@{bucket2}-{location2}, {containerPrefix2}/{path2}");
            var container    = CloudStorage.GetContainer(bucket, containerPrefix, location, provider);
            var dir          = container.GetDirectoryReference(path);
            var basename     = dir.Name;
            var prefixLength = basename.Length;
            var container2   = CloudStorage.GetContainer(bucket2, containerPrefix2, location2, provider2);
            var dir2         = container2.GetDirectoryReference(path2);

            if (!Object.ReferenceEquals(container, null))
            {
                CustomizedBlobContinuationToken token = null;
                do
                {
                    var lst = await dir.ListBlobsSegmentedAsync(true, BlobListingDetails.Metadata, null, token, null, null);

                    var opt = new ParallelOptions();
                    opt.MaxDegreeOfParallelism = maxDegreeOfParallelism;
                    foreach (var item in lst.Results)
                    {
                        var blockItem = item.ToBlockBlob();
                        if (!Object.ReferenceEquals(blockItem, null))
                        {
                            // No need to deal with directories.
                            var itemname = blockItem.Name.Substring(prefixLength);
                            var destItem = dir2.GetBlockBlobReference(itemname);
                            var bytes    = await blockItem.DownloadByteArrayAsync();

                            await destItem.UploadFromByteArrayAsync(bytes, 0, bytes.Length);

                            logger.LogInformation($"Copy item {itemname}");
                        }
                    }
                    ;
                    token = lst.ContinuationToken;
                } while (token != null);
            }
        }
Пример #2
0
        public static async Task List(string bucket, string containerPrefix,
                                      string path, string location, String provider, bool bUseFlat, ILogger logger)
        {
            logger.LogInformation($"Listing {provider}@{bucket}-{location}, {containerPrefix}/{path}, flat = {bUseFlat}");
            var container = CloudStorage.GetContainer(bucket, containerPrefix, location, provider);
            var dir       = container.GetDirectoryReference(path);
            int cnt       = 0;
            int cntdir    = 0;

            if (!Object.ReferenceEquals(container, null))
            {
                CustomizedBlobContinuationToken token = null;
                do
                {
                    var lst = await dir.ListBlobsSegmentedAsync(bUseFlat, BlobListingDetails.Metadata,
                                                                null, token, null, null);

                    foreach (var item in lst.Results)
                    {
                        logger.LogInformation($"{item.Uri}");
                        var blockItem = item.ToBlockBlob();
                        if (!Object.ReferenceEquals(blockItem, null))
                        {
                            cnt++;
                        }
                        var dirItem = item.ToBlobDirectory();
                        if (!Object.ReferenceEquals(dirItem, null))
                        {
                            cntdir++;
                        }
                    }
                    ;
                    token = lst.ContinuationToken;
                } while (token != null);
            }
            logger.LogInformation($"Total files == {cnt}, dir == {cntdir}");
        }
Пример #3
0
 public static BlobContainer GetPrivateContainer(string location, String provider = CloudProvider.Any)
 {
     return(CloudStorage.GetContainer("journal", "private", location, provider));
 }
Пример #4
0
 /// <summary>
 /// Get a azure blob container. This function should only be used by publish, as it access
 /// containers of all location. To access the container of one default location, use
 /// AzureAccount.Container.
 /// </summary>
 /// <param name="location"></param>
 /// <returns></returns>
 public static BlobContainer GetContainer(string location, String provider = CloudProvider.Any)
 {
     return(CloudStorage.GetContainer("cdn", "public", location, provider));
 }