@@ -32,7 +32,7 @@ public class AddAzureRmIotHubRoute : IotHubBaseCmdlet
32
32
private const string ResourceParameterSet = "ResourceSet" ;
33
33
private const string InputObjectParameterSet = "InputObjectSet" ;
34
34
35
- [ Parameter ( Position = 0 , Mandatory = true , ParameterSetName = InputObjectParameterSet , ValueFromPipeline = true , HelpMessage = "IotHub Object " ) ]
35
+ [ Parameter ( Position = 0 , Mandatory = true , ParameterSetName = InputObjectParameterSet , ValueFromPipeline = true , HelpMessage = "IotHub object " ) ]
36
36
[ ValidateNotNullOrEmpty ]
37
37
public PSIotHub InputObject { get ; set ; }
38
38
@@ -55,16 +55,15 @@ public class AddAzureRmIotHubRoute : IotHubBaseCmdlet
55
55
[ ValidateNotNullOrEmpty ]
56
56
public string RouteName { get ; set ; }
57
57
58
- [ Parameter ( Position = 2 , Mandatory = true , ParameterSetName = InputObjectParameterSet , HelpMessage = "Source of the route" ) ]
59
- [ Parameter ( Position = 2 , Mandatory = true , ParameterSetName = ResourceIdParameterSet , HelpMessage = "Source of the route" ) ]
60
- [ Parameter ( Position = 3 , Mandatory = true , ParameterSetName = ResourceParameterSet , HelpMessage = "Source of the route" ) ]
58
+ [ Parameter ( Mandatory = true , ParameterSetName = InputObjectParameterSet , HelpMessage = "Source of the route" ) ]
59
+ [ Parameter ( Mandatory = true , ParameterSetName = ResourceIdParameterSet , HelpMessage = "Source of the route" ) ]
60
+ [ Parameter ( Mandatory = true , ParameterSetName = ResourceParameterSet , HelpMessage = "Source of the route" ) ]
61
61
[ ValidateNotNullOrEmpty ]
62
- [ ValidateSet ( new string [ ] { "Invalid" , "DeviceMessages" , "TwinChangeEvents" , "DeviceLifecycleEvents" , "DeviceJobLifecycleEvents" } , IgnoreCase = true ) ]
63
- public string Source { get ; set ; }
62
+ public PSRoutingSource Source { get ; set ; }
64
63
65
- [ Parameter ( Position = 3 , Mandatory = true , ParameterSetName = InputObjectParameterSet , HelpMessage = "Name of the routing endpoint" ) ]
66
- [ Parameter ( Position = 3 , Mandatory = true , ParameterSetName = ResourceIdParameterSet , HelpMessage = "Name of the routing endpoint" ) ]
67
- [ Parameter ( Position = 4 , Mandatory = true , ParameterSetName = ResourceParameterSet , HelpMessage = "Name of the routing endpoint" ) ]
64
+ [ Parameter ( Mandatory = true , ParameterSetName = InputObjectParameterSet , HelpMessage = "Name of the routing endpoint" ) ]
65
+ [ Parameter ( Mandatory = true , ParameterSetName = ResourceIdParameterSet , HelpMessage = "Name of the routing endpoint" ) ]
66
+ [ Parameter ( Mandatory = true , ParameterSetName = ResourceParameterSet , HelpMessage = "Name of the routing endpoint" ) ]
68
67
[ ValidateNotNullOrEmpty ]
69
68
public string EndpointName { get ; set ; }
70
69
@@ -96,26 +95,18 @@ public override void ExecuteCmdlet()
96
95
iotHubDescription = this . IotHubClient . IotHubResource . Get ( this . ResourceGroupName , this . Name ) ;
97
96
}
98
97
99
- PSRoutingSource psRoutingSource ;
100
- if ( Enum . TryParse < PSRoutingSource > ( this . Source , true , out psRoutingSource ) )
101
- {
102
- iotHubDescription . Properties . Routing . Routes . Add (
103
- new RouteProperties (
104
- this . RouteName ,
105
- psRoutingSource . ToString ( ) ,
106
- new List < string > ( ) { this . EndpointName } ,
107
- this . Enabled . IsPresent ,
108
- string . IsNullOrEmpty ( this . Condition ) ? null : this . Condition
109
- ) ) ;
98
+ iotHubDescription . Properties . Routing . Routes . Add (
99
+ new RouteProperties (
100
+ this . RouteName ,
101
+ this . Source . ToString ( ) ,
102
+ new List < string > ( ) { this . EndpointName } ,
103
+ this . Enabled . IsPresent ,
104
+ string . IsNullOrEmpty ( this . Condition ) ? null : this . Condition
105
+ ) ) ;
110
106
111
- this . IotHubClient . IotHubResource . CreateOrUpdate ( this . ResourceGroupName , this . Name , iotHubDescription ) ;
112
- IotHubDescription updatedIotHubDescription = this . IotHubClient . IotHubResource . Get ( this . ResourceGroupName , this . Name ) ;
113
- this . WriteObject ( IotHubUtils . ToPSRouteMetadata ( updatedIotHubDescription . Properties . Routing . Routes . FirstOrDefault ( x => x . Name . Equals ( this . RouteName , StringComparison . OrdinalIgnoreCase ) ) ) , false ) ;
114
- }
115
- else
116
- {
117
- throw new ArgumentException ( "Invalid Routing Source" ) ;
118
- }
107
+ this . IotHubClient . IotHubResource . CreateOrUpdate ( this . ResourceGroupName , this . Name , iotHubDescription ) ;
108
+ IotHubDescription updatedIotHubDescription = this . IotHubClient . IotHubResource . Get ( this . ResourceGroupName , this . Name ) ;
109
+ this . WriteObject ( IotHubUtils . ToPSRouteMetadata ( updatedIotHubDescription . Properties . Routing . Routes . FirstOrDefault ( x => x . Name . Equals ( this . RouteName , StringComparison . OrdinalIgnoreCase ) ) ) , false ) ;
119
110
}
120
111
}
121
112
}
0 commit comments