@@ -181,26 +181,35 @@ public IEnumerable<Runbook> ListRunbooks(string automationAccountName)
181
181
public Runbook CreateRunbookByName ( string automationAccountName , string runbookName , string description ,
182
182
string [ ] tags )
183
183
{
184
- var runbookModel = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
185
- if ( runbookModel != null )
184
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
186
185
{
187
- throw new ResourceCommonException ( typeof ( Runbook ) ,
188
- string . Format ( CultureInfo . CurrentCulture , Resources . RunbookAlreadyExists , runbookName ) ) ;
189
- }
186
+ var runbookModel = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
187
+ if ( runbookModel != null )
188
+ {
189
+ throw new ResourceCommonException ( typeof ( Runbook ) ,
190
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookAlreadyExists , runbookName ) ) ;
191
+ }
190
192
191
- var rdcprop = new RunbookCreateDraftProperties ( )
192
- {
193
- Description = description ,
194
- RunbookType = RunbookTypeEnum . Script ,
195
- Draft = new RunbookDraft ( ) ,
196
- ServiceManagementTags = ( tags != null ) ? string . Join ( Constants . RunbookTagsSeparatorString , tags ) : null
197
- } ;
193
+ var rdcprop = new RunbookCreateDraftProperties ( )
194
+ {
195
+ Description = description ,
196
+ RunbookType = RunbookTypeEnum . Script ,
197
+ Draft = new RunbookDraft ( ) ,
198
+ ServiceManagementTags =
199
+ ( tags != null ) ? string . Join ( Constants . RunbookTagsSeparatorString , tags ) : null
200
+ } ;
198
201
199
- var rdcparam = new RunbookCreateDraftParameters ( ) { Name = runbookName , Properties = rdcprop , Tags = null } ;
202
+ var rdcparam = new RunbookCreateDraftParameters ( )
203
+ {
204
+ Name = runbookName ,
205
+ Properties = rdcprop ,
206
+ Tags = null
207
+ } ;
200
208
201
- this . automationManagementClient . Runbooks . CreateWithDraft ( automationAccountName , rdcparam ) ;
209
+ this . automationManagementClient . Runbooks . CreateWithDraft ( automationAccountName , rdcparam ) ;
202
210
203
- return this . GetRunbook ( automationAccountName , runbookName ) ;
211
+ return this . GetRunbook ( automationAccountName , runbookName ) ;
212
+ }
204
213
}
205
214
206
215
public Runbook CreateRunbookByPath ( string automationAccountName , string runbookPath , string description ,
@@ -209,31 +218,37 @@ public Runbook CreateRunbookByPath(string automationAccountName, string runbookP
209
218
210
219
var runbookName = Path . GetFileNameWithoutExtension ( runbookPath ) ;
211
220
212
- var runbookModel = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
213
- if ( runbookModel != null )
221
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
214
222
{
215
- throw new ResourceCommonException ( typeof ( Runbook ) ,
216
- string . Format ( CultureInfo . CurrentCulture , Resources . RunbookAlreadyExists , runbookName ) ) ;
217
- }
223
+ var runbookModel = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
224
+ if ( runbookModel != null )
225
+ {
226
+ throw new ResourceCommonException ( typeof ( Runbook ) ,
227
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookAlreadyExists , runbookName ) ) ;
228
+ }
218
229
219
- var runbook = this . CreateRunbookByName ( automationAccountName , runbookName , description , tags ) ;
230
+ var runbook = this . CreateRunbookByName ( automationAccountName , runbookName , description , tags ) ;
220
231
221
- var rduprop = new RunbookDraftUpdateParameters ( )
222
- {
223
- Name = runbookName ,
224
- Stream = File . ReadAllText ( runbookPath )
225
- } ;
232
+ var rduprop = new RunbookDraftUpdateParameters ( )
233
+ {
234
+ Name = runbookName ,
235
+ Stream = File . ReadAllText ( runbookPath )
236
+ } ;
226
237
227
- this . automationManagementClient . RunbookDraft . Update ( automationAccountName , rduprop ) ;
238
+ this . automationManagementClient . RunbookDraft . Update ( automationAccountName , rduprop ) ;
228
239
229
- return runbook ;
240
+ return runbook ;
241
+ }
230
242
}
231
243
232
244
public void DeleteRunbook ( string automationAccountName , string runbookName )
233
245
{
234
246
try
235
247
{
236
- this . automationManagementClient . Runbooks . Delete ( automationAccountName , runbookName ) ;
248
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
249
+ {
250
+ this . automationManagementClient . Runbooks . Delete ( automationAccountName , runbookName ) ;
251
+ }
237
252
}
238
253
catch ( CloudException cloudException )
239
254
{
@@ -250,119 +265,153 @@ public void DeleteRunbook(string automationAccountName, string runbookName)
250
265
public Runbook UpdateRunbook ( string automationAccountName , string runbookName , string description ,
251
266
string [ ] tags , bool ? logProgress , bool ? logVerbose )
252
267
{
253
- var runbookModel = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
254
- if ( runbookModel == null )
268
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
255
269
{
256
- throw new ResourceCommonException ( typeof ( Runbook ) ,
257
- string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
258
- }
270
+ var runbookModel = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
271
+ if ( runbookModel == null )
272
+ {
273
+ throw new ResourceCommonException ( typeof ( Runbook ) ,
274
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
275
+ }
259
276
260
- var runbookUpdateParameters = new RunbookUpdateParameters ( ) ;
261
- runbookUpdateParameters . Name = runbookName ;
262
- runbookUpdateParameters . Tags = null ;
277
+ var runbookUpdateParameters = new RunbookUpdateParameters ( ) ;
278
+ runbookUpdateParameters . Name = runbookName ;
279
+ runbookUpdateParameters . Tags = null ;
263
280
264
- runbookUpdateParameters . Properties = new RunbookUpdateProperties ( ) ;
265
- runbookUpdateParameters . Properties . Description = description ?? runbookModel . Properties . Description ;
266
- runbookUpdateParameters . Properties . LogProgress = ( logProgress . HasValue ) ? logProgress . Value : runbookModel . Properties . LogProgress ;
267
- runbookUpdateParameters . Properties . LogVerbose = ( logVerbose . HasValue ) ? logVerbose . Value : runbookModel . Properties . LogVerbose ;
268
- runbookUpdateParameters . Properties . ServiceManagementTags = ( tags != null )
269
- ? string . Join ( Constants . RunbookTagsSeparatorString , tags )
270
- : runbookModel . Properties . ServiceManagementTags ;
281
+ runbookUpdateParameters . Properties = new RunbookUpdateProperties ( ) ;
282
+ runbookUpdateParameters . Properties . Description = description ?? runbookModel . Properties . Description ;
283
+ runbookUpdateParameters . Properties . LogProgress = ( logProgress . HasValue )
284
+ ? logProgress . Value
285
+ : runbookModel . Properties . LogProgress ;
286
+ runbookUpdateParameters . Properties . LogVerbose = ( logVerbose . HasValue )
287
+ ? logVerbose . Value
288
+ : runbookModel . Properties . LogVerbose ;
289
+ runbookUpdateParameters . Properties . ServiceManagementTags = ( tags != null )
290
+ ? string . Join ( Constants . RunbookTagsSeparatorString , tags )
291
+ : runbookModel . Properties . ServiceManagementTags ;
271
292
272
- var runbook = this . automationManagementClient . Runbooks . Update ( automationAccountName , runbookUpdateParameters ) . Runbook ;
293
+ var runbook =
294
+ this . automationManagementClient . Runbooks . Update ( automationAccountName , runbookUpdateParameters )
295
+ . Runbook ;
273
296
274
- return new Runbook ( automationAccountName , runbook ) ;
297
+ return new Runbook ( automationAccountName , runbook ) ;
298
+ }
275
299
}
276
300
277
301
public RunbookDefinition UpdateRunbookDefinition ( string automationAccountName , string runbookName ,
278
302
string runbookPath , bool overwrite )
279
303
{
280
- var runbook = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
281
- if ( runbook == null )
304
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
282
305
{
283
- throw new ResourceNotFoundException ( typeof ( Runbook ) ,
284
- string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
285
- }
306
+ var runbook = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
307
+ if ( runbook == null )
308
+ {
309
+ throw new ResourceNotFoundException ( typeof ( Runbook ) ,
310
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
311
+ }
286
312
287
- if ( ( 0 !=
288
- String . Compare ( runbook . Properties . State , RunbookState . Published , CultureInfo . InvariantCulture ,
289
- CompareOptions . IgnoreCase ) && overwrite == false ) )
290
- {
291
- throw new ResourceCommonException ( typeof ( Runbook ) ,
292
- string . Format ( CultureInfo . CurrentCulture , Resources . RunbookAlreadyHasDraft , runbookName ) ) ;
293
- }
313
+ if ( ( 0 !=
314
+ String . Compare ( runbook . Properties . State , RunbookState . Published , CultureInfo . InvariantCulture ,
315
+ CompareOptions . IgnoreCase ) && overwrite == false ) )
316
+ {
317
+ throw new ResourceCommonException ( typeof ( Runbook ) ,
318
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookAlreadyHasDraft , runbookName ) ) ;
319
+ }
294
320
295
- this . automationManagementClient . RunbookDraft . Update ( automationAccountName ,
296
- new RunbookDraftUpdateParameters { Name = runbookName , Stream = File . ReadAllText ( runbookPath ) } ) ;
321
+ this . automationManagementClient . RunbookDraft . Update ( automationAccountName ,
322
+ new RunbookDraftUpdateParameters { Name = runbookName , Stream = File . ReadAllText ( runbookPath ) } ) ;
297
323
298
- var content =
299
- this . automationManagementClient . RunbookDraft . Content ( automationAccountName , runbookName ) . Stream ;
324
+ var content =
325
+ this . automationManagementClient . RunbookDraft . Content ( automationAccountName , runbookName ) . Stream ;
300
326
301
- return new RunbookDefinition ( automationAccountName , runbook , content , Constants . Draft ) ;
327
+ return new RunbookDefinition ( automationAccountName , runbook , content , Constants . Draft ) ;
328
+ }
302
329
}
303
330
304
331
public IEnumerable < RunbookDefinition > ListRunbookDefinitionsByRunbookName ( string automationAccountName ,
305
332
string runbookName , bool ? isDraft )
306
333
{
307
334
var ret = new List < RunbookDefinition > ( ) ;
308
-
309
- var runbook = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
310
- if ( runbook == null )
335
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
311
336
{
312
- throw new ResourceNotFoundException ( typeof ( Runbook ) ,
313
- string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
314
- }
315
-
316
- var draftContent = String . Empty ;
317
- var publishedContent = String . Empty ;
337
+ var runbook = this . TryGetRunbookModel ( automationAccountName , runbookName ) ;
338
+ if ( runbook == null )
339
+ {
340
+ throw new ResourceNotFoundException ( typeof ( Runbook ) ,
341
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookNotFound , runbookName ) ) ;
342
+ }
318
343
319
- if ( 0 != String . Compare ( runbook . Properties . State , RunbookState . Published , CultureInfo . InvariantCulture , CompareOptions . IgnoreCase ) && ( ! isDraft . HasValue || isDraft . Value ) )
320
- {
321
- draftContent = this . automationManagementClient . RunbookDraft . Content ( automationAccountName , runbookName ) . Stream ;
322
- }
323
- if ( 0 != String . Compare ( runbook . Properties . State , RunbookState . New , CultureInfo . InvariantCulture , CompareOptions . IgnoreCase ) && ( ! isDraft . HasValue || ! isDraft . Value ) )
324
- {
325
- publishedContent = this . automationManagementClient . Runbooks . Content ( automationAccountName , runbookName ) . Stream ;
326
- }
344
+ var draftContent = String . Empty ;
345
+ var publishedContent = String . Empty ;
327
346
328
- // if no slot specified return both draft and publish content
329
- if ( false == isDraft . HasValue )
330
- {
331
- if ( false == String . IsNullOrEmpty ( draftContent ) ) ret . Add ( new RunbookDefinition ( automationAccountName , runbook , draftContent , Constants . Draft ) ) ;
332
- if ( false == String . IsNullOrEmpty ( publishedContent ) ) ret . Add ( new RunbookDefinition ( automationAccountName , runbook , publishedContent , Constants . Published ) ) ;
333
- }
334
- else
335
- {
336
- if ( true == isDraft . Value )
347
+ if ( 0 !=
348
+ String . Compare ( runbook . Properties . State , RunbookState . Published , CultureInfo . InvariantCulture ,
349
+ CompareOptions . IgnoreCase ) && ( ! isDraft . HasValue || isDraft . Value ) )
337
350
{
351
+ draftContent =
352
+ this . automationManagementClient . RunbookDraft . Content ( automationAccountName , runbookName ) . Stream ;
353
+ }
354
+ if ( 0 !=
355
+ String . Compare ( runbook . Properties . State , RunbookState . New , CultureInfo . InvariantCulture ,
356
+ CompareOptions . IgnoreCase ) && ( ! isDraft . HasValue || ! isDraft . Value ) )
357
+ {
358
+ publishedContent =
359
+ this . automationManagementClient . Runbooks . Content ( automationAccountName , runbookName ) . Stream ;
360
+ }
338
361
339
- if ( String . IsNullOrEmpty ( draftContent ) ) throw new ResourceCommonException ( typeof ( Runbook ) ,
340
- string . Format ( CultureInfo . CurrentCulture , Resources . RunbookHasNoDraftVersion , runbookName ) ) ;
341
- if ( false == String . IsNullOrEmpty ( draftContent ) ) ret . Add ( new RunbookDefinition ( automationAccountName , runbook , draftContent , Constants . Draft ) ) ;
362
+ // if no slot specified return both draft and publish content
363
+ if ( false == isDraft . HasValue )
364
+ {
365
+ if ( false == String . IsNullOrEmpty ( draftContent ) )
366
+ ret . Add ( new RunbookDefinition ( automationAccountName , runbook , draftContent , Constants . Draft ) ) ;
367
+ if ( false == String . IsNullOrEmpty ( publishedContent ) )
368
+ ret . Add ( new RunbookDefinition ( automationAccountName , runbook , publishedContent ,
369
+ Constants . Published ) ) ;
342
370
}
343
371
else
344
372
{
345
- if ( String . IsNullOrEmpty ( publishedContent ) ) throw new ResourceCommonException ( typeof ( Runbook ) ,
346
- string . Format ( CultureInfo . CurrentCulture , Resources . RunbookHasNoPublishedVersion , runbookName ) ) ;
373
+ if ( true == isDraft . Value )
374
+ {
347
375
348
- if ( false == String . IsNullOrEmpty ( publishedContent ) ) ret . Add ( new RunbookDefinition ( automationAccountName , runbook , publishedContent , Constants . Published ) ) ;
376
+ if ( String . IsNullOrEmpty ( draftContent ) )
377
+ throw new ResourceCommonException ( typeof ( Runbook ) ,
378
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookHasNoDraftVersion ,
379
+ runbookName ) ) ;
380
+ if ( false == String . IsNullOrEmpty ( draftContent ) )
381
+ ret . Add ( new RunbookDefinition ( automationAccountName , runbook , draftContent , Constants . Draft ) ) ;
382
+ }
383
+ else
384
+ {
385
+ if ( String . IsNullOrEmpty ( publishedContent ) )
386
+ throw new ResourceCommonException ( typeof ( Runbook ) ,
387
+ string . Format ( CultureInfo . CurrentCulture , Resources . RunbookHasNoPublishedVersion ,
388
+ runbookName ) ) ;
389
+
390
+ if ( false == String . IsNullOrEmpty ( publishedContent ) )
391
+ ret . Add ( new RunbookDefinition ( automationAccountName , runbook , publishedContent ,
392
+ Constants . Published ) ) ;
393
+ }
349
394
}
350
- }
351
395
352
- return ret ;
396
+ return ret ;
397
+ }
353
398
}
354
399
355
400
public Runbook PublishRunbook ( string automationAccountName , string runbookName )
356
401
{
357
- this . automationManagementClient . RunbookDraft . Publish (
402
+ using ( var request = new RequestSettings ( this . automationManagementClient ) )
403
+ {
404
+ this . automationManagementClient . RunbookDraft . Publish (
358
405
automationAccountName ,
359
406
new RunbookDraftPublishParameters
360
407
{
361
408
Name = runbookName ,
362
409
PublishedBy = Constants . ClientIdentity
363
410
} ) ;
364
411
365
- return this . GetRunbook ( automationAccountName , runbookName ) ;
412
+ return this . GetRunbook ( automationAccountName , runbookName ) ;
413
+ }
414
+
366
415
}
367
416
368
417
public Job StartRunbook ( string automationAccountName , string runbookName , IDictionary parameters )
0 commit comments