@@ -24,10 +24,21 @@ namespace Microsoft.Azure.Commands.Sql.Replication.Cmdlet
24
24
/// <summary>
25
25
/// Cmdlet to fail over Azure SQL Database Replication Link to the secondary database
26
26
/// </summary>
27
- [ Cmdlet ( VerbsCommon . Set , "AzureSqlDatabaseSecondary" ,
27
+ [ Cmdlet ( VerbsCommon . Set , "AzureSqlDatabaseSecondary" ,
28
+ DefaultParameterSetName = ByDatabaseName ,
28
29
ConfirmImpact = ConfirmImpact . Medium ) ]
29
30
public class SetAzureSqlDatabaseSecondary : AzureSqlDatabaseSecondaryCmdletBase
30
31
{
32
+ /// <summary>
33
+ /// ParameterSet to set properties for a given Azure SQL Database Secondary
34
+ /// </summary>
35
+ internal const string ByDatabaseName = "ByDatabaseName" ;
36
+
37
+ /// <summary>
38
+ /// ParameterSet to get a Replication Link by its partner Azure SQL Server Name
39
+ /// </summary>
40
+ internal const string ByFailoverParams = "ByFailoverParams" ;
41
+
31
42
/// <summary>
32
43
/// Gets or sets the name of the primary Azure SQL Database with the replication link to remove.
33
44
/// </summary>
@@ -51,8 +62,9 @@ public class SetAzureSqlDatabaseSecondary : AzureSqlDatabaseSecondaryCmdletBase
51
62
/// Gets or sets a value indicating whether this is a failover.
52
63
/// </summary>
53
64
/// <returns></returns>
54
- [ Parameter ( Mandatory = false ,
65
+ [ Parameter ( Mandatory = true ,
55
66
ValueFromPipelineByPropertyName = false ,
67
+ ParameterSetName = ByFailoverParams ,
56
68
HelpMessage = "Whether this operation is a failover." ) ]
57
69
public SwitchParameter Failover { get ; set ; }
58
70
@@ -62,6 +74,7 @@ public class SetAzureSqlDatabaseSecondary : AzureSqlDatabaseSecondaryCmdletBase
62
74
/// <returns></returns>
63
75
[ Parameter ( Mandatory = false ,
64
76
ValueFromPipelineByPropertyName = false ,
77
+ ParameterSetName = ByFailoverParams ,
65
78
HelpMessage = "Whether this failover operation will allow data loss." ) ]
66
79
public SwitchParameter AllowDataLoss { get ; set ; }
67
80
@@ -91,19 +104,20 @@ protected override IEnumerable<AzureReplicationLinkModel> ApplyUserInputToModel(
91
104
/// <returns>The input entity</returns>
92
105
protected override IEnumerable < AzureReplicationLinkModel > PersistChanges ( IEnumerable < AzureReplicationLinkModel > entity )
93
106
{
94
- if ( this . MyInvocation . BoundParameters . ContainsKey ( "Failover" ) )
95
- {
96
- return new List < AzureReplicationLinkModel > ( ) { ModelAdapter . FailoverLink ( this . ResourceGroupName ,
97
- this . ServerName ,
98
- this . DatabaseName ,
99
- this . PartnerResourceGroupName ,
100
- this . MyInvocation . BoundParameters . ContainsKey ( "AllowDataLoss" ) ? true : false )
101
- } ;
102
- }
103
- else
107
+
108
+ switch ( ParameterSetName )
104
109
{
105
- // Warning user that no options were provided so no action can be taken.
106
- WriteWarning ( Resources . SetSecondaryNoOptionProvided ) ;
110
+ case ByFailoverParams :
111
+ return new List < AzureReplicationLinkModel > ( ) { ModelAdapter . FailoverLink ( this . ResourceGroupName ,
112
+ this . ServerName ,
113
+ this . DatabaseName ,
114
+ this . PartnerResourceGroupName ,
115
+ this . MyInvocation . BoundParameters . ContainsKey ( "AllowDataLoss" ) ? true : false )
116
+ } ;
117
+ default :
118
+ // Warning user that no options were provided so no action can be taken.
119
+ WriteWarning ( Resources . SetSecondaryNoOptionProvided ) ;
120
+ break ;
107
121
}
108
122
109
123
return entity ;
0 commit comments