예제 #1
0
        // <summary>
        /// Helper function to convert ps recovery point model from service response.
        /// </summary>
        public static RecoveryPointBase GetPSAzureRecoveryPoints(
            ServiceClientModel.RecoveryPointResponse rpResponse,
            ItemBase item)
        {
            if (rpResponse == null || rpResponse.RecPoint == null)
            {
                throw new ArgumentNullException(Resources.GetRPResponseIsNull);
            }

            RecoveryPointBase result = null;

            Dictionary <UriEnums, string> uriDict = HelperUtils.ParseUri(item.Id);
            string containerUri      = HelperUtils.GetContainerUri(uriDict, item.Id);
            string containerName     = IdUtils.GetNameFromUri(containerUri);
            string protectedItemUri  = HelperUtils.GetProtectedItemUri(uriDict, item.Id);
            string protectedItemName = IdUtils.GetNameFromUri(protectedItemUri);

            if (rpResponse.RecPoint.Properties.GetType() ==
                typeof(ServiceClientModel.RecoveryPoint))
            {
                ServiceClientModel.RecoveryPoint recPoint =
                    rpResponse.RecPoint.Properties as ServiceClientModel.RecoveryPoint;

                DateTime recPointTime = DateTime.ParseExact(
                    recPoint.RecoveryPointTime,
                    @"MM/dd/yyyy HH:mm:ss",
                    CultureInfo.InvariantCulture);

                AzureVmRecoveryPoint vmResult = new AzureVmRecoveryPoint()
                {
                    RecoveryPointId      = rpResponse.RecPoint.Name,
                    BackupManagementType = item.BackupManagementType,
                    ItemName             = protectedItemName,
                    ContainerName        = containerName,
                    ContainerType        = item.ContainerType,
                    RecoveryPointTime    = recPointTime,
                    RecoveryPointType    = recPoint.RecoveryPointType,
                    Id           = rpResponse.RecPoint.Id,
                    WorkloadType = item.WorkloadType,
                    RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                    EncryptionEnabled           = recPoint.IsSourceVMEncrypted.HasValue ?
                                                  recPoint.IsSourceVMEncrypted.Value : false,
                    IlrSessionActive = recPoint.IsInstantILRSessionActive,
                };

                if (vmResult.EncryptionEnabled)
                {
                    vmResult.KeyAndSecretDetails = new KeyAndSecretDetails()
                    {
                        SecretUrl     = recPoint.KeyAndSecret.BekDetails.SecretUrl,
                        KeyUrl        = recPoint.KeyAndSecret.KekDetails.KeyUrl,
                        SecretData    = recPoint.KeyAndSecret.BekDetails.SecretData,
                        KeyBackupData = recPoint.KeyAndSecret.KekDetails.KeyBackupData,
                        KeyVaultId    = recPoint.KeyAndSecret.KekDetails.KeyVaultId,
                        SecretVaultId = recPoint.KeyAndSecret.BekDetails.SecretVaultId,
                    };
                }

                result = vmResult;
            }

            if (rpResponse.RecPoint.Properties.GetType() ==
                typeof(ServiceClientModel.GenericRecoveryPoint))
            {
                ServiceClientModel.GenericRecoveryPoint recPoint =
                    rpResponse.RecPoint.Properties as ServiceClientModel.GenericRecoveryPoint;

                DateTime recPointTime = DateTime.ParseExact(
                    recPoint.RecoveryPointTime,
                    @"MM/dd/yyyy HH:mm:ss",
                    CultureInfo.InvariantCulture);

                AzureSqlRecoveryPoint sqlResult = new AzureSqlRecoveryPoint()
                {
                    RecoveryPointId      = rpResponse.RecPoint.Name,
                    BackupManagementType = item.BackupManagementType,
                    ItemName             = protectedItemName,
                    ContainerName        = containerName,
                    ContainerType        = item.ContainerType,
                    RecoveryPointTime    = recPointTime,
                    RecoveryPointType    = recPoint.RecoveryPointType,
                    Id           = rpResponse.RecPoint.Id,
                    WorkloadType = item.WorkloadType,
                    RecoveryPointAdditionalInfo = recPoint.RecoveryPointAdditionalInfo,
                    SourceResourceId            = item.SourceResourceId,
                    FriendlyName = recPoint.FriendlyName
                };

                result = sqlResult;
            }
            return(result);
        }