public void AddCollectionListTest() { bool nullFail = ggMock.Users.Add(null as Dictionary <string, int>, false); Assert.IsFalse(nullFail); bool done = ggMock.Users.Add(new int[] { 123, 456, 789, 987, 7645, 234 }, false); Assert.IsTrue(done); Assert.AreEqual(ggMock.Users.Count, 6); Assert.IsTrue(ggMock.Users.Contains(987)); Assert.IsTrue(ggMock.Users.Contains(123)); Assert.IsFalse(ggMock.Users.Contains(9999)); Assert.IsFalse(ggMock.Users.Contains(1111)); bool done2 = ggMock.Users.Add(new Dictionary <string, int> { { "Paul", 222 }, { "John", 333 }, { "Tom", 444 } }, false); Assert.IsTrue(done2); Assert.AreEqual(ggMock.Users.Count, 9); Assert.IsTrue(ggMock.Users.Contains(333)); Assert.IsTrue(ggMock.Users.Contains(444)); Assert.IsFalse(ggMock.Users.Contains(555)); GGUser paul = ggMock.Users.Find(x => x.GGNick == "Paul"); Assert.IsNotNull(paul); Assert.AreEqual(paul.GGNick, "Paul"); Assert.AreEqual(paul.GGNumber, 222); bool done3 = ggMock.Users.Add(new int[] { 7776, 456, 4554, 8776 }, false); // 456 x 2 Assert.IsTrue(done3); Assert.AreEqual(ggMock.Users.Count, 12); Assert.IsTrue(ggMock.Users.Contains(456)); }
/// <summary> /// 用户注册 /// </summary> /// <param name="user"></param> /// <returns></returns> public static bool RegisterUser(GGUser user) { string sql = @"INSERT INTO [dbo].[GGUser] ([userId] ,[userPwd] ,[userNickName] ,[qqSign] ,[userImg] ,[createTime]) VALUES (@userId, @userPwd, @userNickName, @qqSign, @userImg, @createTime)"; object[] valArr = { user.userId, user.userPwd, user.userNickName, user.qqSign, user.userImg, DateTime.Now }; if (DBHelper.Excute(sql, valArr) > 0) { return(true); } else { return(false); } }
/// <summary> /// 加入某个组。 /// </summary> public JoinGroupResult JoinGroup(string userID, string groupID) { GGGroup group = this.groupCache.Get(groupID); if (group == null) { return(JoinGroupResult.GroupNotExist); } GGUser user = this.userCache.Get(userID); if (!user.GroupList.Contains(groupID)) { user.JoinGroup(groupID); this.dbPersister.ChangeUserGroups(user.UserID, user.Groups); } if (!group.MemberList.Contains(userID)) { group.AddMember(userID); this.dbPersister.UpdateGroup(group); } return(JoinGroupResult.Succeed); }
public void SimpleUserTest() { GGUser user1 = new GGUser() { GGNick = "John", GGNumber = 234567, City = "NYC" }; GGUser user2 = new GGUser() { GGNick = "John", GGNumber = 98765, City = "Los Angeles" }; GGUser user3 = new GGUser() { GGNick = "Mark", GGNumber = 234567 }; GGUser user4 = new GGUser() { GGNick = "Monica", GGNumber = 98765 }; GGUser user5 = new GGUser() { GGNick = "Monica", GGNumber = 123 }; Assert.AreEqual(user1, user3); Assert.AreEqual(user2, user4); Assert.AreNotEqual(user1, user2); Assert.AreNotEqual(user2, user5); Assert.AreNotEqual(user4, user5); }
public void UserStatusChanged(GGUser user, string groupName) { ChatListSubItem[] items = this.chatListBox.GetSubItemsById(user.ID); if (items == null || items.Length == 0) { return; } //System.IO.MemoryStream ms = new System.IO.MemoryStream(user.HeadImageData); //System.Drawing.Image img = System.Drawing.Image.FromStream(ms); //items[0].HeadImage = img; items[0].Status = this.ConvertUserStatus(user.UserStatus); if (groupName == "") { groupName = "我的好友"; } ChatListItem item = this.catelogManager.Get(groupName); if (item != null) { item.SubItems.Sort(); } this.chatListBox.Invalidate(); }
/// <summary> /// 获取某个用户的所有联系人(组友,好友)。 /// 建议:由于该方法经常被调用,可将组友关系缓存在内存中,而非每次都遍历计算一遍。 /// </summary> public List <string> GetAllContacts(string userID) { List <string> contacts = new List <string>(); GGUser user = this.userCache.Get(userID); if (user == null) { return(contacts); } contacts = user.GetAllFriendList(); foreach (string groupID in user.GroupList) { GGGroup g = this.groupCache.Get(groupID); if (g != null) { foreach (string memberID in g.MemberList) { if (memberID != userID && !contacts.Contains(memberID)) { contacts.Add(memberID); } } } } return(contacts); }
public void UserStatusChanged(GGUser user) { //string recentID = RecentListBox.ConstructRecentID(user); ChatListSubItem[] items = this.chatListBox.GetSubItemsById(user.ID); if (items == null || items.Length == 0) { return; } for (int i = 0; i < items.Length; i++) { if (items[i].ID == user.JID.Bare) { items[i].Status = this.ConvertUserStatus(user.UserStatus); this.chatListBox.Invalidate(); break; } } //items[0].DisplayName = user.Name; //System.IO.MemoryStream ms = new System.IO.MemoryStream(user.HeadImageData); //System.Drawing.Image img = System.Drawing.Image.FromStream(ms); //items[0].HeadImage = img; }
private void chatListBox_DragSubItemDrop(object sender, DragListEventArgs e) { if (this.FriendCatalogMoved != null) { GGUser user = (GGUser)e.QSubItem.Tag; this.FriendCatalogMoved(user.ID, e.QSubItem.OwnerListItem.Text, e.HSubItem.OwnerListItem.Text); } }
public void UpdateUser(GGUser t) { using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser <GGUser> accesser = scope.NewOrmAccesser <GGUser>(); accesser.Update(t); scope.Commit(); } }
void UserManager_SomeOneDisconnected(UserData data, ESFramework.Server.DisconnectedType obj2) { GGUser user = this.globalCache.GetUser(data.UserID); if (user != null) { user.UserStatus = UserStatus.OffLine; } }
public void UpdateUserFriends(GGUser t) { using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser <GGUser> accesser = scope.NewOrmAccesser <GGUser>(); accesser.Update(new ColumnUpdating(GGUser._Friends, t.Friends), new Filter(GGUser._UserID, t.UserID)); scope.Commit(); } }
public void UpdateUser(GGUser t) { using (var scope = _transactionScopeFactory.NewTransactionScope()) { var accessor = scope.NewOrmAccesser <GGUser>(); accessor.Update(t); scope.Commit(); } }
public void UserInfoChanged(GGUser user) { ChatListSubItem[] items = this.chatListBox.GetSubItemsById(user.ID); if (items != null && items.Length > 0) //有可能部门发生了变化 { GGUser origin = (GGUser)items[0].Tag; ChatListItem ownerItem = this.GetCatelogChatListItem(origin); ownerItem.SubItems.Remove(items[0]); this.AddUser(user); //有可能是新添加的好友 } }
/// <summary> /// 获取某个用户的好友列表。 /// </summary> public List <string> GetFriends(string userID) { GGUser user = this.userCache.Get(userID); if (user == null) { return(new List <string>()); } return(user.GetAllFriendList()); }
public void MoveFriend(string ownerID, string friendID, string oldCatalog, string newCatalog) { GGUser user = this.userCache.Get(ownerID); if (user == null) { return; } user.MoveFriend(friendID, oldCatalog, newCatalog); this.dbPersister.UpdateUserFriends(user); }
public void RemoveFriendCatalog(string ownerID, string catalogName) { GGUser user = this.userCache.Get(ownerID); if (user == null) { return; } user.RemvoeFriendCatalog(catalogName); this.dbPersister.UpdateUserFriends(user); }
public void UserShallowCopyTest() { GGUser user = new GGUser() { GGNick = "Monica", GGNumber = 123 }; GGUser copy = user.Clone() as GGUser; Assert.IsNotNull(copy); Assert.AreEqual(copy, user); Assert.AreNotSame(copy, user); }
public GGUser GetUser(string userID) { GGUser user = null; using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser <GGUser> accesser = scope.NewOrmAccesser <GGUser>(); user = accesser.GetOne(userID); scope.Commit(); } return(user); }
public void ChangeFriendCatalogName(string ownerID, string oldName, string newName) { GGUser user = this.userCache.Get(ownerID); if (user == null) { return; } user.ChangeFriendCatalogName(oldName, newName); this.dbPersister.UpdateUserFriends(user); }
public void ImplicitConversionTest() { GGUser user = 12345; Assert.AreEqual(user.GGNumber, 12345); int back = user; Assert.AreEqual(back, 12345); user = "******"; Assert.AreEqual(user.GGNick, "John"); string nick = user; Assert.AreEqual(nick, "John"); }
public void UpdateUser(GGUser user) { GGUser old = this.userCache.Get(user.UserID); if (old == null) { return; } user.Friends = old.Friends; //0922 user.Groups = old.Groups; //0922 user.Version = old.Version + 1; this.userCache.Add(user.UserID, user); this.dbPersister.UpdateUser(user); }
/// <summary> /// 添加好友,建立双向关系 /// </summary> public void AddFriend(string ownerID, string friendID, string catalogName) { GGUser user1 = this.userCache.Get(ownerID); GGUser user2 = this.userCache.Get(friendID); if (user1 == null || user2 == null) { return; } user1.AddFriend(friendID, catalogName); user2.AddFriend(ownerID, user2.DefaultFriendCatalog); this.dbPersister.UpdateUserFriends(user1); this.dbPersister.UpdateUserFriends(user2); }
private ChatListItem GetCatelogChatListItem(GGUser user) { var catelog = "我的好友"; foreach (var pair in this.currentUser.FriendDicationary) { if (pair.Value.Contains(user.ID)) { catelog = pair.Key; break; } } this.AssureCatalog(catelog); return(this.catelogManager.Get(catelog)); }
/// <summary> /// 踢人 /// </summary> public void RemoveMemberGroup(string userID, string groupID) { GGGroup group = this.groupCache.Get(groupID); if (group != null) { group.RemoveMember(userID); } this.dbPersister.UpdateGroup(group); GGUser user = this.userCache.Get(userID); user.QuitGroup(groupID); this.dbPersister.ChangeUserGroups(userID, groupID); }
public void UserStatusChanged(GGUser user) { string recentID = RecentListBox.ConstructRecentID(user); ChatListSubItem[] items = this.chatListBox.GetSubItemsById(recentID); if (items == null || items.Length == 0) { return; } items[0].DisplayName = user.Name; items[0].HeadImage = this.resourceGetter.GetHeadImage(user); items[0].Status = this.ConvertUserStatus(user.UserStatus); this.chatListBox.Invalidate(); }
private void chatShow_MouseEnterHead(object sender, ChatListEventArgs e) { if (this.userInformationForm == null) { return; } ChatListSubItem item = e.MouseOnSubItem; if (item == null) { item = e.SelectSubItem; } Point loc = this.PointToScreen(this.Location); //int top = this.Top + this.chatListBox.Top + (item.HeadRect.Y - this.chatListBox.chatVScroll.Value); //int left = this.Left - 279 - 5; int top = loc.Y + (item.HeadRect.Y - this.chatListBox.chatVScroll.Value) - this.Location.Y; int left = loc.X - 279 - 5; //int ph = Screen.GetWorkingArea(this).Height; //if (top + 181 > ph) //{ // top = ph - 181 - 5; //} if (left < 0) { left = this.Right + 5; } GGUser user = (GGUser)item.Tag; Form form = (Form)this.userInformationForm; this.userInformationForm.SetUser(user); form.Location = new Point(left, top); if (!this.firstShow) { form.Show(); } else { this.firstShow = true; } form.Location = new Point(left, top); }
public void Initialize(GGUser current, IHeadImageGetter getter, IUserInformationForm form) { this.resourceGetter = getter; this.currentUser = current; this.userInformationForm = form; if (this.userInformationForm != null) { ((Form)this.userInformationForm).Visible = false; } this.AssureCatalog(this.currentUser.DefaultFriendCatalog); foreach (var catalog in this.currentUser.GetFriendCatalogList()) { this.AssureCatalog(catalog); } }
private void chatListBox_DoubleClickSubItem(object sender, ChatListEventArgs e) { ChatListSubItem item = e.SelectSubItem; GGUser friend = (GGUser)item.Tag; item.IsTwinkle = false; if (friend.ID == this.currentUser.ID) { return; } if (this.UserDoubleClicked != null) { this.UserDoubleClicked(friend); } }
private void toolStripMenuItem51_Click(object sender, EventArgs e) { ChatListSubItem item = this.chatListBox.SelectSubItem; GGUser friend = (GGUser)item.Tag; item.IsTwinkle = false; if (friend.ID == this.currentUser.ID) { return; } if (this.UserDoubleClicked != null) { this.UserDoubleClicked(friend); } }
public RegisterResult Register(GGUser user) { try { if (this.globalCache.IsUserExist(user.UserID)) { return RegisterResult.Existed; } this.globalCache.InsertUser(user); return RegisterResult.Succeed; } catch (Exception ee) { return RegisterResult.Error; } }
public RegisterResult Register(GGUser user) { try { if (this.globalCache.IsUserExist(user.UserID)) { return(RegisterResult.Existed); } this.globalCache.InsertUser(user); return(RegisterResult.Succeed); } catch (Exception ee) { return(RegisterResult.Error); } }
public SearchFriendForm(MainForm form, GGUser mine) { InitializeComponent(); this.mainForm = form; this.currentUser = mine; }
void do_globalUserCache_FriendInfoChanged(GGUser user) { this.friendListBox1.UserInfoChanged(user); this.recentListBox1.UserStatusChanged(user); ChatForm form = this.chatFormManager.GetForm(user.UserID); if (form != null) { form.OnFriendInfoChanged(user); } foreach (GroupChatForm groupForm in this.groupChatFormManager.GetAllForms()) { groupForm.OnUserInfoChanged(user); } }
private void do_globalUserCache_FriendStatusChanged(GGUser friend) { this.friendListBox1.UserStatusChanged(friend); this.recentListBox1.UserStatusChanged(friend); ChatForm form = this.chatFormManager.GetForm(friend.UserID); if (form != null) { form.FriendStateChanged(friend.UserStatus); } foreach (GroupChatForm groupForm in this.groupChatFormManager.GetAllForms()) { if (groupForm != null) { groupForm.GroupmateStateChanged(friend.UserID, friend.UserStatus); return; } } }
public void UpdateUser(GGUser t) { using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser<GGUser> accesser = scope.NewOrmAccesser<GGUser>(); accesser.Update(t); scope.Commit(); } }
public void UpdateUserFriends(GGUser t) { using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope()) { IOrmAccesser<GGUser> accesser = scope.NewOrmAccesser<GGUser>(); accesser.Update(new ColumnUpdating(GGUser._Friends, t.Friends), new Filter(GGUser._UserID, t.UserID)); scope.Commit(); } }
void form_UserInfoChanged(GGUser user) { this.labelSignature.Text = this.globalUserCache.CurrentUser.Signature; this.skinButton_headImage.Image = GlobalResourceManager.GetHeadImage(this.globalUserCache.CurrentUser); this.labelName.Text = this.globalUserCache.CurrentUser.Name; this.globalUserCache.AddOrUpdateUser(this.globalUserCache.CurrentUser); foreach (ChatForm chatForm in this.chatFormManager.GetAllForms()) { chatForm.OnMyInfoChanged(this.globalUserCache.CurrentUser); } }
public static Image GetHeadImage(GGUser user) { return GlobalResourceManager.GetHeadImage(user, false); }
/// <summary> /// 插入一个新用户。 /// </summary> public void InsertUser(GGUser user) { this.userCache.Add(user.UserID, user); this.dbPersister.InsertUser(user); }
void globalUserCache_FriendAdded(GGUser friend) { this.friendListBox1.AddUser(friend); }
void globalUserCache_FriendInfoChanged(GGUser user) { GlobalResourceManager.UiSafeInvoker.ActionOnUI<GGUser>(this.do_globalUserCache_FriendInfoChanged, user); }
void globalUserCache_FriendStatusChanged(GGUser friend) { GlobalResourceManager.UiSafeInvoker.ActionOnUI<GGUser>(this.do_globalUserCache_FriendStatusChanged, friend); }
public static Image GetHeadImageOnline(GGUser user) { if (user.HeadImageIndex >= 0) { if (user.HeadImageIndex < GlobalResourceManager.headImages.Length) { return GlobalResourceManager.headImages[user.HeadImageIndex]; } return GlobalResourceManager.headImages[0]; } else { return user.HeadImage; } }
public static Image GetHeadImage(GGUser user, bool mine) { if (user.HeadImageIndex >= 0) { Image[] ary = (mine ? !user.OnlineOrHide : user.OfflineOrHide) ? GlobalResourceManager.headImagesGrey : GlobalResourceManager.headImages; if (user.HeadImageIndex < GlobalResourceManager.headImages.Length) { return ary[user.HeadImageIndex]; } return ary[0]; } else { return (mine ? !user.OnlineOrHide : user.OfflineOrHide) ? user.HeadImageGrey : user.HeadImage; } }