public async Task Execute(IJobExecutionContext context) { /*Industry ind = new Industry(await db.getJObjectAsync(auction.industryID, "industries")); * ind.CompanyId = auction.currentWinner; * await db.SetJObjectAsync(ind.SerializeIntoJObject(), "industries"); * string markchan = (string)await db.GetFieldAsync("MarketChannel", "channel", "system"); * * await comm.deleteMessageTask(markchan, auction.messageID); * * await comm.PostMessageTask(markchan, $"Auction with ID {auction.id} has been accepted by <@{(string)await db.GetFieldAsync(auction.currentWinner, "name", "companies")}>!"); * await db.RemoveObjectAsync(auction.id, "transactions");*/ IndustryAuction auction = (IndustryAuction)context.JobDetail.JobDataMap.Get("auction"); StockMarketService market = (StockMarketService)context.JobDetail.JobDataMap.Get("market"); CommandHandlingService comm = (CommandHandlingService)context.JobDetail.JobDataMap.Get("command"); DataBaseHandlingService db = (DataBaseHandlingService)context.JobDetail.JobDataMap.Get("db"); auction = new IndustryAuction(await db.getJObjectAsync(auction.id, "transactions")); Industry ind = new Industry(await db.getJObjectAsync(auction.industryID, "industries")); ind.CompanyId = auction.currentWinner; await db.SetJObjectAsync(ind.SerializeIntoJObject(), "industries"); await db.RemoveObjectAsync(auction.id, "transactions"); string markchan = (string)await db.GetFieldAsync("MarketChannel", "channel", "system"); await comm.deleteMessageTask(markchan, auction.messageID); await comm.PostMessageTask(markchan, $"Auction with ID {auction.id} has been accepted by {(string)await db.GetFieldAsync(auction.currentWinner, "name", "companies")}!"); }
public IndustryCommands(IndustryService ind, CompanyService com, DataBaseHandlingService db, CommandHandlingService comm, StockMarketService markserv) { _companyService = com; _dataBaseService = db; _commandService = comm; _marketService = markserv; _industryService = ind; }
public ResourceCommands(CompanyService com, DataBaseHandlingService db, CommandHandlingService comm, StockMarketService markserv, ResourceHandlingService res) { _companyService = com; _dataBaseService = db; _commandService = comm; _marketService = markserv; _resourceHandlingService = res; }
public CompanyCommands(CompanyService com, DataBaseHandlingService db, CommandHandlingService comm, StockMarketService markserv) { CompanyService = com; dataBaseService = db; CommandService = comm; MarketService = markserv; guild = ulong.Parse(Resources.guild); #if DEBUG guild = ulong.Parse(Resources.devguild); #endif }
public void Sell_Stock_Add_Trade() { //Arrange var mockRepository = new Mock <ITrade>(); mockRepository.Setup(x => x.AddTrade(It.IsAny <Trade>())); var tradeService = new StockMarketService(mockRepository.Object, DataToTest.Stocks()); //Act tradeService.SellStock(DataToTest.Tea.Symbol, 0.75, 2); //Assert mockRepository.Verify(x => x.AddTrade(It.IsAny <Trade>())); }
public StockMarketServiceTest() { _stockMarketService = new StockMarketService(new Repositories.Trade(), DataToTest.Stocks()); }
public StockMarketCommands(DataBaseHandlingService _db, CommandHandlingService _CommandService, StockMarketService _MarketService) { db = _db; CommandService = _CommandService; MarketService = _MarketService; }
public async Task schedule(DataBaseHandlingService db, CommandHandlingService CommandService, StockMarketService marketService) { if (plannedEnd.Ticks <= DateTime.Now.Ticks) { Industry ind = new Industry(await db.getJObjectAsync(this.industryID, "industries")); ind.CompanyId = this.currentWinner; await db.SetJObjectAsync(ind.SerializeIntoJObject(), "industries"); await db.RemoveObjectAsync(this.id, "transactions"); string markchan = (string)await db.GetFieldAsync("MarketChannel", "channel", "system"); await CommandService.deleteMessageTask(markchan, this.messageID); await CommandService.PostMessageTask(markchan, $"Auction with ID {this.id} has been won by <@{(string)await db.GetFieldAsync(this.currentWinner, "name", "companies")}>!"); return; } JobDataMap map = new JobDataMap(); map.Add("market", marketService); map.Add("auction", this); map.Add("command", CommandService); map.Add("db", db); IJobDetail job = JobBuilder.Create <Job>().SetJobData(map).Build(); ITrigger trigger = TriggerBuilder.Create().WithSimpleSchedule(x => x.WithInterval(TimeSpan.FromMilliseconds(1)).WithRepeatCount(1)).StartAt(plannedEnd).Build(); await CommandService.scheduler.ScheduleJob(job, trigger); }
private async Task <ulong> LodgeTransactionTask(DataBaseHandlingService db, CommandHandlingService CommandService, StockMarketService marketService, int hours, int mins) { EmbedFieldBuilder typeField = new EmbedFieldBuilder().WithIsInline(true).WithName("Type:").WithValue($"Industry Auction"); EmbedFieldBuilder companyField = new EmbedFieldBuilder().WithIsInline(true).WithName("ID:").WithValue(industryID); EmbedFieldBuilder amountField = new EmbedFieldBuilder().WithIsInline(true).WithName("Type:").WithValue((string)await db.GetFieldAsync(industryID, "Type", "industries")); EmbedFieldBuilder priceField = new EmbedFieldBuilder().WithIsInline(true).WithName("Price:").WithValue("$" + price); EmbedBuilder emb = new EmbedBuilder().WithTitle("Stock Market Offer").WithDescription($"Use the command `&bid [ticker] {id.ToString()} [price]` to accept this offer.").WithFooter($"Transaction ID: {id.ToString()}").AddField(typeField).AddField(companyField).AddField(amountField).AddField(priceField).WithColor(Color.Green); Discord.Rest.RestUserMessage message = await CommandService.PostEmbedTask((string)await db.GetFieldAsync("MarketChannel", "channel", "system"), emb.Build()); DateTime now = DateTime.UtcNow; DateTime scheduled = now.AddHours(hours).AddMinutes(mins); plannedEnd = scheduled; JobDataMap map = new JobDataMap(); map.Add("market", marketService); map.Add("auction", this); map.Add("command", CommandService); map.Add("db", db); IJobDetail job = JobBuilder.Create <Job>().SetJobData(map).Build(); ITrigger trigger = TriggerBuilder.Create().WithSimpleSchedule(x => x.WithInterval(TimeSpan.FromMilliseconds(1)).WithRepeatCount(1)).StartAt(plannedEnd).Build(); await CommandService.scheduler.ScheduleJob(job, trigger); return(message.Id); }
/// <summary> /// The constructor for a new transaction. /// </summary> /// <param name="_price">The price per share</param> /// <param name="_shares">The total amount of shares</param> /// <param name="_type">Buy, sell, or private</param> /// <param name="_author">The user who initiated the transaction</param> /// <param name="_ticker">The ticker of the company who's shares are being traded</param> /// <param name="db">A DataBaseHandlingService object</param> /// <param name="command">A CommandHandlingService object</param> /// <param name="hours">Hours until auction ends</param> /// <param name="mins">Minutes until auction ends</param> /// <param name="_industryID">Id of industry being sold</param> public IndustryAuction(double _price, string _type, string _industryID, DataBaseHandlingService db, CommandHandlingService command, StockMarketService marketService, int hours, int mins) { price = _price; currentWinner = ""; industryID = _industryID; id = "ind-" + Guid.NewGuid().ToString(); currentUser = ""; type = "auction"; messageID = Convert.ToString(LodgeTransactionTask(db, command, marketService, hours, mins).GetAwaiter().GetResult()); }