Пример #1
0
 public static LongRunningOperationResponse UnpairStorageClassification(
     this SiteRecoveryManagementClient client,
     Fabric primaryFabric,
     StorageClassification primaryClassification,
     string armResourceName)
 {
     return(client.StorageClassificationMapping.UnpairStorageClassification(
                primaryFabric.Name,
                primaryClassification.Name,
                armResourceName,
                GetRequestHeaders()));
 }
Пример #2
0
        /// <summary>
        /// Gets fabric Id from classification ARM Id.
        /// </summary>
        /// <param name="classification">Storage classification.</param>
        /// <returns>ARM Id of the fabric.</returns>
        public static string GetFabricId(
            this StorageClassification classification)
        {
            string[] tokens = classification.Id.UnFormatArmId(
                ARMResourceIdPaths.StorageClassificationResourceIdPath);

            string vaultId = classification.Id.GetVaultArmId();

            return(vaultId + "/" + string.Format(
                       ARMResourceIdPaths.FabricResourceIdPath,
                       tokens[0]));
        }
Пример #3
0
        public static StorageClassificationMappingOperationResponse PairStorageClassification(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            StorageClassification primaryClassification,
            StorageClassification recoveryClassification,
            string armResourceName)
        {
            StorageClassificationMappingInputProperties props = new StorageClassificationMappingInputProperties()
            {
                TargetStorageClassificationId = recoveryClassification.Id
            };

            StorageClassificationMappingInput input = new StorageClassificationMappingInput()
            {
                Properties = props
            };

            return(client.StorageClassificationMapping.PairStorageClassification(
                       primaryFabric.Name,
                       primaryClassification.Name,
                       armResourceName,
                       input,
                       GetRequestHeaders()) as StorageClassificationMappingOperationResponse);
        }
        /// <summary>
        /// Gets the replication storage object by name.
        /// </summary>
        /// <param name='fabricName'>
        /// Required. Fabric unique name.
        /// </param>
        /// <param name='storageClassificationName'>
        /// Required. Storage classification unique name.
        /// </param>
        /// <param name='customRequestHeaders'>
        /// Optional. Request header parameters.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// The response model for the storage object
        /// </returns>
        public async Task <StorageClassificationResponse> GetAsync(string fabricName, string storageClassificationName, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken)
        {
            // Validate
            if (fabricName == null)
            {
                throw new ArgumentNullException("fabricName");
            }
            if (storageClassificationName == null)
            {
                throw new ArgumentNullException("storageClassificationName");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("fabricName", fabricName);
                tracingParameters.Add("storageClassificationName", storageClassificationName);
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                TracingAdapter.Enter(invocationId, this, "GetAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/Subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/resourceGroups/";
            url = url + Uri.EscapeDataString(this.Client.ResourceGroupName);
            url = url + "/providers/";
            url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            url = url + "/";
            url = url + Uri.EscapeDataString(this.Client.ResourceType);
            url = url + "/";
            url = url + Uri.EscapeDataString(this.Client.ResourceName);
            url = url + "/replicationFabrics/";
            url = url + Uri.EscapeDataString(fabricName);
            url = url + "/replicationStorageClassifications/";
            url = url + Uri.EscapeDataString(storageClassificationName);
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2015-11-10");
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            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("Accept-Language", customRequestHeaders.Culture);
                httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId);
                httpRequest.Headers.Add("x-ms-version", "2015-01-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
                    StorageClassificationResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new StorageClassificationResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            StorageClassification storageClassificationInstance = new StorageClassification();
                            result.StorageClassification = storageClassificationInstance;

                            JToken propertiesValue = responseDoc["properties"];
                            if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                            {
                                StorageClassificationProperties propertiesInstance = new StorageClassificationProperties();
                                storageClassificationInstance.Properties = propertiesInstance;

                                JToken friendlyNameValue = propertiesValue["friendlyName"];
                                if (friendlyNameValue != null && friendlyNameValue.Type != JTokenType.Null)
                                {
                                    string friendlyNameInstance = ((string)friendlyNameValue);
                                    propertiesInstance.FriendlyName = friendlyNameInstance;
                                }
                            }

                            JToken idValue = responseDoc["id"];
                            if (idValue != null && idValue.Type != JTokenType.Null)
                            {
                                string idInstance = ((string)idValue);
                                storageClassificationInstance.Id = idInstance;
                            }

                            JToken nameValue = responseDoc["name"];
                            if (nameValue != null && nameValue.Type != JTokenType.Null)
                            {
                                string nameInstance = ((string)nameValue);
                                storageClassificationInstance.Name = nameInstance;
                            }

                            JToken typeValue = responseDoc["type"];
                            if (typeValue != null && typeValue.Type != JTokenType.Null)
                            {
                                string typeInstance = ((string)typeValue);
                                storageClassificationInstance.Type = typeInstance;
                            }

                            JToken locationValue = responseDoc["location"];
                            if (locationValue != null && locationValue.Type != JTokenType.Null)
                            {
                                string locationInstance = ((string)locationValue);
                                storageClassificationInstance.Location = locationInstance;
                            }

                            JToken tagsSequenceElement = ((JToken)responseDoc["tags"]);
                            if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                            {
                                foreach (JProperty property in tagsSequenceElement)
                                {
                                    string tagsKey   = ((string)property.Name);
                                    string tagsValue = ((string)property.Value);
                                    storageClassificationInstance.Tags.Add(tagsKey, tagsValue);
                                }
                            }

                            JToken clientRequestIdValue = responseDoc["ClientRequestId"];
                            if (clientRequestIdValue != null && clientRequestIdValue.Type != JTokenType.Null)
                            {
                                string clientRequestIdInstance = ((string)clientRequestIdValue);
                                result.ClientRequestId = clientRequestIdInstance;
                            }

                            JToken correlationRequestIdValue = responseDoc["CorrelationRequestId"];
                            if (correlationRequestIdValue != null && correlationRequestIdValue.Type != JTokenType.Null)
                            {
                                string correlationRequestIdInstance = ((string)correlationRequestIdValue);
                                result.CorrelationRequestId = correlationRequestIdInstance;
                            }

                            JToken dateValue = responseDoc["Date"];
                            if (dateValue != null && dateValue.Type != JTokenType.Null)
                            {
                                string dateInstance = ((string)dateValue);
                                result.Date = dateInstance;
                            }

                            JToken contentTypeValue = responseDoc["ContentType"];
                            if (contentTypeValue != null && contentTypeValue.Type != JTokenType.Null)
                            {
                                string contentTypeInstance = ((string)contentTypeValue);
                                result.ContentType = contentTypeInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Content != null && httpResponse.Content.Headers.Contains("Content-Type"))
                    {
                        result.ContentType = httpResponse.Content.Headers.GetValues("Content-Type").FirstOrDefault();
                    }
                    if (httpResponse.Headers.Contains("Date"))
                    {
                        result.Date = httpResponse.Headers.GetValues("Date").FirstOrDefault();
                    }
                    if (httpResponse.Headers.Contains("x-ms-client-request-id"))
                    {
                        result.ClientRequestId = httpResponse.Headers.GetValues("x-ms-client-request-id").FirstOrDefault();
                    }
                    if (httpResponse.Headers.Contains("x-ms-correlation-request-id"))
                    {
                        result.CorrelationRequestId = httpResponse.Headers.GetValues("x-ms-correlation-request-id").FirstOrDefault();
                    }
                    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();
                }
            }
        }