示例#1
0
        /// <summary>
        /// 
        /// </summary>
        public void UpdateCurrentUserInfo()
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                try
                {
                    UsersGet op = new UsersGet(_settings.UserId, usersInfo =>
                    {
                        _waitHandle.Set();

                        if (usersInfo != null && _settings != null && usersInfo.Any())
                        {
                            var info = usersInfo.FirstOrDefault();

                            if (info != null)
                                Deployment.Current.Dispatcher.BeginInvoke(() => { CurrentUser.UserInfo = info; });
                        }
                    });
                    op.Execute();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("EntityService -> Initialize -> UsersGet failed: " + ex.Message);

                    _waitHandle.Set();
                }
            });
        }
示例#2
0
        public void GetFriendRequests(Action finishedCallback)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                try
                {
                    var op = new FriendsGetRequests(1, friends =>
                    {
                        try
                        {
                            _stateCounter.CountOfRequests = friends.Count;

                            // Collect all uids to load info.
                            var dict = new Dictionary<int, string>();
                            string uids = string.Empty;
                            string mutualUids = string.Empty;
                            foreach (var request in friends)
                            {
                                uids += request.Uid.ToString() + ",";

                                dict.Add(request.Uid, request.Message == null ? string.Empty : request.Message);

                                if (request.MutualFriends != null)
                                {
                                    foreach (var mutual in request.MutualFriends.Uids)
                                    {
                                        mutualUids += mutual.ToString() + ",";
                                    }
                                }
                            }

                            // Get friends requests.
                            if (!string.IsNullOrEmpty(uids))
                            {
                                UsersGet op1 = new UsersGet(uids, info =>
                                {
                                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                                    {
                                        try
                                        {
                                            FriendsRequests.Clear();

                                            foreach (var user in info)
                                            {
                                                var model = new FriendViewModel(user.Uid, user.FullName, string.Empty,
                                                    user.FirstName, user.LastName, user.IsOnline, -1, user.PhotoBig, DefaultAvatar);

                                                string message = string.Empty;
                                                dict.TryGetValue(user.Uid, out message);
                                                model.Message = message;
                                                FriendsRequests.Add(model);//new FriendRequestViewModel(model, user.Photo, message));
                                            }

                                            if (string.IsNullOrEmpty(mutualUids))
                                                finishedCallback();
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine("UsersGet in GetFriendRequests failed: " + ex.Message);
                                            finishedCallback();
                                        }
                                    });
                                });
                                op1.Execute();
                            }

                            // Get mutual friends.
                            if (!string.IsNullOrEmpty(mutualUids))
                            {
                                UsersGet op2 = new UsersGet(mutualUids, info =>
                                {
                                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                                    {
                                        try
                                        {
                                            FriendsMutual.Clear();

                                            foreach (var user in info)
                                            {
                                                var inFriends = Friends.FirstOrDefault(x => x.Uid == user.Uid);

                                                if (inFriends == null)
                                                    FriendsMutual.Add(new FriendViewModel(user.Uid, user.FullName, string.Empty,
                                                        user.FirstName, user.LastName, user.IsOnline, -1, user.PhotoBig, DefaultAvatar));
                                            }

                                            finishedCallback();
                                        }
                                        catch (Exception ex)
                                        {
                                            Debug.WriteLine("UsersGet in GetFriendRequests failed: " + ex.Message);
                                            finishedCallback();
                                        }
                                    });
                                });
                                op2.Execute();
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(uids))
                                    finishedCallback();
                            }
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("GetFriendRequests failed in EntityService: " + ex.Message);
                            finishedCallback();
                        }
                    });
                    op.Execute();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("GetFriendRequests failed: " + ex.Message);
                }
            });
        }