public async Task <TableLayoutPanel> GetLayoutPanelAsync(User i_LoggedInUser) { StateSettings appConfigServiceStateSettings = AppConfigService.GetInstance().StateSettings; TableLayoutPanel panel = new TableLayoutPanel { ColumnCount = 1, AutoScroll = true }; ILikeService likeService = new LikesService(i_LoggedInUser); // get data as defined in settings List <Task> getDataTasks = new List <Task>(); Dictionary <string, int> allPostemItemsLikes = new Dictionary <string, int>(); foreach (KeyValuePair <eLikedItem, bool> keyValuePair in appConfigServiceStateSettings.LikedItems.Where(i_Item => i_Item.Value)) { Task getDataTask = Task.Run( async() => { PropertyInfo propertyInfo = i_LoggedInUser.GetType() .GetProperty(keyValuePair.Key.ToString()); if (propertyInfo != null) { try { object prop = propertyInfo.GetValue(i_LoggedInUser, null); IEnumerable collectionOfUnknownType = (IEnumerable)prop; ObservableCollection <PostedItem> currentPostedItems = new ObservableCollection <PostedItem>(); foreach (PostedItem o in collectionOfUnknownType) { currentPostedItems.Add(o); } Dictionary <string, int> currenLikes = await likeService.GetLikesHistogram(currentPostedItems).ConfigureAwait(false); allPostemItemsLikes.AddRange <string, int>(currenLikes); } catch (Exception) { Console.WriteLine(Resources.FailedToRretrieveDataLikesForErrorMessage + propertyInfo); } } }); getDataTasks.Add(getDataTask); } await Task.WhenAll(getDataTasks); Chart likeMeTheMostChart = ChartsUtil.CreateChart("Who Likes me the most!", DockStyle.Top, allPostemItemsLikes.OrderByDescending(i_L => i_L.Value). Take(appConfigServiceStateSettings.NumberOfFriend)); Chart likeMeTheLeastChart = ChartsUtil.CreateChart("Who Likes me the least!", DockStyle.Bottom, allPostemItemsLikes.OrderBy(i_L => i_L.Value). Take(appConfigServiceStateSettings.NumberOfFriend)); panel.Controls.Add(likeMeTheMostChart, 0, 0); panel.Controls.Add(likeMeTheLeastChart, 0, 1); return(panel); }
public async Task <TableLayoutPanel> GetLayoutPanelAsync(User i_LoggedInUser) { ILikeService likeService = new LikesService(i_LoggedInUser); ObservableCollection <PostedItem> items = new ObservableCollection <PostedItem>(i_LoggedInUser.PhotosTaggedIn); Dictionary <string, int> userLikesPhotos = await likeService.GetLikesHistogram(items); items = new ObservableCollection <PostedItem>(i_LoggedInUser.Posts); Dictionary <string, int> userLikesPosts = await likeService.GetLikesHistogram(items); items = new ObservableCollection <PostedItem>(i_LoggedInUser.Albums); Dictionary <string, int> userLikesAlbums = await likeService.GetLikesHistogram(items); TableLayoutPanel panel = new TableLayoutPanel { ColumnCount = 3, AutoScroll = true }; panel.RowStyles.Add(new RowStyle(SizeType.AutoSize, 40F)); fillLikeToTable("Photos", userLikesPhotos, panel, 0, 0); fillLikeToTable("Posts", userLikesPosts, panel, 0, 1); fillLikeToTable("Albums", userLikesAlbums, panel, 0, 2); return(panel); }