Inheritance: ASRProtectionEntity
Example #1
0
        /// <summary>
        /// Write Protection Entity
        /// </summary>
        /// <param name="protectableItem"></param>
        private void WriteProtectionEntity(ProtectableItem protectableItem)
        {
            ASRVirtualMachine entity = RecoveryServicesClient.FetchProtectionEntityData <ASRVirtualMachine>(
                protectableItem, this.ProtectionContainer.ID, this.ProtectionContainer.Name);

            this.WriteObject(entity);
        }
Example #2
0
        /// <summary>
        /// Write Protection Entity
        /// </summary>
        /// <param name="protectableItem"></param>
        internal T FetchProtectionEntityData <T>(ProtectableItem protectableItem, string protectionContainerId, string protectionContainerName)
        {
            ReplicationProtectedItemResponse replicationProtectedItemResponse = null;

            if (!String.IsNullOrEmpty(protectableItem.Properties.ReplicationProtectedItemId))
            {
                replicationProtectedItemResponse = this.GetAzureSiteRecoveryReplicationProtectedItem(
                    Utilities.GetValueFromArmId(protectionContainerId, ARMResourceTypeConstants.ReplicationFabrics),
                    protectionContainerName,
                    Utilities.GetValueFromArmId(protectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));
            }

            if (replicationProtectedItemResponse != null && replicationProtectedItemResponse.ReplicationProtectedItem != null)
            {
                PolicyResponse policyResponse = this.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(
                                                                                    replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));
                if (typeof(T) == typeof(ASRVirtualMachine))
                {
                    var pe = new ASRVirtualMachine(protectableItem, replicationProtectedItemResponse.ReplicationProtectedItem, policyResponse.Policy);
                    return((T)Convert.ChangeType(pe, typeof(T)));
                }
                else
                {
                    var pe = new ASRProtectionEntity(protectableItem, replicationProtectedItemResponse.ReplicationProtectedItem, policyResponse.Policy);
                    return((T)Convert.ChangeType(pe, typeof(T)));
                }
            }
            else
            {
                if (typeof(T) == typeof(ASRVirtualMachine))
                {
                    var pe = new ASRVirtualMachine(protectableItem);
                    return((T)Convert.ChangeType(pe, typeof(T)));
                }
                else
                {
                    var pe = new ASRProtectionEntity(protectableItem);
                    return((T)Convert.ChangeType(pe, typeof(T)));
                }
            }
        }