Skip to content

Commit

Permalink
Remove obsolete methods from INotifier (#15631)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Apr 1, 2024
1 parent 88a61bd commit 4ec7f42
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 82 deletions.
20 changes: 2 additions & 18 deletions src/OrchardCore/OrchardCore.DisplayManagement/Notify/INotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,16 @@ namespace OrchardCore.DisplayManagement.Notify
/// </remarks>
public interface INotifier
{
/// <summary>
/// Adds a new UI notification.
/// </summary>
/// <param name="type">
/// The type of the notification (notifications with different types can be displayed differently).</param>
/// <param name="message">A localized message to display.</param>
[Obsolete("This method will be removed in a later version. Use AddAsync()")]
void Add(NotifyType type, LocalizedHtmlString message);

/// <summary>
/// Adds a new UI notification asynchronously.
/// </summary>
/// <param name="type">
/// The type of the notification (notifications with different types can be displayed differently).</param>
/// <param name="message">A localized message to display.</param>
/// <remarks>
/// Added with a default interface implementation for backwards compatability.
/// Added with a default interface implementation for backwards compatibility.
/// </remarks>
ValueTask AddAsync(NotifyType type, LocalizedHtmlString message)
{
#pragma warning disable CS0618 // Type or member is obsolete
Add(type, message);
#pragma warning restore CS0618 // Type or member is obsolete

return new ValueTask();
}
ValueTask AddAsync(NotifyType type, LocalizedHtmlString message);

/// <summary>
/// Get all notifications added.
Expand Down
18 changes: 3 additions & 15 deletions src/OrchardCore/OrchardCore.DisplayManagement/Notify/Notifier.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,30 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.Extensions.Logging;

namespace OrchardCore.DisplayManagement.Notify
{
public class Notifier : INotifier
{
private readonly List<NotifyEntry> _entries;
private readonly List<NotifyEntry> _entries = [];
private readonly ILogger _logger;

public Notifier(ILogger<Notifier> logger)
{
_entries = [];
_logger = logger;
}

public void Add(NotifyType type, LocalizedHtmlString message)
{
throw new System.NotImplementedException();
}

public ValueTask AddAsync(NotifyType type, LocalizedHtmlString message)
{
if (_logger.IsEnabled(LogLevel.Information))
{
_logger.LogInformation("Notification '{NotificationType}' with message '{NotificationMessage}'", type, message.ToString());
}
_logger.LogInformation("Notification '{NotificationType}' with message '{NotificationMessage}'", type, message);

_entries.Add(new NotifyEntry { Type = type, Message = message });

return ValueTask.CompletedTask;
}

public IList<NotifyEntry> List()
{
return _entries;
}
=> _entries;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Localization;

namespace OrchardCore.DisplayManagement.Notify
{
public static class NotifierExtensions
{
/// <summary>
/// Adds a new UI notification of type Information.
/// </summary>
/// <seealso cref="INotifier.Add"/>
/// <param name="notifier">The <see cref="INotifier"/>.</param>
/// <param name="message">A localized message to display.</param>
[Obsolete("This method will be removed in a later version. Use InformationAsync()")]
public static void Information(this INotifier notifier, LocalizedHtmlString message)
{
notifier.Add(NotifyType.Information, message);
}

/// <summary>
/// Adds a new UI notification of type Information.
/// </summary>
Expand All @@ -27,18 +14,6 @@ public static void Information(this INotifier notifier, LocalizedHtmlString mess
public static ValueTask InformationAsync(this INotifier notifier, LocalizedHtmlString message)
=> notifier.AddAsync(NotifyType.Information, message);

/// <summary>
/// Adds a new UI notification of type Warning.
/// </summary>
/// <seealso cref="INotifier.Add"/>
/// <param name="notifier">The <see cref="INotifier"/>.</param>
/// <param name="message">A localized message to display.</param>
[Obsolete("This method will be removed in a later version. Use WarningAsync()")]
public static void Warning(this INotifier notifier, LocalizedHtmlString message)
{
notifier.Add(NotifyType.Warning, message);
}

/// <summary>
/// Adds a new UI notification of type Warning.
/// </summary>
Expand All @@ -48,18 +23,6 @@ public static void Warning(this INotifier notifier, LocalizedHtmlString message)
public static ValueTask WarningAsync(this INotifier notifier, LocalizedHtmlString message)
=> notifier.AddAsync(NotifyType.Warning, message);

/// <summary>
/// Adds a new UI notification of type Error.
/// </summary>
/// <seealso cref="INotifier.Add"/>
/// <param name="notifier">The <see cref="INotifier"/>.</param>
/// <param name="message">A localized message to display.</param>
[Obsolete("This method will be removed in a later version. Use ErrorAsync()")]
public static void Error(this INotifier notifier, LocalizedHtmlString message)
{
notifier.Add(NotifyType.Error, message);
}

/// <summary>
/// Adds a new UI notification of type Error.
/// </summary>
Expand All @@ -69,18 +32,6 @@ public static void Error(this INotifier notifier, LocalizedHtmlString message)
public static ValueTask ErrorAsync(this INotifier notifier, LocalizedHtmlString message)
=> notifier.AddAsync(NotifyType.Error, message);

/// <summary>
/// Adds a new UI notification of type Success.
/// </summary>
/// <seealso cref="INotifier.Add"/>
/// <param name="notifier">The <see cref="INotifier"/>.</param>
/// <param name="message">A localized message to display.</param>
[Obsolete("This method will be removed in a later version. Use SuccessAsync()")]
public static void Success(this INotifier notifier, LocalizedHtmlString message)
{
notifier.Add(NotifyType.Success, message);
}

/// <summary>
/// Adds a new UI notification of type Success.
/// </summary>
Expand Down

0 comments on commit 4ec7f42

Please sign in to comment.