public static GithubRepositoryHook UpdateRepositoryHook(this IGithubServiceManagement proxy, string owner, string repository, string id, GithubRepositoryHook hook)
 {
     return proxy.EndUpdateRepositoryHook(proxy.BeginUpdateRepositoryHook(owner, repository, id, hook, null, null));
 }
        protected void CreateOrUpdateHook(string owner, string repository, Site website)
        {
            string baseUri = website.GetProperty("repositoryuri");
            string publishingUsername = website.GetProperty("publishingusername");
            string publishingPassword = website.GetProperty("publishingpassword");
            UriBuilder newUri = new UriBuilder(baseUri);
            newUri.UserName = publishingUsername;
            newUri.Password = publishingPassword;
            newUri.Path = "/deploy";

            string deployUri = newUri.ToString();

            List<GithubRepositoryHook> repositoryHooks = new List<GithubRepositoryHook>();
            InvokeInGithubOperationContext(() => { repositoryHooks = PSCmdlet.GithubChannel.GetRepositoryHooks(owner, repository); });

            var existingHook = repositoryHooks.FirstOrDefault(h => h.Name.Equals("web") && new Uri(h.Config.Url).Host.Equals(new Uri(deployUri).Host));
            if (existingHook != null)
            {
                if (!existingHook.Config.Url.Equals(newUri.ToString(), StringComparison.InvariantCultureIgnoreCase))
                {
                    existingHook.Config.Url = deployUri;
                    InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.UpdateRepositoryHook(owner, repository, existingHook.Id, existingHook));
                    InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.TestRepositoryHook(owner, repository, existingHook.Id));
                }
                else
                {
                    throw new Exception(Resources.LinkAlreadyEstablished);
                }
            }
            else
            {
                GithubRepositoryHook githubRepositoryHook = new GithubRepositoryHook()
                {
                    Name = "web",
                    Active = true,
                    Events = new List<string> { "push" },
                    Config = new GithubRepositoryHookConfig
                    {
                        Url = deployUri,
                        InsecureSsl = "1",
                        ContentType = "form"
                    }
                };

                InvokeInGithubOperationContext(() => { githubRepositoryHook = PSCmdlet.GithubChannel.CreateRepositoryHook(owner, repository, githubRepositoryHook); });
                InvokeInGithubOperationContext(() => PSCmdlet.GithubChannel.TestRepositoryHook(owner, repository, githubRepositoryHook.Id));
            }  
        }
 public IAsyncResult BeginUpdateRepositoryHook(string owner, string repository, string id, GithubRepositoryHook hook, AsyncCallback callback, object state)
 {
     SimpleServiceManagementAsyncResult result = new SimpleServiceManagementAsyncResult();
     result.Values["owner"] = owner;
     result.Values["repository"] = repository;
     result.Values["id"] = id;
     result.Values["hook"] = hook;
     result.Values["callback"] = callback;
     result.Values["state"] = state;
     return result;
 }