ValidateReplicationStartTime() public static method

Validates if the time span object has a valid value.
public static ValidateReplicationStartTime ( TimeSpan timeSpan ) : void
timeSpan TimeSpan Time span object to be validated
return void
        /// <summary>
        /// Creates an E2A Policy Object
        /// </summary>
        private void EnterpriseToAzurePolicyObject()
        {
            if (string.Compare(this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Properties.Resources.IncorrectReplicationProvider,
                              this.ReplicationProvider));
            }

            PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);

            ushort replicationFrequencyInSeconds =
                PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);

            var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput()
            {
                ApplicationConsistentSnapshotFrequencyInHours =
                    this.ApplicationConsistentSnapshotFrequencyInHours,
                Encryption = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Encryption)) ?
                             this.Encryption :
                             Constants.Disable,
                OnlineIrStartTime            = this.ReplicationStartTime,
                RecoveryPointHistoryDuration = this.RecoveryPoints,
                ReplicationInterval          = replicationFrequencyInSeconds
            };

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

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

            var createPolicyInputProperties = new CreatePolicyInputProperties()
            {
                ProviderSpecificInput = hyperVReplicaAzurePolicyInput
            };

            var createPolicyInput = new CreatePolicyInput()
            {
                Properties = createPolicyInputProperties
            };

            LongRunningOperationResponse response =
                RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput);

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

            WriteObject(new ASRJob(jobResponse.Job));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates an E2A Protection Profile Object
        /// </summary>
        private void EnterpriseToAzureProtectionProfileObject()
        {
            if (string.Compare(this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Properties.Resources.IncorrectReplicationProvider,
                              this.ReplicationProvider));
            }

            PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);

            ushort replicationFrequencyInSeconds =
                PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);

            HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInput =
                new HyperVReplicaAzureProtectionProfileInput()
            {
                ApplicationConsistentSnapshotFrequencyInHours =
                    this.ApplicationConsistentSnapshotFrequencyInHours,
                ReplicationInterval          = replicationFrequencyInSeconds,
                RecoveryPointHistoryDuration = this.RecoveryPoints,
                OnlineReplicationStartTime   = this.ReplicationStartTime,
                Encryption = "Disable"
            };

            var storageAccount = new CustomerStorageAccount();

            storageAccount.StorageAccountName = this.RecoveryAzureStorageAccount;
            storageAccount.SubscriptionId     = this.RecoveryAzureSubscription;

            hyperVReplicaAzureProtectionProfileInput.StorageAccounts =
                new System.Collections.Generic.List <CustomerStorageAccount>();
            hyperVReplicaAzureProtectionProfileInput.StorageAccounts.Add(storageAccount);

            CreateProtectionProfileInput createProtectionProfileInput =
                new CreateProtectionProfileInput();

            createProtectionProfileInput.Name = this.Name;
            createProtectionProfileInput.ReplicationProvider         = this.ReplicationProvider;
            createProtectionProfileInput.ReplicationProviderSettings =
                hyperVReplicaAzureProtectionProfileInput;

            LongRunningOperationResponse response =
                RecoveryServicesClient.CreateProtectionProfile(createProtectionProfileInput);

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

            WriteObject(new ASRJob(jobResponse.Job));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates an E2E Protection Profile object
        /// </summary>
        private void EnterpriseToEnterpriseProtectionProfileObject()
        {
            if (string.Compare(this.ReplicationProvider, Constants.HyperVReplica, StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Properties.Resources.IncorrectReplicationProvider,
                              this.ReplicationProvider));
            }

            PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);

            ushort replicationFrequencyInSeconds =
                PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);

            HyperVReplicaProtectionProfileInput hyperVReplicaProtectionProfileInput
                = new HyperVReplicaProtectionProfileInput()
                {
                ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours,
                ReplicationFrequencyInSeconds = replicationFrequencyInSeconds,
                OnlineReplicationStartTime    = this.ReplicationStartTime,
                Compression = this.CompressionEnabled == true ? "Enable" : "Disable",
                InitialReplicationMethod =
                    (string.Compare(this.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? "OverNetwork" : "Offline",
                RecoveryPoints            = this.RecoveryPoints,
                ReplicationPort           = this.ReplicationPort,
                ReplicaDeletion           = this.AllowReplicaDeletion == true ? "Required" : "NotRequired",
                AllowedAuthenticationType =
                    (ushort)((string.Compare(this.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2)
                };

            CreateProtectionProfileInput createProtectionProfileInput = new CreateProtectionProfileInput();

            createProtectionProfileInput.Name = this.Name;
            createProtectionProfileInput.ReplicationProvider         = this.ReplicationProvider;
            createProtectionProfileInput.ReplicationProviderSettings =
                hyperVReplicaProtectionProfileInput;

            LongRunningOperationResponse response =
                RecoveryServicesClient.CreateProtectionProfile(createProtectionProfileInput);

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

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

            PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);

            ushort replicationFrequencyInSeconds =
                PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds);

            var createPolicyInputProperties = new CreatePolicyInputProperties();

            if (string.Compare(this.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) == 0)
            {
                createPolicyInputProperties.ProviderSpecificInput = new HyperVReplica2012PolicyInput()
                {
                    AllowedAuthenticationType =
                        (ushort)((string.Compare(this.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2),
                    ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours,
                    Compression = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Compression)) ?
                                  this.Compression :
                                  Constants.Disable,
                    InitialReplicationMethod =
                        (string.Compare(this.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? "OverNetwork" : "Offline",
                    OnlineReplicationStartTime = this.ReplicationStartTime,
                    RecoveryPoints             = this.RecoveryPoints,
                    ReplicaDeletion            = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicaDeletion)) ?
                                                 this.ReplicaDeletion :
                                                 Constants.NotRequired,
                    ReplicationPort = this.ReplicationPort
                };
            }
            else
            {
                createPolicyInputProperties.ProviderSpecificInput = new HyperVReplica2012R2PolicyInput()
                {
                    AllowedAuthenticationType =
                        (ushort)((string.Compare(this.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2),
                    ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours,
                    Compression = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Compression)) ?
                                  this.Compression :
                                  Constants.Disable,
                    InitialReplicationMethod =
                        (string.Compare(this.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? "OverNetwork" : "Offline",
                    OnlineReplicationStartTime = this.ReplicationStartTime,
                    RecoveryPoints             = this.RecoveryPoints,
                    ReplicaDeletion            = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicaDeletion)) ?
                                                 this.ReplicaDeletion :
                                                 Constants.NotRequired,
                    ReplicationFrequencyInSeconds = replicationFrequencyInSeconds,
                    ReplicationPort = this.ReplicationPort
                };
            }

            var createPolicyInput = new CreatePolicyInput()
            {
                Properties = createPolicyInputProperties
            };

            LongRunningOperationResponse responseBlue =
                RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput);

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

            WriteObject(new ASRJob(jobResponseBlue.Job));
        }