public SetQueueServicePropertiesRequest(StorageAccountSettings settings, StorageServiceProperties properties) : base(settings) { _properties = properties; _content = PrepareContent(properties); }
internal HttpMessage CreateSetPropertiesRequest(StorageServiceProperties storageServiceProperties, int?timeout, string requestId) { var message = _pipeline.CreateMessage(); var request = message.Request; request.Method = RequestMethod.Put; var uri = new RawRequestUriBuilder(); uri.AppendRaw(url, false); uri.AppendPath("/", false); uri.AppendQuery("restype", "service", true); uri.AppendQuery("comp", "properties", true); if (timeout != null) { uri.AppendQuery("timeout", timeout.Value, true); } request.Uri = uri; request.Headers.Add("x-ms-version", version); if (requestId != null) { request.Headers.Add("x-ms-client-request-id", requestId); } request.Headers.Add("Content-Type", "application/xml"); using var content = new XmlWriterContent(); content.XmlWriter.WriteObjectValue(storageServiceProperties, "StorageServiceProperties"); request.Content = content; return(message); }
public ResponseWithHeaders <StorageServiceProperties, ServiceGetPropertiesHeaders> GetProperties(int?timeout = null, string requestId = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("ServiceClient.GetProperties"); scope.Start(); try { using var message = CreateGetPropertiesRequest(timeout, requestId); _pipeline.Send(message, cancellationToken); var headers = new ServiceGetPropertiesHeaders(message.Response); switch (message.Response.Status) { case 200: { StorageServiceProperties value = default; var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); if (document.Element("StorageServiceProperties") is XElement storageServicePropertiesElement) { value = StorageServiceProperties.DeserializeStorageServiceProperties(storageServicePropertiesElement); } return(ResponseWithHeaders.FromValue(value, headers, message.Response)); } default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } } catch (Exception e) { scope.Failed(e); throw; } }
public ResponseWithHeaders <ServiceSetPropertiesHeaders> SetProperties(StorageServiceProperties storageServiceProperties, int?timeout = null, string requestId = null, CancellationToken cancellationToken = default) { if (storageServiceProperties == null) { throw new ArgumentNullException(nameof(storageServiceProperties)); } using var scope = _clientDiagnostics.CreateScope("ServiceClient.SetProperties"); scope.Start(); try { using var message = CreateSetPropertiesRequest(storageServiceProperties, timeout, requestId); _pipeline.Send(message, cancellationToken); var headers = new ServiceSetPropertiesHeaders(message.Response); switch (message.Response.Status) { case 202: return(ResponseWithHeaders.FromValue(headers, message.Response)); default: throw _clientDiagnostics.CreateRequestFailedException(message.Response); } } catch (Exception e) { scope.Failed(e); throw; } }
public Task StoragePutServicePropertiesXML() => TestStatus(async(host, pipeline) => { var properties = new StorageServiceProperties() { Logging = new Logging("1.0", true, false, true, new RetentionPolicy(true, 7)), HourMetrics = new Metrics(true) { Version = "1.0", IncludeAPIs = false, RetentionPolicy = new RetentionPolicy(true) { Days = 7, } }, MinuteMetrics = new Metrics(true) { Version = "1.0", IncludeAPIs = true, RetentionPolicy = new RetentionPolicy(true) { Days = 7, } } }; return(await new XmlClient(ClientDiagnostics, pipeline, host).PutServicePropertiesAsync(properties)); });
public virtual Response SetProperties(StorageServiceProperties storageServiceProperties, int?timeout = null, string requestId = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("ServiceClient.SetProperties"); scope.Start(); try { return(RestClient.SetProperties(storageServiceProperties, timeout, requestId, cancellationToken).GetRawResponse()); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response PutServiceProperties(StorageServiceProperties properties, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("XmlClient.PutServiceProperties"); scope.Start(); try { return(RestClient.PutServiceProperties(properties, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual async Task <Response> PutServicePropertiesAsync(StorageServiceProperties properties, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("XmlClient.PutServiceProperties"); scope.Start(); try { return(await RestClient.PutServicePropertiesAsync(properties, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
private static byte[] PrepareContent(StorageServiceProperties properties) { var sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<StorageServiceProperties>"); // Logging properties sb.AppendFormat("<Logging><Version>{0}</Version><Delete>{1}</Delete><Read>{2}</Read><Write>{3}</Write>", "1.0", properties.Logging.Delete ? "true" : "false", properties.Logging.Read ? "true" : "false", properties.Logging.Write ? "true" : "false"); if (properties.Logging.RetentionPolicyEnabled) { sb.AppendFormat("<RetentionPolicy><Enabled>true</Enabled><Days>{0}</Days></RetentionPolicy></Logging>", properties.Logging.RetentionPolicyNumberOfDays); } else { sb.Append("<RetentionPolicy><Enabled>false</Enabled></RetentionPolicy></Logging>"); } // Metrics properties sb.AppendFormat("<Metrics><Version>{0}</Version><Enabled>{1}</Enabled>", "1.0", properties.Metrics.Enabled ? "true" : "false"); if (properties.Metrics.Enabled) { sb.AppendFormat("<IncludeAPIs>{0}</IncludeAPIs>", properties.Metrics.IncludeAPIs ? "true" : "false"); } if (properties.Metrics.RetentionPolicyEnabled) { sb.AppendFormat("<RetentionPolicy><Enabled>true</Enabled><Days>{0}</Days></RetentionPolicy></Metrics>", properties.Metrics.RetentionPolicyNumberOfDays); } else { sb.Append("<RetentionPolicy><Enabled>false</Enabled></RetentionPolicy></Metrics>"); } sb.Append("</StorageServiceProperties>"); return(Encoding.ASCII.GetBytes(sb.ToString())); }
public async ValueTask <ResponseWithHeaders <StorageServiceProperties, ServiceGetPropertiesHeaders> > GetPropertiesAsync(int?timeout = null, string requestId = null, CancellationToken cancellationToken = default) { using var message = CreateGetPropertiesRequest(timeout, requestId); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); var headers = new ServiceGetPropertiesHeaders(message.Response); switch (message.Response.Status) { case 200: { StorageServiceProperties value = default; var document = XDocument.Load(message.Response.ContentStream, LoadOptions.PreserveWhitespace); if (document.Element("StorageServiceProperties") is XElement storageServicePropertiesElement) { value = StorageServiceProperties.DeserializeStorageServiceProperties(storageServicePropertiesElement); } return(ResponseWithHeaders.FromValue(value, headers, message.Response)); } default: throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); } }
public virtual Response SetProperties(StorageServiceProperties storageServiceProperties, int?timeout = null, string requestId = null, CancellationToken cancellationToken = default) { return(RestClient.SetProperties(storageServiceProperties, timeout, requestId, cancellationToken).GetRawResponse()); }
public virtual async Task <Response> SetPropertiesAsync(StorageServiceProperties storageServiceProperties, int?timeout = null, string requestId = null, CancellationToken cancellationToken = default) { return((await RestClient.SetPropertiesAsync(storageServiceProperties, timeout, requestId, cancellationToken).ConfigureAwait(false)).GetRawResponse()); }
public async Task ParseResponseBodyAsync(Stream responseStream) { Properties = new StorageServiceProperties(); using (StreamReader sr = new StreamReader(responseStream)) { var content = await sr.ReadToEndAsync(); if (content.Length > 0) { var xDoc = XDocument.Parse(content); foreach (var topField in xDoc.Root.Elements()) { if (topField.Name.LocalName.Equals("Logging", StringComparison.InvariantCultureIgnoreCase)) { foreach (var field in topField.Elements()) { switch (field.Name.LocalName) { case "Version": Properties.Logging.Version = StorageAnalyticsVersionNumber.v1_0; break; case "Delete": Properties.Logging.Delete = field.Value.Equals("true"); break; case "Read": Properties.Logging.Read = field.Value.Equals("true"); break; case "Write": Properties.Logging.Write = field.Value.Equals("true"); break; case "RetentionPolicy": foreach (var retentionField in field.Elements()) { switch (retentionField.Name.LocalName) { case "Enabled": Properties.Logging.RetentionPolicyEnabled = retentionField.Value.Equals("true"); break; case "Days": Properties.Logging.RetentionPolicyNumberOfDays = int.Parse(retentionField.Value); break; } } break; } } } else if (topField.Name.LocalName.Equals("Metrics", StringComparison.InvariantCultureIgnoreCase)) { foreach (var field in topField.Elements()) { switch (field.Name.LocalName) { case "Version": Properties.Metrics.Version = StorageAnalyticsVersionNumber.v1_0; break; case "Enabled": Properties.Metrics.Enabled = field.Value.Equals("true"); break; case "IncludeAPIs": Properties.Metrics.IncludeAPIs = field.Value.Equals("true"); break; case "RetentionPolicy": foreach (var retentionField in field.Elements()) { switch (retentionField.Name.LocalName) { case "Enabled": Properties.Metrics.RetentionPolicyEnabled = retentionField.Value.Equals("true"); break; case "Days": Properties.Metrics.RetentionPolicyNumberOfDays = int.Parse(retentionField.Value); break; } } break; } } } } } } }
public async ValueTask <ResponseWithHeaders <ServiceSetPropertiesHeaders> > SetPropertiesAsync(StorageServiceProperties storageServiceProperties, int?timeout = null, string requestId = null, CancellationToken cancellationToken = default) { if (storageServiceProperties == null) { throw new ArgumentNullException(nameof(storageServiceProperties)); } using var message = CreateSetPropertiesRequest(storageServiceProperties, timeout, requestId); await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); var headers = new ServiceSetPropertiesHeaders(message.Response); switch (message.Response.Status) { case 202: return(ResponseWithHeaders.FromValue(headers, message.Response)); default: throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false); } }
public async Task SetQueueServicePropertiesAsync(StorageServiceProperties expectedServiceProperties) { var request = new SetQueueServicePropertiesRequest(_account, expectedServiceProperties); await request.ExecuteAsync(); }
public void SetQueueServiceProperties(StorageServiceProperties expectedServiceProperties) { var request = new SetQueueServicePropertiesRequest(_account, expectedServiceProperties); request.Execute(); }