GetPackagesBlobContainer() static private method

static private GetPackagesBlobContainer ( Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient ) : Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
blobClient Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient
return Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer
        private IEnumerable <string> GetPackageBlobFileNames()
        {
            var blobClient            = CreateBlobClient();
            var packagesBlobContainer = Util.GetPackagesBlobContainer(blobClient);

            return(packagesBlobContainer.ListBlobs().Select(bi => bi.Uri.Segments.Last()));
        }
Esempio n. 2
0
        public override void ExecuteCommand()
        {
            new BackupPackageFileTask
            {
                BackupStorage  = BackupStorage,
                StorageAccount = StorageAccount,
                PackageId      = PackageId,
                PackageVersion = PackageVersion,
                PackageHash    = PackageHash,
                WhatIf         = WhatIf
            }.ExecuteCommand();

            var blobClient            = CreateBlobClient();
            var packagesBlobContainer = Util.GetPackagesBlobContainer(blobClient);
            var packageFileBlob       = Util.GetPackageFileBlob(
                packagesBlobContainer,
                PackageId,
                PackageVersion);
            var fileName = Util.GetPackageFileName(
                PackageId,
                PackageVersion);

            if (packageFileBlob.Exists())
            {
                Log.Info("Deleting package file '{0}'.", fileName);
                if (!WhatIf)
                {
                    packageFileBlob.DeleteIfExists();
                }
            }
            else
            {
                Log.Warn("Package file does not exist '{0}'.", fileName);
            }
        }
        public override void ExecuteCommand()
        {
            var blobClient = CreateBlobClient();

            var packagesBlobContainer = Util.GetPackagesBlobContainer(blobClient);

            Log.Info("Listing all blobs...");
            var blobs = packagesBlobContainer.ListBlobs();

            Log.Info("Looking for broken blobs");
            ConcurrentBag <CloudBlockBlob> broken = new ConcurrentBag <CloudBlockBlob>();

            Parallel.ForEach(blobs, blob =>
            {
                var packageFileBlob = packagesBlobContainer.GetBlockBlobReference(blob.Uri.ToString());
                packageFileBlob.FetchAttributes();
                if (packageFileBlob.Properties.ContentType != "application/zip")
                {
                    broken.Add(packageFileBlob);
                }
            });
            Log.Info("Fixing {0} broken blobs...");
            int totalCount     = broken.Count;
            int processedCount = 0;

            Parallel.ForEach(broken, packageFileBlob =>
            {
                if (!WhatIf)
                {
                    packageFileBlob.Properties.ContentType = "application/zip";
                    packageFileBlob.SetProperties();
                }
                Log.Info("Fixed '{0}' ({1} of {2}).", packageFileBlob.Uri.Segments.Last(), Interlocked.Increment(ref processedCount), totalCount);
            });
        }
        string DownloadPackage(Package package)
        {
            var cloudClient = CreateBlobClient();

            var packagesBlobContainer = Util.GetPackagesBlobContainer(cloudClient);

            var packageFileName = Util.GetPackageFileName(package.Id, package.Version);

            var downloadPath = Path.Combine(_tempFolder, packageFileName);

            var blob = packagesBlobContainer.GetBlockBlobReference(packageFileName);

            blob.DownloadToFile(downloadPath);

            return(downloadPath);
        }
        void UploadPackage(
            string id,
            string version,
            string downloadPath)
        {
            var blobClient            = CreateBlobClient();
            var packagesBlobContainer = Util.GetPackagesBlobContainer(blobClient);
            var packageFileName       = Util.GetPackageFileName(
                id,
                version);
            var packageBlob = packagesBlobContainer.GetBlockBlobReference(packageFileName);

            packageBlob.UploadFile(downloadPath);
            packageBlob.Properties.ContentType = "application/zip";
            packageBlob.SetProperties();
        }