public BackupEngineListResponse ListBackupEngine(BackupEngineListQueryParams queryParams, PaginationRequest paginationParam)
        {
            string rsVaultRgName = CommonTestHelper.GetSetting(TestConstants.RsVaultRgName);
            string rsVaultName   = CommonTestHelper.GetSetting(TestConstants.RsVaultName);

            BackupEngineListResponse response = Client.BackupEngines.List(rsVaultRgName, rsVaultName, queryParams, paginationParam, CommonTestHelper.GetCustomRequestHeaders());

            Assert.NotNull(response);
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            Assert.NotNull(response.ItemList);
            return(response);
        }
Ejemplo n.º 2
0
        public void ListDPMBakcupEngineTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();

                string resourceNamespace = ConfigurationManager.AppSettings["ResourceNamespace"];

                var client = GetServiceClient <RecoveryServicesBackupManagementClient>(resourceNamespace);
                BackupEngineHelpers         backupEngineTestHelper = new BackupEngineHelpers(client);
                BackupEngineListQueryParams queryParam             = new BackupEngineListQueryParams();
                //queryParam.ProviderType = "DPM";
                PaginationRequest paginationParam = new PaginationRequest();
                paginationParam.Top = "200";
                AzureOperationResponse   response             = backupEngineTestHelper.ListBackupEngine(queryParam, paginationParam);
                BackupEngineListResponse backupEngineResponse = response as BackupEngineListResponse;
                string backupEngineUniqueName = CommonTestHelper.GetSetting(TestConstants.RsVaultDpmContainerUniqueName);
                Assert.NotNull(backupEngineResponse.ItemList.BackupEngines[0].Properties as BackupEngineBase);
                Assert.Equal(backupEngineUniqueName, backupEngineResponse.ItemList.BackupEngines[0].Name);
            }
        }
        /// <summary>
        /// Lists all the backup engines registered to your Recovery Services
        /// Vault based on the query parameters and the pagination parameters
        /// passed in the arguments.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. Resource group name of your recovery services vault.
        /// </param>
        /// <param name='resourceName'>
        /// Required. Name of your recovery services vault.
        /// </param>
        /// <param name='queryParams'>
        /// Required. Query parameters for listing backup engines.
        /// </param>
        /// <param name='paginationParams'>
        /// Optional. Pagination parameters for controlling the response.
        /// </param>
        /// <param name='customRequestHeaders'>
        /// Required. Request header parameters.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// Response returned by the list backup engines operation.
        /// </returns>
        public async Task <BackupEngineListResponse> ListAsync(string resourceGroupName, string resourceName, BackupEngineListQueryParams queryParams, PaginationRequest paginationParams, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (resourceName == null)
            {
                throw new ArgumentNullException("resourceName");
            }
            if (queryParams == null)
            {
                throw new ArgumentNullException("queryParams");
            }
            if (customRequestHeaders == null)
            {
                throw new ArgumentNullException("customRequestHeaders");
            }

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

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceGroupName", resourceGroupName);
                tracingParameters.Add("resourceName", resourceName);
                tracingParameters.Add("queryParams", queryParams);
                tracingParameters.Add("paginationParams", paginationParams);
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                TracingAdapter.Enter(invocationId, this, "ListAsync", 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(resourceGroupName);
            url = url + "/providers/";
            if (this.Client.ResourceNamespace != null)
            {
                url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            }
            url = url + "/";
            url = url + "vaults";
            url = url + "/";
            url = url + Uri.EscapeDataString(resourceName);
            url = url + "/backupEngines";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2016-05-01");
            List <string> odataFilter = new List <string>();

            if (queryParams.BackupManagementType != null)
            {
                odataFilter.Add("backupManagementType eq '" + Uri.EscapeDataString(queryParams.BackupManagementType) + "'");
            }
            if (odataFilter.Count > 0)
            {
                queryParameters.Add("$filter=" + string.Join(null, odataFilter));
            }
            if (paginationParams != null && paginationParams.SkipToken != null)
            {
                queryParameters.Add("$skiptoken=" + Uri.EscapeDataString(paginationParams.SkipToken));
            }
            if (paginationParams != null && paginationParams.Top != null)
            {
                queryParameters.Add("$top=" + Uri.EscapeDataString(paginationParams.Top));
            }
            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);

                // 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
                    BackupEngineListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

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

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            BackupEngineResourceList itemListInstance = new BackupEngineResourceList();
                            result.ItemList = itemListInstance;

                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    BackupEngineResource backupEngineResourceInstance = new BackupEngineResource();
                                    itemListInstance.BackupEngines.Add(backupEngineResourceInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        string typeName = ((string)propertiesValue["backupEngineType"]);
                                        if (typeName == "DpmBackupEngine")
                                        {
                                            DpmBackupEngine dpmBackupEngineInstance = new DpmBackupEngine();

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

                                            JToken backupManagementTypeValue = propertiesValue["backupManagementType"];
                                            if (backupManagementTypeValue != null && backupManagementTypeValue.Type != JTokenType.Null)
                                            {
                                                string backupManagementTypeInstance = ((string)backupManagementTypeValue);
                                                dpmBackupEngineInstance.BackupManagementType = backupManagementTypeInstance;
                                            }

                                            JToken registrationStatusValue = propertiesValue["registrationStatus"];
                                            if (registrationStatusValue != null && registrationStatusValue.Type != JTokenType.Null)
                                            {
                                                string registrationStatusInstance = ((string)registrationStatusValue);
                                                dpmBackupEngineInstance.RegistrationStatus = registrationStatusInstance;
                                            }

                                            JToken healthStatusValue = propertiesValue["healthStatus"];
                                            if (healthStatusValue != null && healthStatusValue.Type != JTokenType.Null)
                                            {
                                                string healthStatusInstance = ((string)healthStatusValue);
                                                dpmBackupEngineInstance.HealthStatus = healthStatusInstance;
                                            }

                                            JToken backupEngineTypeValue = propertiesValue["backupEngineType"];
                                            if (backupEngineTypeValue != null && backupEngineTypeValue.Type != JTokenType.Null)
                                            {
                                                string backupEngineTypeInstance = ((string)backupEngineTypeValue);
                                                dpmBackupEngineInstance.BackupEngineType = backupEngineTypeInstance;
                                            }

                                            JToken canReRegisterValue = propertiesValue["canReRegister"];
                                            if (canReRegisterValue != null && canReRegisterValue.Type != JTokenType.Null)
                                            {
                                                bool canReRegisterInstance = ((bool)canReRegisterValue);
                                                dpmBackupEngineInstance.CanReRegister = canReRegisterInstance;
                                            }

                                            JToken backupEngineIdValue = propertiesValue["backupEngineId"];
                                            if (backupEngineIdValue != null && backupEngineIdValue.Type != JTokenType.Null)
                                            {
                                                string backupEngineIdInstance = ((string)backupEngineIdValue);
                                                dpmBackupEngineInstance.BackupEngineId = backupEngineIdInstance;
                                            }
                                            backupEngineResourceInstance.Properties = dpmBackupEngineInstance;
                                        }
                                        if (typeName == "AzureBackupServerEngine")
                                        {
                                            AzureBackupServerEngine azureBackupServerEngineInstance = new AzureBackupServerEngine();

                                            JToken friendlyNameValue2 = propertiesValue["friendlyName"];
                                            if (friendlyNameValue2 != null && friendlyNameValue2.Type != JTokenType.Null)
                                            {
                                                string friendlyNameInstance2 = ((string)friendlyNameValue2);
                                                azureBackupServerEngineInstance.FriendlyName = friendlyNameInstance2;
                                            }

                                            JToken backupManagementTypeValue2 = propertiesValue["backupManagementType"];
                                            if (backupManagementTypeValue2 != null && backupManagementTypeValue2.Type != JTokenType.Null)
                                            {
                                                string backupManagementTypeInstance2 = ((string)backupManagementTypeValue2);
                                                azureBackupServerEngineInstance.BackupManagementType = backupManagementTypeInstance2;
                                            }

                                            JToken registrationStatusValue2 = propertiesValue["registrationStatus"];
                                            if (registrationStatusValue2 != null && registrationStatusValue2.Type != JTokenType.Null)
                                            {
                                                string registrationStatusInstance2 = ((string)registrationStatusValue2);
                                                azureBackupServerEngineInstance.RegistrationStatus = registrationStatusInstance2;
                                            }

                                            JToken healthStatusValue2 = propertiesValue["healthStatus"];
                                            if (healthStatusValue2 != null && healthStatusValue2.Type != JTokenType.Null)
                                            {
                                                string healthStatusInstance2 = ((string)healthStatusValue2);
                                                azureBackupServerEngineInstance.HealthStatus = healthStatusInstance2;
                                            }

                                            JToken backupEngineTypeValue2 = propertiesValue["backupEngineType"];
                                            if (backupEngineTypeValue2 != null && backupEngineTypeValue2.Type != JTokenType.Null)
                                            {
                                                string backupEngineTypeInstance2 = ((string)backupEngineTypeValue2);
                                                azureBackupServerEngineInstance.BackupEngineType = backupEngineTypeInstance2;
                                            }

                                            JToken canReRegisterValue2 = propertiesValue["canReRegister"];
                                            if (canReRegisterValue2 != null && canReRegisterValue2.Type != JTokenType.Null)
                                            {
                                                bool canReRegisterInstance2 = ((bool)canReRegisterValue2);
                                                azureBackupServerEngineInstance.CanReRegister = canReRegisterInstance2;
                                            }

                                            JToken backupEngineIdValue2 = propertiesValue["backupEngineId"];
                                            if (backupEngineIdValue2 != null && backupEngineIdValue2.Type != JTokenType.Null)
                                            {
                                                string backupEngineIdInstance2 = ((string)backupEngineIdValue2);
                                                azureBackupServerEngineInstance.BackupEngineId = backupEngineIdInstance2;
                                            }
                                            backupEngineResourceInstance.Properties = azureBackupServerEngineInstance;
                                        }
                                    }

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

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

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

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

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

                                    JToken eTagValue = valueValue["eTag"];
                                    if (eTagValue != null && eTagValue.Type != JTokenType.Null)
                                    {
                                        string eTagInstance = ((string)eTagValue);
                                        backupEngineResourceInstance.ETag = eTagInstance;
                                    }
                                }
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                itemListInstance.NextLink = nextLinkInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }