public override Task Handle(HandlerContext <Command> context) { Roster roster = CompositionRoot.DocumentSession.Load <Roster>(context.Payload.RosterId); MatchResult matchResult = new( roster, context.Payload.Result.TeamScore, context.Payload.Result.OpponentScore, roster.BitsMatchId); Player[] players = CompositionRoot.DocumentSession.Load <Player>(roster.Players); MatchSerie[] matchSeries = context.Payload.Result.CreateMatchSeries(); Dictionary <string, ResultForPlayerIndex.Result> resultsForPlayer = CompositionRoot.DocumentSession.Query <ResultForPlayerIndex.Result, ResultForPlayerIndex>() .Where(x => x.Season == roster.Season) .ToArray() .ToDictionary(x => x.PlayerId); matchResult.RegisterSeries( task => context.PublishMessage(task), matchSeries, context.Payload.Result.OpponentSeries, players, resultsForPlayer); CompositionRoot.EventStoreSession.Store(matchResult); return(Task.CompletedTask); }
public override Task Handle(HandlerContext <Command> context) { int season = CompositionRoot.DocumentSession.LatestSeasonOrDefault(SystemTime.UtcNow.Year); Roster[] rosters = CompositionRoot.DocumentSession.Query <Roster, RosterSearchTerms>() .Where(x => x.Season == season) .ToArray(); List <VerifyMatchTask> toVerify = new(); foreach (Roster roster in rosters) { if (roster.BitsMatchId == 0) { continue; } if (roster.Date.ToUniversalTime() > SystemTime.UtcNow) { Logger.InfoFormat( "Too early to verify {bitsMatchId}", roster.BitsMatchId); continue; } if (roster.IsVerified && context.Payload.Force == false) { Logger.InfoFormat( "Skipping {bitsMatchId} because it is already verified", roster.BitsMatchId); } else { VerifyMatchTask verifyTask = new( roster.BitsMatchId, roster.Id !, context.Payload.Force); toVerify.Add(verifyTask); } } foreach (VerifyMatchTask verifyMatchMessage in toVerify) { Logger.InfoFormat( "Scheduling verification of {bitsMatchId}", verifyMatchMessage.BitsMatchId); context.PublishMessage(verifyMatchMessage); } return(Task.CompletedTask); }
public override Task Handle(HandlerContext <Command> context) { SendEmailTask task = SendEmailTask.Create( context.Payload.Recipient, context.Payload.ReplyTo, context.Payload.Subject, context.Payload.Content, context.Payload.Rate, context.Payload.PerSeconds, context.Payload.Key); context.PublishMessage(task); return(Task.CompletedTask); }
public override Task Handle(HandlerContext <Command> context) { Roster roster = CompositionRoot.DocumentSession.Load <Roster>(context.Payload.RosterId); MatchResult4 matchResult = new( roster, context.Payload.Result.TeamScore, context.Payload.Result.OpponentScore, roster.BitsMatchId); Player[] players = CompositionRoot.DocumentSession.Load <Player>(roster.Players); MatchSerie4[] matchSeries = context.Payload.Result.CreateMatchSeries(); matchResult.RegisterSeries( task => context.PublishMessage(task), matchSeries, players, context.Payload.SummaryText ?? string.Empty, context.Payload.SummaryHtml ?? string.Empty); CompositionRoot.EventStoreSession.Store(matchResult); return(Task.CompletedTask); }
public override Task Handle(HandlerContext <Command> context) { IndexCreator.CreateIndexes(CompositionRoot.DocumentStore); User admin = CompositionRoot.DocumentSession.Load <User>(User.AdminId); if (admin == null) { admin = new("", "", context.Payload.Email, context.Payload.Password) { Id = User.AdminId }; admin.Initialize(t => context.PublishMessage(t)); admin.Activate(); CompositionRoot.DocumentSession.Store(admin); } else { admin.SetEmail(context.Payload.Email); admin.SetPassword(context.Payload.Password); admin.Activate(); } return(Task.CompletedTask); }
public override async Task Handle(HandlerContext <Command> context) { IQueryable <string> query = from rosterMail in CompositionRoot.Databases.Snittlistan.RosterMails where rosterMail.RosterKey == context.Payload.RosterKey && rosterMail.PublishedDate == null select rosterMail.RosterKey; string[] rosterIds = await query.ToArrayAsync(); Logger.InfoFormat("roster mails found: {@rosterIds}", rosterIds); if (rosterIds.Any() == false) { TenantFeatures features = await CompositionRoot.GetFeatures(); _ = CompositionRoot.Databases.Snittlistan.RosterMails.Add( new(context.Payload.RosterKey)); PublishRosterMailsTask task = new( context.Payload.RosterKey, context.Payload.RosterLink, context.Payload.UserProfileLink); context.PublishMessage(task, DateTime.Now.AddMinutes(features.RosterMailDelayMinutes)); } }
public override async Task Handle(HandlerContext <Command> context) { // TODO might be comma-separated values Roster roster = CompositionRoot.DocumentSession.LoadEx <Roster>(context.Payload.RosterKey); AuditLogEntry auditLogEntry = roster.AuditLogEntries.Single(x => x.CorrelationId == context.CorrelationId); RosterState before = (RosterState)auditLogEntry.Before; RosterState after = (RosterState)auditLogEntry.After; HashSet <string> affectedPlayers = new(before.Players.Concat(after.Players)); // find user who did the last edit-players action AuditLogEntry?editPlayersAction = roster.AuditLogEntries.LastOrDefault( x => x.Action == Roster.ChangeType.EditPlayers.ToString()); if (editPlayersAction == null) { throw new Exception($"No edit-players action found in roster {roster.Id}"); } Dictionary <string, Player> playersDict = CompositionRoot.DocumentSession.Load <Player>(affectedPlayers) .ToDictionary(x => x.Id); Player?editPlayer = CompositionRoot.DocumentSession.Load <Player>(editPlayersAction.UserId); User? editUser = CompositionRoot.DocumentSession.FindUserByEmail(editPlayersAction.UserId); string replyToEmail = editPlayer?.Email ?? editUser?.Email ?? throw new Exception($"Unable to find edit-players action user with id '{editPlayersAction.UserId}'"); if (editPlayer is not null) { _ = affectedPlayers.Add(editPlayer.Id); playersDict[editPlayer.Id] = editPlayer; } // only send to players that have accepted email, or have not yet decided string[] propertyKeys = affectedPlayers.Select(UserSettings.GetKey).ToArray(); Dictionary <string, UserSettings> properties = Enumerable.ToDictionary( await context.Databases.Snittlistan.KeyValueProperties.Where( x => propertyKeys.Contains(x.Key)) .ToArrayAsync(), x => x.Key, x => (UserSettings)x.Value); foreach (string playerId in affectedPlayers) { Player player = playersDict[playerId]; do { if (properties.TryGetValue( UserSettings.GetKey(playerId), out UserSettings? settings)) { Logger.InfoFormat( "found user settings for {playerId} {@settings}", playerId, settings); } else { Logger.InfoFormat( "no user settings found for {playerId}", playerId); } if (string.IsNullOrEmpty(player.Email)) { Logger.InfoFormat("no email set for player {playerId}", playerId); break; } if ((settings?.RosterMailEnabled ?? true) == false) { Logger.InfoFormat("roster mail disabled for player {playerId}", playerId); break; } PublishRosterMailTask message = new( context.Payload.RosterKey, player.Id, player.Email, player.Nickname ?? player.Name, replyToEmail, context.Payload.RosterLink, context.Payload.UserProfileLink); context.PublishMessage(message); }while (false); } RosterMail rosterMail = await context.Databases.Snittlistan.RosterMails.SingleAsync( x => x.RosterKey == context.Payload.RosterKey && x.PublishedDate == null); rosterMail.MarkPublished(DateTime.Now); }
public override async Task Handle(HandlerContext <Command> context) { Roster roster = CompositionRoot.DocumentSession.Load <Roster>(context.Payload.RosterId); if (roster.IsVerified && context.Payload.Force == false) { return; } WebsiteConfig websiteConfig = CompositionRoot.DocumentSession.Load <WebsiteConfig>(WebsiteConfig.GlobalId); HeadInfo result = await CompositionRoot.BitsClient.GetHeadInfo(roster.BitsMatchId); ParseHeaderResult header = BitsParser.ParseHeader(result, websiteConfig.ClubId); // chance to update roster values Roster.Update update = new( Roster.ChangeType.VerifyMatchMessage, "system") { OilPattern = header.OilPattern, Date = header.Date, Opponent = header.Opponent, Location = header.Location }; if (roster.MatchResultId != null) { // update match result values BitsMatchResult bitsMatchResult = await CompositionRoot.BitsClient.GetBitsMatchResult(roster.BitsMatchId); Player[] players = CompositionRoot.DocumentSession.Query <Player, PlayerSearch>() .ToArray() .Where(x => x.PlayerItem?.LicNbr != null) .ToArray(); BitsParser parser = new(players); if (roster.IsFourPlayer) { MatchResult4?matchResult = CompositionRoot.EventStoreSession.Load <MatchResult4>(roster.MatchResultId); Parse4Result?parseResult = parser.Parse4(bitsMatchResult, websiteConfig.ClubId); update.Players = parseResult !.GetPlayerIds(); bool isVerified = matchResult !.Update( t => context.PublishMessage(t), roster, parseResult.TeamScore, parseResult.OpponentScore, roster.BitsMatchId, parseResult.CreateMatchSeries(), players); update.IsVerified = isVerified; } else { MatchResult?matchResult = CompositionRoot.EventStoreSession.Load <MatchResult>(roster.MatchResultId); ParseResult?parseResult = parser.Parse(bitsMatchResult, websiteConfig.ClubId); update.Players = parseResult !.GetPlayerIds(); Dictionary <string, ResultForPlayerIndex.Result> resultsForPlayer = CompositionRoot.DocumentSession.Query <ResultForPlayerIndex.Result, ResultForPlayerIndex>() .Where(x => x.Season == roster.Season) .ToArray() .ToDictionary(x => x.PlayerId); MatchSerie[] matchSeries = parseResult.CreateMatchSeries(); bool isVerified = matchResult !.Update( t => context.PublishMessage(t), roster, parseResult.TeamScore, parseResult.OpponentScore, matchSeries, parseResult.OpponentSeries, players, resultsForPlayer); update.IsVerified = isVerified; } } _ = roster.UpdateWith(context.CorrelationId, update); }