コード例 #1
0
 public void FriendStatusTest()
 {
     FriendStatusMessage x = new FriendStatusMessage();
     FriendStatusMessage y = new FriendStatusMessage(x.getMessageString());
     Assert.AreEqual(x.UserStatus, y.UserStatus);
     Assert.AreEqual(x.sender, y.sender);
     Assert.AreEqual(x.receiver, y.receiver);
 }
コード例 #2
0
        public void TestUpdateContacts_NewUserAdded()
        {
            HomePage screen = new HomePage();
            screen.UserDetails = userDetails;
            messageSpecs.FriendStatusMessage x = new FriendStatusMessage();
            x.sender = "1";
            x.UserStatus = FriendStatusMessage.LoggedOnStatus.Online;
            screen.updateContacts(x.getMessageString());
            messageSpecs.FriendStatusMessage y = new FriendStatusMessage();
            y.sender = "2";
            y.UserStatus = FriendStatusMessage.LoggedOnStatus.Online;
            screen.updateContacts(y.getMessageString());

            int check1 = screen.ContactsList.RowCount;
            Assert.AreEqual(3, check1);
            this.releaseResources(screen);
        }
コード例 #3
0
        public void TestUpdateContacts_UserStatusChange()
        {
            HomePage screen = new HomePage();
            screen.UserDetails = userDetails;
            messageSpecs.FriendStatusMessage y = new FriendStatusMessage();
            y.sender = "2";
            y.UserStatus = FriendStatusMessage.LoggedOnStatus.Offline;
            screen.updateContacts(y.getMessageString());

            object c = screen.ContactsList.Controls[0];
            object status = ((MessageANiner.UserControls.ContactControl)(c)).avilability;
            Assert.AreEqual(MessageANiner.UserControls.ContactControl.Status.Offline, status);

            y.UserStatus = FriendStatusMessage.LoggedOnStatus.Online;
            screen.updateContacts(y.getMessageString());

            status = ((MessageANiner.UserControls.ContactControl)(c)).avilability;
            Assert.AreEqual(MessageANiner.UserControls.ContactControl.Status.Online, status);

            this.releaseResources(screen);
        }
コード例 #4
0
        public void TestUpdateMessage()
        {
            HomePage screen = new HomePage();
            screen.UserDetails = userDetails;
            messageSpecs.FriendStatusMessage y = new FriendStatusMessage();
            y.sender = "0000000002";
            y.UserStatus = FriendStatusMessage.LoggedOnStatus.Online;
            screen.updateContacts(y.getMessageString());

            messageSpecs.TextMessage tm = new TextMessage();
            tm.sender = "0000000001";
            tm.receiver = "0000000002";
            tm.TextToSend = "ABCD";
            screen.updateMessages(tm.getMessageString());

            object isChatpresent = screen.openChatWindows.ContainsKey(long.Parse(tm.receiver));
            Assert.AreEqual(true, isChatpresent);

            object chatWindow = screen.openChatWindows[long.Parse(tm.receiver)];
            string messageString = ((MessageANiner.UserControls.MessageHolder)(((((MessageANiner.UserControls.ChatWindow)(chatWindow)).chatMessageArea.Controls[0])))).richTextBoxContent.Text;
            Assert.AreEqual("0000000001 : ABCD", messageString);
            this.releaseResources(screen);
        }
コード例 #5
0
    public void handleContactResponseMessage(string message, SortedList<long, SocketAsyncEventArgs> clientList)
    {
        messageSpecs.ContactResponseMessage responseMessage = new messageSpecs.ContactResponseMessage(message);
        mySql.doExecuteNonQuery(string.Format("EXEC UpdateContactResponse @Requested = '{0}', @Requestee = '{1}', @Response = '{2}'",responseMessage.sender,responseMessage.receiver,((int)responseMessage.Reply).ToString()));
        if (responseMessage.Reply == messageSpecs.ContactResponseMessage.ContactResponse.Accept)
        {
            try
            {
                messageSpecs.FriendStatusMessage friendsMessage = new messageSpecs.FriendStatusMessage();
                if (clientList.ContainsKey(long.Parse(responseMessage.receiver)))
                {
                    friendsMessage.sender = responseMessage.sender;
                    friendsMessage.receiver = responseMessage.receiver;
                    friendsMessage.UserStatus = messageSpecs.FriendStatusMessage.LoggedOnStatus.Online;
                    sendFriendStatMessage(friendsMessage, clientList[long.Parse(responseMessage.receiver)]);

                    friendsMessage.sender = responseMessage.receiver;
                    friendsMessage.receiver = responseMessage.sender;
                    sendFriendStatMessage(friendsMessage, clientList[long.Parse(responseMessage.sender)]);
                }
                else
                {
                    friendsMessage.sender = responseMessage.receiver;
                    friendsMessage.receiver = responseMessage.sender;
                    friendsMessage.UserStatus = messageSpecs.FriendStatusMessage.LoggedOnStatus.Offline;
                    sendFriendStatMessage(friendsMessage, clientList[long.Parse(responseMessage.sender)]);
                }
            }
            catch { }
            
        }
    }
コード例 #6
0
    public void handleGroupCreation(string message,SortedList<long, SocketAsyncEventArgs> clientList,SortedList<long, System.Collections.ArrayList> groupLookup)
    {
        messageSpecs.CreateGroupMessage grpMsg = new messageSpecs.CreateGroupMessage(message);
        SqlDataReader dr = null;
        try
        {
            long grpID = 0;
            dr = mySql.getDataReader(string.Format("EXEC createGroup '{0}'",grpMsg.GroupName));
            
            while (dr.Read())
            {
                grpID = (long)dr[0];
            }

            if (grpID == 0)
                return;
            System.Collections.ArrayList userList = new System.Collections.ArrayList();

            messageSpecs.FriendStatusMessage fMessage = new messageSpecs.FriendStatusMessage();
            fMessage.sender = grpID.ToString();
            fMessage.UserStatus = messageSpecs.FriendStatusMessage.LoggedOnStatus.Group;
            foreach (string UID in grpMsg.memberList)
            {
                userList.Add(long.Parse(UID));
                mySql.doExecuteNonQuery(string.Format("INSERT INTO GroupTable VALUES('{0}','{1}')", grpID, UID));

                if (clientList.ContainsKey(long.Parse(UID)))
                {
                    fMessage.receiver = UID;
                    sendFriendStatMessage(fMessage, clientList[long.Parse(UID)]);
                }
            }
            groupLookup.Add(grpID, userList);
        }
        catch
        {

        }
    }
コード例 #7
0
    public string handleContactAdding(string message, SortedList<long, SocketAsyncEventArgs> clientList)
    {
        string returnString = "";
        SqlDataReader dr = null;
        try
        {
            messageSpecs.AddContactMessage contactMessage = new messageSpecs.AddContactMessage(message);

            if (contactMessage.sender == contactMessage.receiver)
            {
                contactMessage.ReturnMessage = "You cannot add yourself as a friend!";
                return contactMessage.getMessageString();
            }


            contactMessage.ReturnMessage = "Failed trying to add user";
            dr = mySql.getDataReader(string.Format("EXEC addContact '{0}','{1}'", contactMessage.sender, contactMessage.receiver));
            while (dr.Read())
            {
                if ((bool)dr["Completed"])
                {
                    contactMessage.ReturnMessage = "Friend request was sent";
                    if (clientList.ContainsKey(long.Parse(contactMessage.receiver)))
                    {
                        messageSpecs.FriendStatusMessage fStatus = new messageSpecs.FriendStatusMessage();
                        fStatus.receiver = contactMessage.receiver;
                        fStatus.sender = contactMessage.sender;
                        fStatus.UserStatus = messageSpecs.FriendStatusMessage.LoggedOnStatus.Friend;
                        sendFriendStatMessage(fStatus, clientList[long.Parse(contactMessage.receiver)]);
                    }
                }
                else
                {
                    contactMessage.ReturnMessage = "User already is a friend";
                }

            }
            returnString = contactMessage.getMessageString();
        }
        catch
        {

        }
        finally
        {
            if (dr != null)
                dr.Close();
        }

        return returnString;
    }
コード例 #8
0
    public void sendFriendLogonMessages(long loggingInUID, SortedList<long, SocketAsyncEventArgs> clientList, messageSpecs.FriendStatusMessage.LoggedOnStatus status)
    {
        SqlDataReader dr = null;
        try
        {
            dr = mySql.getDataReader(string.Format("EXEC getFriends @UID = '{0}'", loggingInUID));

            while (dr.Read())
            {
                if ((int)dr["Response"] == 0)
                {
                    messageSpecs.FriendStatusMessage friendMessage = new messageSpecs.FriendStatusMessage();
                    friendMessage.UserStatus = messageSpecs.FriendStatusMessage.LoggedOnStatus.Friend;
                    friendMessage.sender = ((long)dr["Friend"]).ToString();
                    friendMessage.receiver = loggingInUID.ToString();
                    sendFriendStatMessage(friendMessage, clientList[loggingInUID]);
                }
                else if ((int)dr["Response"] == 2)
                {
                    messageSpecs.FriendStatusMessage friendMessage = new messageSpecs.FriendStatusMessage();
                    friendMessage.UserStatus = messageSpecs.FriendStatusMessage.LoggedOnStatus.Group;
                    friendMessage.sender = ((long)dr["Friend"]).ToString();
                    friendMessage.receiver = loggingInUID.ToString();
                    sendFriendStatMessage(friendMessage, clientList[loggingInUID]);
                }
                else if (clientList.ContainsKey((long)dr["Friend"]))
                {
                    messageSpecs.FriendStatusMessage friendMessage = new messageSpecs.FriendStatusMessage();
                    friendMessage.UserStatus = status;
                    friendMessage.sender = loggingInUID.ToString();
                    friendMessage.receiver = ((long)dr["Friend"]).ToString();
                    sendFriendStatMessage(friendMessage, clientList[(long)dr["Friend"]]);

                    friendMessage.sender = ((long)dr["Friend"]).ToString();
                    friendMessage.receiver = loggingInUID.ToString();
                    sendFriendStatMessage(friendMessage, clientList[loggingInUID]);
                }
                else
                {
                    messageSpecs.FriendStatusMessage friendMessage = new messageSpecs.FriendStatusMessage();
                    friendMessage.UserStatus = messageSpecs.FriendStatusMessage.LoggedOnStatus.Offline;
                    friendMessage.sender = ((long)dr["Friend"]).ToString();
                    friendMessage.receiver = loggingInUID.ToString();
                    sendFriendStatMessage(friendMessage, clientList[loggingInUID]);
                }

            }
        }
        catch
        {

        }
        finally
        {
            if (dr != null)
                dr.Close();
        }
    }
コード例 #9
0
        public void updateContacts(string message)
        {
            messageSpecs.FriendStatusMessage friendMsg = new FriendStatusMessage(message);

            friendList.Add(friendMsg);

            ContactControl addingContact = null;

            foreach (ContactControl currentContact in ContactsList.Controls)
            {
                if (currentContact.UID == long.Parse(friendMsg.sender))
                {
                    addingContact = currentContact;
                    currentContact.UpdateStatus(friendMsg.UserStatus);
                    break;
                }
            }

            if (addingContact == null)
            {
                addingContact = new ContactControl(long.Parse(friendMsg.sender), friendMsg.FirstName.Trim() + " " + friendMsg.LastName.Trim(), friendMsg.UserStatus);
                addingContact.contactClicked += new DelContactClick(openchatwindow);

                ContactsList.RowCount += 1;
                ContactsList.Controls.Add(addingContact, 0, ContactsList.RowCount - 2);
                ContactsList.RowStyles[ContactsList.RowCount - 2].SizeType = SizeType.Absolute;
                ContactsList.RowStyles[ContactsList.RowCount - 2].Height = 40;
            }

        }
コード例 #10
0
        public void TestUpdateMessageCount()
        {
            HomePage screen = new HomePage();
            screen.UserDetails = userDetails;
            messageSpecs.FriendStatusMessage y = new FriendStatusMessage();
            y.sender = "0000000002";
            y.UserStatus = FriendStatusMessage.LoggedOnStatus.Offline;
            screen.updateContacts(y.getMessageString());

            messageSpecs.TextMessage tm = new TextMessage();
            tm.sender = "0000000001";
            tm.receiver = "0000000002";
            tm.TextToSend = "ABCD";
            screen.openedChatWindowUID = 0000224;

            screen.openedChatWindowUID = 0000224;
            screen.updateMessages(tm.getMessageString());

            object c = screen.ContactsList.Controls[0];
            int msgCount = ((MessageANiner.UserControls.ContactControl)(c)).msgCount;
            Assert.AreEqual(1, msgCount);

            screen.openedChatWindowUID = 0000224;
            tm.TextToSend = "PQRS";
            screen.updateMessages(tm.getMessageString());

            c = screen.ContactsList.Controls[0];
            msgCount = ((MessageANiner.UserControls.ContactControl)(c)).msgCount;
            Assert.AreEqual(2, msgCount);
            this.releaseResources(screen);
        }