public void Add(UserMatchData userMatchData) { //get correct elo(s) types to display var formatingTargetTypes = EloFormattController.GetTargetEloTypes(userMatchData.MatchType); var playerPanel = new PlayerPanel2 { //PlayerName = userStats.Name, //Civilization = userStats.Civilization, //PlayerColor = userStats.Color, //OneVsOneElo = null, //TeamGameElo = null, PrimaryUserRankModeDisplay = formatingTargetTypes.Item1, SecondaryUserRankModeDisplay = formatingTargetTypes.Item2, UserMatchData = userMatchData, Width = 275 }; if (userMatchData.Team == 1) { playerPanel.ContentAlign = PlayerPanelContentAlignMode.Left; team1.Children.Add(playerPanel); } else if (userMatchData.Team == 2) { playerPanel.ContentAlign = PlayerPanelContentAlignMode.Right; team2.Children.Add(playerPanel); } }
PlayerPanel2 GetPlayerPanelByUserGameProfileId(UserGameProfileId userGameProfileId) { PlayerPanel2 panelToFind = null; this.Dispatcher.Invoke(() => { //search for data related with userGameProfileId in fisrt collection (team 1) foreach (var child in team1.Children) { var control = child as PlayerPanel2; if (control.UserMatchData.UserGameProfileId.ProfileId == userGameProfileId.ProfileId) { panelToFind = control; break; } } //search for data related with userGameProfileId in second collection (team 2) foreach (var child in team2.Children) { if (panelToFind != null) { break; } var control = child as PlayerPanel2; if (control.UserMatchData.UserGameProfileId.ProfileId == userGameProfileId.ProfileId) { panelToFind = control; break; } } }); return(panelToFind); }
void HandleUserRatingChanged(Tuple <UserGameProfileId, UserData> userRatingData) { var id = userRatingData.Item1; var rank = userRatingData.Item2; UserMatchData targetData = null; PlayerPanel2 targetControl = null; team1.Dispatcher.Invoke(() => { //search for data related with userGameProfileId in fisrt collection (team 1) foreach (var child in team1.Children) { var control = child as PlayerPanel2; if (control.UserMatchData.UserGameProfileId.ProfileId == id.ProfileId) { targetData = control.UserMatchData; targetControl = control; break; } } //search for data related with userGameProfileId in second collection (team 2) foreach (var child in team2.Children) { if (targetData != null) { break; } var control = child as PlayerPanel2; if (control.UserMatchData.UserGameProfileId.ProfileId == id.ProfileId) { targetData = control.UserMatchData; targetControl = control; break; } } //if found if (targetData != null) { team1.Dispatcher.Invoke(() => { var logPropertiesBeforeUpdate = new Dictionary <string, object> { { "update target", targetData.ToString() } }; #if DEBUG LogService.Debug($"Updating user data {id} rank", logPropertiesBeforeUpdate); #else LogService.Trace($"Updating user data {id} rank"); #endif try { targetData.MergeUserRank(rank); //todo: refactor implementing INotifyPropertyChanged chain in models to auto perform property update targetControl.UpdateUserELO(); } catch (Exception e) { //rethrow if should be handled ie: if exception is StackOverflowException e.RethrowIfExceptionCantBeHandled(); var logProperties = new Dictionary <string, object>(); logProperties.Add("id", id); logProperties.Add("stack", e.StackTrace); LogService.Warning($"Unable to merge user ratings: {e.ToString()}", logProperties); } }); } else { var logProperties = new Dictionary <string, object> { //logProperties.Add("Team 1: ", team1.Children); //logProperties.Add("Team 2: ", team2.Children); { "User id to update: ", id } }; LogService.Error("Unable to find game profileId to update"); } }); }