Exemple #1
0
        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,
                                       BlobContainerClient container,
                                       IEnumerable <FileInfo> fileslist,
                                       IEnumerable <string> extensions,
                                       int cacheControlMaxAgeSeconds)
        {
            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();


                ContentTypeHelper.CurrentContentTypes.TryGetValue(fileInfo.Extension, out string contentType);

                string filePath = GetFilePath(SourceDir, fileInfo, true);

                BlobClient blob = container.GetBlobClient(filePath);

                if (extensions.Contains(fileInfo.Extension, StringComparer.OrdinalIgnoreCase))
                {
                    CATFunctions.Print("Compress file - " + filePath);

                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        using (var brotliStream = new BrotliStream(memoryStream, CompressionMode.Compress, true))

                            using (var blobStream = fileInfo.OpenRead())
                            {
                                blobStream.CopyTo(brotliStream);
                            }


                        memoryStream.Position = 0;
                        blob.Upload(memoryStream);



                        CATFunctions.Print("uploading file - " + filePath);


                        BlobHttpHeaders headers = new()
                        {
                            ContentType     = contentType,
                            ContentEncoding = "br",
                            CacheControl    = cacheControlHeader,
                        };

                        blob.SetHttpHeadersAsync(headers);
                    }
Exemple #3
0
        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();
        }