Esempio n. 1
0
        private bool CloudBlobDirectorySetupWithDelimiter(CloudBlobContainer container, string delimiter = "/")
        {
            try
            {
                for (int i = 1; i < 3; i++)
                {
                    for (int j = 1; j < 3; j++)
                    {
                        for (int k = 1; k < 3; k++)
                        {
                            String        directory = "TopDir" + i + delimiter + "MidDir" + j + delimiter + "EndDir" + k + delimiter + "EndBlob" + k;
                            CloudPageBlob blob1     = container.GetPageBlobReference(directory);
                            blob1.Create(0);
                        }
                    }

                    CloudPageBlob blob2 = container.GetPageBlobReference("TopDir" + i + delimiter + "Blob" + i);
                    blob2.Create(0);
                }

                return(true);
            }
            catch (StorageException)
            {
                throw;
            }
        }
Esempio n. 2
0
        public void CloudBlobDirectoryGetParent()
        {
            foreach (String delimiter in Delimiters)
            {
                CloudBlobClient client = GenerateCloudBlobClient();
                client.DefaultDelimiter = delimiter;
                string             name      = GetRandomContainerName();
                CloudBlobContainer container = client.GetContainerReference(name);
                try
                {
                    container.Create();
                    CloudPageBlob blob = container.GetPageBlobReference("Dir1" + delimiter + "Blob1");
                    blob.Create(0);
                    Assert.AreEqual("Dir1" + delimiter + "Blob1", blob.Name);

                    // get the blob's parent
                    CloudBlobDirectory parent = blob.Parent;
                    Assert.AreEqual(parent.Prefix, "Dir1" + delimiter);

                    // get container as parent
                    CloudBlobDirectory root = parent.Parent;
                    Assert.AreEqual(root.Prefix, "");

                    // make sure the parent of the container dir is null
                    CloudBlobDirectory empty = root.Parent;
                    Assert.IsNull(empty);

                    // from container, get directory reference to container
                    root = container.GetDirectoryReference("");
                    Assert.AreEqual("", root.Prefix);
                    Assert.AreEqual(container.Uri.AbsoluteUri, root.Uri.AbsoluteUri);

                    List <IListBlobItem> list = root.ListBlobs().ToList();
                    Assert.AreEqual(1, list.Count);

                    // make sure the parent of the container dir is null
                    empty = root.Parent;
                    Assert.IsNull(empty);

                    blob.DeleteIfExists();
                }
                finally
                {
                    container.DeleteIfExists();
                }
            }
        }
Esempio n. 3
0
        public void CloudBlobDirectoryValidateInRootContainer()
        {
            foreach (String delimiter in Delimiters)
            {
                CloudBlobClient client = GenerateCloudBlobClient();
                client.DefaultDelimiter = delimiter;
                CloudBlobContainer container = client.GetContainerReference("$root");

                CloudPageBlob pageBlob = container.GetPageBlobReference("Dir1" + delimiter + "Blob1");

                if (delimiter == "/")
                {
                    TestHelper.ExpectedException(
                        () => pageBlob.Create(0),
                        "Try to create a CloudBlobDirectory/blob which has a slash in its name in the root container",
                        HttpStatusCode.BadRequest);
                }

                else
                {
                    CloudPageBlob blob = container.GetPageBlobReference("TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir1" + delimiter + "EndBlob1");

                    CloudBlobDirectory directory = blob.Parent;
                    Assert.AreEqual(directory.Prefix, "TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir1" + delimiter);
                    Assert.AreEqual(directory.Uri, container.Uri + "/TopDir1" + delimiter + "MidDir1" + delimiter + "EndDir1" + delimiter);

                    CloudBlobDirectory directory1 = container.GetDirectoryReference("TopDir1" + delimiter);
                    CloudBlobDirectory subdir1    = directory1.GetDirectoryReference("MidDir" + delimiter);
                    CloudBlobDirectory parent1    = subdir1.Parent;
                    Assert.AreEqual(parent1.Prefix, directory1.Prefix);
                    Assert.AreEqual(parent1.Uri, directory1.Uri);

                    CloudBlobDirectory subdir2 = subdir1.GetDirectoryReference("EndDir" + delimiter);
                    CloudBlobDirectory parent2 = subdir2.Parent;
                    Assert.AreEqual(parent2.Prefix, subdir1.Prefix);
                    Assert.AreEqual(parent2.Uri, subdir1.Uri);
                }
            }
        }
Esempio n. 4
0
        public static async Task <List <string> > CreateBlobs(CloudBlobContainer container, int count, BlobType type)
        {
            string        name;
            List <string> blobs = new List <string>();
            List <Task>   tasks = new List <Task>();

            for (int i = 0; i < count; i++)
            {
                switch (type)
                {
                case BlobType.BlockBlob:
                    name = "bb" + Guid.NewGuid().ToString();
                    CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
                    tasks.Add(Task.Run(() => blockBlob.PutBlockList(new string[] { })));
                    blobs.Add(name);
                    break;

                case BlobType.PageBlob:
                    name = "pb" + Guid.NewGuid().ToString();
                    CloudPageBlob pageBlob = container.GetPageBlobReference(name);
                    tasks.Add(Task.Run(() => pageBlob.Create(0)));
                    blobs.Add(name);
                    break;

                case BlobType.AppendBlob:
                    name = "ab" + Guid.NewGuid().ToString();
                    CloudAppendBlob appendBlob = container.GetAppendBlobReference(name);
                    tasks.Add(Task.Run(() => appendBlob.CreateOrReplace()));
                    blobs.Add(name);
                    break;
                }
            }
            await Task.WhenAll(tasks);

            return(blobs);
        }