noplogger improvements, fixes, etc...

This commit is contained in:
Loretta 2025-10-21 15:30:43 +02:00
parent a261318005
commit 0c604bde9e
3 changed files with 60 additions and 48 deletions

View File

@ -17,6 +17,7 @@ using Nop.Services.Catalog;
using FruitBank.Common.Dtos; using FruitBank.Common.Dtos;
using Mango.Nop.Core.Extensions; using Mango.Nop.Core.Extensions;
using Nop.Core.Domain.Orders; using Nop.Core.Domain.Orders;
using WebMarkupMin.Core.Loggers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
@ -177,6 +178,9 @@ public class FruitBankDbContext : MgDbContextBase,
{ {
try try
{ {
//Logger.Warning($"UpdateShippingItemAsync");
//throw new Exception($"Teszt");
ProductDto? productDto = null; ProductDto? productDto = null;
var productIsMeasurable = false; var productIsMeasurable = false;
@ -313,6 +317,10 @@ public class FruitBankDbContext : MgDbContextBase,
if (!await SetupShippingItemPalletMeauringValues(shippingItemPallet)) return null; if (!await SetupShippingItemPalletMeauringValues(shippingItemPallet)) return null;
await ShippingItemPallets.InsertAsync(shippingItemPallet); await ShippingItemPallets.InsertAsync(shippingItemPallet);
var shippingItem = await ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false);
await UpdateShippingItemAsync(shippingItem);
return shippingItemPallet; return shippingItemPallet;
} }
@ -324,6 +332,10 @@ public class FruitBankDbContext : MgDbContextBase,
if (!await SetupShippingItemPalletMeauringValues(shippingItemPallet)) return null; if (!await SetupShippingItemPalletMeauringValues(shippingItemPallet)) return null;
await ShippingItemPallets.UpdateAsync(shippingItemPallet); await ShippingItemPallets.UpdateAsync(shippingItemPallet);
var shippingItem = await ShippingItems.GetByIdAsync(shippingItemPallet.ShippingItemId, false);
await UpdateShippingItemAsync(shippingItem);
return shippingItemPallet; return shippingItemPallet;
} }

View File

@ -1,24 +1,14 @@
using System.Diagnostics.CodeAnalysis; using AyCode.Core.Loggers;
using AyCode.Core.Loggers;
using AyCode.Interfaces.Entities;
using FruitBank.Common.Dtos;
using FruitBank.Common.Entities; using FruitBank.Common.Entities;
using FruitBank.Common.Interfaces; using FruitBank.Common.Interfaces;
using FruitBank.Common.Loggers;
using FruitBank.Common.Server;
using Humanizer;
using Mango.Nop.Core.Loggers;
using Mango.Nop.Services; using Mango.Nop.Services;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Nop.Core; using Nop.Core;
using Nop.Core.Domain.Catalog; using Nop.Core.Domain.Catalog;
using Nop.Core.Events; using Nop.Core.Events;
using Nop.Plugin.Misc.FruitBankPlugin.Controllers;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.FruitBankPlugin.Services; using Nop.Plugin.Misc.FruitBankPlugin.Services;
using Nop.Services.Common;
using Nop.Services.Events; using Nop.Services.Events;
using System.Globalization;
using Mango.Nop.Core.Extensions; using Mango.Nop.Core.Extensions;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.EventConsumers; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.EventConsumers;
@ -87,53 +77,62 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAcc, FruitBa
bool? isMeasurable = null; bool? isMeasurable = null;
var isMeasurableChanged = false; var isMeasurableChanged = false;
var productDto = product.Id > 0 ? await ctx.ProductDtos.GetByIdAsync(product.Id, false) : null; try
//IsMeasurable
isMeasurable = form[nameof(IMeasurable.IsMeasurable)].ToString().Contains("true");
var productDtoIsMeasurable = productDto?.GenericAttributes.GetValueOrNull<bool>(nameof(IMeasurable.IsMeasurable));
if (productDtoIsMeasurable == null || productDtoIsMeasurable.Value != isMeasurable.Value)
{ {
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, bool>(product.Id, nameof(IMeasurable.IsMeasurable), isMeasurable.Value); var productDto = product.Id > 0 ? await ctx.ProductDtos.GetByIdAsync(product.Id, false) : null;
isMeasurableChanged = true;
//IsMeasurable
isMeasurable = form[nameof(IMeasurable.IsMeasurable)].ToString().Contains("true");
var productDtoIsMeasurable = productDto?.GenericAttributes.GetValueOrNull<bool>(nameof(IMeasurable.IsMeasurable));
if (productDtoIsMeasurable == null || productDtoIsMeasurable.Value != isMeasurable.Value)
{
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, bool>(product.Id, nameof(IMeasurable.IsMeasurable), isMeasurable.Value);
isMeasurableChanged = true;
}
//NetWeight
var netWeight = double.Round(CommonHelper.To<double>(form[nameof(IMeasuringNetWeight.NetWeight)].ToString()), 1);
var productDtoNetWeight = productDto?.GenericAttributes.GetValueOrNull<double>(nameof(IMeasuringNetWeight.NetWeight));
if (productDtoNetWeight == null || double.Round(productDtoNetWeight.Value, 1) != netWeight)
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight);
//Tára
var tare = double.Round(CommonHelper.To<double>(form[nameof(ITare.Tare)].ToString()), 1);
if (tare < 0) throw new Exception($"FruitBankEventConsumer->SaveProductCustomAttributesAsync(); (tare < 0); productId: {product.Id}; tare: {tare}");
if (productDto == null || productDto.Tare != tare)
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(ITare.Tare), tare);
//IncomingQuantity
var incomingQuantity = CommonHelper.To<int>(form[nameof(IIncomingQuantity.IncomingQuantity)].ToString());
if (incomingQuantity < 0) throw new Exception($"FruitBankEventConsumer->SaveProductCustomAttributesAsync(); (incomingQuantity < 0); productId: {product.Id}; incomingQuantity: {incomingQuantity}");
if (productDto == null || productDto.IncomingQuantity != incomingQuantity)
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, int>(product.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity);
}
catch (Exception ex)
{
Logger.Error($"FruitBankEventConsumer->SaveProductCustomAttributesAsync; {ex.Message}", ex);
} }
//NetWeight
var netWeight = double.Round(CommonHelper.To<double>(form[nameof(IMeasuringNetWeight.NetWeight)].ToString()), 1);
var productDtoNetWeight = productDto?.GenericAttributes.GetValueOrNull<double>(nameof(IMeasuringNetWeight.NetWeight));
if (productDtoNetWeight == null || double.Round(productDtoNetWeight.Value, 1) != netWeight)
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(IMeasuringNetWeight.NetWeight), netWeight);
//Tára
var tare = double.Round(CommonHelper.To<double>(form[nameof(ITare.Tare)].ToString()), 1);
if (tare < 0) throw new Exception($"FruitBankEventConsumer->SaveProductCustomAttributesAsync(); (tare < 0); productId: {product.Id}; tare: {tare}");
if (productDto == null || productDto.Tare != tare)
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, double>(product.Id, nameof(ITare.Tare), tare);
//IncomingQuantity
var incomingQuantity = CommonHelper.To<int>(form[nameof(IIncomingQuantity.IncomingQuantity)].ToString());
if (incomingQuantity < 0) throw new Exception($"FruitBankEventConsumer->SaveProductCustomAttributesAsync(); (incomingQuantity < 0); productId: {product.Id}; incomingQuantity: {incomingQuantity}");
if (productDto == null || productDto.IncomingQuantity != incomingQuantity)
await fruitBankAttributeService.InsertOrUpdateGenericAttributeAsync<Product, int>(product.Id, nameof(IIncomingQuantity.IncomingQuantity), incomingQuantity);
return (isMeasurableChanged, isMeasurable); return (isMeasurableChanged, isMeasurable);
} }
public async Task HandleEventAsync(EntityInsertedEvent<ShippingItemPallet> eventMessage) public async Task HandleEventAsync(EntityInsertedEvent<ShippingItemPallet> eventMessage)
{ {
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}"); return;
Logger.Info($"HandleEventAsync EntityInsertedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity); await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity);
} }
public async Task HandleEventAsync(EntityUpdatedEvent<ShippingItemPallet> eventMessage) public async Task HandleEventAsync(EntityUpdatedEvent<ShippingItemPallet> eventMessage)
{ {
Logger.Info($"HandleEventAsync EntityUpdatedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}"); return;
Logger.Info($"HandleEventAsync EntityUpdatedEvent<ShippingItemPallet>; id: {eventMessage.Entity.Id}");
await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity); await UpdateShippingItemMeasuringValuesAsync(eventMessage.Entity);
} }

View File

@ -2,9 +2,9 @@
using AyCode.Core.Loggers; using AyCode.Core.Loggers;
using DevExpress.AspNetCore; using DevExpress.AspNetCore;
using FruitBank.Common; using FruitBank.Common;
using FruitBank.Common.Interfaces; using FruitBank.Common.Interfaces;
using FruitBank.Common.Server.Interfaces;
using FruitBank.Common.Server.Services.Loggers; using FruitBank.Common.Server.Services.Loggers;
using FruitBank.Common.Server.Services.SignalRs; using FruitBank.Common.Server.Services.SignalRs;
using Mango.Nop.Core.Loggers; using Mango.Nop.Core.Loggers;
@ -16,6 +16,9 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Nop.Core.Domain.Orders; using Nop.Core.Domain.Orders;
using Nop.Core.Infrastructure; using Nop.Core.Infrastructure;
using Nop.Data;
using Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
using Nop.Plugin.Misc.FruitBankPlugin.Controllers;
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
using Nop.Plugin.Misc.FruitBankPlugin.Factories; using Nop.Plugin.Misc.FruitBankPlugin.Factories;
using Nop.Plugin.Misc.FruitBankPlugin.Filters; using Nop.Plugin.Misc.FruitBankPlugin.Filters;
@ -27,9 +30,6 @@ using Nop.Services.Events;
using Nop.Web.Areas.Admin.Factories; using Nop.Web.Areas.Admin.Factories;
using Nop.Web.Areas.Admin.Models.Catalog; using Nop.Web.Areas.Admin.Models.Catalog;
using Nop.Web.Areas.Admin.Models.Orders; using Nop.Web.Areas.Admin.Models.Orders;
using FruitBank.Common.Server.Interfaces;
using Nop.Plugin.Misc.FruitBankPlugin.Controllers;
using Nop.Plugin.Misc.FruitBankPlugin.Areas.Admin.Controllers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Infrastructure; namespace Nop.Plugin.Misc.FruitBankPlugin.Infrastructure;
@ -50,9 +50,10 @@ public class PluginNopStartup : INopStartup
//register services and interfaces //register services and interfaces
services.AddSingleton<ILockService, LockService>(); services.AddSingleton<ILockService, LockService>();
services.AddTransient<INopLoggerMsSqlNopDataProvider, NopLoggerMsSqlNopDataProvider>();
services.AddScoped<IAcLogWriterBase, ConsoleLogWriter>(); services.AddScoped<IAcLogWriterBase, ConsoleLogWriter>();
//services.AddScoped<IAcLogWriterBase, NopLogWriter>(); services.AddScoped<IAcLogWriterBase, NopLogWriter>();
services.AddScoped<LoggerToLoggerApiController2>(); services.AddScoped<LoggerToLoggerApiController2>();
//services.AddSingleton<SessionService>(); //services.AddSingleton<SessionService>();