private ProcessResults ProcessNewMessages(IList <GroupMessage> raw) { var results = new ProcessResults(); //process messages in batches to reduce the size of the Transactions //and have less loss due to an error const int batchSize = 10; for (int start = 0; start < raw.Count; start += batchSize) { NH.UsingSession(s => { var battle = s.Get <Battle>(settings.BattleId.Value); var p = new IntelReportProcessor(s, battle); for (int i = start; i < raw.Count && i < (start + batchSize); ++i) { bool isBot; p.ProcessMessage(raw[i], out isBot); results.LastMessageWasBot = isBot; s.Flush(); } results.NewStatsCount += p.NewStatsCount; }); } return(results); }
public BattleSelector() { InitializeComponent(); dtpBattleStarts.Value = DateTime.Today; dtpBattleEnds.Value = DateTime.Today.AddDays(3); listBox1.DisplayMember = "Name"; NH.UsingSession(s => { LoadBattles(s); }); }
private string GetLastNonBotGroupMessageId() { string lastMessageId = null; NH.UsingSession(s => { lastMessageId = s.QueryOver <IntelReport>() .Where(x => x.Battle.Id == settings.BattleId.Value) .And(x => x.GroupId == settings.GroupId) .And(x => x.IsBotMessage == false) .Select(x => x.MessageId) .OrderBy(x => x.CreateDateUTC).Desc .Take(1) .SingleOrDefault <string>(); }); return(lastMessageId); }
private void btnCreateBattle_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtBattleName.Text)) { MessageBox.Show(this, "Please enter a battle name."); return; } NH.UsingSession(s => { var b = new Battle { Name = txtBattleName.Text, StartDateUTC = dtpBattleStarts.Value.ToUniversalTime(), EndDateUTC = dtpBattleEnds.Value.ToUniversalTime() }; s.Save(b); LoadBattles(s); }); }
private void TryUpdateIntelSheet() { IList <BattleStat> allStats = null; NH.UsingSession(s => { Team teamAlias = null; allStats = s.QueryOver <BattleStat>() .JoinAlias(x => x.Team, () => teamAlias) .Where(x => x.Battle.Id == settings.BattleId.Value) .And(x => !x.IsDeleted) .OrderBy(x => x.Team).Asc .ThenBy(x => x.Stat.Level).Desc .ThenBy(x => x.Stat.DefenseValue).Desc .ThenBy(x => x.Stat.Name).Asc .List(); }); var sheetData = allStats.GroupBy(x => new { TeamId = x.Team.Id, TeamName = x.Team.Name }) .Select(k => new IntelDataRow { Team = k.Key.TeamName, Stats = k.Key.TeamName + "\n" + string.Join("\n", k.Select(x => x.Stat) .OrderByDescending(x => x.Level) .ThenByDescending(x => x.DefenseValue) .ThenBy(x => x.Name) .Select(x => x.ToLine())) }).OrderBy(x => x.Team).ToList(); try { google.MergeSheet(settings.WorksheetCellsFeedURI, settings.WorksheetListFeedURI, sheetData); } catch (Exception ex) { LogError("MergeSheet", ex); } }
private void TryPostSpeadsheetURL() { GroupMessage botMessage = null; try { botMessage = groupMe.PostGroupMessage(settings.GroupId, settings.SpreadsheetURL); } catch (Exception ex) { LogError("PostGroupMessage", ex); } if (botMessage != null) { NH.UsingSession(s => { var battle = s.Get <Battle>(settings.BattleId.Value); new IntelReportProcessor(s, battle).ProcessBotPost(botMessage); }); } }