/// <summary> /// Returns information about a dropped Azure SQL Database that can be /// restored. /// </summary> /// <param name='serverName'> /// Required. The name of the Azure SQL Database Server on which the /// database was hosted. /// </param> /// <param name='entityId'> /// Required. The entity ID of the restorable dropped Azure SQL /// Database to be obtained. /// </param> /// <param name='cancellationToken'> /// Cancellation token. /// </param> /// <returns> /// Contains the response to the Get Restorable Dropped Database /// request. /// </returns> public async Task <RestorableDroppedDatabaseGetResponse> GetAsync(string serverName, string entityId, CancellationToken cancellationToken) { // Validate if (serverName == null) { throw new ArgumentNullException("serverName"); } if (entityId == null) { throw new ArgumentNullException("entityId"); } // Tracing bool shouldTrace = TracingAdapter.IsEnabled; string invocationId = null; if (shouldTrace) { invocationId = TracingAdapter.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("serverName", serverName); tracingParameters.Add("entityId", entityId); TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters); } // Construct URL string url = "/" + (this.Client.Credentials.SubscriptionId == null ? "" : Uri.EscapeDataString(this.Client.Credentials.SubscriptionId)) + "/services/sqlservers/servers/" + Uri.EscapeDataString(serverName) + "/restorabledroppeddatabases/" + Uri.EscapeDataString(entityId); string baseUrl = this.Client.BaseUri.AbsoluteUri; // Trim '/' character from the end of baseUrl and beginning of url. if (baseUrl[baseUrl.Length - 1] == '/') { baseUrl = baseUrl.Substring(0, baseUrl.Length - 1); } if (url[0] == '/') { url = url.Substring(1); } url = baseUrl + "/" + url; url = url.Replace(" ", "%20"); // Create HTTP transport objects HttpRequestMessage httpRequest = null; try { httpRequest = new HttpRequestMessage(); httpRequest.Method = HttpMethod.Get; httpRequest.RequestUri = new Uri(url); // Set Headers httpRequest.Headers.Add("x-ms-version", "2012-03-01"); // Set Credentials cancellationToken.ThrowIfCancellationRequested(); await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false); // Send Request HttpResponseMessage httpResponse = null; try { if (shouldTrace) { TracingAdapter.SendRequest(invocationId, httpRequest); } cancellationToken.ThrowIfCancellationRequested(); httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false); if (shouldTrace) { TracingAdapter.ReceiveResponse(invocationId, httpResponse); } HttpStatusCode statusCode = httpResponse.StatusCode; if (statusCode != HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false)); if (shouldTrace) { TracingAdapter.Error(invocationId, ex); } throw ex; } // Create Result RestorableDroppedDatabaseGetResponse result = null; // Deserialize Response if (statusCode == HttpStatusCode.OK) { cancellationToken.ThrowIfCancellationRequested(); string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); result = new RestorableDroppedDatabaseGetResponse(); XDocument responseDoc = XDocument.Parse(responseContent); XElement serviceResourceElement = responseDoc.Element(XName.Get("ServiceResource", "http://schemas.microsoft.com/windowsazure")); if (serviceResourceElement != null) { RestorableDroppedDatabase serviceResourceInstance = new RestorableDroppedDatabase(); result.Database = serviceResourceInstance; XElement entityIdElement = serviceResourceElement.Element(XName.Get("EntityId", "http://schemas.microsoft.com/windowsazure")); if (entityIdElement != null) { string entityIdInstance = entityIdElement.Value; serviceResourceInstance.EntityId = entityIdInstance; } XElement serverNameElement = serviceResourceElement.Element(XName.Get("ServerName", "http://schemas.microsoft.com/windowsazure")); if (serverNameElement != null) { string serverNameInstance = serverNameElement.Value; serviceResourceInstance.ServerName = serverNameInstance; } XElement editionElement = serviceResourceElement.Element(XName.Get("Edition", "http://schemas.microsoft.com/windowsazure")); if (editionElement != null) { string editionInstance = editionElement.Value; serviceResourceInstance.Edition = editionInstance; } XElement maxSizeBytesElement = serviceResourceElement.Element(XName.Get("MaxSizeBytes", "http://schemas.microsoft.com/windowsazure")); if (maxSizeBytesElement != null) { long maxSizeBytesInstance = long.Parse(maxSizeBytesElement.Value, CultureInfo.InvariantCulture); serviceResourceInstance.MaximumDatabaseSizeInBytes = maxSizeBytesInstance; } XElement creationDateElement = serviceResourceElement.Element(XName.Get("CreationDate", "http://schemas.microsoft.com/windowsazure")); if (creationDateElement != null) { DateTime creationDateInstance = DateTime.Parse(creationDateElement.Value, CultureInfo.InvariantCulture); serviceResourceInstance.CreationDate = creationDateInstance; } XElement deletionDateElement = serviceResourceElement.Element(XName.Get("DeletionDate", "http://schemas.microsoft.com/windowsazure")); if (deletionDateElement != null) { DateTime deletionDateInstance = DateTime.Parse(deletionDateElement.Value, CultureInfo.InvariantCulture); serviceResourceInstance.DeletionDate = deletionDateInstance; } XElement recoveryPeriodStartDateElement = serviceResourceElement.Element(XName.Get("RecoveryPeriodStartDate", "http://schemas.microsoft.com/windowsazure")); if (recoveryPeriodStartDateElement != null && !string.IsNullOrEmpty(recoveryPeriodStartDateElement.Value)) { DateTime recoveryPeriodStartDateInstance = DateTime.Parse(recoveryPeriodStartDateElement.Value, CultureInfo.InvariantCulture); serviceResourceInstance.RecoveryPeriodStartDate = recoveryPeriodStartDateInstance; } XElement nameElement = serviceResourceElement.Element(XName.Get("Name", "http://schemas.microsoft.com/windowsazure")); if (nameElement != null) { string nameInstance = nameElement.Value; serviceResourceInstance.Name = nameInstance; } XElement typeElement = serviceResourceElement.Element(XName.Get("Type", "http://schemas.microsoft.com/windowsazure")); if (typeElement != null) { string typeInstance = typeElement.Value; serviceResourceInstance.Type = typeInstance; } XElement stateElement = serviceResourceElement.Element(XName.Get("State", "http://schemas.microsoft.com/windowsazure")); if (stateElement != null) { string stateInstance = stateElement.Value; serviceResourceInstance.State = stateInstance; } } } result.StatusCode = statusCode; if (httpResponse.Headers.Contains("x-ms-request-id")) { result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (shouldTrace) { TracingAdapter.Exit(invocationId, result); } return(result); } finally { if (httpResponse != null) { httpResponse.Dispose(); } } } finally { if (httpRequest != null) { httpRequest.Dispose(); } } }
public void AddToRestorableDroppedDatabases(RestorableDroppedDatabase restorableDroppedDatabase) { base.AddObject("RestorableDroppedDatabases", restorableDroppedDatabase); }
/// <summary> /// Ensures any extra property on the given <paramref name="database"/> is loaded. /// </summary> /// <param name="database">The database that needs the extra properties.</param> private void LoadExtraProperties(RestorableDroppedDatabase database) { // Fill in the context property database.Context = this; }
public static RestorableDroppedDatabase CreateRestorableDroppedDatabase(string entityId, long maxSizeBytes, global::System.DateTime creationDate, global::System.DateTime deletionDate) { RestorableDroppedDatabase restorableDroppedDatabase = new RestorableDroppedDatabase(); restorableDroppedDatabase.EntityId = entityId; restorableDroppedDatabase.MaxSizeBytes = maxSizeBytes; restorableDroppedDatabase.CreationDate = creationDate; restorableDroppedDatabase.DeletionDate = deletionDate; return restorableDroppedDatabase; }
/// <summary> /// Given a set of restorable dropped database properties this will create and return a <see cref="RestorableDroppedDatabase"/> /// object with the fields filled in. /// </summary> /// <param name="entityId">The entity ID of the database.</param> /// <param name="name">The name of the database.</param> /// <param name="serverName">The name of the server that contained the database.</param> /// <param name="edition">The edition of the database.</param> /// <param name="maximumDatabaseSizeInBytes">The maximum size of the database.</param> /// <param name="creationDate">The creation date of the database.</param> /// <param name="deletionDate">The deletion date of the database.</param> /// <param name="recoveryPeriodStartDate">The start date of the recovery period for this database.</param> /// <returns>A <see cref="RestorableDroppedDatabase"/> object.</returns> private RestorableDroppedDatabase CreateRestorableDroppedDatabaseFromResponse( string entityId, string name, string serverName, string edition, long maximumDatabaseSizeInBytes, DateTime creationDate, DateTime deletionDate, DateTime? recoveryPeriodStartDate) { var result = new RestorableDroppedDatabase() { EntityId = entityId, Name = name, ServerName = serverName, Edition = edition, MaxSizeBytes = maximumDatabaseSizeInBytes, CreationDate = creationDate, DeletionDate = deletionDate, RecoveryPeriodStartDate = recoveryPeriodStartDate, }; this.LoadExtraProperties(result); return result; }