Exemple #1
0
 private object GetPayload(WebHookSubscription subscription, WebHookEventType eventType, Node node,
                           VersionNumber previousVersion)
 {
     return(string.IsNullOrWhiteSpace(subscription.Payload)
         ? GetDefaultPayload(subscription, eventType, node, previousVersion)
         : JsonConvert.DeserializeObject(subscription.Payload));
 }
Exemple #2
0
        private object GetPayload(WebHookSubscription subscription, WebHookEventType eventType, Node node,
                                  VersionNumber previousVersion)
        {
            var defaultPayload = GetDefaultPayload(subscription, eventType, node, previousVersion);

            return(string.IsNullOrWhiteSpace(subscription.Payload)
                ? defaultPayload
                : GetMergedPayload(subscription, eventType, node, defaultPayload));
        }
Exemple #3
0
 private object GetDefaultPayload(WebHookSubscription subscription, WebHookEventType eventType, Node node,
                                  VersionNumber previousVersion)
 {
     return(new
     {
         nodeId = node?.Id ?? 0,
         versionId = node?.VersionId ?? 0,
         version = node?.Version?.ToString(),
         previousVersion = previousVersion?.ToString(),
         versionModificationDate = node?.VersionModificationDate ?? DateTime.MinValue,
         modifiedBy = node?.ModifiedById ?? 0,
         path = node?.Path,
         name = node?.Name,
         displayName = node?.DisplayName,
         eventName = eventType.ToString(),
         subscriptionId = subscription.Id,
         sentTime = DateTime.UtcNow,
         repository = _clientStoreOptions.RepositoryUrl?.RemoveUrlSchema()
     });
 }
Exemple #4
0
        private object GetMergedPayload(WebHookSubscription subscription, WebHookEventType eventType, Node node, object defaultPayload)
        {
            // replace dynamic parameters (e.g. currentuser, content.Path, etc.)
            var replacedPayload = TemplateManager.Replace(typeof(WebHooksTemplateReplacer), subscription.Payload,
                                                          new WebHooksTemplateReplacerContext
            {
                Node         = node,
                EventType    = eventType,
                Subscription = subscription
            });

            var defaultJson = JsonConvert.SerializeObject(defaultPayload, Formatting.Indented);
            var jo          = JsonConvert.DeserializeObject <JObject>(defaultJson);

            // merge the provided custom payload into the default
            var newJson = JsonConvert.DeserializeObject <JObject>(replacedPayload);

            jo.Merge(newJson);

            return(jo);
        }
Exemple #5
0
 public Task FireWebHookAsync(WebHookSubscription subscription, WebHookEventType eventType, Node node, CancellationToken cancel)
 {
     return(_webHookClient.SendAsync(subscription.Url, eventType.ToString(), node.Id, subscription.Id,
                                     subscription.HttpMethod, GetPayload(subscription, eventType, node, null),
                                     subscription.HttpHeaders, cancel));
 }
Exemple #6
0
        private static Task FireWebHook(HttpContext context, WebHookSubscription webhook, Node node, WebHookEventType eventType)
        {
            var eventProcessor = context.RequestServices.GetService <IWebHookEventProcessor>();

            return(eventProcessor.FireWebHookAsync(webhook, eventType, node, context.RequestAborted));
        }
Exemple #7
0
 public WebHookSubscriptionInfo(WebHookSubscription subscription, WebHookEventType eventType)
 {
     Subscription = subscription;
     EventType    = eventType;
 }