@@ -41,62 +41,76 @@ public Model.Webhook CreateWebhook(
41
41
{
42
42
Requires . Argument ( "ResourceGroupName" , resourceGroupName ) . NotNull ( ) ;
43
43
Requires . Argument ( "AutomationAccountName" , automationAccountName ) . NotNull ( ) ;
44
- var rbAssociationProperty = new RunbookAssociationProperty { Name = runbookName } ;
45
-
46
- var createOrUpdateProperties = new WebhookCreateOrUpdateProperties
47
- {
48
- IsEnabled = isEnabled ,
49
- ExpiryTime = expiryTime ,
50
- Runbook = rbAssociationProperty ,
51
- Uri =
52
- this . automationManagementClient
53
- . Webhooks . GenerateUri (
54
- resourceGroupName ,
55
- automationAccountName ) . Uri
56
- } ;
57
- if ( runbookParameters != null )
44
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
58
45
{
59
- createOrUpdateProperties . Parameters =
60
- runbookParameters . Cast < DictionaryEntry > ( )
61
- . ToDictionary ( kvp => ( string ) kvp . Key , kvp => ( string ) kvp . Value ) ;
62
- }
46
+ var rbAssociationProperty = new RunbookAssociationProperty { Name = runbookName } ;
47
+ var createOrUpdateProperties = new WebhookCreateOrUpdateProperties
48
+ {
49
+ IsEnabled = isEnabled ,
50
+ ExpiryTime = expiryTime ,
51
+ Runbook = rbAssociationProperty ,
52
+ Uri =
53
+ this . automationManagementClient
54
+ . Webhooks . GenerateUri (
55
+ resourceGroupName ,
56
+ automationAccountName ) . Uri
57
+ } ;
58
+ if ( runbookParameters != null )
59
+ {
60
+ createOrUpdateProperties . Parameters =
61
+ runbookParameters . Cast < DictionaryEntry > ( )
62
+ . ToDictionary ( kvp => ( string ) kvp . Key , kvp => ( string ) kvp . Value ) ;
63
+ }
64
+
65
+ var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters (
66
+ name ,
67
+ createOrUpdateProperties ) ;
63
68
64
- var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters ( name , createOrUpdateProperties ) ;
65
-
66
- var webhook = this . automationManagementClient . Webhooks . CreateOrUpdate (
67
- resourceGroupName ,
68
- automationAccountName ,
69
- webhookCreateOrUpdateParameters ) . Webhook ;
69
+ var webhook =
70
+ this . automationManagementClient . Webhooks . CreateOrUpdate (
71
+ resourceGroupName ,
72
+ automationAccountName ,
73
+ webhookCreateOrUpdateParameters ) . Webhook ;
70
74
71
- return new Model . Webhook ( resourceGroupName , automationAccountName , webhook , webhookCreateOrUpdateParameters . Properties . Uri ) ;
75
+ return new Model . Webhook (
76
+ resourceGroupName ,
77
+ automationAccountName ,
78
+ webhook ,
79
+ webhookCreateOrUpdateParameters . Properties . Uri ) ;
80
+ }
72
81
}
73
82
74
83
public Model . Webhook GetWebhook ( string resourceGroupName , string automationAccountName , string name )
75
84
{
76
85
Requires . Argument ( "ResourceGroupName" , resourceGroupName ) . NotNull ( ) ;
77
86
Requires . Argument ( "AutomationAccountName" , automationAccountName ) . NotNull ( ) ;
78
-
79
- try
87
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
80
88
{
81
- var webhook =
82
- this . automationManagementClient . Webhooks . Get ( resourceGroupName , automationAccountName , name ) . Webhook ;
83
- if ( webhook == null )
89
+ try
84
90
{
85
- throw new ResourceNotFoundException ( typeof ( Webhook ) ,
86
- string . Format ( CultureInfo . CurrentCulture , Resources . WebhookNotFound , name ) ) ;
87
- }
91
+ var webhook =
92
+ this . automationManagementClient . Webhooks . Get ( resourceGroupName , automationAccountName , name )
93
+ . Webhook ;
94
+ if ( webhook == null )
95
+ {
96
+ throw new ResourceNotFoundException (
97
+ typeof ( Webhook ) ,
98
+ string . Format ( CultureInfo . CurrentCulture , Resources . WebhookNotFound , name ) ) ;
99
+ }
88
100
89
- return new Model . Webhook ( resourceGroupName , automationAccountName , webhook ) ;
90
- }
91
- catch ( CloudException cloudException )
92
- {
93
- if ( cloudException . Response . StatusCode == HttpStatusCode . NotFound )
94
- {
95
- throw new ResourceNotFoundException ( typeof ( Webhook ) ,
96
- string . Format ( CultureInfo . CurrentCulture , Resources . WebhookNotFound , name ) ) ;
101
+ return new Model . Webhook ( resourceGroupName , automationAccountName , webhook ) ;
97
102
}
103
+ catch ( CloudException cloudException )
104
+ {
105
+ if ( cloudException . Response . StatusCode == HttpStatusCode . NotFound )
106
+ {
107
+ throw new ResourceNotFoundException (
108
+ typeof ( Webhook ) ,
109
+ string . Format ( CultureInfo . CurrentCulture , Resources . WebhookNotFound , name ) ) ;
110
+ }
98
111
99
- throw ;
112
+ throw ;
113
+ }
100
114
}
101
115
}
102
116
@@ -105,30 +119,35 @@ public Model.Webhook GetWebhook(string resourceGroupName, string automationAccou
105
119
Requires . Argument ( "ResourceGroupName" , resourceGroupName ) . NotNull ( ) ;
106
120
Requires . Argument ( "AutomationAccountName" , automationAccountName ) . NotNull ( ) ;
107
121
WebhookListResponse response ;
108
-
109
- if ( string . IsNullOrEmpty ( nextLink ) )
122
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
110
123
{
111
- if ( runbookName == null )
124
+ if ( string . IsNullOrEmpty ( nextLink ) )
112
125
{
113
- response = this . automationManagementClient . Webhooks . List (
114
- resourceGroupName ,
115
- automationAccountName ,
116
- null ) ;
126
+ if ( runbookName == null )
127
+ {
128
+ response = this . automationManagementClient . Webhooks . List (
129
+ resourceGroupName ,
130
+ automationAccountName ,
131
+ null ) ;
132
+ }
133
+ else
134
+ {
135
+ response = this . automationManagementClient . Webhooks . List (
136
+ resourceGroupName ,
137
+ automationAccountName ,
138
+ runbookName ) ;
139
+ }
117
140
}
118
141
else
119
142
{
120
- response = this . automationManagementClient . Webhooks . List (
121
- resourceGroupName ,
122
- automationAccountName ,
123
- runbookName ) ;
143
+ response = this . automationManagementClient . Webhooks . ListNext ( nextLink ) ;
124
144
}
145
+
146
+ nextLink = response . NextLink ;
147
+ return
148
+ response . Webhooks . Select ( w => new Model . Webhook ( resourceGroupName , automationAccountName , w ) )
149
+ . ToList ( ) ;
125
150
}
126
- else
127
- {
128
- response = this . automationManagementClient . Webhooks . ListNext ( nextLink ) ;
129
- }
130
- nextLink = response . NextLink ;
131
- return response . Webhooks . Select ( w => new Model . Webhook ( resourceGroupName , automationAccountName , w ) ) . ToList ( ) ;
132
151
}
133
152
134
153
public Model . Webhook UpdateWebhook (
@@ -140,46 +159,56 @@ public Model.Webhook UpdateWebhook(
140
159
{
141
160
Requires . Argument ( "ResourceGroupName" , resourceGroupName ) . NotNull ( ) ;
142
161
Requires . Argument ( "AutomationAccountName" , automationAccountName ) . NotNull ( ) ;
143
- var webhookModel = this . automationManagementClient . Webhooks . Get ( resourceGroupName , automationAccountName , name ) . Webhook ;
144
- var webhookPatchProperties = new WebhookPatchProperties ( ) ;
145
- if ( webhookModel != null )
162
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
146
163
{
147
- if ( isEnabled != null )
164
+ var webhookModel =
165
+ this . automationManagementClient . Webhooks . Get ( resourceGroupName , automationAccountName , name ) . Webhook ;
166
+ var webhookPatchProperties = new WebhookPatchProperties ( ) ;
167
+ if ( webhookModel != null )
148
168
{
149
- webhookPatchProperties . IsEnabled = isEnabled . Value ;
150
- }
151
- if ( parameters != null )
152
- {
153
- webhookPatchProperties . Parameters =
154
- parameters . Cast < DictionaryEntry > ( )
155
- . ToDictionary ( kvp => ( string ) kvp . Key , kvp => ( string ) kvp . Value ) ;
169
+ if ( isEnabled != null )
170
+ {
171
+ webhookPatchProperties . IsEnabled = isEnabled . Value ;
172
+ }
173
+ if ( parameters != null )
174
+ {
175
+ webhookPatchProperties . Parameters =
176
+ parameters . Cast < DictionaryEntry > ( )
177
+ . ToDictionary ( kvp => ( string ) kvp . Key , kvp => ( string ) kvp . Value ) ;
178
+ }
156
179
}
180
+
181
+ var webhookPatchParameters = new WebhookPatchParameters ( name ) { Properties = webhookPatchProperties } ;
182
+ var webhook =
183
+ this . automationManagementClient . Webhooks . Patch (
184
+ resourceGroupName ,
185
+ automationAccountName ,
186
+ webhookPatchParameters ) . Webhook ;
187
+
188
+ return new Model . Webhook ( resourceGroupName , automationAccountName , webhook ) ;
157
189
}
158
-
159
- var webhookPatchParameters = new WebhookPatchParameters ( name ) { Properties = webhookPatchProperties } ;
160
- var webhook =
161
- this . automationManagementClient . Webhooks . Patch (
162
- resourceGroupName ,
163
- automationAccountName ,
164
- webhookPatchParameters ) . Webhook ;
165
- return new Model . Webhook ( resourceGroupName , automationAccountName , webhook ) ;
166
190
}
167
191
168
192
public void DeleteWebhook ( string resourceGroupName , string automationAccountName , string name )
169
193
{
170
194
Requires . Argument ( "ResourceGroupName" , resourceGroupName ) . NotNull ( ) ;
171
195
Requires . Argument ( "AutomationAccountName" , automationAccountName ) . NotNull ( ) ;
172
- try
173
- {
174
- this . automationManagementClient . Webhooks . Delete ( resourceGroupName , automationAccountName , name ) ;
175
- }
176
- catch ( CloudException cloudException )
196
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
177
197
{
178
- if ( cloudException . Response . StatusCode == HttpStatusCode . NoContent )
198
+ try
199
+ {
200
+ this . automationManagementClient . Webhooks . Delete ( resourceGroupName , automationAccountName , name ) ;
201
+ }
202
+ catch ( CloudException cloudException )
179
203
{
180
- throw new ResourceNotFoundException ( typeof ( Webhook ) , string . Format ( CultureInfo . CurrentCulture , Resources . WebhookNotFound , name ) ) ;
204
+ if ( cloudException . Response . StatusCode == HttpStatusCode . NoContent )
205
+ {
206
+ throw new ResourceNotFoundException (
207
+ typeof ( Webhook ) ,
208
+ string . Format ( CultureInfo . CurrentCulture , Resources . WebhookNotFound , name ) ) ;
209
+ }
210
+ throw ;
181
211
}
182
- throw ;
183
212
}
184
213
}
185
214
}
0 commit comments