/// <summary> /// Tests the Azure Table storage connection. /// </summary> /// <param name="connectionString">Azure Table storage connection string to use to connect to the account.</param> /// <returns>Task that represents asynchronous connection operation.</returns> public async Task TestConnection(AzureTableProbeClientParameter azureTableProbeClientParameter) { if (String.IsNullOrEmpty(azureTableProbeClientParameter.ConnectionString)) { throw Errors.ConnectionStringMissing(); } CloudStorageAccount account = CloudStorageAccount.Parse(azureTableProbeClientParameter.ConnectionString); CloudTableClient client = account.CreateCloudTableClient(); var properties = await client.GetServicePropertiesAsync(); if (properties == null) { throw Errors.EmptyResponseReceived(); } /// If a secondary specific setting has been requested, make sure that they have a secondary configured. if (azureTableProbeClientParameter.LocationMode != null && azureTableProbeClientParameter.LocationMode != AzureTableLocationMode.PrimaryOnly) { try { client.DefaultRequestOptions.LocationMode = LocationMode.SecondaryOnly; var props = await client.GetServicePropertiesAsync(); } catch (StorageException e) { throw Errors.SecondaryNotDefined(e.Message); } } }
/// <summary> /// Query the Cross-Origin Resource Sharing (CORS) rules for the Table service /// </summary> /// <param name="tableClient"></param> private static async Task CorsSample(CloudTableClient tableClient) { Console.WriteLine(); // Get service properties Console.WriteLine("Get service properties"); ServiceProperties originalProperties = await tableClient.GetServicePropertiesAsync(); try { // Add CORS rule Console.WriteLine("Add CORS rule"); CorsRule corsRule = new CorsRule { AllowedHeaders = new List <string> { "*" }, AllowedMethods = CorsHttpMethods.Get, AllowedOrigins = new List <string> { "*" }, ExposedHeaders = new List <string> { "*" }, MaxAgeInSeconds = 3600 }; ServiceProperties serviceProperties = await tableClient.GetServicePropertiesAsync(); serviceProperties.Cors.CorsRules.Add(corsRule); await tableClient.SetServicePropertiesAsync(serviceProperties); } finally { // Revert back to original service properties Console.WriteLine("Revert back to original service properties"); await tableClient.SetServicePropertiesAsync(originalProperties); } Console.WriteLine(); }
public async Task <Tuple <bool, string> > HealthCheck() { try { _ = await _cloudTableClient.GetServicePropertiesAsync(); return(new Tuple <bool, string>(true, "OK")); } catch (Exception ex) { return(new Tuple <bool, string>(false, ex.Message)); } }
/// <summary> /// Manage the properties of the Table service. /// </summary> /// <param name="tableClient"></param> private static async Task ServicePropertiesSample(CloudTableClient tableClient) { Console.WriteLine(); // Get service properties Console.WriteLine("Get service properties"); ServiceProperties originalProperties = await tableClient.GetServicePropertiesAsync(); try { // Set service properties Console.WriteLine("Set service properties"); ServiceProperties props = await tableClient.GetServicePropertiesAsync(); props.Logging.LoggingOperations = LoggingOperations.Read | LoggingOperations.Write; props.Logging.RetentionDays = 5; props.Logging.Version = Constants.AnalyticsConstants.LoggingVersionV1; props.HourMetrics.MetricsLevel = MetricsLevel.Service; props.HourMetrics.RetentionDays = 6; props.HourMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1; props.MinuteMetrics.MetricsLevel = MetricsLevel.Service; props.MinuteMetrics.RetentionDays = 6; props.MinuteMetrics.Version = Constants.AnalyticsConstants.MetricsVersionV1; await tableClient.SetServicePropertiesAsync(props); } finally { // Revert back to original service properties Console.WriteLine("Revert back to original service properties"); await tableClient.SetServicePropertiesAsync(originalProperties); } Console.WriteLine(); }
public Task <ServiceProperties> GetServicePropertiesAsync(TableRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken) { return(cloudTableClientImplementation.GetServicePropertiesAsync(requestOptions, operationContext, cancellationToken)); }