@@ -25,7 +25,7 @@ namespace Microsoft.Azure.Commands.RecoveryServices
25
25
/// <summary>
26
26
/// Creates Azure Site Recovery Protection Profile object in memory.
27
27
/// </summary>
28
- [ Cmdlet ( VerbsCommon . New , "AzureSiteRecoveryProtectionProfile " , DefaultParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
28
+ [ Cmdlet ( VerbsCommon . New , "AzureSiteRecoveryProtectionProfileObject " , DefaultParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
29
29
[ OutputType ( typeof ( ASRProtectionProfile ) ) ]
30
30
public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCmdletBase
31
31
{
@@ -50,7 +50,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
50
50
[ ValidateSet (
51
51
Constants . OnlineReplicationMethod ,
52
52
Constants . OfflineReplicationMethod ) ]
53
- [ DefaultValue ( Constants . OnlineReplicationMethod ) ]
54
53
public string ReplicationMethod { get ; set ; }
55
54
56
55
/// <summary>
@@ -80,7 +79,11 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
80
79
[ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
81
80
[ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure ) ]
82
81
[ ValidateNotNullOrEmpty ]
83
- public ushort ReplicationFrequencyInSeconds { get ; set ; }
82
+ [ ValidateSet (
83
+ Constants . Thirty ,
84
+ Constants . ThreeHundred ,
85
+ Constants . NineHundred ) ]
86
+ public string ReplicationFrequencyInSeconds { get ; set ; }
84
87
85
88
/// <summary>
86
89
/// Gets or sets Recovery Points of the Protection Profile.
@@ -112,7 +115,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
112
115
/// </summary>
113
116
[ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
114
117
[ ValidateNotNullOrEmpty ]
115
- [ DefaultValue ( 0 ) ]
116
118
public ushort ReplicationPort { get ; set ; }
117
119
118
120
/// <summary>
@@ -131,7 +133,6 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
131
133
[ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
132
134
[ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure ) ]
133
135
[ ValidateNotNullOrEmpty ]
134
- [ DefaultValue ( null ) ]
135
136
public TimeSpan ? ReplicationStartTime { get ; set ; }
136
137
137
138
/// <summary>
@@ -151,12 +152,12 @@ public override void ExecuteCmdlet()
151
152
{
152
153
try
153
154
{
154
- switch ( this . ReplicationProvider )
155
+ switch ( this . ParameterSetName )
155
156
{
156
- case Constants . HyperVReplica :
157
+ case ASRParameterSets . EnterpriseToEnterprise :
157
158
this . EnterpriseToEnterpriseProtectionProfileObject ( ) ;
158
159
break ;
159
- case Constants . HyperVReplicaAzure :
160
+ case ASRParameterSets . EnterpriseToAzure :
160
161
this . EnterpriseToAzureProtectionProfileObject ( ) ;
161
162
break ;
162
163
}
@@ -182,13 +183,23 @@ protected override void StopProcessing()
182
183
/// </summary>
183
184
private void EnterpriseToAzureProtectionProfileObject ( )
184
185
{
185
- //// Verify whether the storage account is associated with the account or not.
186
- //// PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);
186
+ if ( string . Compare ( this . ReplicationProvider , Constants . HyperVReplicaAzure , StringComparison . OrdinalIgnoreCase ) != 0 )
187
+ {
188
+ throw new InvalidOperationException (
189
+ string . Format (
190
+ Properties . Resources . IncorrectReplicationProvider ,
191
+ this . ReplicationProvider ) ) ;
192
+ }
187
193
188
194
// Verify whether the subscription is associated with the account or not.
189
195
PSRecoveryServicesClientHelper . ValidateSubscriptionAccountAssociation ( this . RecoveryAzureSubscription ) ;
190
196
191
- this . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
197
+ // Verify whether the storage account is associated with the subscription or not.
198
+ //// PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);
199
+
200
+ PSRecoveryServicesClientHelper . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
201
+
202
+ ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
192
203
193
204
ASRProtectionProfile protectionProfile = new ASRProtectionProfile ( )
194
205
{
@@ -198,7 +209,7 @@ private void EnterpriseToAzureProtectionProfileObject()
198
209
RecoveryAzureSubscription = this . RecoveryAzureSubscription ,
199
210
RecoveryAzureStorageAccountName = this . RecoveryAzureStorageAccount ,
200
211
EncryptStoredData = this . EncryptStoredData ,
201
- ReplicationFrequencyInSeconds = this . ReplicationFrequencyInSeconds ,
212
+ ReplicationFrequencyInSeconds = replicationFrequencyInSeconds ,
202
213
RecoveryPoints = this . RecoveryPoints ,
203
214
ApplicationConsistentSnapshotFrequencyInHours = this . ApplicationConsistentSnapshotFrequencyInHours ,
204
215
ReplicationStartTime = this . ReplicationStartTime ,
@@ -210,29 +221,21 @@ private void EnterpriseToAzureProtectionProfileObject()
210
221
}
211
222
212
223
/// <summary>
213
- /// Validates if the time span object has a valid value.
224
+ /// Creates an E2E Protection Profile object
214
225
/// </summary>
215
- /// <param name="timeSpan">Time span object to be validated</param>
216
- private void ValidateReplicationStartTime ( TimeSpan ? timeSpan )
226
+ private void EnterpriseToEnterpriseProtectionProfileObject ( )
217
227
{
218
- if ( timeSpan == null )
219
- {
220
- return ;
221
- }
222
-
223
- if ( TimeSpan . Compare ( timeSpan . Value , new TimeSpan ( 24 , 0 , 0 ) ) == 1 )
228
+ if ( string . Compare ( this . ReplicationProvider , Constants . HyperVReplica , StringComparison . OrdinalIgnoreCase ) != 0 )
224
229
{
225
230
throw new InvalidOperationException (
226
- string . Format ( Properties . Resources . ReplicationStartTimeInvalid ) ) ;
231
+ string . Format (
232
+ Properties . Resources . IncorrectReplicationProvider ,
233
+ this . ReplicationProvider ) ) ;
227
234
}
228
- }
229
235
230
- /// <summary>
231
- /// Creates an E2E Protection Profile object
232
- /// </summary>
233
- private void EnterpriseToEnterpriseProtectionProfileObject ( )
234
- {
235
- this . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
236
+ PSRecoveryServicesClientHelper . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
237
+
238
+ ushort replicationFrequencyInSeconds = PSRecoveryServicesClientHelper . ConvertReplicationFrequencyToUshort ( this . ReplicationFrequencyInSeconds ) ;
236
239
237
240
ASRProtectionProfile protectionProfile = new ASRProtectionProfile ( )
238
241
{
@@ -241,7 +244,7 @@ private void EnterpriseToEnterpriseProtectionProfileObject()
241
244
HyperVReplicaProviderSettingsObject = new HyperVReplicaProviderSettings ( )
242
245
{
243
246
ReplicationMethod = this . ReplicationMethod ,
244
- ReplicationFrequencyInSeconds = this . ReplicationFrequencyInSeconds ,
247
+ ReplicationFrequencyInSeconds = replicationFrequencyInSeconds ,
245
248
RecoveryPoints = this . RecoveryPoints ,
246
249
ApplicationConsistentSnapshotFrequencyInHours = this . ApplicationConsistentSnapshotFrequencyInHours ,
247
250
CompressionEnabled = this . CompressionEnabled ,
0 commit comments