@@ -107,7 +107,7 @@ public void DeleteSchedule(string automationAccountName, string scheduleName)
107
107
}
108
108
catch ( CloudException cloudException )
109
109
{
110
- if ( cloudException . Response . StatusCode == HttpStatusCode . NotFound )
110
+ if ( cloudException . Response . StatusCode == HttpStatusCode . NoContent )
111
111
{
112
112
throw new ResourceNotFoundException ( typeof ( Schedule ) ,
113
113
string . Format ( CultureInfo . CurrentCulture , Resources . ScheduleNotFound , scheduleName ) ) ;
@@ -144,6 +144,8 @@ public Schedule UpdateSchedule(string automationAccountName, string scheduleName
144
144
{
145
145
AutomationManagement . Models . Schedule scheduleModel = this . GetScheduleModel ( automationAccountName ,
146
146
scheduleName ) ;
147
+ isEnabled = ( isEnabled . HasValue ) ? isEnabled : scheduleModel . Properties . IsEnabled ;
148
+ description = description ?? scheduleModel . Properties . Description ; ;
147
149
return this . UpdateScheduleHelper ( automationAccountName , scheduleModel , isEnabled , description ) ;
148
150
}
149
151
@@ -228,7 +230,20 @@ public Runbook CreateRunbookByPath(string automationAccountName, string runbookP
228
230
229
231
public void DeleteRunbook ( string automationAccountName , string runbookName )
230
232
{
231
- this . automationManagementClient . Runbooks . Delete ( automationAccountName , runbookName ) ;
233
+ try
234
+ {
235
+ this . automationManagementClient . Runbooks . Delete ( automationAccountName , runbookName ) ;
236
+ }
237
+ catch ( CloudException cloudException )
238
+ {
239
+ if ( cloudException . Response . StatusCode == HttpStatusCode . NoContent )
240
+ {
241
+ throw new ResourceNotFoundException ( typeof ( Connection ) , string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
242
+ }
243
+
244
+ throw ;
245
+ }
246
+
232
247
}
233
248
234
249
public Runbook UpdateRunbook ( string automationAccountName , string runbookName , string description ,
@@ -249,7 +264,7 @@ public Runbook UpdateRunbook(string automationAccountName, string runbookName, s
249
264
runbookUpdateParameters . Properties = new RunbookUpdateProperties ( ) ;
250
265
runbookUpdateParameters . Properties . Description = description ?? runbookModel . Properties . Description ;
251
266
runbookUpdateParameters . Properties . LogProgress = ( logProgress . HasValue ) ? logProgress . Value : runbookModel . Properties . LogProgress ;
252
- runbookUpdateParameters . Properties . LogVerbose = ( logProgress . HasValue ) ? logProgress . Value : runbookModel . Properties . LogVerbose ;
267
+ runbookUpdateParameters . Properties . LogVerbose = ( logVerbose . HasValue ) ? logVerbose . Value : runbookModel . Properties . LogVerbose ;
253
268
254
269
var runbook = this . automationManagementClient . Runbooks . Update ( automationAccountName , runbookUpdateParameters ) . Runbook ;
255
270
@@ -266,8 +281,8 @@ public RunbookDefinition UpdateRunbookDefinition(string automationAccountName, s
266
281
string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
267
282
}
268
283
269
- if ( ( 0 = =
270
- String . Compare ( runbook . Properties . State , RunbookState . Edit , CultureInfo . InvariantCulture ,
284
+ if ( ( 0 ! =
285
+ String . Compare ( runbook . Properties . State , RunbookState . Published , CultureInfo . InvariantCulture ,
271
286
CompareOptions . IgnoreCase ) && overwrite == false ) )
272
287
{
273
288
throw new ResourceCommonException ( typeof ( Runbook ) ,
@@ -295,19 +310,40 @@ public IEnumerable<RunbookDefinition> ListRunbookDefinitionsByRunbookName(string
295
310
string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
296
311
}
297
312
298
- if ( 0 !=
299
- String . Compare ( runbook . Properties . State , RunbookState . Published , CultureInfo . InvariantCulture ,
300
- CompareOptions . IgnoreCase ) && isDraft != null && isDraft . Value == true )
313
+ var draftContent = String . Empty ;
314
+ var publishedContent = String . Empty ;
315
+
316
+ if ( 0 != String . Compare ( runbook . Properties . State , RunbookState . Published , CultureInfo . InvariantCulture , CompareOptions . IgnoreCase ) )
301
317
{
302
- var draftContent =
303
- this . automationManagementClient . RunbookDraft . Content ( automationAccountName , runbookName ) . Stream ;
304
- ret . Add ( new RunbookDefinition ( automationAccountName , runbook , draftContent , Constants . Draft ) ) ;
318
+ draftContent = this . automationManagementClient . RunbookDraft . Content ( automationAccountName , runbookName ) . Stream ;
305
319
}
306
- else
320
+ if ( 0 != String . Compare ( runbook . Properties . State , RunbookState . New , CultureInfo . InvariantCulture , CompareOptions . IgnoreCase ) )
307
321
{
308
- var publishedContent =
309
- this . automationManagementClient . Runbooks . Content ( automationAccountName , runbookName ) . Stream ;
310
- ret . Add ( new RunbookDefinition ( automationAccountName , runbook , publishedContent , Constants . Published ) ) ;
322
+ publishedContent = this . automationManagementClient . Runbooks . Content ( automationAccountName , runbookName ) . Stream ;
323
+ }
324
+
325
+ // if no slot specified return both draft and publish content
326
+ if ( false == isDraft . HasValue )
327
+ {
328
+ if ( false == String . IsNullOrEmpty ( draftContent ) ) ret . Add ( new RunbookDefinition ( automationAccountName , runbook , draftContent , Constants . Draft ) ) ;
329
+ if ( false == String . IsNullOrEmpty ( publishedContent ) ) ret . Add ( new RunbookDefinition ( automationAccountName , runbook , publishedContent , Constants . Published ) ) ;
330
+ }
331
+ else
332
+ {
333
+ if ( isDraft . Value == true )
334
+ {
335
+
336
+ if ( String . IsNullOrEmpty ( draftContent ) ) throw new ResourceCommonException ( typeof ( Runbook ) ,
337
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookHasNoDraftVersion , runbookName ) ) ;
338
+ if ( false == String . IsNullOrEmpty ( draftContent ) ) ret . Add ( new RunbookDefinition ( automationAccountName , runbook , draftContent , Constants . Draft ) ) ;
339
+ }
340
+ else
341
+ {
342
+ if ( String . IsNullOrEmpty ( publishedContent ) ) throw new ResourceCommonException ( typeof ( Runbook ) ,
343
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookHasNoPublishedVersion , runbookName ) ) ;
344
+
345
+ if ( false == String . IsNullOrEmpty ( publishedContent ) ) ret . Add ( new RunbookDefinition ( automationAccountName , runbook , publishedContent , Constants . Published ) ) ;
346
+ }
311
347
}
312
348
313
349
return ret ;
@@ -421,10 +457,15 @@ public void DeleteVariable(string automationAccountName, string variableName)
421
457
this . automationManagementClient . Variables . Delete ( automationAccountName , variableName ) ;
422
458
}
423
459
}
424
- catch ( ResourceNotFoundException )
460
+ catch ( CloudException cloudException )
425
461
{
426
- // the variable does not exists or already deleted. Do nothing. Return.
427
- return ;
462
+ if ( cloudException . Response . StatusCode == HttpStatusCode . NoContent )
463
+ {
464
+ throw new ResourceNotFoundException ( typeof ( Variable ) ,
465
+ string . Format ( CultureInfo . CurrentCulture , Resources . VariableNotFound , variableName ) ) ;
466
+ }
467
+
468
+ throw ;
428
469
}
429
470
}
430
471
@@ -583,10 +624,11 @@ public CredentialInfo CreateCredential(string automationAccountName, string name
583
624
public CredentialInfo UpdateCredential ( string automationAccountName , string name , string userName , string password ,
584
625
string description )
585
626
{
627
+ var exisitngCredential = this . GetCredential ( automationAccountName , name ) ;
586
628
var credentialUpdateParams = new AutomationManagement . Models . CredentialUpdateParameters ( ) ;
587
629
credentialUpdateParams . Name = name ;
588
630
credentialUpdateParams . Properties = new AutomationManagement . Models . CredentialUpdateProperties ( ) ;
589
- if ( description != null ) credentialUpdateParams . Properties . Description = description ;
631
+ credentialUpdateParams . Properties . Description = description ?? exisitngCredential . Description ;
590
632
591
633
credentialUpdateParams . Properties . UserName = userName ;
592
634
credentialUpdateParams . Properties . Password = password ;
@@ -647,7 +689,7 @@ public void DeleteCredential(string automationAccountName, string name)
647
689
{
648
690
if ( cloudException . Response . StatusCode == HttpStatusCode . NotFound )
649
691
{
650
- throw new ResourceNotFoundException ( typeof ( Schedule ) , string . Format ( CultureInfo . CurrentCulture , Resources . CredentialNotFound , name ) ) ;
692
+ throw new ResourceNotFoundException ( typeof ( Credential ) , string . Format ( CultureInfo . CurrentCulture , Resources . CredentialNotFound , name ) ) ;
651
693
}
652
694
653
695
throw ;
@@ -757,9 +799,9 @@ public void DeleteModule(string automationAccountName, string name)
757
799
}
758
800
catch ( CloudException cloudException )
759
801
{
760
- if ( cloudException . Response . StatusCode == HttpStatusCode . NotFound )
802
+ if ( cloudException . Response . StatusCode == HttpStatusCode . NoContent )
761
803
{
762
- throw new ResourceNotFoundException ( typeof ( Schedule ) , string . Format ( CultureInfo . CurrentCulture , Resources . ModuleNotFound , name ) ) ;
804
+ throw new ResourceNotFoundException ( typeof ( Module ) , string . Format ( CultureInfo . CurrentCulture , Resources . ModuleNotFound , name ) ) ;
763
805
}
764
806
765
807
throw ;
@@ -1129,7 +1171,19 @@ public IEnumerable<CertificateInfo> ListCertificates(string automationAccountNam
1129
1171
1130
1172
public void DeleteCertificate ( string automationAccountName , string name )
1131
1173
{
1132
- this . automationManagementClient . Certificates . Delete ( automationAccountName , name ) ;
1174
+ try
1175
+ {
1176
+ this . automationManagementClient . Certificates . Delete ( automationAccountName , name ) ;
1177
+ }
1178
+ catch ( CloudException cloudException )
1179
+ {
1180
+ if ( cloudException . Response . StatusCode == HttpStatusCode . NoContent )
1181
+ {
1182
+ throw new ResourceNotFoundException ( typeof ( Schedule ) , string . Format ( CultureInfo . CurrentCulture , Resources . CertificateNotFound , name ) ) ;
1183
+ }
1184
+
1185
+ throw ;
1186
+ }
1133
1187
}
1134
1188
1135
1189
#endregion
@@ -1230,7 +1284,19 @@ public IEnumerable<Connection> ListConnections(string automationAccountName)
1230
1284
1231
1285
public void DeleteConnection ( string automationAccountName , string name )
1232
1286
{
1233
- this . automationManagementClient . Connections . Delete ( automationAccountName , name ) ;
1287
+ try
1288
+ {
1289
+ this . automationManagementClient . Connections . Delete ( automationAccountName , name ) ;
1290
+ }
1291
+ catch ( CloudException cloudException )
1292
+ {
1293
+ if ( cloudException . Response . StatusCode == HttpStatusCode . NoContent )
1294
+ {
1295
+ throw new ResourceNotFoundException ( typeof ( Connection ) , string . Format ( CultureInfo . CurrentCulture , Resources . ConnectionNotFound , name ) ) ;
1296
+ }
1297
+
1298
+ throw ;
1299
+ }
1234
1300
}
1235
1301
1236
1302
#endregion
0 commit comments