diff --git a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js index 70a4829..b8d8a0a 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js +++ b/Nop.Plugin.Misc.AuctionPlugin/Content/Js/LiveAnnouncement.js @@ -42,6 +42,10 @@ console.log("SignalR connected! connectionId: " + window.ConnectionId); }); + connection.on("OnDateTimeReceive", dateTime => { + console.log("SignalR date received! dateTime: " + dateTime); + }); + function start() { connection.start().catch(function (err) { setTimeout(function () { diff --git a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs index 1f7a2a8..026f958 100644 --- a/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.AuctionPlugin/Infrastructure/PluginNopStartup.cs @@ -52,11 +52,6 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure hubOptions.KeepAliveInterval = TimeSpan.FromMinutes(10); }); - //register services and interfaces - //IRepository _customerBidRepository; - //protected readonly IShortTermCacheManager _shortTermCacheManager; - // protected readonly IStaticCacheManager _staticCacheManager; - services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -72,13 +67,15 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Infrastructure services.AddScoped(); services.AddScoped(); - services.AddScoped(); - //services.AddScoped(); + services.AddScoped(); //TODO: ez mi? - J. + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); + + services.AddHostedService(); } /// diff --git a/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionBackgroundService.cs b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionBackgroundService.cs new file mode 100644 index 0000000..ea3dfe8 --- /dev/null +++ b/Nop.Plugin.Misc.AuctionPlugin/Services/AuctionBackgroundService.cs @@ -0,0 +1,19 @@ +using Mango.Nop.Services; +using Microsoft.AspNetCore.SignalR; +using Nop.Plugin.Misc.AuctionPlugin.Hubs; +using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages; +using Nop.Services.Logging; + +namespace Nop.Plugin.Misc.AuctionPlugin.Services; + +public class AuctionBackgroundService(ILogger logger, IServiceProvider service, IHubContext auctionHubContext, AuctionService auctionService) : MgBackgroundServiceBase(logger, service) +{ + protected override async Task OnExecuteAsync() + { + //var auctionDto = auctionService.GetProductToAuctionDtosByAuctionId() + //await auctionHubContext.Clients.All.SendAsync("send", new MessageWrapper()); + + await auctionHubContext.Clients.All.SendAsync("OnDateTimeReceive", DateTime.Now.ToString("G")); + await Task.Delay(15000); + } +} \ No newline at end of file