diff --git a/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs b/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs index 6658b84..c34535c 100644 --- a/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs @@ -50,6 +50,26 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers return await measurementService.ProcessAndSaveFullShippingJson(fullShippingJson, customerId); } + [SignalR(SignalRTags.GetGenericAttributeDtosByEntityIdAndKeyGroup)] + public async Task> GetGenericAttributeDtosByEntityIdAndKeyGroup(int productId, string keyGroup, int storeId) + { + return await ctx.GetGenericAttributeDtosByEntityIdAndKeyGroup(productId, keyGroup, storeId); + } + + [SignalR(SignalRTags.AddGenericAttributeDto)] + public async Task AddGenericAttributeDto(GenericAttributeDto genericAttributeDto) + { + await ctx.GenericAttributeDtos.InsertAsync(genericAttributeDto); + return await ctx.GenericAttributeDtos.GetByIdAsync(genericAttributeDto.Id); + } + + [SignalR(SignalRTags.UpdateGenericAttributeDto)] + public async Task UpdateGenericAttributeDto(GenericAttributeDto genericAttributeDto) + { + await ctx.GenericAttributeDtos.UpdateAsync(genericAttributeDto); + return await ctx.GenericAttributeDtos.GetByIdAsync(genericAttributeDto.Id); + } + [SignalR(SignalRTags.GetMeasuringModels)] public Task> GetMeasuringModels() { diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs index bc33984..1a3587c 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs @@ -69,6 +69,7 @@ public class FruitBankDbContext : MgDbContextBase, public IRepository CustomerAddressMappings { get; set; } public IRepository GenericAttributes { get; set; } + public IRepository GenericAttributeDtos { get; set; } public IRepository StockQuantityHistories { get; set; } public IRepository StockQuantityHistoriesExt { get; set; } @@ -86,6 +87,7 @@ public class FruitBankDbContext : MgDbContextBase, IRepository customerAddressMappingRepository, IRepository customerRoleRepository, IRepository genericAttributes, + IRepository genericAttributeDtos, IRepository stockQuantityHistories, IRepository stockQuantityHistoriesExt, IEventPublisher eventPublisher, @@ -119,6 +121,7 @@ public class FruitBankDbContext : MgDbContextBase, CustomerAddressMappings = customerAddressMappingRepository; GenericAttributes = genericAttributes; + GenericAttributeDtos = genericAttributeDtos; StockQuantityHistories = stockQuantityHistories; StockQuantityHistoriesExt = stockQuantityHistoriesExt; @@ -676,7 +679,17 @@ public class FruitBankDbContext : MgDbContextBase, productDto.StockQuantity += quantityToChange; if (weightToChange == 0) return; - productDto.GenericAttributes = await GenericAttributes.Table.Where(x => x.EntityId == productDto.Id && x.KeyGroup == nameof(Product) && x.StoreId == _storeContext.GetCurrentStore().Id).ToListAsync(); + productDto.GenericAttributes = await GetGenericAttributeDtosByEntityIdAndKeyGroup(productDto.Id, nameof(Product), (await _storeContext.GetCurrentStoreAsync()).Id); + } + + public async Task> GetGenericAttributeDtosByEntityIdAndKeyGroup(int entityId, string keyGroup, int? storeId = null) //TODO: StoreId!!! - J. + { + storeId ??= (await _storeContext.GetCurrentStoreAsync()).Id; + + var result = await GenericAttributeDtos.Table + .Where(x => x.KeyGroup == keyGroup && x.EntityId == entityId && x.StoreId == storeId.Value).ToListAsync(); + + return result; } public async Task UpdateStockQuantityAndWeightAsync(Product product, int quantityToChange, string message, double weightToChange = 0) diff --git a/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs b/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs index 6a2f500..e1f11a7 100644 --- a/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs +++ b/Nop.Plugin.Misc.AIPlugin/Infrastructure/PluginNopStartup.cs @@ -120,11 +120,12 @@ public class PluginNopStartup : INopStartup services.AddSignalR(hubOptions => { hubOptions.EnableDetailedErrors = true; - hubOptions.MaximumReceiveMessageSize = null; // 256 * 1024; + hubOptions.MaximumReceiveMessageSize = 30_000_000; // 256 * 1024; unlimited: null; hubOptions.KeepAliveInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignalRKeepAliveIntervalSecond); hubOptions.ClientTimeoutInterval = TimeSpan.FromSeconds(FruitBankConstClient.SignarlRTimeoutIntervalSecond); + //hubOptions.MaximumParallelInvocationsPerClient = 1; //default: 1; - //hubOptions.StatefulReconnectBufferSize = 1_000_000; //default: 100,000 bytes; + hubOptions.StatefulReconnectBufferSize = 30_000_000; //30MB; //default: 100,000 bytes; //hubOptions.HandshakeTimeout = TimeSpan.FromSeconds(15); //default timeout is 15 seconds }); } @@ -143,10 +144,14 @@ public class PluginNopStartup : INopStartup endpoints.MapHub(fruitBankHubEndPoint, options => { options.Transports = HttpTransportType.WebSockets;// | HttpTransportType.LongPolling; - options.WebSockets.CloseTimeout = new TimeSpan(0, 0, 10); //default: 5 sec. + options.WebSockets.CloseTimeout = TimeSpan.FromSeconds(10); //default: 5 sec. //options.LongPolling.PollTimeout = new TimeSpan(0, 0, 90); //default: 90 sec. - options.TransportSendTimeout = new TimeSpan(60); //default: 10 sec. + options.AllowStatefulReconnects = true; + options.TransportMaxBufferSize = 30_000_000; // Increasing this value allows the server to receive larger messages. default: 65KB; unlimited: 0; + options.ApplicationMaxBufferSize = 30_000_000; //Increasing this value allows the server to send larger messages. default: 65KB; unlimited: 0; + + options.TransportSendTimeout = TimeSpan.FromSeconds(60); //default: 10 sec. }); }); }); @@ -156,7 +161,10 @@ public class PluginNopStartup : INopStartup { app.UseEndpoints(endpoints => { - endpoints.MapHub(loggrHubEndPoint); + endpoints.MapHub(loggrHubEndPoint, options => + { + options.AllowStatefulReconnects = false; + }); }); }); } diff --git a/Nop.Plugin.Misc.AIPlugin/Mapping/NameCompatibility.cs b/Nop.Plugin.Misc.AIPlugin/Mapping/NameCompatibility.cs index 1a6c213..010dd47 100644 --- a/Nop.Plugin.Misc.AIPlugin/Mapping/NameCompatibility.cs +++ b/Nop.Plugin.Misc.AIPlugin/Mapping/NameCompatibility.cs @@ -4,6 +4,7 @@ using FruitBank.Common.Entities; using Mango.Nop.Core.Dtos; using Mango.Nop.Core.Entities; using Nop.Core.Domain.Catalog; +using Nop.Core.Domain.Common; using Nop.Core.Domain.Orders; using Nop.Data.Mapping; @@ -16,6 +17,8 @@ public partial class NameCompatibility : INameCompatibility /// public Dictionary TableNames => new Dictionary { + { typeof(GenericAttributeDto), nameof(GenericAttribute)}, + { typeof(Files), FruitBankConstClient.FilesDbTableName}, { typeof(Pallet), FruitBankConstClient.PalletDbTableName}, { typeof(Partner), FruitBankConstClient.PartnerDbTableName },