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 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); }