public static void EmptyContainer(CloudBlobContainer container) { var blobInfos = container.ListBlobs(null, true, BlobListingDetails.None); CATFunctions.Print("Deleting old files (" + blobInfos.Count() + ")", true, false); CATFunctions.ShowProgress(blobInfos.Count()); CATFunctions.StartSubProcess("Deleting old files..."); Parallel.ForEach(blobInfos, (blobInfo) => { CloudBlob blob = (CloudBlob)blobInfo; blob.Delete(); CATFunctions.Progress(); CATFunctions.Print("Deleting blob " + blob.Name); }); CATFunctions.Print("Container is empty", true, true); CATFunctions.EndSubProcess(); CATFunctions.FinishProgress(); }
public static void UploadFiles(string SourceDir, CloudBlobContainer container, IEnumerable <FileInfo> fileslist, IEnumerable <string> extensions, int cacheControlMaxAgeSeconds) { int SourceDirLenght = SourceDir.Length + 1; string cacheControlHeader = "public, max-age=" + cacheControlMaxAgeSeconds.ToString(); CATFunctions.Print("Processing files...", true, false); CATFunctions.ShowProgress(fileslist.Count()); CATFunctions.StartSubProcess("Uploading files..."); Parallel.ForEach(fileslist, (fileInfo) => { CATFunctions.Progress(); string contentType; ContentTypeHelper.CurrentContentTypes.TryGetValue(fileInfo.Extension, out contentType); string filePath = GetFilePath(SourceDirLenght, fileInfo); CloudBlockBlob blob = container.GetBlockBlobReference(filePath); if (extensions.Contains(fileInfo.Extension, StringComparer.OrdinalIgnoreCase)) { byte[] compressedBytes; CATFunctions.Print("Gzip file - " + filePath); using (MemoryStream memoryStream = new MemoryStream()) { using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress)) using (var blobStream = fileInfo.OpenRead()) { blobStream.CopyTo(gzipStream); } compressedBytes = memoryStream.ToArray(); CATFunctions.Print("uploading file - " + filePath); blob.UploadFromByteArray(compressedBytes, 0, compressedBytes.Length); blob.Properties.CacheControl = cacheControlHeader; blob.Properties.ContentEncoding = "gzip"; blob.Properties.ContentType = contentType; blob.SetProperties(); } } else { CATFunctions.Print("uploading file - " + filePath); blob.UploadFromFile(fileInfo.FullName); blob.Properties.CacheControl = cacheControlHeader; blob.Properties.ContentType = contentType; blob.SetProperties(); } }); CATFunctions.EndSubProcess(); CATFunctions.FinishProgress(); }