Exemple #1
0
        public async Task SaveImage_GetImage_DeleteFile()
        {
            try
            {
                var    notifier         = new ProgressCancelNotifier();
                string connectionString = ConfigurationManager.AppSettings["AzureStorageConnectionString"];
                string containerName    = Guid.NewGuid().ToString();

                var blobContainer = new BlobContainer(notifier, false);
                await blobContainer.CreateContainerAsync(connectionString, containerName, BlobContainerPublicAccessEnum.Off);

                var theImage = Image.FromFile(ImagePath1);
                theImage = theImage.ScaleImage(500, 500);

                string fileName  = "imagetest.jpeg";
                string fileName2 = "imagetest2.jpeg";
                string fakeName  = "imagetest241.jpeg";

                //save
                if (await blobContainer.SaveFileAsync(connectionString, containerName, theImage.ToStream(), fileName) == null)
                {
                    throw new Exception();
                }
                if (await blobContainer.SaveFileAsync(connectionString, containerName, theImage.ToStream(), fileName2) == null)
                {
                    throw new Exception();
                }

                //get
                var getImage = await blobContainer.GetFileAsync(connectionString, containerName, fileName);

                if (getImage == null)
                {
                    throw new Exception();
                }

                var getImage2 = await blobContainer.GetFileAsync(connectionString, containerName, fakeName);

                if (getImage2 != null)
                {
                    throw new Exception();
                }

                //delete
                if (!await blobContainer.DeleteFileAsync(connectionString, containerName, fileName))
                {
                    throw new Exception();
                }
                if (!await blobContainer.DeleteFileAsync(connectionString, containerName, fileName2))
                {
                    throw new Exception();
                }

                await blobContainer.DeleteContainerAsync(connectionString, containerName);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #2
0
        public async Task SavePDF_GetImage_DeleteFile()
        {
            var    notifier         = new ProgressCancelNotifier();
            string connectionString = ConfigurationManager.AppSettings["AzureStorageConnectionString"];
            string containerName    = Guid.NewGuid().ToString();

            var blobContainer = new BlobContainer(notifier, false);
            await blobContainer.CreateContainerAsync(connectionString, containerName, BlobContainerPublicAccessEnum.Off);

            var theFile = File.ReadAllBytes(pdfPath);

            string fileName  = "pdf1.pdf";
            string fileName2 = "pdf2.pdf";
            string fakeName  = "pdf1001.pdf";

            //save
            if (await blobContainer.SaveFileAsync(connectionString, containerName, theFile, fileName) == null)
            {
                throw new Exception();
            }
            if (await blobContainer.SaveFileAsync(connectionString, containerName, theFile, fileName2) == null)
            {
                throw new Exception();
            }

            //get
            var getImage = await blobContainer.GetFileAsync(connectionString, containerName, fileName);

            if (getImage == null)
            {
                throw new Exception();
            }

            var getImage2 = await blobContainer.GetFileAsync(connectionString, containerName, fakeName);

            if (getImage2 != null)
            {
                throw new Exception();
            }

            //delete
            if (!await blobContainer.DeleteFileAsync(connectionString, containerName, fileName))
            {
                throw new Exception();
            }
            if (!await blobContainer.DeleteFileAsync(connectionString, containerName, fileName2))
            {
                throw new Exception();
            }

            await blobContainer.DeleteContainerAsync(connectionString, containerName);
        }