Skip to content

Commit

Permalink
Merge pull request #154 from 1nf0rmagician/update/NotificationPublish…
Browse files Browse the repository at this point in the history
…erAPI

Extend NotificationPublisher API
  • Loading branch information
Toxantron authored Mar 6, 2022
2 parents e6d1131 + da4e5c4 commit 22caa2e
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/Moryx.Notifications/INotificationPublisher.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +8,7 @@ namespace Moryx.Notifications
/// <summary>
/// Notification publisher facade
/// </summary>
[Obsolete]
public interface INotificationPublisher
{
/// <summary>
Expand Down
42 changes: 42 additions & 0 deletions src/Moryx.Notifications/INotificationPublisherExtended.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Notification publisher facade
/// </summary>
public interface INotificationPublisherExtended
{
/// <summary>
/// Returns all active notifications
/// </summary>
Notification[] GetAll();

/// <summary>
/// Gets a <see cref="Notification"/> corresponding to a specific <paramref name="id"/>
/// If this is an inactive <see cref="Notification"/>, than the NotificationHistory will be used to search for the asked <see cref="Notification"/>
/// </summary>
/// <param name="id">Id of the desired <see cref="Notification"/></param>
/// <returns>A <see cref="Notification"/> correspodning to the given id if it exists; null otherwise</returns>
Notification Get(Guid id);

/// <summary>
/// Acknowledge the given Notificatione
/// </summary>
/// <param name="notification">The notification to be acknowledged</param>
void Acknowledge(Notification notification);

/// <summary>
/// Raised if notification was published
/// </summary>
event EventHandler<Notification> Published;

/// <summary>
/// Raised if notification was acknowledged
/// </summary>
event EventHandler<Notification> Acknowledged;
}
}
4 changes: 3 additions & 1 deletion src/Moryx.Notifications/Notification/INotification.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,6 +8,7 @@ namespace Moryx.Notifications
/// <summary>
/// Additional notification interface to manipulate the notification properties in managing plugins
/// </summary>
[Obsolete]
public interface IManagedNotification : INotification
{
/// <summary>
Expand Down Expand Up @@ -72,6 +73,7 @@ public interface IManagedNotification : INotification
/// <summary>
/// Message for a consumer
/// </summary>
[Obsolete]
public interface INotification
{
/// <summary>
Expand Down
118 changes: 82 additions & 36 deletions src/Moryx.Notifications/Notification/Notification.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,56 +14,67 @@ public class Notification : IManagedNotification
public Guid Identifier { get; private set; }

/// <inheritdoc />
Guid IManagedNotification.Identifier
{
get => Identifier;
set => Identifier = value;
}
public Severity Severity { get; set; }

/// <inheritdoc />
public DateTime? Acknowledged { get; private set; }

DateTime? IManagedNotification.Acknowledged
{
get => Acknowledged;
set => Acknowledged = value;
}

/// <inheritdoc cref="IManagedNotification.IsAcknowledgable" />
public bool IsAcknowledgable { get; set; }
public string Title { get; set; }

/// <inheritdoc />
public string Acknowledger { get; private set; }

string IManagedNotification.Acknowledger
{
get => Acknowledger;
set => Acknowledger = value;
}

public string Message { get; set; }

/// <inheritdoc />
public DateTime Created { get; private set; }

DateTime IManagedNotification.Created
{
get => Created;
set => Created = value;
}
public string Sender { get; set; }

/// <inheritdoc />
string IManagedNotification.Sender { get; set; }
public string Source { get; set; }

/// <inheritdoc />
string IManagedNotification.Source { get; set; }
public bool IsAcknowledgable { get; set; }

// TODO: AL6 remove explicit backing attribute for property
private DateTime? _acknowledged;
/// <inheritdoc />
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;
/// <inheritdoc />
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;
/// <inheritdoc />
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.");
}
}

/// <summary>
/// Creates a new notification
Expand All @@ -75,6 +86,7 @@ public Notification()
/// <summary>
/// Creates a new notification with title and message
/// </summary>
[Obsolete]
public Notification(string title, string message, Severity severity) : this()
{
Title = title;
Expand All @@ -85,9 +97,43 @@ public Notification(string title, string message, Severity severity) : this()
/// <summary>
/// Creates a new notification with title and message
/// </summary>
[Obsolete]
public Notification(string title, string message, Severity severity, bool isAcknowledgable) : this(title, message, severity)
{
IsAcknowledgable = isAcknowledgable;
}

#region IManagedNotification
/// <inheritdoc />
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;
}

/// <inheritdoc />
string IManagedNotification.Sender { get; set; }

/// <inheritdoc />
string IManagedNotification.Source { get; set; }
#endregion
}
}

0 comments on commit 22caa2e

Please sign in to comment.