Esempio n. 1
0
 public Task <List <FriendModel> > GetUserFriendsAsync()
 {
     return(Task.Run(() =>
     {
         LoginService loginService = LoginService.GetInstance();
         return r_FriendsService.GetUserFriendsAsync(loginService.LoggedInUser);
     }));
 }
        public async Task <TableLayoutPanel> GetLayoutPanelAsync(User i_LoggedInUser)
        {
            IFriendService     friendService = new FriendService();
            List <FriendModel> userFriends   = await friendService.GetUserFriendsAsync(i_LoggedInUser);

            TableLayoutPanel panel = new TableLayoutPanel {
                ColumnCount = 2, AutoScroll = true, Padding = new Padding(10)
            };

            panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize, 40F));
            panel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize, 20F));
            panel.RowStyles.Add(new RowStyle(SizeType.AutoSize, 50F));

            int       tempRowIndex         = 0;
            const int k_ImageColumnIndex   = 0;
            const int k_DetailsColumnIndex = 1;

            foreach (FriendModel friend in userFriends)
            {
                foreach (KeyValuePair <string, string> propertyForDisplay in friend.GetPropertiesForDisplay())
                {
                    Uri  uriResult;
                    bool isImageUrl = Uri.TryCreate(propertyForDisplay.Value, UriKind.Absolute, out uriResult) &&
                                      (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

                    if (isImageUrl)
                    {
                        panel.Controls.Add(new PictureBox {
                            ImageLocation = propertyForDisplay.Value, AutoSize = true
                        }, k_ImageColumnIndex, tempRowIndex);
                    }
                    else
                    {
                        panel.Controls.Add(new Label {
                            Font = new Font(AppUtil.sr_FontFamily, AppConfigService.GetInstance().LabelFontSize), AutoSize = true, Text = propertyForDisplay.Value
                        }, k_DetailsColumnIndex, tempRowIndex);
                    }
                }
                tempRowIndex++;
            }
            return(panel);
        }
        private async Task initializeAsync()
        {
            IFriendService friendService = new FriendService();

            m_UserFriends = await friendService.GetUserFriendsAsync(r_LoggedInUser);
        }