当前位置: 首页>>代码示例>>C#>>正文


C# CloudBlobClient.GetContainerReference方法代码示例

本文整理汇总了C#中Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetContainerReference方法的典型用法代码示例。如果您正苦于以下问题:C# CloudBlobClient.GetContainerReference方法的具体用法?C# CloudBlobClient.GetContainerReference怎么用?C# CloudBlobClient.GetContainerReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient的用法示例。


在下文中一共展示了CloudBlobClient.GetContainerReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AzureMediaProvider

		/// <summary>
		/// Default constructor.
		/// </summary>
		public AzureMediaProvider() {
			var config = GetConfig() ;

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

			mediaContainer = client.GetContainerReference("media") ;
			mediaContainer.CreateIfNotExists() ;

			uploadContainer = client.GetContainerReference("uploads") ;
			uploadContainer.CreateIfNotExists() ;
		}
开发者ID:nagyist,项目名称:Piranha.Azure,代码行数:15,代码来源:AzureMediaProvider.cs

示例2: WebJobsStorageAccount

        public WebJobsStorageAccount(string connectionString)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new InvalidOperationException("connectionString");
            }

            _connectionString = connectionString;
            _storageAccount = CloudStorageAccount.Parse(connectionString);
            _blobClient = _storageAccount.CreateCloudBlobClient();
            _dashboardContainer = _blobClient.GetContainerReference(DashboardContainerName);
            _hostsContainer = _blobClient.GetContainerReference(HostsContainerName);
        }
开发者ID:farukc,项目名称:azure-webjobs-sdk-dashboard-tests,代码行数:13,代码来源:WebJobsStorageAccount.cs

示例3: UploadFilesOfDirectory

		/// <summary>
		/// Recursively upload everything in the remote directory.
		/// </summary>
		/// <param name="localDirectory"></param>
		/// <param name="remoteContainerPath"></param>
		/// <param name="client"></param>
		/// <returns></returns>
		private async Task UploadFilesOfDirectory(string localDirectory, string remoteContainerPath, CloudBlobClient client, IEnumerable<string> skipDirectories)
		{
			Console.WriteLine("");
			Console.WriteLine("Uploading files from " + localDirectory + "...");
			CloudBlobContainer container;
			string filePrefix = "";
			if (remoteContainerPath.Contains("/"))
			{
				string[] directoryStructure = remoteContainerPath.Split('/');
				container = client.GetContainerReference(directoryStructure[0]);
				filePrefix = string.Join("/", directoryStructure.Skip(1));
			}
			else
			{ 
				container = client.GetContainerReference(remoteContainerPath);
				try
				{
					await container.CreateIfNotExistsAsync();
					await container.SetPermissionsAsync(new BlobContainerPermissions()
					{
						PublicAccess = BlobContainerPublicAccessType.Blob
					});
				}
				catch (Exception ex)
				{
					Console.WriteLine(string.Format("Exception configuring container. {0} may be an illegal name. \n Message: {1}. \n Inner exception: {2}. \n\n Press any key to exit.", remoteContainerPath, ex.Message, ex.InnerException));
				}							
			}
									
			DirectoryInfo local = new DirectoryInfo(localDirectory);
			List<Task> uploads = new List<Task>();
			foreach (FileInfo file in local.GetFiles())
			{
				uploads.Add(ProcessAndUploadFile(file, container, filePrefix));
			}
			if (uploads.Count() > 0)
			{
				await Task.WhenAll(uploads);
			}			
			
			foreach (DirectoryInfo child in local.GetDirectories())
			{
				//if (!skipDirectories.Contains(child.Name))
				//{
					string nextContainer = remoteContainerPath.Contains("$root") ? child.Name : remoteContainerPath + "/" + child.Name;
					await UploadFilesOfDirectory(child.FullName, nextContainer, client, skipDirectories);
				//}				
			}					
			return;
		}
开发者ID:hydrojumbo,项目名称:quito-climate-study,代码行数:57,代码来源:Uploader.cs

示例4: Blob

 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="blobClient">use BlobConn to get blobClient</param>
 /// <param name="clientContainerName">This should be the ID of the User</param>
 /// <returns></returns>
 public Blob(CloudBlobClient blobClient, string clientContainerName)
 {
     //Get a reference to a container and create container for first time use user
     container = blobClient.GetContainerReference(clientContainerName);
     container.CreateIfNotExists();
     indicator = "OK";
 }
开发者ID:hangmiao,项目名称:DBLike,代码行数:13,代码来源:Blob.cs

示例5: BlobFileProvider

        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);
                        }
                    }
                }
            }
        }
开发者ID:crb02005,项目名称:RandomTables,代码行数:30,代码来源:BlobProvider.cs

示例6: Initialise

        /// <summary>
        /// Occurs when a storage provider operation has completed.
        /// </summary>
        //public event EventHandler<StorageProviderEventArgs> StorageProviderOperationCompleted;

        #endregion

        // Initialiser method
        private void Initialise(string storageAccount, string containerName)
        {
            if (String.IsNullOrEmpty(containerName))
                throw new ArgumentException("You must provide the base Container Name", "containerName");
            
            ContainerName = containerName;

            _account = CloudStorageAccount.Parse(storageAccount);
            _blobClient = _account.CreateCloudBlobClient();
            _container = _blobClient.GetContainerReference(ContainerName);
            try
            {
                _container.FetchAttributes();
            }
            catch (StorageException)
            {
                Trace.WriteLine(string.Format("Create new container: {0}", ContainerName), "Information");
                _container.Create();

                // set new container's permissions
                // Create a permission policy to set the public access setting for the container. 
                BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

                // The public access setting explicitly specifies that the container is private,
                // so that it can't be accessed anonymously.
                containerPermissions.PublicAccess = BlobContainerPublicAccessType.Off;

                //Set the permission policy on the container.
                _container.SetPermissions(containerPermissions);
            }
        }
开发者ID:Cache22,项目名称:wedge,代码行数:39,代码来源:AzureBlobStorageProvider.cs

示例7: ImageStore

        public ImageStore()
        {
            _client = Account.CreateCloudBlobClient();
            _container = _client.GetContainerReference(ContainerName);

            _container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);
        }
开发者ID:brporter,项目名称:slackmeme,代码行数:7,代码来源:ImageStore.cs

示例8: AzureBlobController

		public AzureBlobController()
		{
			var credentials = new StorageCredentials(ConfigurationManager.AppSettings["AzureAccountName"], ConfigurationManager.AppSettings["AzureKeyValue"]);
			var azureBlobUri = new Uri("https://" + ConfigurationManager.AppSettings["AzureAccountName"] + ".blob.core.windows.net");
			var client = new CloudBlobClient(azureBlobUri, credentials);
			_container = client.GetContainerReference(TestContainerName);
		}
开发者ID:Neonsonne,项目名称:dbSpeed,代码行数:7,代码来源:AzureBlobController.cs

示例9: BlobManager

        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");
            }
        }
开发者ID:oumartraore,项目名称:SupStorage,代码行数:28,代码来源:BlobManager.cs

示例10: BlobContainer

        public BlobContainer(string name)
        {
            // hämta connectionsträngen från config // RoleEnviroment bestämmer settingvalue runtime
            //var connectionString = RoleEnvironment.GetConfigurationSettingValue("PhotoAppStorage");
            //var connectionString = CloudConfigurationManager.GetSetting("CloudStorageApp");
            // hämtar kontot utfrån connectionsträngens värde
            //var account = CloudStorageAccount.Parse(connectionString);

            //var account = CloudStorageAccount.DevelopmentStorageAccount;

            var cred = new StorageCredentials("jholm",
                "/bVipQ2JxjWwYrZQfHmzhaBx1p1s8BoD/wX6VWOmg4/gpVo/aALrjsDUKqzXsFtc9utepPqe65NposrXt9YsyA==");
            var account = new CloudStorageAccount(cred, true);

            // skapar en blobclient
            _client = account.CreateCloudBlobClient();

            m_BlobContainer = _client.GetContainerReference(name);

            // Om det inte finns någon container med det namnet
            if (!m_BlobContainer.Exists())
            {
                // Skapa containern
                m_BlobContainer.Create();
                var permissions = new BlobContainerPermissions()
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                };
                // Sätter public access till blobs
                m_BlobContainer.SetPermissions(permissions);
            }
        }
开发者ID:jonteho,项目名称:cloud-storage,代码行数:32,代码来源:BlobContainer.cs

示例11: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            //--Connection String --

            //storage account
            CloudStorageAccount objStorage = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("BlobConnectionString"));
            // get the Client reference using storage blob end point
            CloudBlobClient objClient = new CloudBlobClient(objStorage.BlobEndpoint, objStorage.Credentials);

            // Get Container reference

            CloudBlobContainer blobContainer = objClient.GetContainerReference("mycontainer");

            // Create the container if it does not exist
            blobContainer.CreateIfNotExists();
            //set public permission
            blobContainer.SetPermissions(new BlobContainerPermissions
            {
                PublicAccess = BlobContainerPublicAccessType.Blob
            });

            //list blobs in the container
            IEnumerable<IListBlobItem> objBlobList = blobContainer.ListBlobs();
            foreach (IListBlobItem objItem in objBlobList)
            {
                Response.Write("<img src='" + objItem.Uri + "'/>");
                Response.Write("<br>");
            }
        }
开发者ID:ryyap,项目名称:CSCService,代码行数:29,代码来源:AzureBlob.aspx.cs

示例12: StorageHelper

        public StorageHelper()
        {
            _adminuser = "administrator";
            _standarduser = "standard-student";

            try
            {
                var connstring = ConfigurationManager.AppSettings["AzureStorage"];
                var acct = CloudStorageAccount.Parse(connstring);
                client = acct.CreateCloudBlobClient();
                var dir = client.GetContainerReference("studentconnect");
               var adminpwd = dir.GetBlobReferenceFromServer("_adminpassword");
                // If you get a 403 - Forbidden warning here, its because you dont have access to SD's Azure Storage account.
                // Get your own FREE here.  http://www.windowsazure.com/en-us/pricing/free-trial/
                var adminpwdText = adminpwd.DownloadText();
                var schoolsRef = dir.GetBlobReferenceFromServer("_schools");
                var schoolsText = schoolsRef.DownloadText();

                _adminpassword = adminpwdText;
                _schools = this.ParseSchoolText(schoolsText);
            }
            finally
            {

            }
        }
开发者ID:kishorejoshi,项目名称:StudentConnectAdmin,代码行数:26,代码来源:StorageHelper.cs

示例13: LocationModeWithMissingUriAsync

        public async Task LocationModeWithMissingUriAsync()
        {
            AssertSecondaryEndpoint();

            CloudBlobClient client = GenerateCloudBlobClient();
            CloudBlobClient primaryOnlyClient = new CloudBlobClient(client.BaseUri, client.Credentials);
            CloudBlobContainer container = primaryOnlyClient.GetContainerReference("nonexistingcontainer");

            BlobRequestOptions options = new BlobRequestOptions()
            {
                LocationMode = LocationMode.SecondaryOnly,
                RetryPolicy = new NoRetry(),
            };

            Exception e = await TestHelper.ExpectedExceptionAsync<Exception>(
                async () => await container.FetchAttributesAsync(null, options, null),
                "Request should fail when an URI is not provided for the target location");
            Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException));

            options.LocationMode = LocationMode.SecondaryThenPrimary;
            e = await TestHelper.ExpectedExceptionAsync<Exception>(
                async () => await container.FetchAttributesAsync(null, options, null),
                "Request should fail when an URI is not provided for the target location");
            Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException));

            options.LocationMode = LocationMode.PrimaryThenSecondary;
            e = await TestHelper.ExpectedExceptionAsync<Exception>(
                async () => await container.FetchAttributesAsync(null, options, null),
                "Request should fail when an URI is not provided for the target location");
            Assert.IsInstanceOfType(e.InnerException, typeof(InvalidOperationException));
        }
开发者ID:tamram,项目名称:azure-storage-net,代码行数:31,代码来源:SecondaryTests.cs

示例14: UploadFile

        public virtual Uri UploadFile(
            string storageName,
            Uri blobEndpointUri,
            string storageKey,
            string filePath,
            BlobRequestOptions blobRequestOptions)
        {
            StorageCredentials credentials = new StorageCredentials(storageName, storageKey);
            CloudBlobClient client = new CloudBlobClient(blobEndpointUri, credentials);
            string blobName = string.Format(
                CultureInfo.InvariantCulture,
                "{0}_{1}",
                DateTime.UtcNow.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture),
                Path.GetFileName(filePath));

            CloudBlobContainer container = client.GetContainerReference(ContainerName);
            container.CreateIfNotExists();
            CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

            BlobRequestOptions uploadRequestOption = blobRequestOptions ?? new BlobRequestOptions();

            if (!uploadRequestOption.ServerTimeout.HasValue)
            {
                uploadRequestOption.ServerTimeout = TimeSpan.FromMinutes(300);
            }

            using (FileStream readStream = File.OpenRead(filePath))
            {
                blob.UploadFromStream(readStream, AccessCondition.GenerateEmptyCondition(), uploadRequestOption);
            }

            return new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}{3}", client.BaseUri, ContainerName, client.DefaultDelimiter, blobName));
        }
开发者ID:FrankSiegemund,项目名称:azure-powershell,代码行数:33,代码来源:CloudBlobUtility.cs

示例15: CreateBlockBlob

 private static async Task<CloudBlockBlob> CreateBlockBlob(CloudBlobClient client, string containerName, string title)
 {
     var container = client.GetContainerReference(containerName);
     await container.CreateIfNotExistsAsync();
     await container.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
     return container.GetBlockBlobReference(title);
 }
开发者ID:muojp,项目名称:SoracomApiCrawler,代码行数:7,代码来源:SoracomCrawler.cs


注:本文中的Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient.GetContainerReference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。