using Microsoft.AspNetCore.Mvc; using Nop.Core; using Nop.Plugin.Misc.AuctionPlugin; using Nop.Services.Cms; using Nop.Services.Logging; using Nop.Web.Framework.Components; using Nop.Web.Framework.Infrastructure; namespace Nop.Plugin.AuctionPlugin.Components { [ViewComponent(Name = "LiveAnnouncement")] public class LiveAnnouncementViewComponent : NopViewComponent { protected readonly ILogger _logger; protected readonly IWorkContext _workContext; protected readonly IWidgetPluginManager _widgetPluginManager; public LiveAnnouncementViewComponent(ILogger logger, IWorkContext workContext, IWidgetPluginManager widgetPluginManager) { _logger = logger; _workContext = workContext; _widgetPluginManager = widgetPluginManager; } public async Task InvokeAsync(string widgetZone, object additionalData) { await _logger.InformationAsync("SignalR Widget called"); //ensure that what3words widget is active and enabled var customer = await _workContext.GetCurrentCustomerAsync(); await _logger.InformationAsync($"SignalR Widget called customer: {customer.Email}"); if (!await _widgetPluginManager.IsPluginActiveAsync(AuctionDefaults.SystemName, customer)) return Content(string.Empty); await _logger.InformationAsync("SignalR Widget: widget active"); if (!widgetZone.Equals(PublicWidgetZones.HeaderAfter)) { return Content(string.Empty); } return View("~/Plugins/Misc.AuctionPlugin/Views/LiveAnnouncement.cshtml"); } } }