improvements, fixes, etc..
This commit is contained in:
parent
fa07f23d70
commit
edaef40fb7
|
|
@ -1,226 +1,243 @@
|
||||||
var MessageHandler = (function () {
|
var MessageHandler = (function() {
|
||||||
// Handlers for each message type
|
// Handlers for each message type
|
||||||
var animation = "slideDown";
|
var animation = "slideDown";
|
||||||
var handlers = {
|
var handlers = {
|
||||||
announcement: function (data) {
|
announcement: function(messageWrapper) {
|
||||||
var myObject = JSON.parse(data);
|
var announcementNotification = JSON.parse(messageWrapper.data);
|
||||||
|
|
||||||
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
|
||||||
if (!liveScreen) {
|
|
||||||
toastr.info(`<div class="item announcemantToast">${myObject.message}</div>`, myObject.title, {
|
|
||||||
"closeButton": true,
|
|
||||||
"positionClass": "toast-bottom-left",
|
|
||||||
"newestOnTop": true,
|
|
||||||
"progressBar": true,
|
|
||||||
"preventDuplicates": false,
|
|
||||||
"onclick": null,
|
|
||||||
"showDuration": "30000",
|
|
||||||
"hideDuration": "1000",
|
|
||||||
"timeOut": "5000",
|
|
||||||
"extendedTimeOut": "1000",
|
|
||||||
"showEasing": "swing",
|
|
||||||
"hideEasing": "linear",
|
|
||||||
"showMethod": animation,
|
|
||||||
"hideMethod": "fadeOut"
|
|
||||||
});
|
|
||||||
$('.toast-info').css("background-color", "#008080");
|
|
||||||
}
|
|
||||||
|
|
||||||
},
|
|
||||||
bidNotification: function (data) {
|
|
||||||
|
|
||||||
|
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
||||||
console.log(data);
|
if (!liveScreen && !messageWrapper.hideToaster) {
|
||||||
var myObject = JSON.parse(data);
|
toastr.info(`<div class="item announcemantToast">${announcementNotification.message}</div>`,
|
||||||
console.log(myObject);
|
announcementNotification.title,
|
||||||
|
{
|
||||||
|
"closeButton": true,
|
||||||
|
"positionClass": "toast-bottom-left",
|
||||||
|
"newestOnTop": true,
|
||||||
|
"progressBar": true,
|
||||||
|
"preventDuplicates": false,
|
||||||
|
"onclick": null,
|
||||||
|
"showDuration": "30000",
|
||||||
|
"hideDuration": "1000",
|
||||||
|
"timeOut": "5000",
|
||||||
|
"extendedTimeOut": "1000",
|
||||||
|
"showEasing": "swing",
|
||||||
|
"hideEasing": "linear",
|
||||||
|
"showMethod": animation,
|
||||||
|
"hideMethod": "fadeOut"
|
||||||
|
});
|
||||||
|
$('.toast-info').css("background-color", "#008080");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
var auctionDto = myObject.auctionDto;
|
bidNotification: function(messageWrapper) {
|
||||||
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
var bidNotification = JSON.parse(messageWrapper.data);
|
||||||
|
|
||||||
//var productAuctionMappingId = productToAuctionDto.id;
|
console.log(bidNotification);
|
||||||
//console.log(productAuctionMappingId);
|
|
||||||
|
|
||||||
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
var auctionDto = bidNotification.auctionDto;
|
||||||
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
||||||
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
|
|
||||||
|
|
||||||
if (publicProductBidBox)
|
//var productAuctionMappingId = productToAuctionDto.id;
|
||||||
{
|
//console.log(productAuctionMappingId);
|
||||||
//var audio = new Audio('../Plugins/Misc.AuctionPlugin/Content/ding.mp3');
|
|
||||||
//audio.play();
|
|
||||||
refreshPublicBidBox(myObject);
|
|
||||||
}
|
|
||||||
if (publicInfo) {
|
|
||||||
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
|
|
||||||
window[functionName](auctionDto);
|
|
||||||
}
|
|
||||||
if (liveScreen)
|
|
||||||
{
|
|
||||||
|
|
||||||
updateOnBid(myObject);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
toastr.success(`<div class="item bidToast"><p>${myObject.currentPrice}</p><p>${myObject.productName}</p></div>`, "New bid arrived", {
|
|
||||||
"closeButton": true,
|
|
||||||
"positionClass": "toast-bottom-left",
|
|
||||||
"newestOnTop": true,
|
|
||||||
"progressBar": true,
|
|
||||||
"preventDuplicates": false,
|
|
||||||
"onclick": null,
|
|
||||||
"showDuration": "30000",
|
|
||||||
"hideDuration": "1000",
|
|
||||||
"timeOut": "5000",
|
|
||||||
"extendedTimeOut": "1000",
|
|
||||||
"showEasing": "swing",
|
|
||||||
"hideEasing": "linear",
|
|
||||||
"showMethod": animation,
|
|
||||||
"hideMethod": "fadeOut"
|
|
||||||
});
|
|
||||||
$('.toast-success').css("background-color", "#4caf50");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ProductToAuctionStatusNotification: function (data) {
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
var myObject = JSON.parse(data);
|
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||||
var auctionDto = myObject.auctionDto;
|
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
||||||
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
|
||||||
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
|
||||||
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
|
||||||
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
|
|
||||||
|
|
||||||
if (!liveScreen) {
|
if (publicProductBidBox) {
|
||||||
var messageTitle = "";
|
//var audio = new Audio('../Plugins/Misc.AuctionPlugin/Content/ding.mp3');
|
||||||
var messageText = "";
|
//audio.play();
|
||||||
var messageColor = "";
|
refreshPublicBidBox(bidNotification);
|
||||||
switch (productToAuctionDto.auctionStatus) {
|
}
|
||||||
case AuctionStatus.None:
|
if (publicInfo) {
|
||||||
messageTitle = `Item reset`;
|
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
|
||||||
messageText = `The bids on item with index ${productToAuctionDto.sortIndex} has been resetted`;
|
window[functionName](auctionDto);
|
||||||
messageColor = "#6c757d";
|
}
|
||||||
break;
|
if (liveScreen) {
|
||||||
case AuctionStatus.Active:
|
|
||||||
messageTitle = `Item activated`;
|
|
||||||
messageText = `The bids on item with index ${productToAuctionDto.sortIndex} has been activated`;
|
|
||||||
messageColor = "#4caf50";
|
|
||||||
break;
|
|
||||||
case AuctionStatus.FirstWarning:
|
|
||||||
messageTitle = `First warning!`;
|
|
||||||
messageText = `Hurry up! If no more bids, this item will be closed soon!`;
|
|
||||||
messageColor = "#ffc107";
|
|
||||||
break;
|
|
||||||
case AuctionStatus.SecondWarning:
|
|
||||||
messageTitle = `Second warning!`;
|
|
||||||
messageText = `Hurry up! If no more bids, this item will be closed soon!`;
|
|
||||||
messageColor = "#dc3545";
|
|
||||||
break;
|
|
||||||
case AuctionStatus.Pause:
|
|
||||||
messageTitle = `Administrative message`;
|
|
||||||
messageText = `The administrator has suspended the auction, it will go on soon probably`;
|
|
||||||
messageColor = "#6c757d";
|
|
||||||
break;
|
|
||||||
case AuctionStatus.Sold:
|
|
||||||
messageTitle = `Item sold!`;
|
|
||||||
messageText = `The item has been sold, we are transitioning to the next item!`;
|
|
||||||
messageColor = "#4caf50";
|
|
||||||
break;
|
|
||||||
case AuctionStatus.NotSold:
|
|
||||||
messageTitle = `Item closed!`;
|
|
||||||
messageText = `The item has been closed, we are transitioning to the next item!`;
|
|
||||||
messageColor = "#6c757d";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
updateOnBid(bidNotification);
|
||||||
|
} else if (!messageWrapper.hideToaster) {
|
||||||
|
toastr.success(
|
||||||
|
`<div class="item bidToast"><p>${bidNotification.currentPrice}</p><p>${bidNotification.productName
|
||||||
|
}</p></div>`,
|
||||||
|
"New bid arrived",
|
||||||
|
{
|
||||||
|
"closeButton": true,
|
||||||
|
"positionClass": "toast-bottom-left",
|
||||||
|
"newestOnTop": true,
|
||||||
|
"progressBar": true,
|
||||||
|
"preventDuplicates": false,
|
||||||
|
"onclick": null,
|
||||||
|
"showDuration": "30000",
|
||||||
|
"hideDuration": "1000",
|
||||||
|
"timeOut": "5000",
|
||||||
|
"extendedTimeOut": "1000",
|
||||||
|
"showEasing": "swing",
|
||||||
|
"hideEasing": "linear",
|
||||||
|
"showMethod": animation,
|
||||||
|
"hideMethod": "fadeOut"
|
||||||
|
});
|
||||||
|
$('.toast-success').css("background-color", "#4caf50");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
toastr.success(`<div class="item bidToast"><p>${messageText}</p></div>`, messageTitle, {
|
ProductToAuctionStatusNotification: function(messageWrapper) {
|
||||||
"closeButton": true,
|
var auctionStatusNotification = JSON.parse(messageWrapper.data);
|
||||||
"positionClass": "toast-bottom-left",
|
|
||||||
"newestOnTop": true,
|
|
||||||
"progressBar": true,
|
|
||||||
"preventDuplicates": false,
|
|
||||||
"onclick": null,
|
|
||||||
"showDuration": "30000",
|
|
||||||
"hideDuration": "1000",
|
|
||||||
"timeOut": "5000",
|
|
||||||
"extendedTimeOut": "1000",
|
|
||||||
"showEasing": "swing",
|
|
||||||
"hideEasing": "linear",
|
|
||||||
"showMethod": animation,
|
|
||||||
"hideMethod": "fadeOut"
|
|
||||||
});
|
|
||||||
$('.toast-success').css("background-color", messageColor);
|
|
||||||
}
|
|
||||||
if (publicProductBidBox) {
|
|
||||||
handleAuctionUpdate(myObject);
|
|
||||||
}
|
|
||||||
if (liveScreen) {
|
|
||||||
reloadOnUpdate();
|
|
||||||
}
|
|
||||||
if (publicInfo) {
|
|
||||||
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
|
|
||||||
window[functionName](auctionDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
// var publicProductBidBox = document.getElementById("publicProductBidBox");
|
var auctionDto = auctionStatusNotification.auctionDto;
|
||||||
// if (publicProductBidBox)
|
var productToAuctionDto = auctionDto.productToAuctionDtos[0];
|
||||||
// {
|
var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||||
// refreshPublicBidBox(myObject);
|
var liveScreen = document.getElementById("auctionProductLiveScreenBox");
|
||||||
// }
|
var publicInfo = document.getElementById("publicInfoOverlay" + productToAuctionDto.productId);
|
||||||
},
|
|
||||||
//openItemMessage: function (data) {
|
|
||||||
// var myObject = JSON.parse(data);
|
|
||||||
// toastr.success(`<div class="item bidToast"><p>${myObject.nextBidPrice}</p><p>${myObject.productName}</p></div>`, "Item auction is OPENED!", {
|
|
||||||
// "closeButton": true,
|
|
||||||
// "positionClass": "toast-top-right",
|
|
||||||
// "newestOnTop": true,
|
|
||||||
// "progressBar": true,
|
|
||||||
// "preventDuplicates": false,
|
|
||||||
// "onclick": null,
|
|
||||||
// "showDuration": "30000",
|
|
||||||
// "hideDuration": "1000",
|
|
||||||
// "timeOut": "5000",
|
|
||||||
// "extendedTimeOut": "1000",
|
|
||||||
// "showEasing": "swing",
|
|
||||||
// "hideEasing": "linear",
|
|
||||||
// "showMethod": animation,
|
|
||||||
// "hideMethod": "fadeOut"
|
|
||||||
// });
|
|
||||||
// $('.toast-success').css("background-color", "#4caf50");
|
|
||||||
|
|
||||||
// var publicProductBidBox = document.getElementById("publicProductBidBox");
|
if (!liveScreen && !messageWrapper.hideToaster) {
|
||||||
// if (publicProductBidBox) {
|
var messageTitle = "";
|
||||||
// refreshPublicBidBox(myObject);
|
var messageText = "";
|
||||||
// }
|
var messageColor = "";
|
||||||
|
|
||||||
//},
|
switch (productToAuctionDto.auctionStatus) {
|
||||||
|
case AuctionStatus.None:
|
||||||
|
messageTitle = `Item reset`;
|
||||||
|
messageText = `The bids on item with index ${productToAuctionDto.sortIndex} has been resetted`;
|
||||||
|
messageColor = "#6c757d";
|
||||||
|
break;
|
||||||
|
case AuctionStatus.Active:
|
||||||
|
messageTitle = `Item activated`;
|
||||||
|
messageText = `The bids on item with index ${productToAuctionDto.sortIndex} has been activated`;
|
||||||
|
messageColor = "#4caf50";
|
||||||
|
break;
|
||||||
|
case AuctionStatus.FirstWarning:
|
||||||
|
messageTitle = `First warning!`;
|
||||||
|
messageText = `Hurry up! If no more bids, this item will be closed soon!`;
|
||||||
|
messageColor = "#ffc107";
|
||||||
|
break;
|
||||||
|
case AuctionStatus.SecondWarning:
|
||||||
|
messageTitle = `Second warning!`;
|
||||||
|
messageText = `Hurry up! If no more bids, this item will be closed soon!`;
|
||||||
|
messageColor = "#dc3545";
|
||||||
|
break;
|
||||||
|
case AuctionStatus.Pause:
|
||||||
|
messageTitle = `Administrative message`;
|
||||||
|
messageText = `The administrator has suspended the auction, it will go on soon probably`;
|
||||||
|
messageColor = "#6c757d";
|
||||||
|
break;
|
||||||
|
case AuctionStatus.Sold:
|
||||||
|
messageTitle = `Item sold!`;
|
||||||
|
messageText = `The item has been sold, we are transitioning to the next item!`;
|
||||||
|
messageColor = "#4caf50";
|
||||||
|
break;
|
||||||
|
case AuctionStatus.NotSold:
|
||||||
|
messageTitle = `Item closed!`;
|
||||||
|
messageText = `The item has been closed, we are transitioning to the next item!`;
|
||||||
|
messageColor = "#6c757d";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Add more handlers as needed
|
toastr.success(`<div class="item bidToast"><p>${messageText}</p></div>`,
|
||||||
default: function (data) {
|
messageTitle,
|
||||||
console.warn("Unhandled message type:", data);
|
{
|
||||||
}
|
"closeButton": true,
|
||||||
};
|
"positionClass": "toast-bottom-left",
|
||||||
|
"newestOnTop": true,
|
||||||
|
"progressBar": true,
|
||||||
|
"preventDuplicates": false,
|
||||||
|
"onclick": null,
|
||||||
|
"showDuration": "30000",
|
||||||
|
"hideDuration": "1000",
|
||||||
|
"timeOut": "5000",
|
||||||
|
"extendedTimeOut": "1000",
|
||||||
|
"showEasing": "swing",
|
||||||
|
"hideEasing": "linear",
|
||||||
|
"showMethod": animation,
|
||||||
|
"hideMethod": "fadeOut"
|
||||||
|
});
|
||||||
|
$('.toast-success').css("background-color", messageColor);
|
||||||
|
}
|
||||||
|
|
||||||
// Message router to route to the appropriate handler based on message type
|
if (publicProductBidBox) {
|
||||||
function messageRouter(message) {
|
handleAuctionUpdate(auctionStatusNotification);
|
||||||
// Parse the JSON message
|
}
|
||||||
try {
|
|
||||||
var parsedMessage = JSON.parse(message);
|
|
||||||
var messageType = parsedMessage.messageType;
|
|
||||||
var senderId = parsedMessage.senderId;
|
|
||||||
var messageData = parsedMessage.data;
|
|
||||||
console.log("Message type:" + messageType);
|
|
||||||
console.log("Message sender:" + senderId);
|
|
||||||
console.log("Message content" + parsedMessage.data);
|
|
||||||
// Route to appropriate handler, default if no match
|
|
||||||
(handlers[messageType] || handlers.default)(messageData);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Error parsing message:", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
if (liveScreen) {
|
||||||
handle: messageRouter
|
reloadOnUpdate();
|
||||||
};
|
}
|
||||||
|
|
||||||
|
if (publicInfo) {
|
||||||
|
var functionName = "refreshPublicInfo" + productToAuctionDto.productId;
|
||||||
|
window[functionName](auctionDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
// var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||||
|
// if (publicProductBidBox)
|
||||||
|
// {
|
||||||
|
// refreshPublicBidBox(myObject);
|
||||||
|
// }
|
||||||
|
},
|
||||||
|
|
||||||
|
//openItemMessage: function(messageWrapper) {
|
||||||
|
// var openItemNotification = JSON.parse(messageWrapper.data);
|
||||||
|
|
||||||
|
// if (!messageWrapper.hideToaster) {
|
||||||
|
// toastr.success(
|
||||||
|
// `<div class="item bidToast"><p>${openItemNotification.nextBidPrice}</p><p>${openItemNotification
|
||||||
|
// .productName}</p></div>`,
|
||||||
|
// "Item auction is OPENED!",
|
||||||
|
// {
|
||||||
|
// "closeButton": true,
|
||||||
|
// "positionClass": "toast-top-right",
|
||||||
|
// "newestOnTop": true,
|
||||||
|
// "progressBar": true,
|
||||||
|
// "preventDuplicates": false,
|
||||||
|
// "onclick": null,
|
||||||
|
// "showDuration": "30000",
|
||||||
|
// "hideDuration": "1000",
|
||||||
|
// "timeOut": "5000",
|
||||||
|
// "extendedTimeOut": "1000",
|
||||||
|
// "showEasing": "swing",
|
||||||
|
// "hideEasing": "linear",
|
||||||
|
// "showMethod": animation,
|
||||||
|
// "hideMethod": "fadeOut"
|
||||||
|
// });
|
||||||
|
// $('.toast-success').css("background-color", "#4caf50");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var publicProductBidBox = document.getElementById("publicProductBidBox");
|
||||||
|
// if (publicProductBidBox) {
|
||||||
|
// refreshPublicBidBox(openItemNotification);
|
||||||
|
// }
|
||||||
|
//},
|
||||||
|
|
||||||
|
// Add more handlers as needed
|
||||||
|
default: function(messageWrapperJson) {
|
||||||
|
console.warn("Unhandled message type:", messageWrapperJson);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Message router to route to the appropriate handler based on message type
|
||||||
|
function messageRouter(messageWrapperJson) {
|
||||||
|
// Parse the JSON message
|
||||||
|
try {
|
||||||
|
console.log(messageWrapperJson);
|
||||||
|
|
||||||
|
var messageWrapper = JSON.parse(messageWrapperJson);
|
||||||
|
var messageType = messageWrapper.messageType;
|
||||||
|
//var senderId = messageWrapper.senderId;
|
||||||
|
|
||||||
|
//console.log("Message type:" + messageType);
|
||||||
|
//console.log("Message sender:" + senderId);
|
||||||
|
//console.log("Message hideToaster:" + messageWrapper.hideToaster);
|
||||||
|
//console.log("Message content" + messageWrapper.data);
|
||||||
|
|
||||||
|
// Route to appropriate handler, default if no match
|
||||||
|
(handlers[messageType] || handlers.default)(messageWrapper);
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error parsing message:", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
handle: messageRouter
|
||||||
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
using AyCode.Core.Extensions;
|
using System.Text.Json.Nodes;
|
||||||
|
using AyCode.Core.Extensions;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Nop.Services.Logging;
|
using Nop.Services.Logging;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
using Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
using Nop.Plugin.Misc.AuctionPlugin.Services;
|
||||||
using AyCode.Utils.Extensions;
|
using AyCode.Utils.Extensions;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Nop.Services.Customers;
|
using Nop.Services.Customers;
|
||||||
using Nop.Core;
|
using Nop.Core;
|
||||||
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
using Nop.Plugin.Misc.AuctionPlugin.Domains.Enums;
|
||||||
|
|
@ -11,10 +13,10 @@ using Nop.Plugin.Misc.AuctionPlugin.Domains.Entities;
|
||||||
using Nop.Core.Domain.Catalog;
|
using Nop.Core.Domain.Catalog;
|
||||||
using Nop.Core.Domain.Customers;
|
using Nop.Core.Domain.Customers;
|
||||||
using Nop.Services.Catalog;
|
using Nop.Services.Catalog;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
{
|
{
|
||||||
|
|
||||||
public class AuctionHub(SessionService sessionService, ILogger logger, IProductService productService, AuctionService auctionService, IWorkContext workContext, ICustomerService customerService, ICategoryService categoryService)
|
public class AuctionHub(SessionService sessionService, ILogger logger, IProductService productService, AuctionService auctionService, IWorkContext workContext, ICustomerService customerService, ICategoryService categoryService)
|
||||||
: Hub<IAuctionHubClient>
|
: Hub<IAuctionHubClient>
|
||||||
{
|
{
|
||||||
|
|
@ -166,7 +168,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
productToAuction.BidsCount = await auctionService.GetBidsCountByProductToAuctionIdAsync(productToAuction.Id);
|
productToAuction.BidsCount = await auctionService.GetBidsCountByProductToAuctionIdAsync(productToAuction.Id);
|
||||||
await SetAuctionBidPrice(revertLastBid.BidPrice, productToAuction, product, revertLastBid.CustomerId);
|
await SetAuctionBidPriceAsync(revertLastBid.BidPrice, productToAuction, product, revertLastBid.CustomerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
await SendAuctionBidMessageAsync(messageWrapper, productToAuction, product, customer.Id, ResponseType.ToAllClients);
|
await SendAuctionBidMessageAsync(messageWrapper, productToAuction, product, customer.Id, ResponseType.ToAllClients);
|
||||||
|
|
@ -216,7 +218,13 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
return ResponseType.Error;
|
return ResponseType.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidBidPrice(activeProductAuction.CurrentPrice, bidRequestMessage.BidPrice, activeProductAuction.BidsCount > 0, customer))
|
if (!await IsValidProductPricesAndSyncIfNeedAsync(activeProductAuction, product, customer))
|
||||||
|
{
|
||||||
|
await SendAuctionBidMessageAsync(messageWrapper, activeProductAuction, product, customer.Id, ResponseType.ToAllClients);
|
||||||
|
return ResponseType.Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsValidBidPrice(activeProductAuction, bidRequestMessage.BidPrice, customer))
|
||||||
{
|
{
|
||||||
await SendAuctionBidMessageAsync(messageWrapper, activeProductAuction, product, customer.Id, ResponseType.ToCaller);
|
await SendAuctionBidMessageAsync(messageWrapper, activeProductAuction, product, customer.Id, ResponseType.ToCaller);
|
||||||
return ResponseType.Error;
|
return ResponseType.Error;
|
||||||
|
|
@ -229,7 +237,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
activeProductAuction.BidsCount++;
|
activeProductAuction.BidsCount++;
|
||||||
|
|
||||||
activeProductAuction.AuctionStatus = AuctionStatus.Active;
|
activeProductAuction.AuctionStatus = AuctionStatus.Active;
|
||||||
if (!await SetAuctionBidPrice(auctionBid.BidPrice, activeProductAuction, product, customer.Id))
|
if (!await SetAuctionBidPriceAsync(auctionBid.BidPrice, activeProductAuction, product, customer.Id))
|
||||||
{
|
{
|
||||||
await SendAuctionBidMessageAsync(messageWrapper, activeProductAuction, product, customer.Id, ResponseType.ToCaller);
|
await SendAuctionBidMessageAsync(messageWrapper, activeProductAuction, product, customer.Id, ResponseType.ToCaller);
|
||||||
return ResponseType.Error;
|
return ResponseType.Error;
|
||||||
|
|
@ -373,7 +381,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
await HandleProductToAuctionStatusChangedRequest(customer, statusChangedMessageWrapper);
|
await HandleProductToAuctionStatusChangedRequest(customer, statusChangedMessageWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> SetAuctionBidPrice(decimal bidPrice, ProductToAuctionMapping productToAuction, Product product, int lastBidCustomerId)
|
private async Task<bool> SetAuctionBidPriceAsync(decimal bidPrice, ProductToAuctionMapping productToAuction, Product product, int lastBidCustomerId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -389,18 +397,48 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.Error($"AuctionHub.HandleBidRequest(); SetAuctionBidPrice() == false", ex);
|
logger.Error($"AuctionHub.SetAuctionBidPriceAsync();", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsValidBidPrice(decimal productToAuctionCurrentPrice, decimal bidRequestPrice, bool hasAuctionBidInDb, Customer customer = null)
|
private async Task<bool> IsValidProductPricesAndSyncIfNeedAsync(ProductToAuctionMapping productToAuction, Product product, Customer customer = null)
|
||||||
{
|
{
|
||||||
var nextBidPrice = AuctionService.GetNextBidPrice(productToAuctionCurrentPrice, hasAuctionBidInDb);
|
if (product.Price == productToAuction.CurrentPrice) return true;
|
||||||
|
|
||||||
|
if (productToAuction.AuctionStatus is AuctionStatus.Sold or AuctionStatus.NotSold)
|
||||||
|
{
|
||||||
|
await logger.ErrorAsync($"AuctionHub.SyncProductPricesIfNeedAsync(); (product.Price != productToAuction.CurrentPrice && (productToAuction.AuctionStatus is AuctionStatus.Sold or AuctionStatus.NotSold)); productPrice: {product.Price}; productToAuctionCurrentPrice: {productToAuction.CurrentPrice}; auctionStatus: {productToAuction.AuctionStatus}", null, customer);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await logger.ErrorAsync($"AuctionHub.SyncProductPricesIfNeedAsync(); (product.Price != productToAuction.CurrentPrice); productPrice: {product.Price}; productToAuctionCurrentPrice: {productToAuction.CurrentPrice}", null, customer);
|
||||||
|
|
||||||
|
var lastBidPrice = product.OldPrice;
|
||||||
|
var lastBid = await auctionService.GetLastAuctionBidByProductToAuctionIdAsync(productToAuction.Id);
|
||||||
|
|
||||||
|
if (lastBid == null)
|
||||||
|
{
|
||||||
|
productToAuction.StartingPrice = lastBidPrice;
|
||||||
|
productToAuction.BidsCount = 0;
|
||||||
|
}
|
||||||
|
else lastBidPrice = lastBid.BidPrice;
|
||||||
|
|
||||||
|
await SetAuctionBidPriceAsync(lastBidPrice, productToAuction, product, lastBid?.CustomerId ?? 0);
|
||||||
|
|
||||||
|
await logger.InformationAsync($"AuctionHub.SyncProductPricesIfNeedAsync(); Synchronize the price was successful! lastBidPrice: {lastBidPrice};", null, customer);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool IsValidBidPrice(ProductToAuctionMapping productToAuction, decimal bidRequestPrice, Customer customer = null)
|
||||||
|
{
|
||||||
|
var hasAuctionBidInDb = productToAuction.BidsCount > 0;
|
||||||
|
var nextBidPrice = AuctionService.GetNextBidPrice(productToAuction.CurrentPrice, hasAuctionBidInDb);
|
||||||
|
|
||||||
if (bidRequestPrice != nextBidPrice)
|
if (bidRequestPrice != nextBidPrice)
|
||||||
{
|
{
|
||||||
logger.Warning($"AuctionHub.IsValidBidPrice(); (bidRequestPrice != nextBidPrice); productToAuctionCurrentPrice: {productToAuctionCurrentPrice}; bidRequestPrice: {bidRequestPrice}; hasAuctionBidInDb: {hasAuctionBidInDb}", null, customer);
|
logger.Warning($"AuctionHub.IsValidBidPrice(); (bidRequestPrice != nextBidPrice); productToAuctionCurrentPrice: {productToAuction.CurrentPrice}; bidRequestPrice: {bidRequestPrice}; hasAuctionBidInDb: {hasAuctionBidInDb}", null, customer);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -479,10 +517,24 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
switch (messageWrapper.ResponseType)
|
switch (messageWrapper.ResponseType)
|
||||||
{
|
{
|
||||||
case ResponseType.ToCaller:
|
case ResponseType.ToCaller:
|
||||||
|
messageWrapper.HideToaster = true;
|
||||||
await Clients.Caller.send(messageWrapper.ToJson());
|
await Clients.Caller.send(messageWrapper.ToJson());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ResponseType.ToAllClients:
|
case ResponseType.ToAllClients:
|
||||||
await Clients.All.send(messageWrapper.ToJson());
|
var messageWrapperJson = messageWrapper.ToJson();
|
||||||
|
|
||||||
|
if (messageWrapper.HideToaster) await Clients.All.send(messageWrapperJson);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Clients.Others.send(messageWrapperJson);
|
||||||
|
|
||||||
|
var messageWrapperJObject = JObject.Parse(messageWrapperJson);
|
||||||
|
messageWrapperJObject["hideToaster" /*nameof(MessageWrapper.HideToaster)*/] = "true";
|
||||||
|
|
||||||
|
await Clients.Caller.send(messageWrapperJObject.ToString(Formatting.None));
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ResponseType.Error:
|
case ResponseType.Error:
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs.Messages
|
||||||
public string RequestId { get; set; }
|
public string RequestId { get; set; }
|
||||||
public int RequestCount { get; set; }
|
public int RequestCount { get; set; }
|
||||||
public ResponseType ResponseType { get; set; }
|
public ResponseType ResponseType { get; set; }
|
||||||
|
public bool HideToaster { get; set; }
|
||||||
public string Data { get; set; }
|
public string Data { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,8 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
//- ha bid-elt 1x is, kerüljön a watch-ba
|
//- ha bid-elt 1x is, kerüljön a watch-ba
|
||||||
//- DbTransaction-t vhogy megcsinánli!
|
//- DbTransaction-t vhogy megcsinánli!
|
||||||
|
|
||||||
public class SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext, ICustomerService customerService, ICategoryService categoryService)
|
//public class SignalRMessageHandler(ILogger logger, IProductService productService, AuctionService auctionService, IHubContext<AuctionHub> hubContext, IWorkContext workContext, ICustomerService customerService, ICategoryService categoryService)
|
||||||
{
|
//{
|
||||||
//private readonly Mutex _handleMessageMutex = new();
|
//private readonly Mutex _handleMessageMutex = new();
|
||||||
|
|
||||||
//public async Task HandleMessage(MessageWrapper messageWrapper, SessionItem sessionItem, string connectionId)
|
//public async Task HandleMessage(MessageWrapper messageWrapper, SessionItem sessionItem, string connectionId)
|
||||||
|
|
@ -444,4 +444,4 @@ namespace Nop.Plugin.Misc.AuctionPlugin.Hubs
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue