internal static HookInfoPatch GetPatchModel(NotificationHook hook)
 {
     return(hook switch
     {
         EmailNotificationHook h => new EmailHookInfoPatch()
         {
             HookName = h.Name, Description = h.Description, ExternalLink = h.ExternalLink, /*HookParameter = h.HookParameter,*/ Admins = h.Administrators
         },
         WebNotificationHook h => new WebhookHookInfoPatch()
         {
             HookName = h.Name, Description = h.Description, ExternalLink = h.ExternalLink, /*HookParameter = h.HookParameter,*/ Admins = h.Administrators
         },
         _ => throw new InvalidOperationException("Unknown AlertingHook type.")
     });
Exemple #2
0
        internal static NotificationHook DeserializeNotificationHook(JsonElement element)
        {
            if (element.TryGetProperty("hookType", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                case "Email": return(EmailNotificationHook.DeserializeEmailNotificationHook(element));

                case "Webhook": return(WebNotificationHook.DeserializeWebNotificationHook(element));
                }
            }
            HookType          hookType                = default;
            Optional <string> hookId                  = default;
            string            hookName                = default;
            Optional <string> description             = default;
            Optional <string> externalLink            = default;
            Optional <IReadOnlyList <string> > admins = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("hookType"))
                {
                    hookType = new HookType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("hookId"))
                {
                    hookId = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("hookName"))
                {
                    hookName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("description"))
                {
                    description = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("externalLink"))
                {
                    externalLink = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("admins"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    List <string> array = new List <string>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(item.GetString());
                    }
                    admins = array;
                    continue;
                }
            }
            return(new NotificationHook(hookType, hookId.Value, hookName, description.Value, externalLink.Value, Optional.ToList(admins)));
        }