/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="user">User to hide.</param>
        public UIHideUser(WUser user)
        {
            Contract.Requires(user != null);

            InitializeComponent();
            Title.Text = "Hide " + user.Username + " from:";
            Logo.Source = new BitmapImage(new Uri(user.Avatar));
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="user"></param>
        public UIPerson(WUser user)
        {
            Contract.Requires(user != null);

            InitializeComponent();
            User = user;
            Username.Text = User.Username;

            if (String.IsNullOrEmpty(User.Avatar))
                Avatar.Source = new BitmapImage(new Uri("pack://application:,,,/It.Uniba.Di.Cdg.SocialTfs.Client;component/Images/DefaultAvatar.png"));
            else
                Avatar.Source = new BitmapImage(new Uri(User.Avatar));
        }
        public UIDevelopers(WUser _user)
        {
            InitializeComponent();

            string[] skills = UIController.Proxy.GetSkills(UIController.MyProfile.Username, UIController.Password, _user.Username);
            WEdu[] educations = UIController.Proxy.GetEducations(UIController.MyProfile.Username, UIController.Password, _user.Username);
            WPos[] positions = UIController.Proxy.GetPositions(UIController.MyProfile.Username, UIController.Password, _user.Username);
            WReputation repu = UIController.Proxy.GetReputations(UIController.MyProfile.Username, UIController.Password, _user.Username);
            int metascore = 0;
            int flag = 0;
            if (repu.stackReputationValue != null)
            {
                flag += 5;
                metascore = (int)(repu.stackAnswer * 4 + repu.stackQuestion * 1 + repu.stackBronze * 1 + repu.stackSilver * 2 + repu.stackGold * 4);
            }
            if (repu.ohlohKudoRank != null)
            {
                flag += 2;
                metascore += (int)(repu.ohlohKudoRank * 3 + repu.ohlohKudoScore * 3);
            }
            if (repu.coderwallEndorsements != null)
            {
                flag += 1;
                metascore += (int)(repu.coderwallEndorsements * 3);
            }
            if (flag == 0)
                metascore = 0;
            metascore = metascore / flag;

            UpdateHeader(_user.Username, "", "", _user.Avatar, metascore);
            UpdateExperiences(positions);
            UpdateSkillExp(skills);
            UpdateEducations(educations);
            if ( repu != null )
                if (repu.coderwallEndorsements != null ||
                    repu.ohlohKudoScore !=null ||
                    repu.stackReputationValue !=null)
                {
                    UpdateStackOverflowReputation(repu);
                    UpdateOhlohReputation(repu);
                    UpdateCoderwallReputation(repu);
                    UpdateLinkedInReputation(repu);
                }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="userId">Identifier of the user.</param>
        public UIColleague(int userId)
        {
            Contract.Requires(userId >= 0);

            _user = UIController.Proxy.GetColleagueProfile(UIController.MyProfile.Username, UIController.Password, userId);
            InitializeComponent();

            Timeline.LoadTimeline(_user);
            if (UIController.MyProfile.Id == _user.Id)
                FollowButton.Visibility = Visibility.Hidden;
            else
            {
                if (_user.Followed)
                {
                    FollowButton.InternalImage.Source = _unfollowImage;
                    FollowButton.ToolTip = "Unfollow this user in SocialTFS";
                }
                else
                {
                    FollowButton.InternalImage.Source = _followImage;
                    FollowButton.ToolTip = "Follow this user in SocialTFS";
                }
            }

            MoreButton.InternalImage.Source = new BitmapImage(new Uri("pack://application:,,,/It.Uniba.Di.Cdg.SocialTfs.Client;component/Images/Toolbar/Skills.png"));
            HideButton.InternalImage.Source = new BitmapImage(new Uri("pack://application:,,,/It.Uniba.Di.Cdg.SocialTfs.Client;component/Images/Toolbar/Hide.png"));
            Posts.Text = _user.Statuses.ToString();
            Followings.Text = _user.Followings.ToString();
            Followers.Text = _user.Followers.ToString();

            if (String.IsNullOrEmpty(_user.Avatar))
                AvatarImage.Source = new BitmapImage(new Uri("pack://application:,,,/It.Uniba.Di.Cdg.SocialTfs.Client;component/Images/DefaultAvatar.png"));
            else
                AvatarImage.Source = new BitmapImage(new Uri(_user.Avatar));

            UserName.Text = _user.Username;
        }
        /// <summary>
        /// Convert an User (used for the database) in a WUser (used for the web).
        /// </summary>
        /// <param name="db">Database connector data context.</param>
        /// <param name="user">User that requires the conversion.</param>
        /// <param name="userToConvert">The User to convert.</param>
        /// <param name="calculateInfos">True if you need to have all the information about the User, false otherwise.</param>
        /// <returns>A WUser.</returns>
        public static WUser UserToWUser(ConnectorDataContext db, User user, User userToConvert, bool calculateInfos)
        {
            WUser result = null;

            if (calculateInfos)
            {
                Stopwatch w = Stopwatch.StartNew();
                int stat = db.Posts.Where(p => p.ChosenFeature.user == userToConvert.id).Count();
                w.Stop();
                ILog log = LogManager.GetLogger("QueryLogger");
                log.Info(" Elapsed time: " + w.Elapsed + ", user id: " + userToConvert.id + ", count the number of posts of an user for a certain chosen feature");
                Stopwatch w1 = Stopwatch.StartNew();
                int followings = db.StaticFriends.Where(sf => sf.User == userToConvert).Count();
                w1.Stop();
                ILog log1 = LogManager.GetLogger("QueryLogger");
                log1.Info(" Elapsed time: " + w1.Elapsed + ", count the number of static friends of an user");
                Stopwatch w2 = Stopwatch.StartNew();
                int followers = db.StaticFriends.Where(sf => sf.Friend == userToConvert).Count();
                w2.Stop();
                ILog log2 = LogManager.GetLogger("QueryLogger");
                log2.Info(" Elapsed time: " + w2.Elapsed + ", count the number of users that are static friends of an user");
                Stopwatch w3 = Stopwatch.StartNew();
                int followed = db.StaticFriends.Where(sf => sf.User == user && sf.Friend == userToConvert).Count();
                w3.Stop();
                ILog log3 = LogManager.GetLogger("QueryLogger");
                log3.Info(" Elapsed time: " + w3.Elapsed + ", count the number of users that follow and are followed by an user");
                result = new WUser()
                {
                    Id = userToConvert.id,
                    Username = userToConvert.username,
                    Email = userToConvert.email,
                    Avatar = userToConvert.avatar,
                    Statuses = stat,
                    Followings = followings,
                    Followers = followers,
                    Followed = followed == 1
                };
            }
            else
            {
                result = new WUser()
                {
                    Id = userToConvert.id,
                    Username = userToConvert.username,
                    Email = userToConvert.email,
                    Avatar = userToConvert.avatar,
                    Statuses = -1,
                    Followings = -1,
                    Followers = -1,
                    Followed = false
                };
            }

            return result;
        }
 public UIProfileView(WUser user)
 {
     InitializeComponent();
     _user = user;
 }
 public UISkills(WUser user)
 {
     InitializeComponent();
     _user = user;
 }
 internal void LoadTimeline(WUser user, TimelineType timelineType)
 {
     _owner = user;
     _timelineType = timelineType;
 }
 internal void LoadTimeline(WUser user)
 {
     LoadTimeline(user, TimelineType.PersonalTimeline);
 }
        /// <summary>
        /// Convert an User (used for the database) in a WUser (used for the web).
        /// </summary>
        /// <param name="db">Database connector data context.</param>
        /// <param name="user">User that requires the conversion.</param>
        /// <param name="userToConvert">The User to convert.</param>
        /// <param name="calculateInfos">True if you need to have all the information about the User, false otherwise.</param>
        /// <returns>A WUser.</returns>
        public static WUser UserToWUser(SocialTFSEntities db, User user, User userToConvert, bool calculateInfos)
        {
            WUser result = new WUser();

            //result.Statuses = db.Post.Where( p => p.ChosenFeature.fk_user == userToConvert.pk_id ).Count();
            //result.Followings = db.StaticFriend.Where(sf => sf.fk_user == userToConvert.pk_id ).Count();
            //result.Followers = db.StaticFriend.Where(sf => sf.fk_friend == userToConvert.pk_id).Count();
            //result.Followed = db.StaticFriend.Where(sf => sf.fk_user == user.pk_id && sf.fk_friend == userToConvert.pk_id ).Count() == 1;

            if (calculateInfos)
            {
                result = new WUser()
                {
                    Id = userToConvert.pk_id,
                    Username = userToConvert.username,
                    Email = userToConvert.email,
                    Avatar = userToConvert.avatar,
                    Statuses = db.Post.Where( p => p.ChosenFeature.fk_user == userToConvert.pk_id ).Count(),
                    Followings = db.StaticFriend.Where(sf => sf.User.pk_id == userToConvert.pk_id).Count(),
                    Followers = db.StaticFriend.Where(sf => sf.Friend.pk_id == userToConvert.pk_id).Count(),
                    Followed = db.StaticFriend.Where(sf => sf.User.pk_id == user.pk_id && sf.Friend.pk_id == userToConvert.pk_id).Count() == 1
                };
            }
            else
            {
                result = new WUser()
                {
                    Id = userToConvert.pk_id,
                    Username = userToConvert.username,
                    Email = userToConvert.email,
                    Avatar = userToConvert.avatar,
                    Statuses = -1,
                    Followings = -1,
                    Followers = -1,
                    Followed = false
                };
            }

            return result;
        }