Exemple #1
0
        public FileManager(string ContainerName)
        {
            // Check if Container Name is null or empty
            if (string.IsNullOrEmpty(ContainerName))
            {
                throw new ArgumentNullException("ContainerName", "Container Name can't be empty");
            }
            try
            {
                // Get azure table storage connection string.
                KeyVaultManager keyVaultManager  = new KeyVaultManager();
                string          ConnectionString = keyVaultManager.GetValueFromAzureVault(Constants.SecretName);
                //string ConnectionString = "DefaultEndpointsProtocol=https;AccountName=training2blobstorage;AccountKey=d4swk28SyaP0RkzEssi2Q39Zsg6+rFQ8bv/UvzYfgwHXIqbuYjY1yrUWXXoH50YdTuipEZhnwQ+JS93TMNFRCg==;EndpointSuffix=core.windows.net";

                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);

                CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
                blobContainer = cloudBlobClient.GetContainerReference(ContainerName);

                // Create the container and set the permission
                if (blobContainer.CreateIfNotExists())
                {
                    blobContainer.SetPermissions(
                        new BlobContainerPermissions
                    {
                        PublicAccess = BlobContainerPublicAccessType.Blob
                    }
                        );
                }
            }
            catch (Exception ExceptionObj)
            {
                throw ExceptionObj;
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates a new instance for the monitor
        /// </summary>
        public ConcurrencyMonitor(string leaseConnectionString)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(leaseConnectionString);
            CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer  container      = blobClient.GetContainerReference("leasecontainer");

            container.CreateIfNotExists();
            blob = container.GetBlockBlobReference("leaseblob");
            if (!Exists(blob))
            {
                using (Stream str = new MemoryStream(new byte[] { 0 }))
                {
                    blob.UploadFromStream(str);
                }
            }
        }