/// <summary> /// Initializes a new instance of the <see cref="NotificationConfiguration"/> class /// with the specified properties. /// </summary> /// <param name="label">The friendly name of the notification. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="notificationTypeId">The notification type ID. This is obtained from <see cref="NotificationType.Id">NotificationType.Id</see>, or from the predefined values in <see cref="NotificationTypeId"/>. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="details">A <see cref="NotificationDetails"/> object containing the detailed configuration properties for the specified notification type. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <param name="metadata">A collection of metadata to associate with the notification. If the value is <see langword="null"/>, no custom metadata is associated with the notification. If this value is <see langword="null"/>, the underlying property will be omitted from the JSON representation of the object.</param> /// <exception cref="ArgumentException"> /// If <paramref name="label"/> is empty. /// <para>-or-</para> /// <para>If <paramref name="details"/> is non-<see langword="null"/> and <paramref name="notificationTypeId"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="details"/> does not support notifications of type <paramref name="notificationTypeId"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="metadata"/> contains any empty keys.</para> /// </exception> protected NotificationConfiguration(string label, NotificationTypeId notificationTypeId, NotificationDetails details, IDictionary <string, string> metadata) { if (label == string.Empty) { throw new ArgumentException("label cannot be empty"); } if (details != null && notificationTypeId == null) { throw new ArgumentException("notificationTypeId must be specified if details is specified", "notificationTypeId"); } if (details != null && !details.SupportsNotificationType(notificationTypeId)) { throw new ArgumentException(string.Format("The notification details object does not support '{0}' notifications.", notificationTypeId), "details"); } if (metadata != null && metadata.ContainsKey(string.Empty)) { throw new ArgumentException("metadata cannot contain any empty keys", "metadata"); } _label = label; _type = notificationTypeId; _details = details != null?JObject.FromObject(details) : null; _metadata = metadata; }
/// <summary> /// Deserializes a JSON object to a <see cref="NotificationDetails"/> instance of the proper type. /// </summary> /// <param name="notificationTypeId">The notification type ID.</param> /// <param name="obj">The JSON object representing the notification details.</param> /// <returns>A <see cref="NotificationDetails"/> object corresponding to the JSON object.</returns> /// <exception cref="ArgumentNullException"> /// If <paramref name="notificationTypeId"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="obj"/> is <see langword="null"/>.</para> /// </exception> public static NotificationDetails FromJObject(NotificationTypeId notificationTypeId, JObject obj) { if (notificationTypeId == null) { throw new ArgumentNullException("notificationTypeId"); } if (obj == null) { throw new ArgumentNullException("obj"); } if (notificationTypeId == NotificationTypeId.Webhook) { return(obj.ToObject <WebhookNotificationDetails>()); } else if (notificationTypeId == NotificationTypeId.Email) { return(obj.ToObject <EmailNotificationDetails>()); } else if (notificationTypeId == NotificationTypeId.PagerDuty) { return(obj.ToObject <PagerDutyNotificationDetails>()); } else { return(obj.ToObject <GenericNotificationDetails>()); } }
/// <summary> /// Initializes a new instance of the <see cref="NewNotificationConfiguration"/> class /// with the specified properties. /// </summary> /// <param name="label">The friendly name of the notification.</param> /// <param name="notificationTypeId">The notification type ID. This is obtained from <see cref="NotificationType.Id">NotificationType.Id</see>, or from the predefined values in <see cref="NotificationTypeId"/>.</param> /// <param name="details">A <see cref="NotificationDetails"/> object containing the detailed configuration properties for the specified notification type.</param> /// <param name="metadata">A collection of metadata to associate with the notification. If the value is <see langword="null"/>, no custom metadata is associated with the notification.</param> /// <exception cref="ArgumentNullException"> /// If <paramref name="label"/> is <see langword="null"/>. /// <para>-or-</para> /// <para>If <paramref name="details"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException"> /// If <paramref name="label"/> is empty. /// <para>-or-</para> /// <para>If <paramref name="details"/> is non-<see langword="null"/> and <paramref name="notificationTypeId"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="details"/> does not support notifications of type <paramref name="notificationTypeId"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="metadata"/> contains any empty keys.</para> /// </exception> public NewNotificationConfiguration(string label, NotificationTypeId notificationTypeId, NotificationDetails details, IDictionary <string, string> metadata = null) : base(label, notificationTypeId, details, metadata) { if (label == null) { throw new ArgumentNullException("label"); } if (details == null) { throw new ArgumentNullException("details"); } }
/// <summary> /// Determines whether the current <see cref="NotificationDetails"/> object is compatible /// with notifications of a particular type. /// </summary> /// <param name="notificationTypeId">The notification type ID.</param> /// <returns><see langword="true"/> if the current <see cref="NotificationDetails"/> object is compatible with <paramref name="notificationTypeId"/>; otherwise, <see langword="false"/>.</returns> /// <exception cref="ArgumentNullException">If <paramref name="notificationTypeId"/> is <see langword="null"/>.</exception> protected internal abstract bool SupportsNotificationType(NotificationTypeId notificationTypeId);
/// <summary> /// Initializes a new instance of the <see cref="UpdateNotificationConfiguration"/> class /// with the specified properties. /// </summary> /// <param name="label">The friendly name of the notification. If this value is <see langword="null"/>, the existing value for the notification is not changed.</param> /// <param name="notificationTypeId">The notification type ID. This is obtained from <see cref="NotificationType.Id">NotificationType.Id</see>, or from the predefined values in <see cref="NotificationTypeId"/>. If this value is <see langword="null"/>, the existing value for the notification is not changed.</param> /// <param name="details">A <see cref="NotificationDetails"/> object containing the detailed configuration properties for the specified notification type. If this value is <see langword="null"/>, the existing value for the notification is not changed.</param> /// <param name="metadata">A collection of metadata to associate with the notification. If this value is <see langword="null"/>, the existing value for the notification is not changed.</param> /// <exception cref="ArgumentException"> /// If <paramref name="label"/> is empty. /// <para>-or-</para> /// <para>If <paramref name="details"/> is non-<see langword="null"/> and <paramref name="notificationTypeId"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="details"/> does not support notifications of type <paramref name="notificationTypeId"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="metadata"/> contains any empty keys.</para> /// </exception> public UpdateNotificationConfiguration(string label = null, NotificationTypeId notificationTypeId = null, NotificationDetails details = null, IDictionary <string, string> metadata = null) : base(label, notificationTypeId, details, metadata) { }
/// <inheritdoc/> /// <remarks> /// This class can be used for any notification type. Clients using this class are responsible /// for adding the necessary properties for their specific notification type. /// </remarks> protected internal override bool SupportsNotificationType(NotificationTypeId notificationTypeId) { return(true); }
/// <inheritdoc/> /// <remarks> /// This class only supports <see cref="NotificationTypeId.PagerDuty"/> notifications. /// </remarks> protected internal override bool SupportsNotificationType(NotificationTypeId notificationTypeId) { return(notificationTypeId == NotificationTypeId.PagerDuty); }
/// <inheritdoc/> /// <remarks> /// This class only supports <see cref="NotificationTypeId.Webhook"/> notifications. /// </remarks> protected internal override bool SupportsNotificationType(NotificationTypeId notificationTypeId) { return(notificationTypeId == NotificationTypeId.Webhook); }