/// <summary>
 /// Create the runbook identified by runbook name.  (see
 /// http://aka.ms/azureautomationsdk/runbookoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Automation.IRunbookOperations.
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The create parameters for runbook.
 /// </param>
 /// <returns>
 /// The response model for the runbook create response.
 /// </returns>
 public static RunbookCreateResponse CreateWithDraft(this IRunbookOperations operations, string automationAccount, RunbookCreateDraftParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IRunbookOperations)s).CreateWithDraftAsync(automationAccount, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Create the runbook identified by runbook name.  (see
 /// http://aka.ms/azureautomationsdk/runbookoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.Automation.IRunbookOperations.
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The create parameters for runbook.
 /// </param>
 /// <returns>
 /// The response model for the runbook create response.
 /// </returns>
 public static Task<RunbookCreateResponse> CreateWithDraftAsync(this IRunbookOperations operations, string automationAccount, RunbookCreateDraftParameters parameters)
 {
     return operations.CreateWithDraftAsync(automationAccount, parameters, CancellationToken.None);
 }
        public Runbook CreateRunbookByName(string automationAccountName, string runbookName, string description,
            string[] tags)
        {
            using (var request = new RequestSettings(this.automationManagementClient))
            {
                var runbookModel = this.TryGetRunbookModel(automationAccountName, runbookName);
                if (runbookModel != null)
                {
                    throw new ResourceCommonException(typeof (Runbook),
                        string.Format(CultureInfo.CurrentCulture, Resources.RunbookAlreadyExists, runbookName));
                }

                var rdcprop = new RunbookCreateDraftProperties()
                {
                    Description = description,
                    RunbookType = RunbookTypeEnum.Script,
                    Draft = new RunbookDraft(),
                    ServiceManagementTags =
                        (tags != null) ? string.Join(Constants.RunbookTagsSeparatorString, tags) : null
                };

                var rdcparam = new RunbookCreateDraftParameters()
                {
                    Name = runbookName,
                    Properties = rdcprop,
                    Tags = null
                };

                this.automationManagementClient.Runbooks.CreateWithDraft(automationAccountName, rdcparam);

                return this.GetRunbook(automationAccountName, runbookName);
           }
        }