public async Task <bool> LoadItemData(uint itemId) { /* Init prices */ ItemPricesList.Clear(); MeanPrice = 0; /* Check if BidHouse Dialog is open */ if (!_bidHouseBuyDialogIsLoaded) { throw new Exception("La fenêtre HDV n'est pas ouverte."); } /* Request item type of itemid */ if (!await RequestItemType(itemId)) { return(false); } /* We can now request item prices list*/ if (!await RequestItemPrices(itemId)) { return(false); } return(true); }
private void HandleExchangeTypesItemsExchangerDescriptionForUserMessage(IAccount account, ExchangeTypesItemsExchangerDescriptionForUserMessage message) { ItemPricesList.Clear(); message.ItemTypeDescriptions.ForEach(item => ItemPricesList.Add(item.ObjectUID, item.Prices)); _bidHouseActionEvent.Set(); }
private void HandleExchangeTypesItemsExchangerDescriptionForUserMessage(IAccount account, ExchangeTypesItemsExchangerDescriptionForUserMessage message) { ItemPricesList.Clear(); message.ItemTypeDescriptions.ForEach(item => ItemPricesList.Add(item.Prices)); _bidHouseItemQuantityPriceIsLoaded = true; }
public async Task <bool> BuyItem(uint itemUId, uint quantity) { /* Check if BidHouse Dialog is open */ if (!_bidHouseBuyDialogIsLoaded) { throw new Exception("La fenêtre HDV n'est pas ouverte."); } /* Check quantity */ /* We can use log10(|quantity|)%1 */ if ((quantity != 1) & (quantity != 10) & (quantity != 100)) { throw new Exception("La quantité doit être l'une des suivantes : 1, 10, 100."); } /* Check if item exists in bid house */ var Prices = new List <ulong>(); if (!ItemPricesList.TryGetValue(itemUId, out Prices)) { throw new Exception( $"Cet identifiant ({itemUId}) n'existe pas dans la liste des prix ou cette dernière n'a pas été chargée."); } /* Check if requested quantity exists */ var Price = Prices[Convert.ToInt32(Math.Log10(quantity))]; if (!(Price > 0)) { throw new Exception($"Cette quantité ({quantity}) n'existe pas pour l'item demandé."); } Logger.Default.Log($"Achat de {quantity} de l'item portant l'uid {itemUId} au prix de {Price}", LogMessageType.Info); /* All good, we pay */ var message = new ExchangeBidHouseBuyMessage { Uid = itemUId, Qty = quantity, Price = Price }; /* Check if item was successfully bought */ if (await SendAndWait(message, 3000)) { return(true); } throw new Exception("L'item n'a pas pu être acheté."); }
/// <summary> /// Main Method /// </summary> public async Task GetPayments() { await Task.Run(async() => { //Reads from Purchasess.dat Console.WriteLine("Reads from Purchasess.dat"); await MyLogger.WriteLog("Reads from Purchasess.dat"); PurchasesList = await Purchases.GetPurchases(); Console.WriteLine("Ok"); await MyLogger.WriteLog("Done"); //Reads fom Pricess XML Console.WriteLine("Reads from Pices.xml"); await MyLogger.WriteLog("Reads from Pices.xml"); PricesList = await ItemPricesList.GetItemPricesList(); Console.WriteLine("Ok"); await MyLogger.WriteLog("Done"); //Reads from Payments Json Console.WriteLine("Reads from Payments.json"); await MyLogger.WriteLog("Reads from Payments.json"); PaymentsList = await Payment.GetPaiments(); Console.WriteLine("Ok"); await MyLogger.WriteLog("Done"); Console.WriteLine("Start the PaymentsNotMatched Loop"); await MyLogger.WriteLog("Start the PaymentsNotMatched Loop"); foreach (var p in PurchasesList) { PaymentsNotMatched n = new PaymentsNotMatched(); n.Customer = p.Customer; n.Month = p.Month; n.Year = p.Year; n.AmountPaid = await GetAmoutPayd(p); foreach (var i in p.Item) { //Sum the price to total to pay. n.Amount += await GetPriceForProductAsync(i.Id); } // Get the Due value n.AmountDue = n.AmountPaid - n.Amount; //include only unmatched payments if (n.AmountDue != 0) { paymentsNotMatched.Add(n); } } Console.WriteLine("Done"); await MyLogger.WriteLog("Done"); // Free the memmory PaymentsList.Clear(); PurchasesList.Clear(); //Sort the list List <PaymentsNotMatched> payments = paymentsNotMatched.OrderByDescending(x => x.AmountDue).ToList(); // Free the memmory paymentsNotMatched.Clear(); //Save a json File in Data Folder. Console.WriteLine("Save PaymentsNotMatched.json File in the Data Folder."); await FileUtillities.WriteJasonToFile(payments, AppPath + @"\PaymentsNotMatched.json"); Console.WriteLine("Done"); await MyLogger.WriteLog("Done"); //Save Jason File for the WebApp in the dta Folder for the Web Application Console.WriteLine("Save Jason File for the WebApp in the dta Folder for the Web Application."); await FileUtillities.WriteJasonToFile(payments, JsonPath + @"\PaymentsNotMatched.json"); Console.WriteLine("Done"); await MyLogger.WriteLog("Done"); //Save a csv File Console.WriteLine("Save PaymentsNotMatched.csv File in the Data Folder."); await FileUtillities.CreateCSVFromGenericList(payments, AppPath + @"\PaymentsNotMatched.csv"); Console.WriteLine("Done"); await MyLogger.WriteLog("Done"); //Display the data in a Web Page in WebApp }); }
public async Task <bool> LoadItemData(uint itemId) { /* Init prices */ ItemPricesList.Clear(); MeanPrice = 0; /* Check if BidHouse Dialog is open */ if (!_bidHouseDialogIsLoaded) { throw new Exception("La fenêtre HDV n'est pas ouverte."); } /* Request item type of itemid */ if (!RequestItemType(itemId)) { return(false); } /* Check if item type is loaded */ var source = new CancellationTokenSource(); var checkTypeTask = Task.Run(() => { while (!_bidHouseItemTypeIsLoaded) { if (source.IsCancellationRequested) { break; } } }, source.Token); if (await Task.WhenAny(checkTypeTask, Task.Delay(3000, source.Token)) != checkTypeTask) { source.Cancel(); ExitBidHouseDialog(); throw new Exception("La liste des items n'a pas pu s'ouvrir."); } /* We can now request item prices list*/ RequestItemPrices(itemId); /* Check if prices are loaded */ source = new CancellationTokenSource(); var checkPriceTask = Task.Run(() => { while (!_bidHouseItemQuantityPriceIsLoaded || !_bidHouseItemMeanPriceIsLoaded) { if (source.IsCancellationRequested) { break; } } }, source.Token); if (await Task.WhenAny(checkPriceTask, Task.Delay(3000, source.Token)) == checkPriceTask) { return(true); } source.Cancel(); ExitBidHouseDialog(); throw new Exception("La liste des prix de l'item n'a pas pu être chargée."); }