@@ -67,23 +67,6 @@ public Model.SourceControl CreateSourceControl(
67
67
Requires . Argument ( "branch" , branch ) . NotNullOrEmpty ( ) ;
68
68
}
69
69
70
- bool sourceControlExists = true ;
71
-
72
- try
73
- {
74
- this . GetSourceControl ( resourceGroupName , automationAccountName , name ) ;
75
- }
76
- catch ( ResourceNotFoundException )
77
- {
78
- sourceControlExists = false ;
79
- }
80
-
81
- if ( sourceControlExists )
82
- {
83
- throw new AzureAutomationOperationException (
84
- string . Format ( CultureInfo . CurrentCulture , Resources . SourceControlAlreadyExists , name ) ) ;
85
- }
86
-
87
70
var decryptedAccessToken = Utils . GetStringFromSecureString ( accessToken ) ;
88
71
89
72
var createParams = new SourceControlCreateOrUpdateParameters (
@@ -102,7 +85,14 @@ public Model.SourceControl CreateSourceControl(
102
85
name ,
103
86
createParams ) ;
104
87
105
- return new Model . SourceControl ( sdkSourceControl , automationAccountName , resourceGroupName ) ;
88
+ Model . SourceControl result = null ;
89
+
90
+ if ( sdkSourceControl != null )
91
+ {
92
+ result = new Model . SourceControl ( sdkSourceControl , automationAccountName , resourceGroupName ) ;
93
+ }
94
+
95
+ return result ;
106
96
}
107
97
108
98
public Model . SourceControl UpdateSourceControl (
@@ -119,17 +109,6 @@ public Model.SourceControl UpdateSourceControl(
119
109
Requires . Argument ( "ResourceGroupName" , resourceGroupName ) . NotNullOrEmpty ( ) ;
120
110
Requires . Argument ( "AutomationAccountName" , automationAccountName ) . NotNullOrEmpty ( ) ;
121
111
Requires . Argument ( "name" , name ) . NotNullOrEmpty ( ) ;
122
-
123
- Model . SourceControl existingSourceControl = null ;
124
- try
125
- {
126
- existingSourceControl = this . GetSourceControl ( resourceGroupName , automationAccountName , name ) ;
127
- }
128
- catch ( ResourceNotFoundException )
129
- {
130
- throw new AzureAutomationOperationException (
131
- string . Format ( CultureInfo . CurrentCulture , Resources . SourceControlNotFound , name ) ) ;
132
- }
133
112
134
113
var updateParams = new AutomationManagement . Models . SourceControlUpdateParameters ( ) ;
135
114
@@ -170,7 +149,14 @@ public Model.SourceControl UpdateSourceControl(
170
149
name ,
171
150
updateParams ) ;
172
151
173
- return new Model . SourceControl ( sdkSourceControl , automationAccountName , resourceGroupName ) ;
152
+ Model . SourceControl result = null ;
153
+
154
+ if ( sdkSourceControl != null )
155
+ {
156
+ result = new Model . SourceControl ( sdkSourceControl , automationAccountName , resourceGroupName ) ;
157
+ }
158
+
159
+ return result ;
174
160
}
175
161
176
162
public void DeleteSourceControl (
@@ -182,20 +168,7 @@ public void DeleteSourceControl(
182
168
Requires . Argument ( "automationAccountName" , automationAccountName ) . NotNullOrEmpty ( ) ;
183
169
Requires . Argument ( "name" , name ) . NotNullOrEmpty ( ) ;
184
170
185
- try
186
- {
187
- this . automationManagementClient . SourceControl . Delete ( resourceGroupName , automationAccountName , name ) ;
188
- }
189
- catch ( CloudException cloudException )
190
- {
191
- if ( cloudException . Response . StatusCode == System . Net . HttpStatusCode . NoContent )
192
- {
193
- throw new ResourceNotFoundException ( typeof ( SourceControl ) ,
194
- string . Format ( CultureInfo . CurrentCulture , Resources . SourceControlNotFound , name ) ) ;
195
- }
196
-
197
- throw ;
198
- }
171
+ this . automationManagementClient . SourceControl . Delete ( resourceGroupName , automationAccountName , name ) ;
199
172
}
200
173
201
174
public Model . SourceControl GetSourceControl (
@@ -207,39 +180,16 @@ public Model.SourceControl GetSourceControl(
207
180
Requires . Argument ( "automationAccountName" , automationAccountName ) . NotNullOrEmpty ( ) ;
208
181
Requires . Argument ( "name" , name ) . NotNullOrEmpty ( ) ;
209
182
210
- Model . SourceControl result = null ;
211
- bool throwException = false ;
212
-
213
- try
214
- {
215
- var existingSourceControl = this . automationManagementClient . SourceControl . Get (
216
- resourceGroupName ,
217
- automationAccountName ,
218
- name ) ;
183
+ var existingSourceControl = this . automationManagementClient . SourceControl . Get (
184
+ resourceGroupName ,
185
+ automationAccountName ,
186
+ name ) ;
219
187
220
- if ( existingSourceControl != null )
221
- {
222
- result = new Model . SourceControl ( existingSourceControl , automationAccountName , resourceGroupName ) ;
223
- }
224
- else
225
- {
226
- throwException = true ;
227
- }
228
- }
229
- catch ( Exception ex )
230
- {
231
- if ( ex is CloudException || ex is ErrorResponseException )
232
- {
233
- throwException = true ;
234
- }
235
- else
236
- throw ;
237
- }
188
+ Model . SourceControl result = null ;
238
189
239
- if ( throwException )
190
+ if ( existingSourceControl != null )
240
191
{
241
- throw new ResourceNotFoundException ( typeof ( SourceControl ) ,
242
- string . Format ( CultureInfo . CurrentCulture , Resources . SourceControlNotFound , name ) ) ;
192
+ result = new Model . SourceControl ( existingSourceControl , automationAccountName , resourceGroupName ) ;
243
193
}
244
194
245
195
return result ;
@@ -283,30 +233,21 @@ public Model.SourceControlSyncJob StartSourceControlSyncJob(
283
233
Requires . Argument ( "sourceControlName" , sourceControlName ) . NotNullOrEmpty ( ) ;
284
234
Requires . Argument ( "syncJobId" , syncJobId ) . NotNullOrEmpty ( ) ;
285
235
286
- bool syncJobExists = true ;
287
- try
288
- {
289
- this . GetSourceControlSyncJob ( resourceGroupName , automationAccountName , sourceControlName , syncJobId ) ;
290
- }
291
- catch ( ResourceNotFoundException )
292
- {
293
- syncJobExists = false ;
294
- }
295
-
296
- if ( syncJobExists )
297
- {
298
- throw new AzureAutomationOperationException (
299
- string . Format ( CultureInfo . CurrentCulture , Resources . SourceControlSyncJobAlreadyExist , syncJobId . ToString ( ) ) ) ;
300
- }
301
-
302
236
var sdkSyncJob = this . automationManagementClient . SourceControlSyncJob . Create (
303
237
resourceGroupName ,
304
238
automationAccountName ,
305
239
sourceControlName ,
306
240
syncJobId ,
307
241
new SourceControlSyncJobCreateParameters ( "" ) ) ;
308
242
309
- return new Model . SourceControlSyncJob ( resourceGroupName , automationAccountName , sourceControlName , sdkSyncJob ) ;
243
+ Model . SourceControlSyncJob result = null ;
244
+
245
+ if ( sdkSyncJob != null )
246
+ {
247
+ result = new Model . SourceControlSyncJob ( resourceGroupName , automationAccountName , sourceControlName , sdkSyncJob ) ;
248
+ }
249
+
250
+ return result ;
310
251
}
311
252
312
253
public Model . SourceControlSyncJobRecord GetSourceControlSyncJob (
@@ -320,25 +261,17 @@ public Model.SourceControlSyncJobRecord GetSourceControlSyncJob(
320
261
Requires . Argument ( "sourceControlName" , sourceControlName ) . NotNullOrEmpty ( ) ;
321
262
Requires . Argument ( "syncJobId" , syncJobId ) . NotNullOrEmpty ( ) ;
322
263
323
- Model . SourceControlSyncJobRecord result = null ;
324
-
325
- try
326
- {
327
- var existingSyncJob = this . automationManagementClient . SourceControlSyncJob . Get (
264
+ var existingSyncJob = this . automationManagementClient . SourceControlSyncJob . Get (
328
265
resourceGroupName ,
329
266
automationAccountName ,
330
267
sourceControlName ,
331
268
syncJobId ) ;
332
269
333
- if ( existingSyncJob != null )
334
- {
335
- result = new Model . SourceControlSyncJobRecord ( resourceGroupName , automationAccountName , sourceControlName , existingSyncJob ) ;
336
- }
337
- }
338
- catch ( ErrorResponseException )
270
+ Model . SourceControlSyncJobRecord result = null ;
271
+
272
+ if ( existingSyncJob != null )
339
273
{
340
- throw new ResourceNotFoundException ( typeof ( SourceControl ) ,
341
- string . Format ( CultureInfo . CurrentCulture , Resources . SourceControlSyncJobNotFound , syncJobId . ToString ( ) ) ) ;
274
+ result = new Model . SourceControlSyncJobRecord ( resourceGroupName , automationAccountName , sourceControlName , existingSyncJob ) ;
342
275
}
343
276
344
277
return result ;
@@ -354,7 +287,6 @@ public Model.SourceControlSyncJobRecord GetSourceControlSyncJob(
354
287
Requires . Argument ( "automationAccountName" , automationAccountName ) . NotNullOrEmpty ( ) ;
355
288
Requires . Argument ( "sourceControlName" , sourceControlName ) . NotNullOrEmpty ( ) ;
356
289
357
- // SourceControlListResponse comes from metadata.
358
290
Rest . Azure . IPage < AutomationManagement . Models . SourceControlSyncJob > response ;
359
291
360
292
if ( string . IsNullOrEmpty ( nextLink ) )
@@ -406,7 +338,7 @@ public Model.SourceControlSyncJobRecord GetSourceControlSyncJob(
406
338
407
339
nextLink = response . NextPageLink ;
408
340
409
- return response . Select (
341
+ return response . Select (
410
342
stream => new Model . SourceControlSyncJobStream ( stream , resourceGroupName , automationAccountName , sourceControlName , syncJobId ) ) ;
411
343
}
412
344
@@ -430,8 +362,15 @@ public SourceControlSyncJobStreamRecord GetSourceControlSyncJobStreamRecord(
430
362
syncJobId ,
431
363
syncJobStreamId ) ;
432
364
433
- return new SourceControlSyncJobStreamRecord (
434
- response , resourceGroupName , automationAccountName , sourceControlName , syncJobId ) ;
365
+ SourceControlSyncJobStreamRecord result = null ;
366
+
367
+ if ( response != null )
368
+ {
369
+ result = new SourceControlSyncJobStreamRecord (
370
+ response , resourceGroupName , automationAccountName , sourceControlName , syncJobId ) ;
371
+ }
372
+
373
+ return result ;
435
374
}
436
375
437
376
#region private helper functions
0 commit comments