Example #1
0
        internal static string GetTemporaryFilesUrlFormat(string directoryName)
        {
            var writeDeletePermissions = CreateWriteDeletePermissions();

            string sasUrl = TemporaryContainer.GenerateSasUri(writeDeletePermissions).ToString();

            string urlFormat = sasUrl.Replace("?", $"/{directoryName}/{{0}}?");

            return(urlFormat);
        }
Example #2
0
        public static void DeleteTemporaryFiles(string directoryName)
        {
            var blobItems = GetBlockBlobs(TemporaryContainer, directoryName + "/");

            foreach (var blobItem in blobItems)
            {
                var blob = TemporaryContainer.GetBlobClient(blobItem.Name);

                blob.DeleteIfExists();
            }
        }
        public void AddContainer(TemporaryContainer container)
        {
            lock (_lockingObject)
            {
                if (_containers.Any(c => c.DockerContainerId == container.DockerContainerId))
                {
                    return;
                }

                _containers.Add(container);
            }
        }
Example #4
0
        public static string UploadTemporaryFile(string fileName, string contentType, Stream source, string directoryName)
        {
            if (source != null)
            {
                string fileName2 = EscapeInvalidChars(fileName);

                string fileId = $"{directoryName}/{fileName2}";

                var blob = TemporaryContainer.GetBlobClient(fileId);

                UploadBlobFromStream(blob, fileName, contentType, source);

                return(blob.Name);
            }

            return(null);
        }
Example #5
0
        public static Collection <File> GetTemporaryFiles(string directoryName)
        {
            List <File> files = new List <File>();

            var readPermissions = CreateReadPermissions();

            var blobItems = GetBlockBlobs(TemporaryContainer, directoryName + "/");

            foreach (var blobItem in blobItems)
            {
                var blob = TemporaryContainer.GetBlobClient(blobItem.Name);

                File file = GetFileInfo(blob, readPermissions, blobItem.Properties);

                files.Add(file);
            }

            files.Sort(CompareFilesByLastModifiedAndName);

            return(new Collection <File>(files));
        }
Example #6
0
        private void CopyTemporaryFiles(string directoryName, bool deleteTemporaryFiles)
        {
            var temporaryBlobItems = GetBlockBlobs(TemporaryContainer, directoryName + "/");

            foreach (var tempBlobItem in temporaryBlobItems)
            {
                string fileName = GetNameFromFileId(tempBlobItem.Name);
                string blobName = GetFileId(fileName);

                var blob     = Container.GetBlobClient(blobName);
                var tempBlob = TemporaryContainer.GetBlobClient(tempBlobItem.Name);

                if (MimeType.IsInGroups(tempBlobItem.Properties.ContentType, MimeTypeGroups.Image))
                {
                    Stream source = null;

                    try
                    {
                        var downloadResult = tempBlob.DownloadContent().Value;

                        source = downloadResult.Content.ToStream();

                        byte[] bytes = RotateFlipImageByOrientation(tempBlobItem.Properties.ContentType, source);

                        if (bytes == null)
                        {
                            bytes = downloadResult.Content.ToArray();
                        }

                        if (bytes != null)
                        {
                            var uploadOptions = new BlobUploadOptions
                            {
                                HttpHeaders = new BlobHttpHeaders
                                {
                                    ContentType  = tempBlobItem.Properties.ContentType,
                                    CacheControl = Settings.ClientCacheControl
                                }
                            };

                            blob.Upload(new BinaryData(bytes), uploadOptions);
                        }
                    }
                    finally
                    {
                        source?.Dispose();
                    }

                    DeleteThumbnails(blobName);
                }
                else
                {
                    if (tempBlob.Exists())
                    {
                        blob.StartCopyFromUri(tempBlob.Uri);
                    }
                }

                if (deleteTemporaryFiles)
                {
                    tempBlob.DeleteIfExists();
                }
            }
        }
Example #7
0
        public static File GetTemporaryFileInfo(string fileId)
        {
            var blob = TemporaryContainer.GetBlobClient(fileId);

            return(GetFileInfo(blob, CreateReadPermissions()));
        }