/// <summary>
 /// Create the webhook identified by webhook name.  (see
 /// http://aka.ms/azureautomationsdk/webhookoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IWebhookOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The create or update parameters for webhook.
 /// </param>
 /// <returns>
 /// The response model for the create or update webhook operation.
 /// </returns>
 public static WebhookCreateOrUpdateResponse CreateOrUpdate(this IWebhookOperations operations, string resourceGroupName, string automationAccount, WebhookCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IWebhookOperations)s).CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public Model.Webhook CreateWebhook(
            string resourceGroupName,
            string automationAccountName,
            string name,
            string runbookName,
            bool isEnabled,
            DateTimeOffset expiryTime,
            Hashtable runbookParameters)
        {
            Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
            Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
            using (var request = new RequestSettings(this.automationManagementClient))
            {
                var rbAssociationProperty = new RunbookAssociationProperty { Name = runbookName };
                var createOrUpdateProperties = new WebhookCreateOrUpdateProperties
                                                   {
                                                       IsEnabled = isEnabled,
                                                       ExpiryTime = expiryTime,
                                                       Runbook = rbAssociationProperty,
                                                       Uri =
                                                           this.automationManagementClient
                                                           .Webhooks.GenerateUri(
                                                               resourceGroupName,
                                                               automationAccountName).Uri
                                                   };
                if (runbookParameters != null)
                {
                    createOrUpdateProperties.Parameters =
                        runbookParameters.Cast<DictionaryEntry>()
                            .ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
                }

                var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters(
                    name,
                    createOrUpdateProperties);

                var webhook =
                    this.automationManagementClient.Webhooks.CreateOrUpdate(
                        resourceGroupName,
                        automationAccountName,
                        webhookCreateOrUpdateParameters).Webhook;

                return new Model.Webhook(
                    resourceGroupName,
                    automationAccountName,
                    webhook,
                    webhookCreateOrUpdateParameters.Properties.Uri);
            }
        }
 /// <summary>
 /// Create the webhook identified by webhook name.  (see
 /// http://aka.ms/azureautomationsdk/webhookoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IWebhookOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The create or update parameters for webhook.
 /// </param>
 /// <returns>
 /// The response model for the create or update webhook operation.
 /// </returns>
 public static Task<WebhookCreateOrUpdateResponse> CreateOrUpdateAsync(this IWebhookOperations operations, string resourceGroupName, string automationAccount, WebhookCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None);
 }