diff --git a/src/Moryx.Notifications/INotificationPublisher.cs b/src/Moryx.Notifications/INotificationPublisher.cs index 75914e97..f4997560 100644 --- a/src/Moryx.Notifications/INotificationPublisher.cs +++ b/src/Moryx.Notifications/INotificationPublisher.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020, Phoenix Contact GmbH & Co. KG +// Copyright (c) 2022, Phoenix Contact GmbH & Co. KG // Licensed under the Apache License, Version 2.0 using System; @@ -8,6 +8,7 @@ namespace Moryx.Notifications /// /// Notification publisher facade /// + [Obsolete] public interface INotificationPublisher { /// diff --git a/src/Moryx.Notifications/INotificationPublisherExtended.cs b/src/Moryx.Notifications/INotificationPublisherExtended.cs new file mode 100644 index 00000000..c1adcbcf --- /dev/null +++ b/src/Moryx.Notifications/INotificationPublisherExtended.cs @@ -0,0 +1,42 @@ +// Copyright (c) 2022, Phoenix Contact GmbH & Co. KG +// Licensed under the Apache License, Version 2.0 + +using System; + +namespace Moryx.Notifications +{ + /// + /// Notification publisher facade + /// + public interface INotificationPublisherExtended + { + /// + /// Returns all active notifications + /// + Notification[] GetAll(); + + /// + /// Gets a corresponding to a specific + /// If this is an inactive , than the NotificationHistory will be used to search for the asked + /// + /// Id of the desired + /// A correspodning to the given id if it exists; null otherwise + Notification Get(Guid id); + + /// + /// Acknowledge the given Notificatione + /// + /// The notification to be acknowledged + void Acknowledge(Notification notification); + + /// + /// Raised if notification was published + /// + event EventHandler Published; + + /// + /// Raised if notification was acknowledged + /// + event EventHandler Acknowledged; + } +} diff --git a/src/Moryx.Notifications/Notification/INotification.cs b/src/Moryx.Notifications/Notification/INotification.cs index 07e3a7a4..e8a04993 100644 --- a/src/Moryx.Notifications/Notification/INotification.cs +++ b/src/Moryx.Notifications/Notification/INotification.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020, Phoenix Contact GmbH & Co. KG +// Copyright (c) 2022, Phoenix Contact GmbH & Co. KG // Licensed under the Apache License, Version 2.0 using System; @@ -8,6 +8,7 @@ namespace Moryx.Notifications /// /// Additional notification interface to manipulate the notification properties in managing plugins /// + [Obsolete] public interface IManagedNotification : INotification { /// @@ -72,6 +73,7 @@ public interface IManagedNotification : INotification /// /// Message for a consumer /// + [Obsolete] public interface INotification { /// diff --git a/src/Moryx.Notifications/Notification/Notification.cs b/src/Moryx.Notifications/Notification/Notification.cs index a905d11c..9e38189c 100644 --- a/src/Moryx.Notifications/Notification/Notification.cs +++ b/src/Moryx.Notifications/Notification/Notification.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2020, Phoenix Contact GmbH & Co. KG +// Copyright (c) 2022, Phoenix Contact GmbH & Co. KG // Licensed under the Apache License, Version 2.0 using System; @@ -14,56 +14,67 @@ public class Notification : IManagedNotification public Guid Identifier { get; private set; } /// - Guid IManagedNotification.Identifier - { - get => Identifier; - set => Identifier = value; - } + public Severity Severity { get; set; } /// - public DateTime? Acknowledged { get; private set; } - - DateTime? IManagedNotification.Acknowledged - { - get => Acknowledged; - set => Acknowledged = value; - } - - /// - public bool IsAcknowledgable { get; set; } + public string Title { get; set; } /// - public string Acknowledger { get; private set; } - - string IManagedNotification.Acknowledger - { - get => Acknowledger; - set => Acknowledger = value; - } - + public string Message { get; set; } + /// - public DateTime Created { get; private set; } - - DateTime IManagedNotification.Created - { - get => Created; - set => Created = value; - } + public string Sender { get; set; } /// - string IManagedNotification.Sender { get; set; } + public string Source { get; set; } /// - string IManagedNotification.Source { get; set; } + public bool IsAcknowledgable { get; set; } + // TODO: AL6 remove explicit backing attribute for property + private DateTime? _acknowledged; /// - public Severity Severity { get; set; } + public virtual DateTime? Acknowledged + { + get => _acknowledged; + set + { + if (_acknowledged is null) + _acknowledged = value; + else + throw new InvalidOperationException("Tried to update time of acknowledgement."); + } + } + // TODO: AL6 remove explicit backing attribute for property + private string _acknowledger; /// - public string Title { get; set; } + public virtual string Acknowledger + { + get => _acknowledger; + set + { + if (_acknowledger is null) + _acknowledger = value; + else + throw new InvalidOperationException("Tried to update time acknowledger."); + } + } + // TODO: AL6 Remove backing attribute for property and make property nullable + private DateTime? _created; /// - public string Message { get; set; } + public virtual DateTime Created + { + get => _created ?? default(DateTime); + set + { + if (_created is null) + _created = value; + else + throw new InvalidOperationException("Tried to update creation time."); + } + } /// /// Creates a new notification @@ -75,6 +86,7 @@ public Notification() /// /// Creates a new notification with title and message /// + [Obsolete] public Notification(string title, string message, Severity severity) : this() { Title = title; @@ -85,9 +97,43 @@ public Notification(string title, string message, Severity severity) : this() /// /// Creates a new notification with title and message /// + [Obsolete] public Notification(string title, string message, Severity severity, bool isAcknowledgable) : this(title, message, severity) { IsAcknowledgable = isAcknowledgable; } + + #region IManagedNotification + /// + Guid IManagedNotification.Identifier + { + get => Identifier; + set => Identifier = value; + } + + DateTime? IManagedNotification.Acknowledged + { + get => _acknowledged; + set => _acknowledged = value; + } + + string IManagedNotification.Acknowledger + { + get => Acknowledger; + set => Acknowledger = value; + } + + DateTime IManagedNotification.Created + { + get => Created; + set => Created = value; + } + + /// + string IManagedNotification.Sender { get; set; } + + /// + string IManagedNotification.Source { get; set; } + #endregion } }