/// <summary> /// Get HttpContent by Registration and Message-Content /// </summary> /// <typeparam name="T">Type of Message-Content</typeparam> /// <param name="register">WebHook-Registration</param> /// <param name="content">WebHook-Content</param> /// <returns></returns> private HttpContent GetContent <T>(WebHookRegistration register, T content) { //get specified content? //e.g. XML, CSV, proprietary format? //default: json return(new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(content), System.Text.Encoding.UTF8, "application/json")); }
/// <summary> /// Create and store a new WebHook-Registration /// </summary> /// <param name="messages">Message-Types</param> /// <param name="secret">Secret</param> /// <param name="callbackUrl">Callback-URL</param> /// <returns></returns> public WebHookRegistration Register(string[] messages, string secret, string callbackUrl) { var existing = _register.FirstOrDefault(r => String.Equals(callbackUrl, r.CallbackUrl, StringComparison.InvariantCultureIgnoreCase)); if (existing != null) { _register.Remove(existing); } var newRegistration = new WebHookRegistration(messages, secret, callbackUrl); _register.Add(newRegistration); Console.WriteLine($"=> WebHook: Got new registration from {callbackUrl}"); return(newRegistration); }