/// <summary> /// Query the Cross-Origin Resource Sharing (CORS) rules for the File service /// </summary> /// <param name="shareServiceClient"></param> private static async Task CorsSample(ShareServiceClient shareServiceClient) { Console.WriteLine(); // Get service properties Console.WriteLine("Get service properties"); ShareServiceProperties originalProperties = await shareServiceClient.GetPropertiesAsync(); try { // Add CORS rule Console.WriteLine("Add CORS rule"); var corsRule = new ShareCorsRule { AllowedHeaders = "*", AllowedMethods = "GET", AllowedOrigins = "*", ExposedHeaders = "*", MaxAgeInSeconds = 3600 }; ShareServiceProperties serviceProperties = await shareServiceClient.GetPropertiesAsync(); serviceProperties.Cors.Clear(); serviceProperties.Cors.Add(corsRule); await shareServiceClient.SetPropertiesAsync(serviceProperties); Console.WriteLine("Set property successfully"); } finally { // Revert back to original service properties Console.WriteLine("Revert back to original service properties"); await shareServiceClient.SetPropertiesAsync(originalProperties); Console.WriteLine("Revert properties successfully."); } Console.WriteLine(); }
// </snippet_DeleteSnapshot> // <snippet_UseMetrics> //------------------------------------------------- // Use metrics //------------------------------------------------- public async Task UseMetricsAsync() { // Get the connection string from app settings string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"]; // Instatiate a ShareServiceClient ShareServiceClient shareService = new ShareServiceClient(connectionString); // Set metrics properties for File service await shareService.SetPropertiesAsync(new ShareServiceProperties() { // Set hour metrics HourMetrics = new ShareMetrics() { Enabled = true, IncludeApis = true, Version = "1.0", RetentionPolicy = new ShareRetentionPolicy() { Enabled = true, Days = 14 } }, // Set minute metrics MinuteMetrics = new ShareMetrics() { Enabled = true, IncludeApis = true, Version = "1.0", RetentionPolicy = new ShareRetentionPolicy() { Enabled = true, Days = 7 } } }); // Read the metrics properties we just set ShareServiceProperties serviceProperties = await shareService.GetPropertiesAsync(); // Display the properties Console.WriteLine(); Console.WriteLine($"HourMetrics.InludeApis: {serviceProperties.HourMetrics.IncludeApis}"); Console.WriteLine($"HourMetrics.RetentionPolicy.Days: {serviceProperties.HourMetrics.RetentionPolicy.Days}"); Console.WriteLine($"HourMetrics.Version: {serviceProperties.HourMetrics.Version}"); Console.WriteLine(); Console.WriteLine($"MinuteMetrics.InludeApis: {serviceProperties.MinuteMetrics.IncludeApis}"); Console.WriteLine($"MinuteMetrics.RetentionPolicy.Days: {serviceProperties.MinuteMetrics.RetentionPolicy.Days}"); Console.WriteLine($"MinuteMetrics.Version: {serviceProperties.MinuteMetrics.Version}"); Console.WriteLine(); }