示例#1
0
        public BlobManager(){
            try
            {
                storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"));

                blobClient = storageAccount.CreateCloudBlobClient();
                container = blobClient.GetContainerReference("supstorage");
                container.CreateIfNotExists();
            }
            catch (ArgumentNullException)
            {
                Trace.TraceInformation("CloudStorageAccount Exception null ou vide");
                // Use Application Local Storage Account String
            }
            catch (NullReferenceException)
            {
                Trace.TraceInformation("CloudBlobClient Or CloudBlobContainer Exception");
                // Create Container 
            }
            catch (FormatException)
            {
                Trace.TraceInformation("CloudStorageAccount Exception Connection String Invalid");
            }
            catch (ArgumentException)
            {
                Trace.TraceInformation("CloudStorageAccount Exception connectionString ne peut pas être analysée");
            }
        }
示例#2
0
        /// <summary>
        /// Parameters:
        ///     Block:
        ///         True for BlockBlob, false for PageBlob
        /// </summary>
        internal void UploadBlobTest(Agent agent, string UploadFilePath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
            string blobName           = Path.GetFileName(UploadFilePath);

            Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
            Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Blob, blobName);

            dic["BlobType"] = Type;
            comp.Add(dic);

            // create the container
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                //--------------Upload operation--------------
                Test.Assert(agent.SetAzureStorageBlobContent(UploadFilePath, NEW_CONTAINER_NAME, Type), Utility.GenComparisonData("SendAzureStorageBlob", true));

                StorageBlob.ICloudBlob blob = CommonBlobHelper.QueryBlob(NEW_CONTAINER_NAME, blobName);
                CloudBlobUtil.PackBlobCompareData(blob, dic);
                // Verification for returned values
                agent.OutputValidation(comp);
                Test.Assert(blob != null && blob.Exists(), "blob " + blobName + " should exist!");
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
            }
        }
示例#3
0
        internal void GetContainerTest(Agent agent)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-");

            Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, NEW_CONTAINER_NAME);

            // create container if it does not exist
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> > {
                dic
            };

            try
            {
                //--------------Get operation--------------
                Test.Assert(agent.GetAzureStorageContainer(NEW_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageContainer", true));
                // Verification for returned values
                container.FetchAttributes();
                dic.Add("CloudBlobContainer", container);
                CloudBlobUtil.PackContainerCompareData(container, dic);

                agent.OutputValidation(comp);
            }
            finally
            {
                // clean up
                container.DeleteIfExists();
            }
        }
示例#4
0
        public AzureFileSystem(string containerName, string root, bool isPrivate, CloudStorageAccount storageAccount) {
            // Setup the connection to custom storage accountm, e.g. Development Storage
            _storageAccount = storageAccount;
            ContainerName = containerName;
            _root = String.IsNullOrEmpty(root) ? "": root + "/";
            _absoluteRoot = Combine(Combine(_storageAccount.BlobEndpoint.AbsoluteUri, containerName), _root);

            //using ( new HttpContextWeaver() ) 
            {

                BlobClient = _storageAccount.CreateCloudBlobClient();
                // Get and create the container if it does not exist
                // The container is named with DNS naming restrictions (i.e. all lower case)
                Container = BlobClient.GetContainerReference(ContainerName);

                Container.CreateIfNotExists();

                Container.SetPermissions(isPrivate
                                             ? new BlobContainerPermissions
                                                   {PublicAccess = BlobContainerPublicAccessType.Off}
                                             : new BlobContainerPermissions
                                                   {PublicAccess = BlobContainerPublicAccessType.Blob}); // deny listing 
            }

        }
示例#5
0
        public BlobFileProvider(IEnumerable<string> locations)
            : base()
        {
            _storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
            _blobClient = _storageAccount.CreateCloudBlobClient();
            _container = _blobClient.GetContainerReference("data");
            _container.CreateIfNotExists();

            _strings = new List<string>();
            foreach(string location in locations) {
                foreach (IListBlobItem item in _container.ListBlobs(location,true))
                {
                    if (item.GetType() == typeof(CloudBlockBlob))
                    {
                        CloudBlockBlob blob = (CloudBlockBlob)item;
                        string text;
                        using (var memoryStream = new MemoryStream())
                        {
                            blob.DownloadToStream(memoryStream);
                            text = Encoding.UTF8.GetString(memoryStream.ToArray());
                            if (text[0] == _byteOrderMarkUtf8[0])
                            {
                               text= text.Remove(0,_byteOrderMarkUtf8.Length);
                            }
                            _strings.Add(text);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Upload the generated receipt Pdf to Blob storage.
        /// </summary>
        /// <param name="file">Byte array containig the Pdf file contents to be uploaded.</param>
        /// <param name="fileName">The desired filename of the uploaded file.</param>
        /// <returns></returns>
        public string UploadPdfToBlob(byte[] file, string fileName)
        {
            // Create the blob client.
            blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            blobContainer = blobClient.GetContainerReference(receiptBlobName);

            // Create the container if it doesn't already exist.
            blobContainer.CreateIfNotExists(BlobContainerPublicAccessType.Blob);

            string fileUri = string.Empty;

            CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(fileName);

            using (var stream = new MemoryStream(file))
            {
                // Upload the in-memory Pdf file to blob storage.
                blockBlob.UploadFromStream(stream);
            }

            fileUri = blockBlob.Uri.ToString();

            return fileUri;
        }
示例#7
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections.
            ServicePointManager.DefaultConnectionLimit = 12;

            // Read database connection string and open database.
            var dbConnString = CloudConfigurationManager.GetSetting("TCWAdminPortalDbConnectionString");
            _dbContext = new TCWAdminContext(dbConnString);

            // Open storage account using credentials from .cscfg file.
            var storageAccount = CloudStorageAccount.Parse
                (RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            Trace.TraceInformation("Creating images blob container");
            var blobClient = storageAccount.CreateCloudBlobClient();
            _imagesBlobContainer = blobClient.GetContainerReference("images");
            if (_imagesBlobContainer.CreateIfNotExists())
            {
                // Enable public access on the newly created "images" container.
                _imagesBlobContainer.SetPermissions(
                    new BlobContainerPermissions
                    {
                        PublicAccess = BlobContainerPublicAccessType.Blob
                    });
            }

            Trace.TraceInformation("Creating images queue");
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            _imagesQueue = queueClient.GetQueueReference("images");
            _imagesQueue.CreateIfNotExists();

            Trace.TraceInformation("Storage initialized");
            return base.OnStart();
        }
示例#8
0
        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = 12;

            var dbConnString = CloudConfigurationManager.GetSetting("PhotoGalleryDbConnectionString");
            db = new PhotoGalleryContext(dbConnString);

            var storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            Trace.TraceInformation("Creating images blob container");
            var blobClient = storageAccount.CreateCloudBlobClient();
            imagesBlobContainer = blobClient.GetContainerReference("images");
            if (imagesBlobContainer.CreateIfNotExists())
            {

                imagesBlobContainer.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
            }

            Trace.TraceInformation("Creating images queue");
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            imagesQueue = queueClient.GetQueueReference("images");
            imagesQueue.CreateIfNotExists();

            Trace.TraceInformation("Storage initialized");
            return base.OnStart();
        }
示例#9
0
 public void InitializeContainer(string container)
 {
     var blobClient = StorageAccount.CreateCloudBlobClient();
     blobContainer = blobClient.GetContainerReference(container);
     blobContainer.CreateIfNotExists();
     blobContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });
 }
示例#10
0
 public AzureFileSystem(String connectionString, String containerName)
 {
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
     CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
     container = blobClient.GetContainerReference(containerName.ToLower());
     container.CreateIfNotExists();
 }
示例#11
0
 private void GetClientAndReference()
 {    
     var account = CloudStorageAccount.Parse(_source.ConnectionString);
     var client = account.CreateCloudBlobClient();
     _containerReference = client.GetContainerReference(_source.ContainerName);
     _containerReference.CreateIfNotExists();
 }
示例#12
0
        public ImageStore()
        {
            _client = Account.CreateCloudBlobClient();
            _container = _client.GetContainerReference(ContainerName);

            _container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
        }
        internal void UploadFromString(string accountName, string accountKey, string containerName, string fileName, string sourceFileName, string fileContentType, string content)   //, string name, string fileDescription) {
        {
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount =
                Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(
                    string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};BlobEndpoint=https://{0}.blob.core.windows.net/", accountName, accountKey)
                    );
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient    blobClient = storageAccount.CreateCloudBlobClient();
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container  = blobClient.GetContainerReference(containerName);
            container.CreateIfNotExists();
            string ext = System.IO.Path.GetExtension(sourceFileName);

            //string fileName = String.Format(

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
            blockBlob.Properties.ContentType = fileContentType;
            //blockBlob.Metadata.Add("name", name);
            blockBlob.Metadata.Add("originalfilename", sourceFileName);
            //blockBlob.Metadata.Add("userid", userId.ToString());
            //blockBlob.Metadata.Add("ownerid", userId.ToString());
            DateTime created = DateTime.UtcNow;

            // https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
            // http://stackoverflow.com/questions/114983/given-a-datetime-object-how-do-i-get-a-iso-8601-date-in-string-format
            //blockBlob.Metadata.Add("username", userName);
            blockBlob.Metadata.Add("created", created.ToString("yyyy-MM-ddTHH:mm:ss"));  // "yyyy-MM-ddTHH:mm:ssZ"
            blockBlob.Metadata.Add("modified", created.ToString("yyyy-MM-ddTHH:mm:ss")); // "yyyy-MM-ddTHH:mm:ssZ"
            blockBlob.Metadata.Add("fileext", ext);

            blockBlob.UploadText(content, Encoding.UTF8); // .UploadFromStream(fileInputStream);

            blockBlob.SetMetadata();
        }
示例#14
0
        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount;

            // Read storage account configuration settings
            ConfigureDiagnostics();
            Trace.TraceInformation("Initializing storage account in worker role B");
            var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            // Initialize queue storage
            Trace.TraceInformation("Creating queue client.");
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            sendEmailQueue = queueClient.GetQueueReference("azuremailqueue");
            subscribeQueue = queueClient.GetQueueReference("azuremailsubscribequeue");

            // Initialize blob storage
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            blobContainer = blobClient.GetContainerReference("azuremailblobcontainer");

            // Initialize table storage
            var tableClient = storageAccount.CreateCloudTableClient();
            mailingListTable = tableClient.GetTableReference("mailinglist");
            messageTable = tableClient.GetTableReference("message");
            messagearchiveTable = tableClient.GetTableReference("messagearchive");

            Trace.TraceInformation("WorkerB: Creating blob container, queue, tables, if they don't exist.");
            blobContainer.CreateIfNotExists();
            sendEmailQueue.CreateIfNotExists();
            subscribeQueue.CreateIfNotExists();
            this.messageTable.CreateIfNotExists();
            this.mailingListTable.CreateIfNotExists();
            this.messagearchiveTable.CreateIfNotExists();

            return base.OnStart();
        }
        /// <summary>
        /// create a container with random properties and metadata
        /// </summary>
        /// <param name="containerName">container name</param>
        /// <returns>the created container object with properties and metadata</returns>
        public StorageBlob.CloudBlobContainer CreateContainer(string containerName = "")
        {
            if (String.IsNullOrEmpty(containerName))
            {
                containerName = Utility.GenNameString("container");
            }

            StorageBlob.CloudBlobContainer container = client.GetContainerReference(containerName);
            container.CreateIfNotExists();

            //there is no properties to set
            container.FetchAttributes();

            int minMetaCount       = 1;
            int maxMetaCount       = 5;
            int minMetaValueLength = 10;
            int maxMetaValueLength = 20;
            int count = random.Next(minMetaCount, maxMetaCount);

            for (int i = 0; i < count; i++)
            {
                string metaKey     = Utility.GenNameString("metatest");
                int    valueLength = random.Next(minMetaValueLength, maxMetaValueLength);
                string metaValue   = Utility.GenNameString("metavalue-", valueLength);
                container.Metadata.Add(metaKey, metaValue);
            }

            container.SetMetadata();

            Test.Info(string.Format("create container '{0}'", containerName));
            return(container);
        }
示例#16
0
        public BlobStorage(BlobSettings appSettings)
        {
            try
            {
                if (appSettings.ImageSize != null)
                    ResizeLayer = new ResizeLayer(appSettings.ImageSize, ResizeMode.Min);

                UploadThumbnail = appSettings.UploadThumbnail;

                StorageAccountName = appSettings.StorageAccountName;
                StorageAccountAccessKey = appSettings.StorageAccountAccessKey;

                // Create a blob client and retrieve reference to images container
                BlobClient = StorageAccount.CreateCloudBlobClient();
                Container = BlobClient.GetContainerReference(appSettings.ContainerName);

                // Create the "images" container if it doesn't already exist.
                if (Container.CreateIfNotExists())
                {
                    // Enable public access on the newly created "images" container
                    Container.SetPermissions(
                        new BlobContainerPermissions
                        {
                            PublicAccess =
                                BlobContainerPublicAccessType.Blob
                        });
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
示例#17
0
        public HomeController()
        {
            storageAccount = CloudStorageAccount.Parse(
            ConfigurationManager.AppSettings["StorageConnectionString"]);

            tableClient = storageAccount.CreateCloudTableClient();

            table = tableClient.GetTableReference("fouramigos");

            table.CreateIfNotExists();

            blobClient = storageAccount.CreateCloudBlobClient();

            container = blobClient.GetContainerReference("fouramigos");

            container.CreateIfNotExists();

            BlobContainerPermissions permissions = container.GetPermissions();
            permissions.PublicAccess = BlobContainerPublicAccessType.Container;
            container.SetPermissions(permissions);


            //lägga till nya
            //var tablemodels = new TableModel("Brutus", "Uggla") { Location = "T4", Description="Uggla i träd", Type="Foto" };
            //var tablemodels1 = new TableModel("brutus", "Örn") { Location = "T4", Description="Örn som flyger", Type = "Foto" };

            //var opreation = TableOperation.Insert(tablemodels);
            //var operation2 = TableOperation.Insert(tablemodels1);

            //table.Execute(opreation);
            //table.Execute(operation2);
        }
示例#18
0
 public async Task OpenAsync(PartitionContext context)
 {
     if (!WebJobsHelper.RunAsWebJobs)
         Console.WriteLine(string.Format("EventProcessor initialization. Partition: '{0}', Offset: '{1}'",
             context.Lease.PartitionId, context.Lease.Offset));
     partitionContext = context;
     var retries = 3;
     while (retries > 0)
     {
         var s = string.Empty;
         try
         {
             retries--;
             s = "storage";
             storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["SigfoxDemoStorage"].ConnectionString);
             var blobClient = storageAccount.CreateCloudBlobClient();
             blobContainer = blobClient.GetContainerReference("device");
             blobContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Off });
             blobContainer.CreateIfNotExists();
             s = "cache";
             cacheConnection = await ConnectionMultiplexer.ConnectAsync(ConfigurationManager.ConnectionStrings["SigfoxDemoCache"].ConnectionString);
             cacheDatabase = cacheConnection.GetDatabase();
             s = "database";
             sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SigfoxDemoDatabase"].ConnectionString);
             sqlConnection.Open();
             sqlCommand = new SqlCommand("InsertMessage", sqlConnection) { CommandType = CommandType.StoredProcedure };
             sqlCommand.Parameters.Add(new SqlParameter("@Device", SqlDbType.VarChar));
             sqlCommand.Parameters.Add(new SqlParameter("@Data", SqlDbType.VarChar));
             sqlCommand.Parameters.Add(new SqlParameter("@Mode", SqlDbType.TinyInt));
             sqlCommand.Parameters.Add(new SqlParameter("@Periode", SqlDbType.TinyInt));
             sqlCommand.Parameters.Add(new SqlParameter("@FrameType", SqlDbType.TinyInt));
             sqlCommand.Parameters.Add(new SqlParameter("@Battery", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@Temperature", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@Humidity", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@ILS", SqlDbType.Bit));
             sqlCommand.Parameters.Add(new SqlParameter("@Light", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@Version", SqlDbType.VarChar));
             sqlCommand.Parameters.Add(new SqlParameter("@AlertCount", SqlDbType.Int));
             sqlCommand.Parameters.Add(new SqlParameter("@TimeStamp", SqlDbType.DateTime));
             sqlCommand.Parameters.Add(new SqlParameter("@Duplicate", SqlDbType.Bit));
             sqlCommand.Parameters.Add(new SqlParameter("@Signal", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@Station", SqlDbType.VarChar));
             sqlCommand.Parameters.Add(new SqlParameter("@AvgSignal", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@Latitude", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@Longitude", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@Rssi", SqlDbType.Float));
             sqlCommand.Parameters.Add(new SqlParameter("@SeqNumber", SqlDbType.Int));
             retries = 0;
         }
         catch (Exception e)
         {
             Console.Error.WriteLine("Error opening destination Event Hub: " + e.Message + "(" + s + ")");
             if (retries == 0)
                 throw;
         }
     }
     checkpointStopWatch = new Stopwatch();
     checkpointStopWatch.Start();
 }
示例#19
0
 public AzureKeyValueStore(string connectionString,
     string bucketName)
 {
     var account = CloudStorageAccount.Parse(connectionString);
     var client = account.CreateCloudBlobClient();
     _container = client.GetContainerReference(bucketName);
     _container.CreateIfNotExists();
 }
        public BlobOptimisticDataStore(CloudStorageAccount account, string containerName)
        {
            var blobClient = account.CreateCloudBlobClient();
            blobContainer = blobClient.GetContainerReference(containerName.ToLower());
            blobContainer.CreateIfNotExists();

            blobReferences = new Dictionary<string, ICloudBlob>();
        }
示例#21
0
 /// <summary>Constructor establishes the connection</summary>
 /// <param name="containerName">The name of the container inside Azure</param>
 protected BaseStorage(string containerName)
 {
     var cloudStorageAccount = CloudStorageAccount.Parse(
         CloudConfigurationManager.GetSetting(BlobStorageConnectionStringKey));
     var cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
     _cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName);
     if (!_cloudBlobContainer.Exists()) _cloudBlobContainer.CreateIfNotExists();
 }
示例#22
0
 public void createContainer()
 {
     container = blobClient.GetContainerReference(Constants.blobContainerName);
     if (container.CreateIfNotExists())
     {
         container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
     }
 }
示例#23
0
 public StoreEventProcessor()
 {
     var storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
     blobClient = storageAccount.CreateCloudBlobClient();
     blobContainer = blobClient.GetContainerReference("d2ctutorial");
     blobContainer.CreateIfNotExists();
     queueClient = QueueClient.CreateFromConnectionString(ServiceBusConnectionString, "d2ctutorial");
 }
示例#24
0
 public BlobHelper(String container)
 {
     // get or create blobContainer to communicate with Azure storage service
     var blobClient = StorageAccount.CreateCloudBlobClient();
     blobContainer = blobClient.GetContainerReference(container);
     blobContainer.CreateIfNotExists();
     blobContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });
 }
 //Default structure for messages are
 // /messages/messagetype/queue/filename_guid.ext
 public ReferenceMessage()
 {
     var storageConnectionString = ConfigurationManager.ConnectionStrings[ReferenceMessagesStorage].ConnectionString;
     var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
     var blobClient = storageAccount.CreateCloudBlobClient();
     _container = blobClient.GetContainerReference(ContainerName);
     _container.CreateIfNotExists();
 }
 public SKSEventProcessor()
 {
     var storageAccount = CloudStorageAccount.Parse(StorageConnectionString);
     blobClient = storageAccount.CreateCloudBlobClient();
     blobContainer = blobClient.GetContainerReference("d2ctutorial");
     blobContainer.CreateIfNotExists();
     queueClient = QueueClient.CreateFromConnectionString(ServiceBusConnectionString, 
         ConfigurationManager.AppSettings["serviceBusQueueName"]);
 }
 /// <summary>
 /// Azure Append Blob Receiver
 /// </summary>
 /// <param name="storageAccountName">Storage account name</param>
 /// <param name="storageAccountKey">Storage account key (primary or secondary)</param>
 /// <param name="containerName">Blob container name</param>
 /// <param name="blobNamePrefix">
 /// Blob name prefix. Azure blobs will be named as 'blobNamePrefix-yyyy-MM-dd.txt'
 /// </param>
 public AzureAppendBlobLogWriter(string storageAccountName, string storageAccountKey, string containerName, string blobNamePrefix)
 {
    _blobNamePrefix = blobNamePrefix;
    var creds = new StorageCredentials(storageAccountName, storageAccountKey);
    var account = new CloudStorageAccount(creds, true);
    CloudBlobClient client = account.CreateCloudBlobClient();
    _blobContainer = client.GetContainerReference(containerName);
    _blobContainer.CreateIfNotExists();
 }
        /// <summary>
		/// Default constructor.
		/// </summary>
		public AzureMediaCacheProvider() {
			var config = GetConfig() ;

			account = CloudStorageAccount.Parse(config.Settings.StorageConnectionString.Value) ;
			client = account.CreateCloudBlobClient() ;

            cacheContainer = client.GetContainerReference("cache");
            cacheContainer.CreateIfNotExists();
		}
示例#29
0
        public Blob(string containerName)
        {
            _storageAccount = Account.Get();

            _blobClient = _storageAccount.CreateCloudBlobClient();

            _blobContainer = _blobClient.GetContainerReference(containerName);

            _blobContainer.CreateIfNotExists();
        }
 public PhotoInBlob()
 {
     storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnection"].ConnectionString);
     blobClinet = storageAccount.CreateCloudBlobClient();
     blobContainer = blobClinet.GetContainerReference(ConfigurationManager.AppSettings["blobContainer"].ToString());
     if(blobContainer.CreateIfNotExists())
     {
         blobContainer.SetPermissions(new BlobContainerPermissions() { PublicAccess = BlobContainerPublicAccessType.Blob });
     }
 }
示例#31
0
        public AuthHelpers(IAppConfig appConfig)
        {
            _appConfig = appConfig;

            storageAccount = CloudStorageAccount.Parse(appConfig.StorageConnectionString);
            blobClient = storageAccount.CreateCloudBlobClient();
            container = blobClient.GetContainerReference("apipersistenace");
            container.CreateIfNotExists();
            Blob = container.GetBlockBlobReference("tenantId");
        }
 public SimpleExample()
 {
     CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
     CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
     _leaseContainer = blobClient.GetContainerReference("leaseobjects");
     _leaseContainer.CreateIfNotExists();
     CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
     _table = tableClient.GetTableReference("entities");
     _table.CreateIfNotExists();
 }
示例#33
0
        public string DownloadPublicBlob(string UserId, string BlobName, bool PublicAccess = true)
        {
            //Retrieve a reference to a container.
            //Retrieve storage account from connection string.
            Microsoft.WindowsAzure.Storage.CloudStorageAccount StorageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(Convert.ToString(ConfigurationManager.AppSettings["StorageConnectionString"]));

            // Create the blob client.
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference(UserId);

            // Create the container if it doesn't exist.
            container.CreateIfNotExists();


            //Set permission to public
            if (PublicAccess)
            {
                container.SetPermissions(
                    new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions
                {
                    PublicAccess =
                        Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Blob
                });
            }
            else
            {
                container.SetPermissions(
                    new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions
                {
                    PublicAccess =
                        Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Off
                });
            }



            // Retrieve reference to a blob named

            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blockBlob = container.GetBlockBlobReference(BlobName);

            //var sasToken = blockBlob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
            //{
            //    Permissions = SharedAccessBlobPermissions.Read,
            //    SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10),//assuming the blob can be downloaded in 10 miinutes
            //}, new SharedAccessBlobHeaders()
            //{
            //    ContentDisposition = "attachment; filename=file-name"
            //});

            //return string.Format("{0}{1}", blockBlob.Uri, sasToken);

            return(blockBlob.Uri.ToString());
        }
示例#34
0
            public Test(CloudStorageAccount account)
            {
                blobStorage = account.CreateCloudBlobClient();
                blobContainer = blobStorage.GetContainerReference("testing");
                blobContainer.CreateIfNotExists();

                this.blobContainer.SetPermissions(new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Container
                });
            }
    private void Init(string connectionString, string containerName)
    {
        var cs = CloudConfigurationManager.GetSetting(connectionString);

        var account = CloudStorageAccount.Parse(cs);

        var client = account.CreateCloudBlobClient();

        container = client.GetContainerReference(containerName);
        container.CreateIfNotExists();
    }
示例#36
0
        /// <summary>
        /// Parameters:
        ///     Block:
        ///         True for BlockBlob, false for PageBlob
        /// </summary>
        internal void GetBlobTest(Agent agent, string UploadFilePath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
            string blobName           = Path.GetFileName(UploadFilePath);

            Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
            Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Blob, blobName);

            dic["BlobType"] = Type;
            comp.Add(dic);

            // create the container
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                bool bSuccess = false;
                // upload the blob file
                if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToBlockBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                else if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToPageBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                Test.Assert(bSuccess, "upload file {0} to container {1} should succeed", UploadFilePath, NEW_CONTAINER_NAME);

                //--------------Get operation--------------
                Test.Assert(agent.GetAzureStorageBlob(blobName, NEW_CONTAINER_NAME), Utility.GenComparisonData("GetAzureStorageBlob", true));

                // Verification for returned values
                // get blob object using XSCL
                StorageBlob.ICloudBlob blob = CommonBlobHelper.QueryBlob(NEW_CONTAINER_NAME, blobName);
                blob.FetchAttributes();
                CloudBlobUtil.PackBlobCompareData(blob, dic);
                dic.Add("ICloudBlob", blob);

                agent.OutputValidation(comp);
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
            }
        }
示例#37
0
        /// <summary>
        /// Parameters:
        ///     Block:
        ///         True for BlockBlob, false for PageBlob
        /// </summary>
        internal void DownloadBlobTest(Agent agent, string UploadFilePath, string DownloadDirPath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
            string blobName           = Path.GetFileName(UploadFilePath);

            Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
            Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Blob, blobName);

            dic["BlobType"] = Type;
            comp.Add(dic);

            // create the container
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                bool bSuccess = false;
                // upload the blob file
                if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToBlockBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                else if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToPageBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                Test.Assert(bSuccess, "upload file {0} to container {1} should succeed", UploadFilePath, NEW_CONTAINER_NAME);

                //--------------Download operation--------------
                string downloadFilePath = Path.Combine(DownloadDirPath, blobName);
                Test.Assert(agent.GetAzureStorageBlobContent(blobName, downloadFilePath, NEW_CONTAINER_NAME),
                            Utility.GenComparisonData("GetAzureStorageBlobContent", true));
                StorageBlob.ICloudBlob blob = CommonBlobHelper.QueryBlob(NEW_CONTAINER_NAME, blobName);
                CloudBlobUtil.PackBlobCompareData(blob, dic);
                // Verification for returned values
                agent.OutputValidation(comp);

                Test.Assert(Helper.CompareTwoFiles(downloadFilePath, UploadFilePath),
                            String.Format("File '{0}' should be bit-wise identicial to '{1}'", downloadFilePath, UploadFilePath));
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
            }
        }
示例#38
0
        internal void SetContainerACLTest(Agent agent)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-");

            Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
            Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Container, NEW_CONTAINER_NAME);

            comp.Add(dic);

            // create container if it does not exist
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                StorageBlob.BlobContainerPublicAccessType[] accessTypes = new StorageBlob.BlobContainerPublicAccessType[] {
                    StorageBlob.BlobContainerPublicAccessType.Blob,
                    StorageBlob.BlobContainerPublicAccessType.Container,
                    StorageBlob.BlobContainerPublicAccessType.Off
                };

                // set PublicAccess as one value respetively
                foreach (var accessType in accessTypes)
                {
                    //--------------Set operation--------------
                    Test.Assert(agent.SetAzureStorageContainerACL(NEW_CONTAINER_NAME, accessType),
                                "SetAzureStorageContainerACL operation should succeed");
                    // Verification for returned values
                    dic["PublicAccess"] = accessType;
                    CloudBlobUtil.PackContainerCompareData(container, dic);
                    agent.OutputValidation(comp);

                    Test.Assert(container.GetPermissions().PublicAccess == accessType,
                                "PublicAccess should be equal: {0} = {1}", container.GetPermissions().PublicAccess, accessType);
                }
            }
            finally
            {
                // clean up
                container.DeleteIfExists();
            }
        }
示例#39
0
        internal void RemoveContainerTest(Agent agent)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("astoria-");

            // create container if it does not exist
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                //--------------Remove operation--------------
                Test.Assert(agent.RemoveAzureStorageContainer(NEW_CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageContainer", true));
                Test.Assert(!container.Exists(), "container {0} should not exist!", NEW_CONTAINER_NAME);
            }
            finally
            {
                // clean up
                container.DeleteIfExists();
            }
        }
示例#40
0
        /// <summary>
        /// Create a container and then get it using powershell cmdlet
        /// </summary>
        /// <returns>A CloudBlobContainer object which is returned by PowerShell</returns>
        protected StorageBlob.CloudBlobContainer CreateAndPsGetARandomContainer()
        {
            string containerName = Utility.GenNameString("bvt");

            StorageBlob.CloudBlobContainer container = SetUpStorageAccount.CreateCloudBlobClient().GetContainerReference(containerName);
            container.CreateIfNotExists();

            try
            {
                PowerShellAgent agent = new PowerShellAgent();
                Test.Assert(agent.GetAzureStorageContainer(containerName), Utility.GenComparisonData("GetAzureStorageContainer", true));
                int count = 1;
                Test.Assert(agent.Output.Count == count, string.Format("get container should return only 1 container, actully it's {0}", agent.Output.Count));
                return((StorageBlob.CloudBlobContainer)agent.Output[0]["CloudBlobContainer"]);
            }
            finally
            {
                // clean up
                container.DeleteIfExists();
            }
        }
示例#41
0
        /// <summary>
        /// Parameters:
        ///     Block:
        ///         True for BlockBlob, false for PageBlob
        /// </summary>
        internal void RemoveBlobTest(Agent agent, string UploadFilePath, Microsoft.WindowsAzure.Storage.Blob.BlobType Type)
        {
            string NEW_CONTAINER_NAME = Utility.GenNameString("upload-");
            string blobName           = Path.GetFileName(UploadFilePath);

            Collection <Dictionary <string, object> > comp = new Collection <Dictionary <string, object> >();
            Dictionary <string, object> dic = Utility.GenComparisonData(StorageObjectType.Blob, blobName);

            dic["BlobType"] = Type;
            comp.Add(dic);

            // create the container
            StorageBlob.CloudBlobContainer container = CommonStorageAccount.CreateCloudBlobClient().GetContainerReference(NEW_CONTAINER_NAME);
            container.CreateIfNotExists();

            try
            {
                bool bSuccess = false;
                // upload the blob file
                if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.BlockBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToBlockBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                else if (Type == Microsoft.WindowsAzure.Storage.Blob.BlobType.PageBlob)
                {
                    bSuccess = CommonBlobHelper.UploadFileToPageBlob(NEW_CONTAINER_NAME, blobName, UploadFilePath);
                }
                Test.Assert(bSuccess, "upload file {0} to container {1} should succeed", UploadFilePath, NEW_CONTAINER_NAME);

                //--------------Remove operation--------------
                Test.Assert(agent.RemoveAzureStorageBlob(blobName, NEW_CONTAINER_NAME), Utility.GenComparisonData("RemoveAzureStorageBlob", true));
                StorageBlob.ICloudBlob blob = CommonBlobHelper.QueryBlob(NEW_CONTAINER_NAME, blobName);
                Test.Assert(blob == null, "blob {0} should not exist!", blobName);
            }
            finally
            {
                // cleanup
                container.DeleteIfExists();
            }
        }
示例#42
0
        //Retrieve Blob Container
        public Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer GetCloudBlobContainer(string ContainerName, Boolean PublicAccess = false)
        {
            // Retrieve storage account from connection string.
            Microsoft.WindowsAzure.Storage.CloudStorageAccount StorageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(Convert.ToString(ConfigurationManager.AppSettings["StorageConnectionString"]));

            // Create the blob client.
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

            // Retrieve a reference to a container.
            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = blobClient.GetContainerReference(ContainerName);

            // Create the container if it doesn't exist.
            container.CreateIfNotExists();


            //Set permission to public
            if (PublicAccess)
            {
                container.SetPermissions(
                    new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions
                {
                    PublicAccess =
                        Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Blob
                });
            }
            else
            {
                container.SetPermissions(
                    new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions
                {
                    PublicAccess =
                        Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Off
                });
            }

            return(container);
        }
示例#43
0
        /// <summary>
        /// This method should return TRUE if user account created successfully
        /// FALSE if user record already exist in database
        /// THE CONTAINER IS NAMED AS USERID [unique identifier]
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public Boolean createUser(String fullname, String username, String password)
        {
            Model.UserModel user = new Model.UserModel();
            DBManager.UserM u    = new DBManager.UserM();
            user = u.getUserRecord(connection, username);

            //if user already exist, false
            if (!(user == null))
            {
                return(false);
            }

            //Insert record into USERS table
            u.insertIntoUsers(connection, fullname, username, password);
            user = u.getUserRecord(connection, username);

            //default private container created
            //Container get created by the unique user id
            Console.WriteLine("Container created with " + user.getUid() + " name");

            Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer myContainer = BlobStorageManager.BlobStorage.getCloudBlobContainer((user.getUid()).ToString());
            myContainer.CreateIfNotExists();

            String containerName = (user.getUid()).ToString();

            //Insert record into CONTAINERS table
            DBManager.ResourceM r = new DBManager.ResourceM();
            Console.WriteLine(containerName + "////" + user.getUid());
            Model.AzureContainerModel re = new Model.AzureContainerModel();
            re.setOwner(user.getUid());
            re.setContainerName(containerName);
            re.setGivenName(user.getEmailId());  //Changed here since server front end is considering private container name as user email id
            Boolean res = r.insertIntoResources(connection, re);

            return(res);
        }
示例#44
0
        public void BlobIngressEgressCounters()
        {
            CloudBlobContainer container = GetRandomContainerReference();

            container.CreateIfNotExists();
            CloudBlockBlob blob = container.GetBlockBlobReference("blob1");

            string[] blockIds = new string[] { Convert.ToBase64String(Guid.NewGuid().ToByteArray()), Convert.ToBase64String(Guid.NewGuid().ToByteArray()), Convert.ToBase64String(Guid.NewGuid().ToByteArray()) };
            try
            {
                // 1 byte
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.PutBlock(blockIds[0], new MemoryStream(GetRandomBuffer(1)), null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // 1024
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.PutBlock(blockIds[1], new MemoryStream(GetRandomBuffer(1024)), null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // 98765
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.PutBlock(blockIds[2], new MemoryStream(GetRandomBuffer(98765)), null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // PutBlockList
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.PutBlockList(blockIds, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // GetBlockList
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.DownloadBlockList(BlockListingFilter.All, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                // Download
                TestHelper.ValidateIngressEgress(Selectors.IfUrlContains(blob.Uri.ToString()), () =>
                {
                    OperationContext opContext = new OperationContext();
                    blob.DownloadToStream(Stream.Null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, opContext);
                    return(opContext.LastResult);
                });

                Assert.AreEqual(blob.Properties.Length, 98765 + 1024 + 1);

                // Error Case
                CloudBlockBlob   nullBlob     = container.GetBlockBlobReference("null");
                OperationContext errorContext = new OperationContext();
                try
                {
                    nullBlob.DownloadToStream(Stream.Null, null, new BlobRequestOptions()
                    {
                        RetryPolicy = new RetryPolicies.NoRetry()
                    }, errorContext);
                    Assert.Fail("Null blob, null stream, no download possible.");
                }
                catch (StorageException)
                {
                    Assert.IsTrue(errorContext.LastResult.IngressBytes > 0);
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
示例#45
0
        public void CloudBlobClientListBlobsSegmentedWithEmptyPrefix()
        {
            string             name          = "bb" + GetRandomContainerName();
            CloudBlobClient    blobClient    = GenerateCloudBlobClient();
            CloudBlobContainer rootContainer = blobClient.GetRootContainerReference();
            CloudBlobContainer container     = blobClient.GetContainerReference(name);

            try
            {
                rootContainer.CreateIfNotExists();
                container.Create();
                List <Uri> preExistingBlobs = rootContainer.ListBlobs().Select(b => b.Uri).ToList();

                List <string> blobNames     = CreateBlobs(container, 3, BlobType.BlockBlob);
                List <string> rootBlobNames = CreateBlobs(rootContainer, 2, BlobType.BlockBlob);

                BlobResultSegment     results;
                BlobContinuationToken token       = null;
                List <Uri>            listedBlobs = new List <Uri>();
                do
                {
                    results = blobClient.ListBlobsSegmented("", token);
                    token   = results.ContinuationToken;

                    foreach (IListBlobItem blob in results.Results)
                    {
                        if (preExistingBlobs.Contains(blob.Uri))
                        {
                            continue;
                        }
                        else
                        {
                            if (blob is CloudPageBlob)
                            {
                                ((CloudPageBlob)blob).Delete();
                            }
                            else
                            {
                                ((CloudBlockBlob)blob).Delete();
                            }

                            listedBlobs.Add(blob.Uri);
                        }
                    }
                }while (token != null);

                Assert.AreEqual(2, listedBlobs.Count);
                do
                {
                    results = container.ListBlobsSegmented("", false, BlobListingDetails.None, null, token, null, null);
                    token   = results.ContinuationToken;

                    foreach (IListBlobItem blob in results.Results)
                    {
                        if (preExistingBlobs.Contains(blob.Uri))
                        {
                            continue;
                        }
                        else
                        {
                            if (blob is CloudPageBlob)
                            {
                                ((CloudPageBlob)blob).Delete();
                            }
                            else
                            {
                                ((CloudBlockBlob)blob).Delete();
                            }

                            listedBlobs.Add(blob.Uri);
                        }
                    }
                }while (token != null);

                Assert.AreEqual(5, listedBlobs.Count);
            }
            finally
            {
                container.DeleteIfExists();
            }
        }
示例#46
0
        public void CloudBlobClientListBlobsSegmentedWithPrefixAPM()
        {
            string             name          = "bb" + GetRandomContainerName();
            CloudBlobClient    blobClient    = GenerateCloudBlobClient();
            CloudBlobContainer rootContainer = blobClient.GetRootContainerReference();
            CloudBlobContainer container     = blobClient.GetContainerReference(name);

            try
            {
                rootContainer.CreateIfNotExists();
                container.Create();

                List <string> blobNames     = CreateBlobs(container, 3, BlobType.BlockBlob);
                List <string> rootBlobNames = CreateBlobs(rootContainer, 2, BlobType.BlockBlob);

                using (AutoResetEvent waitHandle = new AutoResetEvent(false))
                {
                    IAsyncResult          result;
                    BlobResultSegment     results;
                    BlobContinuationToken token = null;
                    do
                    {
                        result = blobClient.BeginListBlobsSegmented("bb", token,
                                                                    ar => waitHandle.Set(),
                                                                    null);
                        waitHandle.WaitOne();
                        results = blobClient.EndListBlobsSegmented(result);
                        token   = results.ContinuationToken;

                        foreach (CloudBlockBlob blob in results.Results)
                        {
                            blob.Delete();
                            rootBlobNames.Remove(blob.Name);
                        }
                    }while (token != null);
                    Assert.AreEqual(0, rootBlobNames.Count);

                    result = blobClient.BeginListBlobsSegmented("bb", token,
                                                                ar => waitHandle.Set(),
                                                                null);
                    waitHandle.WaitOne();
                    results = blobClient.EndListBlobsSegmented(result);
                    Assert.AreEqual(0, results.Results.Count());
                    Assert.IsNull(results.ContinuationToken);

                    result = blobClient.BeginListBlobsSegmented(name, token,
                                                                ar => waitHandle.Set(),
                                                                null);
                    waitHandle.WaitOne();
                    results = blobClient.EndListBlobsSegmented(result);
                    Assert.AreEqual(0, results.Results.Count());
                    Assert.IsNull(results.ContinuationToken);

                    token = null;
                    do
                    {
                        result = blobClient.BeginListBlobsSegmented(name + "/", token,
                                                                    ar => waitHandle.Set(),
                                                                    null);
                        waitHandle.WaitOne();
                        results = blobClient.EndListBlobsSegmented(result);
                        token   = results.ContinuationToken;

                        foreach (CloudBlockBlob blob in results.Results)
                        {
                            Assert.IsTrue(blobNames.Remove(blob.Name));
                        }
                    }while (token != null);
                    Assert.AreEqual(0, blobNames.Count);
                }
            }
            finally
            {
                container.DeleteIfExists();
            }
        }