Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove obsolete methods from INotifier #15631

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading