예제 #1
0
 public void SyncToGetStateResponse(GetStateResponse response, Action callback)
 {
     if (response.Alerts != null)
     {
         foreach (Disney.Mix.SDK.Internal.MixDomain.Alert alert in response.Alerts)
         {
             AddAlert(new Alert(alert));
         }
     }
     ClearFriends();
     if (response.Friendships != null)
     {
         foreach (Friendship friendship in response.Friendships)
         {
             PersistUser(friendship.FriendUserId, null, null, null, null);
             FriendDocument friendDocument = new FriendDocument();
             friendDocument.Swid      = friendship.FriendUserId;
             friendDocument.IsTrusted = friendship.IsTrusted.Value;
             FriendDocument doc = friendDocument;
             InsertFriend(doc);
         }
     }
     ClearFriendInvitations();
     if (response.FriendshipInvitations != null)
     {
         foreach (FriendshipInvitation friendshipInvitation in response.FriendshipInvitations)
         {
             List <User>       source    = response.Users;
             Func <User, bool> predicate = (User user) => user.DisplayName == friendshipInvitation.FriendDisplayName;
             User user2 = source.FirstOrDefault(predicate);
             if (user2 != null)
             {
                 string firstName    = user2.FirstName;
                 string userId       = user2.UserId;
                 string hashedUserId = user2.HashedUserId;
                 string status       = user2.Status;
                 PersistUser(userId, hashedUserId, friendshipInvitation.FriendDisplayName, firstName, status);
             }
             FriendInvitationDocument friendInvitationDocument = new FriendInvitationDocument();
             friendInvitationDocument.FriendInvitationId = friendshipInvitation.FriendshipInvitationId.Value;
             friendInvitationDocument.IsInviter          = friendshipInvitation.IsInviter.Value;
             friendInvitationDocument.IsTrusted          = friendshipInvitation.IsTrusted.Value;
             friendInvitationDocument.DisplayName        = friendshipInvitation.FriendDisplayName;
             FriendInvitationDocument doc2 = friendInvitationDocument;
             InsertFriendInvitation(doc2);
         }
     }
     if (response.Users != null)
     {
         foreach (User user3 in response.Users)
         {
             PersistUser(user3.UserId, user3.HashedUserId, user3.DisplayName, user3.FirstName, user3.Status);
         }
     }
     callback();
 }
예제 #2
0
 public void InsertFriendInvitation(FriendInvitationDocument doc)
 {
     try
     {
         friendInvitations.Insert(doc);
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }
예제 #3
0
        private static void HandleFriendshipRemoved(IUserDatabase userDatabase, IInternalLocalUser localUser, AbstractRemoveFriendshipNotificationEventArgs e)
        {
            string          swid           = e.Notification.FriendUserId;
            string          displayName    = null;
            IInternalFriend internalFriend = localUser.InternalFriends.FirstOrDefault((IInternalFriend f) => f.Swid == swid);

            if (internalFriend != null)
            {
                displayName = internalFriend.DisplayName.Text;
            }
            else
            {
                UserDocument userBySwid = userDatabase.GetUserBySwid(swid);
                if (userBySwid != null)
                {
                    displayName = userBySwid.DisplayName;
                }
            }
            userDatabase.DeleteFriend(swid);
            localUser.RemoveFriend(swid, sendEvent: true);
            if (displayName == null)
            {
                return;
            }
            FriendInvitationDocument incomingInvitation = userDatabase.GetFriendInvitationDocuments(isInviter: false).FirstOrDefault((FriendInvitationDocument doc) => doc.DisplayName == displayName);

            if (incomingInvitation != null)
            {
                foreach (IInternalIncomingFriendInvitation item in localUser.InternalIncomingFriendInvitations.Where((IInternalIncomingFriendInvitation i) => i.InvitationId == incomingInvitation.FriendInvitationId))
                {
                    localUser.RemoveIncomingFriendInvitation(item);
                }
                userDatabase.DeleteFriendInvitation(incomingInvitation.FriendInvitationId);
            }
            FriendInvitationDocument outgoingInvitation = userDatabase.GetFriendInvitationDocuments(isInviter: true).FirstOrDefault((FriendInvitationDocument doc) => doc.DisplayName == displayName);

            if (outgoingInvitation == null)
            {
                return;
            }
            foreach (IInternalOutgoingFriendInvitation item2 in localUser.InternalOutgoingFriendInvitations.Where((IInternalOutgoingFriendInvitation i) => i.InvitationId == outgoingInvitation.FriendInvitationId))
            {
                localUser.RemoveOutgoingFriendInvitation(item2);
            }
            userDatabase.DeleteFriendInvitation(outgoingInvitation.FriendInvitationId);
        }
예제 #4
0
        private static void HandleFriendshipInvitationAdded(IUserDatabase userDatabase, IInternalLocalUser localUser, AbstractAddFriendshipInvitationNotificationEventArgs e)
        {
            AddFriendshipInvitationNotification notification = e.Notification;
            FriendshipInvitation invitation = notification.Invitation;
            User friend = notification.Friend;

            userDatabase.PersistUser(null, null, invitation.FriendDisplayName, friend.FirstName, friend.Status);
            FriendInvitationDocument friendInvitationDocument = new FriendInvitationDocument();

            friendInvitationDocument.FriendInvitationId = invitation.FriendshipInvitationId.Value;
            friendInvitationDocument.IsInviter          = invitation.IsInviter.Value;
            friendInvitationDocument.IsTrusted          = invitation.IsTrusted.Value;
            friendInvitationDocument.DisplayName        = invitation.FriendDisplayName;
            FriendInvitationDocument doc = friendInvitationDocument;

            userDatabase.InsertOrUpdateFriendInvitation(doc);
            localUser.AddFriendshipInvitation(invitation, friend);
        }
예제 #5
0
 public void InsertOrUpdateFriendInvitation(FriendInvitationDocument doc)
 {
     try
     {
         FriendInvitationDocument friendInvitationDocument = (from id in friendInvitations.FindDocumentIdsEqual(FriendInvitationDocument.FriendInvitationIdFieldName, doc.FriendInvitationId)
                                                              select friendInvitations.Find(id)).FirstOrDefault();
         if (friendInvitationDocument == null)
         {
             friendInvitations.Insert(doc);
             return;
         }
         doc.Id = friendInvitationDocument.Id;
         friendInvitations.Update(doc);
     }
     catch (CorruptionException ex)
     {
         databaseCorruptionHandler.HandleCorruption(ex);
         throw;
     }
 }