Exemplo n.º 1
0
        /// <summary>
        /// Creates a <see cref="JObject"/> used as the <see cref="HttpRequestMessage"/> entity body for a <see cref="WebHook"/>.
        /// </summary>
        /// <param name="workItem">The <see cref="WebHookWorkItem"/> representing the data to be sent.</param>
        /// <returns>An initialized <see cref="JObject"/>.</returns>
        protected virtual JObject CreateWebHookRequestBody(WebHookWorkItem workItem)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException(nameof(workItem));
            }

            // Set notifications
            var webhookBody = new WebhookBody
            {
                Id      = workItem.Id,
                Attempt = workItem.Offset + 1,
            };
            var properties = workItem.WebHook.Properties;

            if (properties != null)
            {
                webhookBody.Properties = new Dictionary <string, object>(properties);
            }
            webhookBody.Notifications = workItem.Notifications.ToArray();

            var serializer = _settings.Settings != null?JsonSerializer.Create(_settings.Settings) : JsonSerializer.CreateDefault();

            serializer.Converters.Add(new NotificationDictionarySerializer());
            return(JObject.FromObject(webhookBody, serializer));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="JObject"/> used as the <see cref="HttpRequestMessage"/> entity body for a <see cref="WebHook"/>.
        /// </summary>
        /// <param name="workItem">The <see cref="WebHookWorkItem"/> representing the data to be sent.</param>
        /// <returns>An initialized <see cref="JObject"/>.</returns>
        protected virtual void CreateWebHookRequestBody(WebHookWorkItem workItem, StreamWriter writer)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException(nameof(workItem));
            }

            // Set notifications
            var webhookBody = new WebhookBody
            {
                Id      = workItem.Id,
                Attempt = workItem.Offset + 1,
            };
            var properties = workItem.WebHook.Properties;

            if (properties != null)
            {
                webhookBody.Properties = new Dictionary <string, object>(properties);
            }
            webhookBody.Notifications = workItem.Notifications.ToArray();
            _serializer.Serialize(writer, webhookBody);
        }