Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.ServiceClientAdapterNS.ServiceClientAdapter.RestoreDisk C# (CSharp) Метод

RestoreDisk() публичный Метод

Restores the disk based on the recovery point and other input parameters
public RestoreDisk ( AzureVmRecoveryPoint rp, string storageAccountId, string storageAccountLocation, string storageAccountType ) : Microsoft.Azure.Management.RecoveryServices.Backup.Models.BaseRecoveryServicesJobResponse
rp Microsoft.Azure.Commands.RecoveryServices.Backup.Cmdlets.Models.AzureVmRecoveryPoint Recovery point to restore the disk to
storageAccountId string ID of the storage account where to restore the disk
storageAccountLocation string Location of the storage account where to restore the disk
storageAccountType string Type of the storage account where to restore the disk
Результат Microsoft.Azure.Management.RecoveryServices.Backup.Models.BaseRecoveryServicesJobResponse
        public BaseRecoveryServicesJobResponse RestoreDisk(AzureVmRecoveryPoint rp, string storageAccountId, 
            string storageAccountLocation, string storageAccountType)
        {
            string resourceGroupName = BmsAdapter.GetResourceGroupName();
            string resourceName = BmsAdapter.GetResourceName();
            string vaultLocation = BmsAdapter.GetResourceLocation();
            Dictionary<UriEnums, string> uriDict = HelperUtils.ParseUri(rp.Id);
            string containerUri = HelperUtils.GetContainerUri(uriDict, rp.Id);
            string protectedItemUri = HelperUtils.GetProtectedItemUri(uriDict, rp.Id);
            string recoveryPointId = rp.RecoveryPointId;
            //validtion block
            if(storageAccountLocation != vaultLocation)
            {
                throw new Exception(Resources.RestoreDiskIncorrectRegion);
            }
            
            string vmType = containerUri.Split(';')[1].Equals("iaasvmcontainer", StringComparison.OrdinalIgnoreCase) 
                ? "Classic" : "Compute";
            string strType = storageAccountType.Equals("Microsoft.ClassicStorage/StorageAccounts", 
                StringComparison.OrdinalIgnoreCase) ? "Classic" : "Compute";
            if(vmType != strType)
            {
                throw new Exception(String.Format(Resources.RestoreDiskStorageTypeError, vmType));
            }

            IaasVMRestoreRequest restoreRequest = new IaasVMRestoreRequest()
            {
                CreateNewCloudService = false,
                RecoveryPointId = recoveryPointId,
                RecoveryType = RecoveryType.RestoreDisks,
                Region = vaultLocation,
                StorageAccountId = storageAccountId,
                SourceResourceId = rp.SourceResourceId,
            };

            TriggerRestoreRequest triggerRestoreRequest = new TriggerRestoreRequest();
            triggerRestoreRequest.Item = new RestoreRequestResource();
            triggerRestoreRequest.Item.Properties = new RestoreRequest();
            triggerRestoreRequest.Item.Properties = restoreRequest;

            var response = BmsAdapter.Client.Restores.TriggerRestoreAsync(
                resourceGroupName, 
                resourceName, 
                BmsAdapter.GetCustomRequestHeaders(),
                AzureFabricName, 
                containerUri, 
                protectedItemUri, 
                recoveryPointId, 
                triggerRestoreRequest, 
                BmsAdapter.CmdletCancellationToken).Result;

            return response;
        }
    }