/// <summary>
        ///     Creates an E2E Policy object
        /// </summary>
        private void EnterpriseToEnterprisePolicyObject()
        {
            if ((string.Compare(
                     this.InputObject.ReplicationProvider,
                     Constants.HyperVReplica2012,
                     StringComparison.OrdinalIgnoreCase) !=
                 0) &&
                (string.Compare(
                     this.InputObject.ReplicationProvider,
                     Constants.HyperVReplica2012R2,
                     StringComparison.OrdinalIgnoreCase) !=
                 0))
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.IncorrectReplicationProvider,
                              this.InputObject.ReplicationProvider));
            }

            var replicationProviderSettings =
                this.InputObject.ReplicationProviderSettings as ASRHyperVReplicaPolicyDetails;

            this.replicationMethod =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.ReplicationMethod)) ? (string.Compare(
                                                                                  this
                                                                                  .ReplicationMethod,
                                                                                  Constants
                                                                                  .OnlineReplicationMethod,
                                                                                  StringComparison
                                                                                  .OrdinalIgnoreCase) ==
                                                                              0 ? "OverNetwork"
                    : "Offline") : (string.Compare(
                                        replicationProviderSettings.InitialReplicationMethod,
                                        Constants.OnlineReplicationMethod,
                                        StringComparison.OrdinalIgnoreCase) ==
                                    0 ? "OverNetwork" : "Offline");
            this.replicationFrequencyInSeconds =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.ReplicationFrequencyInSeconds))
                    ? PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(
                    this.ReplicationFrequencyInSeconds) : replicationProviderSettings
                .ReplicationFrequencyInSeconds;
            this.recoveryPoints =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.NumberOfRecoveryPointsToRetain)) ? this.NumberOfRecoveryPointsToRetain
                    : replicationProviderSettings.RecoveryPoints;
            this.applicationConsistentSnapshotFrequencyInHours =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(
                        () => this.ApplicationConsistentSnapshotFrequencyInHours))
                    ? this.ApplicationConsistentSnapshotFrequencyInHours
                    : replicationProviderSettings.ApplicationConsistentSnapshotFrequencyInHours;
            this.compression =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.Compression)) ? this.Compression
                    : replicationProviderSettings.Compression;
            this.replicationPort =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.ReplicationPort)) ? this.ReplicationPort
                    : replicationProviderSettings.ReplicationPort;
            this.authentication =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.Authentication)) ? (ushort)(string.Compare(
                                                                                       this
                                                                                       .Authentication,
                                                                                       Constants
                                                                                       .AuthenticationTypeKerberos,
                                                                                       StringComparison
                                                                                       .OrdinalIgnoreCase) ==
                                                                                   0 ? 1 : 2)
                    : (ushort)(string.Compare(
                                   replicationProviderSettings.AllowedAuthenticationType,
                                   Constants.AuthenticationTypeKerberos,
                                   StringComparison.OrdinalIgnoreCase) ==
                               0 ? 1 : 2);
            this.replicationStartTime =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.ReplicationStartTime))
                    ? this.replicationStartTime
                    : replicationProviderSettings.OnlineReplicationStartTime;
            this.replicaDeletion =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.ReplicaDeletion)) ? this.ReplicaDeletion
                    : replicationProviderSettings.ReplicaDeletionOption;

            var updatePolicyProperties = new UpdatePolicyInputProperties();

            if (string.Compare(
                    this.InputObject.ReplicationProvider,
                    Constants.HyperVReplica2012,
                    StringComparison.OrdinalIgnoreCase) ==
                0)
            {
                updatePolicyProperties.ReplicationProviderSettings = new HyperVReplicaPolicyInput
                {
                    AllowedAuthenticationType = this.authentication,
                    ApplicationConsistentSnapshotFrequencyInHours =
                        this.applicationConsistentSnapshotFrequencyInHours,
                    Compression = this.compression,
                    InitialReplicationMethod   = this.replicationMethod,
                    OnlineReplicationStartTime = this.replicationStartTime.ToString(),
                    RecoveryPoints             = this.recoveryPoints,
                    ReplicaDeletion            = this.replicaDeletion,
                    ReplicationPort            = this.replicationPort
                };
            }
            else
            {
                updatePolicyProperties.ReplicationProviderSettings =
                    new HyperVReplicaBluePolicyInput
                {
                    AllowedAuthenticationType = this.authentication,
                    ApplicationConsistentSnapshotFrequencyInHours =
                        this.applicationConsistentSnapshotFrequencyInHours,
                    Compression = this.compression,
                    InitialReplicationMethod      = this.replicationMethod,
                    OnlineReplicationStartTime    = this.replicationStartTime.ToString(),
                    RecoveryPoints                = this.recoveryPoints,
                    ReplicaDeletion               = this.replicaDeletion,
                    ReplicationPort               = this.replicationPort,
                    ReplicationFrequencyInSeconds = this.replicationFrequencyInSeconds
                };
            }

            var updatePolicyInput = new UpdatePolicyInput {
                Properties = updatePolicyProperties
            };

            var responseBlue = this.RecoveryServicesClient.UpdatePolicy(
                this.InputObject.Name,
                updatePolicyInput);

            var jobResponseBlue = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                PSRecoveryServicesClient.GetJobIdFromReponseLocation(responseBlue.Location));

            this.WriteObject(new ASRJob(jobResponseBlue));
        }
        /// <summary>
        ///     Updates an Azure to Azure Policy.
        /// </summary>
        private void UpdateA2APolicy()
        {
            if (string.Compare(
                    this.InputObject.ReplicationProvider,
                    Constants.A2A,
                    StringComparison.OrdinalIgnoreCase) !=
                0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.IncorrectReplicationProvider,
                              this.InputObject.ReplicationProvider));
            }

            // Get the A2A Provider specific details from the Policy.
            var replicationProviderSettings =
                this.InputObject.ReplicationProviderSettings as ASRAzureToAzurePolicyDetails;

            // Set the Paremeters to be updated.
            this.applicationConsistentSnapshotFrequencyInMinutes =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(
                        () =>
                        this.applicationConsistentSnapshotFrequencyInHours))
                    ? this.ApplicationConsistentSnapshotFrequencyInHours * 60
                    : replicationProviderSettings.AppConsistentFrequencyInMinutes;

            this.crashConsistentFrequencyInMinutes =
                replicationProviderSettings.CrashConsistentFrequencyInMinutes;

            this.RecoveryPointRetentionInHours =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(
                        () =>
                        this.RecoveryPointRetentionInHours))
                    ? this.RecoveryPointRetentionInHours
                    : replicationProviderSettings.RecoveryPointHistory / 60;
            this.rpoWarningThresholdInMinutes =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(
                        () =>
                        this.RPOWarningThresholdInMinutes))
                    ? this.RPOWarningThresholdInMinutes
                    : replicationProviderSettings.RecoveryPointThresholdInMinutes;
            this.multiVmSyncStatus =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(
                        () =>
                        this.MultiVmSyncStatus))
                    ? this.MultiVmSyncStatus
                    : (replicationProviderSettings.MultiVmSyncStatus.Equals("Enabled")
                        ? Constants.Enable
                        : Constants.Disable);

            // Set the Provider Specific Input for AzureToAzure.
            var a2APolicyInput = new A2APolicyCreationInput
            {
                AppConsistentFrequencyInMinutes =
                    this.applicationConsistentSnapshotFrequencyInMinutes,
                RecoveryPointHistory = this.RecoveryPointRetentionInHours * 60, // Convert from hours to minutes.
                MultiVmSyncStatus    = this.multiVmSyncStatus,
                CrashConsistentFrequencyInMinutes = this.crashConsistentFrequencyInMinutes
            };

            var updatePolicyProperties = new UpdatePolicyInputProperties
            {
                ReplicationProviderSettings = a2APolicyInput
            };

            // Create the Update Policy Input.
            var updatePolicyInput = new UpdatePolicyInput
            {
                Properties = updatePolicyProperties
            };

            var response = this.RecoveryServicesClient.UpdatePolicy(
                this.InputObject.Name,
                updatePolicyInput);

            var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Creates an E2A Policy Object
        /// </summary>
        private void HyperVToAzurePolicyObject()
        {
            if (string.Compare(
                    this.InputObject.ReplicationProvider,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase) !=
                0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.IncorrectReplicationProvider,
                              this.InputObject.ReplicationProvider));
            }

            var replicationProviderSettings =
                this.InputObject.ReplicationProviderSettings as ASRHyperVReplicaAzurePolicyDetails;

            this.replicationFrequencyInSeconds =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.ReplicationFrequencyInSeconds))
                    ? PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(
                    this.ReplicationFrequencyInSeconds) : (ushort)replicationProviderSettings
                .ReplicationFrequencyInSeconds;
            this.recoveryPoints =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.NumberOfRecoveryPointsToRetain)) ? this.NumberOfRecoveryPointsToRetain
                    : replicationProviderSettings.RecoveryPoints;
            this.applicationConsistentSnapshotFrequencyInHours =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(
                        () => this.ApplicationConsistentSnapshotFrequencyInHours))
                    ? this.ApplicationConsistentSnapshotFrequencyInHours
                    : replicationProviderSettings.ApplicationConsistentSnapshotFrequencyInHours;
            this.replicationStartTime =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.ReplicationStartTime))
                    ? this.replicationStartTime
                    : replicationProviderSettings.OnlineReplicationStartTime;
            this.recoveryAzureStorageAccountId =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.RecoveryAzureStorageAccountId))
                    ? this.RecoveryAzureStorageAccountId
                    : replicationProviderSettings.ActiveStorageAccountId;

            var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput
            {
                ApplicationConsistentSnapshotFrequencyInHours =
                    this.applicationConsistentSnapshotFrequencyInHours,
// encryption is removed from latest API . Service is setting the default vault internally.
// todo :: Warning.
                OnlineReplicationStartTime   = this.replicationStartTime.ToString(),
                RecoveryPointHistoryDuration = this.recoveryPoints,
                ReplicationInterval          = this.replicationFrequencyInSeconds
            };

            hyperVReplicaAzurePolicyInput.StorageAccounts = new List <string>();

            if (this.RecoveryAzureStorageAccountId != null)
            {
                var storageAccount = this.recoveryAzureStorageAccountId;
                hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount);
            }

            var updatePolicyProperties = new UpdatePolicyInputProperties
            {
                ReplicationProviderSettings = hyperVReplicaAzurePolicyInput
            };

            var updatePolicyInput = new UpdatePolicyInput {
                Properties = updatePolicyProperties
            };

            var response = this.RecoveryServicesClient.UpdatePolicy(
                this.InputObject.Name,
                updatePolicyInput);

            var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            this.WriteObject(new ASRJob(jobResponse));
        }