Example #1
0
        public static WebhookTrigger MapToWebhookTrigger(WebhookTriggerModel model)
        {
            var trigger = WebhookTrigger.Create(model.Name);

            if (model.Inactive)
            {
                trigger.Deactivate();
            }
            foreach (var action in model.Actions ?? Enumerable.Empty <string>())
            {
                trigger.AddAction(action);
            }
            foreach (var requester in model.Requesters ?? Enumerable.Empty <string>())
            {
                trigger.AddRequester(requester);
            }
            foreach (var rule in model.Rules ?? new Dictionary <string, IDictionary <string, RuleModel> >())
            {
                trigger.Rules[rule.Key] = rule.Value.ToDictionary(x => x.Key, x => new Rule
                {
                    Comparison = (Comparison)Enum.Parse(typeof(Comparison), x.Value.Comparison, true),
                    Value      = x.Value.Value
                });
            }
            foreach (var ruleActions in model.RulesActions ?? new Dictionary <string, IEnumerable <string> >())
            {
                trigger.RulesActions[ruleActions.Key] = ruleActions.Value;
            }

            return(trigger);
        }
Example #2
0
        public static Webhook MapToWebhook(WebhookModel model)
        {
            var webhook = new Webhook(model.Name, model.Endpoint);

            if (model.Inactive)
            {
                webhook.Deactivate();
            }
            if (!string.IsNullOrWhiteSpace(model.Token))
            {
                webhook.SetToken(model.Token);
            }
            webhook.SetDefaultRequest(model.DefaultRequest);
            foreach (var header in model.DefaultHeaders ?? new Dictionary <string, object>())
            {
                webhook.DefaultHeaders[header.Key] = header.Value;
            }
            foreach (var action in model.Actions ?? Enumerable.Empty <WebhookActionModel>())
            {
                webhook.AddAction(WebhookActionModel.MapToWebhookAction(action));
            }
            foreach (var trigger in model.Triggers ?? Enumerable.Empty <WebhookTriggerModel>())
            {
                webhook.AddTrigger(WebhookTriggerModel.MapToWebhookTrigger(trigger));
            }

            return(webhook);
        }