private void calculateAlone() { MapWithMaxProxy <string, LocationDataEvaluation> userToCheckinLocationMap = new MapWithMaxProxy <string, LocationDataEvaluation>() { MaxComperator = (pair1, pair2) => pair1.Value.UsersWhoVisited.Count.CompareTo(pair2.Value.UsersWhoVisited.Count) }; foreach (User currentFriendToEval in m_LoggedInUser.Friends) { foreach (Checkin currentCheckInToAdd in currentFriendToEval.Checkins) { LocationDataEvaluation outForTryGet; if (!userToCheckinLocationMap.TryGetValue(currentCheckInToAdd.Place.Name, out outForTryGet)) { outForTryGet = new LocationDataEvaluation(currentCheckInToAdd.Place); userToCheckinLocationMap.Add(currentCheckInToAdd.Place.Name, outForTryGet); } outForTryGet.UsersWhoVisited.Add(currentFriendToEval); } } KeyValuePair <string, LocationDataEvaluation> max = userToCheckinLocationMap.GetMaxFromMap(); if (userToCheckinLocationMap.Count != 0) { friendsToAvoidbindingSource.DataSource = max.Value.UsersWhoVisited; placeToAvoidBindingSource.DataSource = max.Value.Location; } panelAloneCalculating.Invoke(new Action(() => panelAloneCalculating.Visible = false)); buttonAlonGet.Invoke(new Action(() => buttonAlonGet.Enabled = true)); panelAloneResults.Invoke(new Action(() => panelAloneResults.Visible = true)); }
private static Tuple <User, UserDataEvaluation> initStalkerObject(User i_UserToStalk, ProgressBar i_ProgressBar) { i_ProgressBar.Invoke(new Action(() => i_ProgressBar.Visible = true)); i_ProgressBar.Invoke(new Action(() => i_ProgressBar.Maximum = i_UserToStalk.Posts.Count + i_UserToStalk.Albums.Count)); MapWithMaxProxy <string, Tuple <User, UserDataEvaluation> > UserNameToDataEvalMap = new MapWithMaxProxy <string, Tuple <User, UserDataEvaluation> >() { MaxComperator = (pair1, pair2) => pair1.Value.Item2.CompareTo(pair2.Value.Item2) }; foreach (Post currentPost in i_UserToStalk.Posts) { calcDataFromUserCollection( currentPost.LikedBy, UserNameToDataEvalMap, new Action <UserDataEvaluation>(data => data.NumberOfPostsLikes++)); calcDataFromCommentCollection( currentPost.Comments, UserNameToDataEvalMap, new Action <UserDataEvaluation>(data => data.NumberOfPostsComments++)); i_ProgressBar.Invoke(new Action(() => i_ProgressBar.Value++)); } foreach (Album currentAlbum in i_UserToStalk.Albums) { foreach (Photo currentPhoto in currentAlbum.Photos) { calcDataFromUserCollection( currentPhoto.LikedBy, UserNameToDataEvalMap, new Action <UserDataEvaluation>(data => data.NumberOfPhotoLike++)); calcDataFromCommentCollection( currentPhoto.Comments, UserNameToDataEvalMap, new Action <UserDataEvaluation>(data => data.NumberOfPhotoComments++)); } i_ProgressBar.Invoke(new Action(() => i_ProgressBar.Value++)); } Tuple <User, UserDataEvaluation> resultStalker; KeyValuePair <string, Tuple <User, UserDataEvaluation> > stalker = UserNameToDataEvalMap.GetMaxFromMap(); if (UserNameToDataEvalMap.Count != 0) { string stalkerName = stalker.Key; User stalkerUser = i_UserToStalk.Friends.Find(data => data.Name == stalkerName); ////stalker is not one of your friends if (stalkerUser == null) { stalkerUser = stalker.Value.Item1; } resultStalker = new Tuple <User, UserDataEvaluation>(stalkerUser, stalker.Value.Item2); } else { resultStalker = new Tuple <User, UserDataEvaluation>(i_UserToStalk, new UserDataEvaluation()); } i_ProgressBar.Invoke(new Action(() => i_ProgressBar.Visible = false)); return(resultStalker); }