13
13
// ----------------------------------------------------------------------------------
14
14
15
15
using System ;
16
+ using System . ComponentModel ;
16
17
using System . Management . Automation ;
17
18
using Microsoft . Azure . Commands . RecoveryServices . SiteRecovery ;
18
19
using Microsoft . Azure . Portal . RecoveryServices . Models . Common ;
@@ -33,7 +34,8 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
33
34
/// <summary>
34
35
/// Gets or sets Replication Provider of the Protection Profile.
35
36
/// </summary>
36
- [ Parameter ( ParameterSetName = ASRParameterSets . Default , Mandatory = true ) ]
37
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise , Mandatory = true ) ]
38
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure , Mandatory = true ) ]
37
39
[ ValidateNotNullOrEmpty ]
38
40
[ ValidateSet (
39
41
Constants . HyperVReplica ,
@@ -43,8 +45,7 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
43
45
/// <summary>
44
46
/// Gets or sets a value for Replication Method of the Protection Profile.
45
47
/// </summary>
46
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise , Mandatory = true ) ]
47
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure , Mandatory = true ) ]
48
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
48
49
[ ValidateNotNullOrEmpty ]
49
50
[ ValidateSet (
50
51
Constants . OnlineReplicationMethod ,
@@ -68,59 +69,61 @@ public class CreateAzureSiteRecoveryProtectionProfileObject : RecoveryServicesCm
68
69
/// <summary>
69
70
/// Gets or sets Replication Frequency of the Protection Profile in seconds.
70
71
/// </summary>
71
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise , Mandatory = true ) ]
72
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure , Mandatory = true ) ]
72
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
73
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure ) ]
73
74
[ ValidateNotNullOrEmpty ]
74
- public int ReplicationFrequencyInSeconds { get ; set ; }
75
+ [ DefaultValue ( 300 ) ]
76
+ public ushort ReplicationFrequencyInSeconds { get ; set ; }
75
77
76
78
/// <summary>
77
79
/// Gets or sets Recovery Points of the Protection Profile.
78
80
/// </summary>
79
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise , Mandatory = true ) ]
80
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure , Mandatory = true ) ]
81
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
82
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure ) ]
81
83
[ ValidateNotNullOrEmpty ]
84
+ [ DefaultValue ( 0 ) ]
82
85
public int RecoveryPoints { get ; set ; }
83
86
84
87
/// <summary>
85
88
/// Gets or sets Application Consistent Snapshot Frequency of the Protection Profile in hours.
86
89
/// </summary>
87
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise , Mandatory = true ) ]
88
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure , Mandatory = true ) ]
90
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
91
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure ) ]
89
92
[ ValidateNotNullOrEmpty ]
93
+ [ DefaultValue ( 0 ) ]
90
94
public int ApplicationConsistentSnapshotFrequencyInHours { get ; set ; }
91
95
92
96
/// <summary>
93
97
/// Gets or sets a value indicating whether Compression needs to be Enabled on the Protection Profile.
94
98
/// </summary>
95
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise , Mandatory = true ) ]
96
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure , Mandatory = true ) ]
97
- [ ValidateNotNullOrEmpty ]
98
- public bool CompressionEnabled { get ; set ; }
99
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
100
+ [ DefaultValue ( true ) ]
101
+ public SwitchParameter CompressionEnabled { get ; set ; }
99
102
100
103
/// <summary>
101
104
/// Gets or sets the Replication Port of the Protection Profile.
102
105
/// </summary>
103
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise , Mandatory = true ) ]
104
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure , Mandatory = true ) ]
106
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
105
107
[ ValidateNotNullOrEmpty ]
106
- public int ReplicationPort { get ; set ; }
108
+ [ DefaultValue ( 8084 ) ]
109
+ public ushort ReplicationPort { get ; set ; }
107
110
108
111
/// <summary>
109
112
/// Gets or sets Replication Start time of the Protection Profile.
110
113
/// </summary>
111
114
[ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
112
115
[ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure ) ]
113
116
[ ValidateNotNullOrEmpty ]
117
+ [ DefaultValue ( null ) ]
114
118
public TimeSpan ? ReplicationStartTime { get ; set ; }
115
119
116
120
/// <summary>
117
121
/// Gets or sets a value indicating whether Replica should be Deleted on
118
122
/// disabling protection of a protection entity protected by the Protection Profile.
119
123
/// </summary>
120
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise , Mandatory = true ) ]
121
- [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToAzure , Mandatory = true ) ]
122
- [ ValidateNotNullOrEmpty ]
123
- public bool AllowReplicaDeletion { get ; set ; }
124
+ [ Parameter ( ParameterSetName = ASRParameterSets . EnterpriseToEnterprise ) ]
125
+ [ DefaultValue ( false ) ]
126
+ public SwitchParameter AllowReplicaDeletion { get ; set ; }
124
127
125
128
#endregion Parameters
126
129
@@ -163,10 +166,12 @@ protected override void StopProcessing()
163
166
private void EnterpriseToAzureProtectionProfileObject ( )
164
167
{
165
168
// Verify whether the storage account is associated with the account or not.
166
- PSRecoveryServicesClientHelper . ValidateStorageAccountAssociation ( this . RecoveryAzureStorageAccount ) ;
169
+ // PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount);
167
170
168
171
// Verify whether the subscription is associated with the account or not.
169
- PSRecoveryServicesClientHelper . ValidateSubscriptionAccountAssociation ( this . RecoveryAzureSubscription ) ;
172
+ // PSRecoveryServicesClientHelper.ValidateSubscriptionAccountAssociation(this.RecoveryAzureSubscription);
173
+
174
+ this . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
170
175
171
176
ASRProtectionProfile protectionProfile = new ASRProtectionProfile ( )
172
177
{
@@ -190,11 +195,31 @@ private void EnterpriseToAzureProtectionProfileObject()
190
195
this . WriteObject ( protectionProfile ) ;
191
196
}
192
197
198
+ /// <summary>
199
+ /// Validates if the time span object has a valid value.
200
+ /// </summary>
201
+ /// <param name="timeSpan">Time span object to be validated</param>
202
+ private void ValidateReplicationStartTime ( TimeSpan ? timeSpan )
203
+ {
204
+ if ( timeSpan == null )
205
+ {
206
+ return ;
207
+ }
208
+
209
+ if ( TimeSpan . Compare ( timeSpan . Value , new TimeSpan ( 24 , 0 , 0 ) ) == 1 )
210
+ {
211
+ throw new InvalidOperationException (
212
+ string . Format ( Properties . Resources . ReplicationStartTimeInvalid ) ) ;
213
+ }
214
+ }
215
+
193
216
/// <summary>
194
217
/// Creates an E2E Protection Profile object
195
218
/// </summary>
196
219
private void EnterpriseToEnterpriseProtectionProfileObject ( )
197
220
{
221
+ this . ValidateReplicationStartTime ( this . ReplicationStartTime ) ;
222
+
198
223
ASRProtectionProfile protectionProfile = new ASRProtectionProfile ( )
199
224
{
200
225
ReplicationProvider = this . ReplicationProvider ,
0 commit comments