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

            RecoveryPointBase result = null;

            if (rpResponse.Properties.GetType() ==
                typeof(ServiceClientModel.IaasVMRecoveryPoint))
            {
                result = GetPSAzureVMRecoveryPoint(rpResponse, item);
            }

            else if (rpResponse.Properties.GetType() ==
                     typeof(ServiceClientModel.AzureFileShareRecoveryPoint))
            {
                result = GetPSAzureFileRecoveryPoint(rpResponse, item);
            }

            else if (rpResponse.Properties.GetType().IsSubclassOf(typeof(ServiceClientModel.AzureWorkloadRecoveryPoint)))
            {
                result = GetPSAzureWorkloadRecoveryPoint(rpResponse, item);
            }

            else if (rpResponse.Properties.GetType() ==
                     typeof(ServiceClientModel.GenericRecoveryPoint))
            {
                result = GetPSAzureGenericRecoveryPoint(rpResponse, item);
            }
            return(result);
        }
Exemplo n.º 2
0
        public AzureWorkloadRecoveryConfig GetConfigObject()
        {
            string            targetServer       = "";
            string            parentName         = "";
            string            restoreRequestType = "";
            RecoveryPointBase recoveryPoint      = RecoveryPoint;
            DateTime          pointInTime        = PointInTime;

            if (ParameterSetName == RpParameterSet)
            {
                Dictionary <UriEnums, string> keyValueDict = HelperUtils.ParseUri(RecoveryPoint.Id);
                string containerUri = HelperUtils.GetContainerUri(keyValueDict, RecoveryPoint.Id);
                try
                {
                    targetServer = containerUri.Split(new string[] { ";" }, StringSplitOptions.None)[3];
                }
                catch
                {
                    targetServer = containerUri.Split(new string[] { ";" }, StringSplitOptions.None)[1];
                }

                string itemUri = HelperUtils.GetProtectedItemUri(keyValueDict, RecoveryPoint.Id);
                parentName = itemUri.Split(new string[] { ";" }, StringSplitOptions.None)[1];
            }

            if (OriginalWorkloadRestore.IsPresent)
            {
                restoreRequestType = "Original WL Restore";
                if (Item != null)
                {
                    targetServer = ((AzureWorkloadSQLDatabaseProtectedItem)Item).ServerName;
                    parentName   = ((AzureWorkloadSQLDatabaseProtectedItem)Item).ParentName;
                }
                if (RecoveryPoint == null)
                {
                    Models.AzureWorkloadRecoveryPoint azureWorkloadRecoveryPoint = new Models.AzureWorkloadRecoveryPoint()
                    {
                        Id = Item.Id + "/recoveryPoints/DefaultRangeRecoveryPoint",
                        RecoveryPointId = "DefaultRangeRecoveryPoint"
                    };
                    recoveryPoint = azureWorkloadRecoveryPoint;
                }
            }
            else if (AlternateWorkloadRestore.IsPresent && Item == null)
            {
                restoreRequestType = "Alternate WL Restore";
                targetServer       = ((AzureWorkloadProtectableItem)TargetItem).ServerName;
                parentName         = ((AzureWorkloadProtectableItem)TargetItem).ParentName;
            }
            else if (Item != null && TargetItem != null)
            {
                restoreRequestType = "Alternate WL Restore to diff item";
                targetServer       = ((AzureWorkloadProtectableItem)TargetItem).ServerName;
                parentName         = ((AzureWorkloadProtectableItem)TargetItem).ParentName;

                Models.AzureWorkloadRecoveryPoint azureWorkloadRecoveryPoint = new Models.AzureWorkloadRecoveryPoint()
                {
                    Id = Item.Id + "/recoveryPoints/DefaultRangeRecoveryPoint",
                    RecoveryPointId = "DefaultRangeRecoveryPoint"
                };
                recoveryPoint = azureWorkloadRecoveryPoint;
            }

            return(new AzureWorkloadRecoveryConfig(targetServer, parentName, restoreRequestType, recoveryPoint, pointInTime));
        }
Exemplo n.º 3
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,
                    SourceResourceId    = item.SourceResourceId,
                    SourceVMStorageType = recPoint.SourceVMStorageType,
                };

                if (vmResult.EncryptionEnabled && recPoint.KeyAndSecret != null)
                {
                    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);
        }