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


C# CloudBlobClient.SetServiceProperties方法代码示例

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


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

示例1: UploadBlobInChunks

        static void UploadBlobInChunks(FileInfo fileInfo, CloudBlockBlob packageBlob, CloudBlobClient blobClient)
        {
            var operationContext = new OperationContext();
            operationContext.ResponseReceived += delegate(object sender, RequestEventArgs args)
            {
                var statusCode = (int) args.Response.StatusCode;
                var statusDescription = args.Response.StatusDescription;
                Log.Verbose("Uploading, response received: " + statusCode + " " + statusDescription);
                if (statusCode >= 400)
                {
                    Log.Error("Error when uploading the package. Azure returned a HTTP status code of: " +
                              statusCode + " " + statusDescription);
                    Log.Verbose("The upload will be retried");
                }
            };

            blobClient.SetServiceProperties(blobClient.GetServiceProperties(), operationContext: operationContext); 

            Log.VerboseFormat("Uploading the package to blob storage. The package file is {0}.", fileInfo.Length.ToFileSizeString());
            
            using (var fileReader = fileInfo.OpenRead())
            {
                var blocklist = new List<string>();

                long uploadedSoFar = 0;

                var data = new byte[1024 * 1024];
                var id = 1;

                while (true)
                {
                    id++;

                    var read = fileReader.Read(data, 0, data.Length);
                    if (read == 0)
                    {
                        packageBlob.PutBlockList(blocklist);
                        break;
                    }

                    var blockId = Convert.ToBase64String(Encoding.UTF8.GetBytes(id.ToString(CultureInfo.InvariantCulture).PadLeft(30, '0')));
                    packageBlob.PutBlock(blockId, new MemoryStream(data, 0, read, true), null);
                    blocklist.Add(blockId);

                    uploadedSoFar += read;

                    Log.VerboseFormat("Uploading package to blob storage: {0} of {1}", uploadedSoFar.ToFileSizeString(), fileInfo.Length.ToFileSizeString());
                }
            }

            Log.Verbose("Upload complete");
        }
开发者ID:bjewell52,项目名称:Calamari,代码行数:52,代码来源:AzurePackageUploader.cs

示例2: UpdateServiceProperties

        private static void UpdateServiceProperties(CloudBlobClient blobClient, List<string> origins, List<string> headers, List<string> methods)
        {
            ServiceProperties props = blobClient.GetServiceProperties();

            Trace.Write(props.Cors.CorsRules.ToString());

            if (! ContainsOrigin(props.Cors.CorsRules, origins))
            {
                props.Cors.CorsRules.Add(
                    new CorsRule
                    {
                        AllowedOrigins = origins,
                        AllowedHeaders = headers,
                        AllowedMethods = ExpandCorsHttpMethods(methods),
                        MaxAgeInSeconds = 1800 // 30 minutes
                    });
                blobClient.SetServiceProperties(props);
            }
        }
开发者ID:lindydonna,项目名称:ContosoMoments,代码行数:19,代码来源:AzureStorageCorsHelper.cs

示例3: azureDriver

 public azureDriver(string connStr, string containerName) {
   //var connStr = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", accountName, accountKey);
   CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connStr);
   blobClient = storageAccount.CreateCloudBlobClient();
   var props = blobClient.GetServiceProperties();
   if (props.Cors.CorsRules.Count == 0) {
     props.Cors.CorsRules.Add(new CorsRule() {
       AllowedHeaders = new List<string>() { "*" },
       AllowedMethods = CorsHttpMethods.Get,
       AllowedOrigins = new List<string>() { "*" },
       ExposedHeaders = new List<string>() { "*" },
       MaxAgeInSeconds = 18000 // 300 minutes
     });
     blobClient.SetServiceProperties(props);
   }
   container = blobClient.GetContainerReference(containerName);
   if (container.CreateIfNotExists()) container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
 }
开发者ID:PavelPZ,项目名称:NetNew,代码行数:18,代码来源:SynchronizeDirs.cs

示例4: ConfigureCorsAndLoggingOnStorageAccount

		/// <summary>
		/// Ensure javascript CORS requests from web APIs work.
		/// </summary>
		/// <remarks>See: http://msdn.microsoft.com/en-us/library/windowsazure/dn535601.aspx </remarks>
		/// <param name="client"></param>
		private static void ConfigureCorsAndLoggingOnStorageAccount(CloudBlobClient client)
		{
			CorsProperties cps = new CorsProperties();
			cps.CorsRules.Add(new CorsRule()
			{
				AllowedOrigins = new List<string>() { "*" },
				AllowedMethods = CorsHttpMethods.Get
			});
			ServiceProperties sp = new Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties();
			sp.Cors = cps;
			sp.Logging.LoggingOperations = LoggingOperations.Read;
			sp.Logging.RetentionDays = 7;
			sp.Logging.Version = "1.0";
			sp.MinuteMetrics.MetricsLevel = MetricsLevel.ServiceAndApi;
			sp.MinuteMetrics.RetentionDays = 7;
			sp.MinuteMetrics.Version = "1.0";
			sp.HourMetrics.MetricsLevel = MetricsLevel.None;
			sp.HourMetrics.RetentionDays = 1;
			sp.HourMetrics.Version = "1.0";
			client.SetServiceProperties(sp,
			new BlobRequestOptions() { MaximumExecutionTime = TimeSpan.FromSeconds(300) }
			,
			null);
		}
开发者ID:hydrojumbo,项目名称:quito-climate-study,代码行数:29,代码来源:Uploader.cs

示例5: SetCors

        private  void SetCors(CloudBlobClient blobClient)
        {
            var newProperties = blobClient.GetServiceProperties();
            try
            {

           
            ConfigureCors(newProperties);
            var blobprop = blobClient.GetServiceProperties();
            // "2011-08-18"; // null;
                    blobClient.SetServiceProperties(newProperties);
                

                }
                catch (Exception ex)
                {

                    //throw;
                }
                
            
        }
开发者ID:cephalin,项目名称:ContosoMoments,代码行数:22,代码来源:ContosoStorage.cs

示例6: InitializeCors

        /// <summary>
        /// Initialize Windows Azure Storage CORS settings.
        /// </summary>
        /// <param name="blobClient">Windows Azure storage blob client</param>
        /// <param name="tableClient">Windows Azure storage table client</param>
        private static void InitializeCors(CloudBlobClient blobClient, CloudTableClient tableClient)
        {
            // CORS should be enabled once at service startup
            ServiceProperties blobServiceProperties = new ServiceProperties();
            ServiceProperties tableServiceProperties = new ServiceProperties();

            // Nullifying un-needed properties so that we don't
            // override the existing ones
            blobServiceProperties.HourMetrics = null;
            tableServiceProperties.HourMetrics = null;
            blobServiceProperties.MinuteMetrics = null;
            tableServiceProperties.MinuteMetrics = null;
            blobServiceProperties.Logging = null;
            tableServiceProperties.Logging = null;

            // Enable and Configure CORS
            ConfigureCors(blobServiceProperties);
            ConfigureCors(tableServiceProperties);

            // Commit the CORS changes into the Service Properties
            blobClient.SetServiceProperties(blobServiceProperties);
            tableClient.SetServiceProperties(tableServiceProperties);
        }
开发者ID:danieros,项目名称:AnimalReUnite,代码行数:28,代码来源:AzureCommon.cs

示例7: TestCorsRules

        private void TestCorsRules(CloudBlobClient client, IList<CorsRule> corsProps)
        {
            props.Cors.CorsRules.Clear();

            foreach (CorsRule rule in corsProps)
            {
                props.Cors.CorsRules.Add(rule);
            }

            client.SetServiceProperties(props);
            TestHelper.AssertServicePropertiesAreEqual(props, client.GetServiceProperties());
        }
开发者ID:benaadams,项目名称:azure-storage-net,代码行数:12,代码来源:BlobAnalyticsUnitTests.cs


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