public void AddOrUpdateUser(GGUser user) { var isNew = !this.userManager.Contains(user.ID); this.userManager.Add(user.ID, user); if (this.FriendInfoChanged != null) { this.FriendInfoChanged(user); } #if Org GGGroup group = this.groupManager.Get(this.companyGroupID); if (this.currentUser.IsInOrg && group != null)//资料发生变化的可能是自己 { if (user.IsInOrg) { group.MemberList.Add(user.ID); } else { group.MemberList.Remove(user.ID); } this.GroupChanged(group, GroupChangedType.SomeoneJoin, user.ID); } #endif }
void do_globalUserCache_GroupInfoChanged(GGGroup group, GroupChangedType type, string userID) { this.groupListBox.GroupInfoChanged(group, type, userID); if (type == GroupChangedType.GroupDeleted) { GroupChatForm form = this.groupChatFormManager.GetForm(group.ID); if (form != null) { form.Close(); } if (userID != null) //为null 表示更改了自己的部门资料 { MessageBoxEx.Show(string.Format("群{0}({1})已经被解散。", group.ID, group.Name)); } return; } GroupChatForm form2 = this.groupChatFormManager.GetForm(group.ID); if (form2 != null) { form2.OnGroupInfoChanged(type, userID); } }
private void btnClose_Click(object sender, EventArgs e) { var groupID = this.skinTextBox_id.SkinTxt.Text.Trim(); if (groupID.Length == 0) { MessageBoxEx.Show("群帐号不能为空!"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } try { var contract = new CreateGroupContract(groupID, this.skinTextBox_name.SkinTxt.Text.Trim(), this.skinTextBox_announce.SkinTxt.Text); var bRes = this.rapidPassiveEngine.CustomizeOutter.Query(InformationTypes.CreateGroup, CompactPropertySerializer.Default.Serialize(contract)); var res = (CreateGroupResult)BitConverter.ToInt32(bRes, 0); if (res == CreateGroupResult.GroupExisted) { MessageBoxEx.Show("同ID的群已经存在!"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } this.group = new GGGroup(groupID, contract.Name, this.rapidPassiveEngine.CurrentUserID, "", this.rapidPassiveEngine.CurrentUserID); this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception ee) { MessageBoxEx.Show("创建群失败!" + ee.Message); this.DialogResult = System.Windows.Forms.DialogResult.None; } }
void ContactsOutter_BroadcastReceived(string broadcasterID, string groupID, int broadcastType, byte[] content, string tag) { if (!this.initialized) { return; } if (this.InvokeRequired) { this.BeginInvoke(new CbGeneric <string, string, int, byte[], string>(this.ContactsOutter_BroadcastReceived), broadcasterID, groupID, broadcastType, content, tag); } else { try { if (broadcastType == BroadcastTypes.BroadcastChat) { GGGroup group = this.globalUserCache.GetGroup(groupID); byte[] decrypted = content; if (GlobalResourceManager.Des3Encryption != null) { decrypted = GlobalResourceManager.Des3Encryption.Decrypt(content); } this.notifyIcon.PushGroupMessage(broadcasterID, groupID, broadcastType, decrypted); ChatMessageRecord record = new ChatMessageRecord(broadcasterID, groupID, decrypted, true); GlobalResourceManager.ChatMessageRecordPersister.InsertChatMessageRecord(record); return; } if (broadcastType == BroadcastTypes.SomeoneJoinGroup) { string userID = System.Text.Encoding.UTF8.GetString(content); this.globalUserCache.OnSomeoneJoinGroup(groupID, userID); return; } if (broadcastType == BroadcastTypes.SomeoneQuitGroup) { string userID = System.Text.Encoding.UTF8.GetString(content); this.globalUserCache.OnSomeoneQuitGroup(groupID, userID); return; } if (broadcastType == BroadcastTypes.GroupDeleted) { string userID = System.Text.Encoding.UTF8.GetString(content); this.globalUserCache.OnGroupDeleted(groupID, userID); return; } } catch (Exception ee) { GlobalResourceManager.Logger.Log(ee, "MainForm.GroupOutter_BroadcastReceived", ESBasic.Loggers.ErrorLevel.Standard); MessageBox.Show(ee.Message); } } }
private void MainForm_Load(object sender, EventArgs e) { try { if (!this.DesignMode) { this.notifyIcon.Visible = true; } //我的好友 foreach (string friendID in this.globalUserCache.CurrentUser.GetAllFriendList()) { if (friendID == this.globalUserCache.CurrentUser.UserID) { continue; } GGUser friend = this.globalUserCache.GetUser(friendID); if (friend != null) { this.friendListBox1.AddUser(friend); } } this.friendListBox1.SortAllUser(); this.friendListBox1.ExpandRoot(); foreach (string groupid in this.globalUserCache.CurrentUser.GroupList) //初期不包含 固定群 { GGGroup group1 = this.globalUserCache.GetGroup(groupid); if (group1 != null) { this.groupListBox.AddGroup(group1); } } //加载最近联系人 int insertIndex = 0; foreach (string recentID in this.globalUserCache.GetRecentList()) { Parameter <string, bool> para = RecentListBox.ParseIDFromRecentID(recentID); IUnit unit = this.globalUserCache.GetUnit(para.Arg1, para.Arg2); if (unit == null) { continue; } this.recentListBox1.AddRecentUnit(unit, insertIndex); ++insertIndex; } this.initialized = true; } catch (Exception ee) { MessageBox.Show(ee.Message); } }
public void OnGroupInfoChanged(string groupID) { GGGroup group = this.groupManager.Get(groupID); if (group == null) { return; } this.GroupChanged(group, GroupChangedType.GroupInfoChanged, null); }
public GGGroup GetGroup(string groupID) { GGGroup group = this.groupManager.Get(groupID); if (group == null) { group = this.DoGetGroup(groupID); this.groupManager.Add(group.ID, group); } return(group); }
private void ToJoinGroup() { JoinGroupForm form = new JoinGroupForm(this.rapidPassiveEngine, this); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { this.globalUserCache.CurrentUser.JoinGroup(form.GroupID); GGGroup group = this.globalUserCache.GetGroup(form.GroupID); this.groupListBox.AddGroup(group); GroupChatForm groupChatForm = this.GetGroupChatForm(group.ID); groupChatForm.AppendSysMessage("您已经成功加入群,可以开始聊天了..."); groupChatForm.Show(); groupChatForm.Focus(); } }
public void OnSomeoneQuitGroup(string groupID, string userID) { GGGroup group = this.groupManager.Get(groupID); if (group == null || !group.MemberList.Contains(userID)) { return; } group.MemberList.Remove(userID); if (this.GroupChanged != null) { this.GroupChanged(group, GroupChangedType.SomeoneQuit, userID); } }
public UpdateGroupInfoForm(IRapidPassiveEngine engine, GlobalUserCache cache, GGGroup group) { InitializeComponent(); this.rapidPassiveEngine = engine; this.currentGroup = group; int registerPort = int.Parse(ConfigurationManager.AppSettings["RemotingPort"]); this.ggService = (IRemotingService)Activator.GetObject(typeof(IRemotingService), string.Format("tcp://{0}:{1}/RemotingService", ConfigurationManager.AppSettings["ServerIP"], registerPort));; this.skinLabel_ID.Text = group.ID; this.skinTextBox_nickName.SkinTxt.Text = group.Name; this.skinTextBox_signature.SkinTxt.Text = group.Announce; globalUserCache = cache; }
public void OnGroupDeleted(string groupID, string operateUserID) { if (this.currentUser.ID == operateUserID) { return; } GGGroup group = this.groupManager.Get(groupID); if (group == null) { return; } this.GroupChanged(group, GroupChangedType.GroupDeleted, operateUserID); this.groupManager.Remove(groupID); }
void recentListBox1_ChatRecordClicked(string unitID, bool isGroup) { ChatRecordForm form = null; if (isGroup) { GGGroup group = this.globalUserCache.GetGroup(unitID); form = new ChatRecordForm(GlobalResourceManager.RemotingService, GlobalResourceManager.ChatMessageRecordPersister, group.GetIDName(), this.globalUserCache.CurrentUser.GetIDName(), this.globalUserCache); form.Show(); } else { GGUser friend = this.globalUserCache.GetUser(unitID); form = new ChatRecordForm(GlobalResourceManager.RemotingService, GlobalResourceManager.ChatMessageRecordPersister, this.globalUserCache.CurrentUser.GetIDName(), friend.GetIDName()); } form.Show(); }
public GroupChatForm(IRapidPassiveEngine engine, string groupID, GlobalUserCache cache, IChatSupporter supporter) { this.rapidPassiveEngine = engine; this.globalUserCache = cache; this.mine = this.globalUserCache.GetUser(this.rapidPassiveEngine.CurrentUserID); this.ggSupporter = supporter; this.currentGroup = this.globalUserCache.GetGroup(groupID); InitializeComponent(); this.chatBoxSend.Initialize(GlobalResourceManager.EmotionDictionary); this.chatBox_history.Initialize(GlobalResourceManager.EmotionDictionary); this.chatBoxSend.Font = SystemSettings.Singleton.Font; this.chatBoxSend.ForeColor = SystemSettings.Singleton.FontColor; this.Size = SystemSettings.Singleton.ChatFormSize; this.linkLabel_softName.Text = GlobalResourceManager.SoftwareName; this.toolShow.SetToolTip(this.panelFriendHeadImage, this.currentGroup.GroupID); this.Text = string.Format("{0}({1})", this.currentGroup.Name, this.currentGroup.GroupID); this.labelGroupName.Text = this.currentGroup.Name; this.label_announce.Text = this.currentGroup.Announce; this.chatBoxSend.Focus(); this.emotionForm = new EmotionForm(); this.emotionForm.Load += new EventHandler(emotionForm_Load); this.emotionForm.Initialize(GlobalResourceManager.EmotionList); this.emotionForm.EmotionClicked += new CbGeneric <int, Image>(emotionForm_Clicked); this.emotionForm.Visible = false; this.emotionForm.LostFocus += new EventHandler(emotionForm_LostFocus); foreach (string memberID in this.currentGroup.MemberList) { GGUser friend = this.globalUserCache.GetUser(memberID); this.AddUserItem(friend); } if (SystemSettings.Singleton.LoadLastWordsWhenChatFormOpened) { LastWordsRecord record = this.currentGroup.Tag as LastWordsRecord; if (record != null) { string talker = string.Format("{0}({1})", record.SpeakerName, record.SpeakerID); this.AppendChatBoxContent(talker, record.SpeakTime, record.ChatBoxContent, Color.Blue); } } }
void form_GroupInfoChanged(GGGroup group) { //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); //} this.Text = string.Format("{0}({1})", this.currentGroup.Name, this.currentGroup.GroupID); this.labelGroupName.Text = this.currentGroup.Name; this.label_announce.Text = this.currentGroup.Announce; return; }
private void 创建群ToolStripMenuItem1_Click(object sender, EventArgs e) { if (this.globalUserCache.CurrentUser.UserStatus == UserStatus.OffLine) { return; } CreateGroupForm form = new CreateGroupForm(this.rapidPassiveEngine); if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { GGGroup group = form.Group; this.globalUserCache.CurrentUser.JoinGroup(group.ID); this.globalUserCache.OnCreateGroup(group); this.groupListBox.AddGroup(group); GroupChatForm groupChatForm = this.GetGroupChatForm(group.ID); groupChatForm.AppendSysMessage("您已经成功创建群..."); groupChatForm.Show(); groupChatForm.Focus(); } }
public string GetGroupName(string groupID) { GGGroup group = this.globalUserCache.GetGroup(groupID); return(group.Name); }
void globalUserCache_GroupInfoChanged(GGGroup group, GroupChangedType type, string userID) { GlobalResourceManager.UiSafeInvoker.ActionOnUI <GGGroup, GroupChangedType, string>(this.do_globalUserCache_GroupInfoChanged, group, type, userID); }
private void RefreshContactRTData(object state) { try { ContactRTDatas contract = this.DoGetContactsRTDatas(); foreach (string userID in this.userManager.GetKeyList()) { if (userID != this.currentUser.ID && !contract.UserStatusDictionary.ContainsKey(userID)) //最新的联系人中不包含缓存用户,则将之从缓存中删除。 { this.userManager.Remove(userID); if (this.FriendRemoved != null) { this.FriendRemoved(userID); } } } foreach (KeyValuePair <string, UserRTData> pair in contract.UserStatusDictionary) { if (pair.Key == this.currentUser.ID) { continue; } GGUser origin = this.userManager.Get(pair.Key); if (origin == null) //不存在于本地缓存中 { GGUser user = this.DoGetUser(pair.Key); this.userManager.Add(user.ID, user); if (this.FriendInfoChanged != null) { this.FriendInfoChanged(user); } } else { //资料变化 if (pair.Value.Version != origin.Version) { GGUser user = this.DoGetUser(pair.Key); if (this.FriendInfoChanged != null) { this.FriendInfoChanged(user); } user.Tag = origin.Tag; this.userManager.Add(user.ID, user); } else { //状态变化 if (origin.UserStatus != pair.Value.UserStatus) { origin.UserStatus = pair.Value.UserStatus; if (this.FriendStatusChanged != null) { this.FriendStatusChanged(origin); } } } } } List <string> updateGroupList = new List <string>(); foreach (string groupID in this.currentUser.GroupList) { GGGroup group = this.groupManager.Get(groupID); if (group == null) { updateGroupList.Add(groupID); continue; } if (contract.GroupVersionDictionary.ContainsKey(groupID)) { if (contract.GroupVersionDictionary[groupID] != group.Version) { updateGroupList.Add(groupID); continue; } } } if (updateGroupList.Count > 0) { //加载组 List <GGGroup> newGroups = this.DoGetSomeGroups(updateGroupList); foreach (GGGroup group in newGroups) { this.groupManager.Add(group.ID, group); if (this.GroupChanged != null) { this.GroupChanged(group, GroupChangedType.MemberInfoChanged, null); } } } if (this.FriendRTDataRefreshCompleted != null) { this.FriendRTDataRefreshCompleted(); } } catch (Exception ee) { this.logger.Log(ee, "GlobalUserCache.RefreshContactRTData", ESBasic.Loggers.ErrorLevel.Standard); } }
/// <summary> /// 当自己创建群时,调用此方法添加到缓存中。 /// </summary> public void OnCreateGroup(GGGroup group) { this.groupManager.Add(group.ID, group); }
public void HandleInformation(string sourceUserID, int informationType, byte[] info) { if (!this.initialized) { return; } #region 需要twinkle的消息 if (informationType == InformationTypes.Chat || informationType == InformationTypes.OfflineMessage || informationType == InformationTypes.OfflineFileResultNotify || informationType == InformationTypes.Vibration || informationType == InformationTypes.VideoRequest || informationType == InformationTypes.AgreeVideo || informationType == InformationTypes.RejectVideo || informationType == InformationTypes.HungUpVideo || informationType == InformationTypes.DiskRequest || informationType == InformationTypes.AgreeDisk || informationType == InformationTypes.RejectDisk || informationType == InformationTypes.RemoteHelpRequest || informationType == InformationTypes.AgreeRemoteHelp || informationType == InformationTypes.RejectRemoteHelp || informationType == InformationTypes.CloseRemoteHelp || informationType == InformationTypes.TerminateRemoteHelp || informationType == InformationTypes.AudioRequest || informationType == InformationTypes.RejectAudio || informationType == InformationTypes.AgreeAudio || informationType == InformationTypes.HungupAudio || informationType == InformationTypes.FriendAddedNotify) { if (informationType == InformationTypes.FriendAddedNotify) { GGUser owner = CompactPropertySerializer.Default.Deserialize <GGUser>(info, 0); // 0922 this.globalUserCache.CurrentUser.AddFriend(owner.ID, this.globalUserCache.CurrentUser.DefaultFriendCatalog); this.globalUserCache.OnFriendAdded(owner); //自然会添加 好友条目 sourceUserID = owner.UserID; } object tag = null; if (informationType == InformationTypes.OfflineMessage) { byte[] bChatBoxContent = null; OfflineMessage msg = CompactPropertySerializer.Default.Deserialize <OfflineMessage>(info, 0); if (msg.InformationType == InformationTypes.Chat) //目前只处理离线的聊天消息 { sourceUserID = msg.SourceUserID; bChatBoxContent = msg.Information; byte[] decrypted = bChatBoxContent; if (GlobalResourceManager.Des3Encryption != null) { decrypted = GlobalResourceManager.Des3Encryption.Decrypt(bChatBoxContent); } ChatMessageRecord record = new ChatMessageRecord(sourceUserID, this.rapidPassiveEngine.CurrentUserID, decrypted, false, false); GlobalResourceManager.ChatMessageRecordPersister.InsertChatMessageRecord(record); ChatBoxContent content = CompactPropertySerializer.Default.Deserialize <ChatBoxContent>(decrypted, 0); tag = new Parameter <ChatBoxContent, DateTime>(content, msg.Time); } } if (informationType == InformationTypes.OfflineFileResultNotify) { OfflineFileResultNotifyContract contract = CompactPropertySerializer.Default.Deserialize <OfflineFileResultNotifyContract>(info, 0); sourceUserID = contract.AccepterID; } GGUser user = this.globalUserCache.GetUser(sourceUserID); this.notifyIcon.PushFriendMessage(sourceUserID, informationType, info, tag); return; } #endregion if (this.InvokeRequired) { this.BeginInvoke(new CbGeneric <string, int, byte[]>(this.HandleInformation), sourceUserID, informationType, info); } else { try { if (informationType == InformationTypes.InputingNotify) { ChatForm form = this.chatFormManager.GetForm(sourceUserID); if (form != null) { form.OnInptingNotify(); } return; } if (informationType == InformationTypes.FriendRemovedNotify) { string friendID = System.Text.Encoding.UTF8.GetString(info); this.globalUserCache.RemovedFriend(friendID); return; } if (informationType == InformationTypes.UserInforChanged) { GGUser user = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <GGUser>(info, 0); this.globalUserCache.AddOrUpdateUser(user); return; } if (informationType == InformationTypes.UpdateGroupInfo) { GGGroup group = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <GGGroup>(info, 0); this.globalUserCache.UpdateGroup(group); return; } if (informationType == InformationTypes.UserStatusChanged) { UserStatusChangedContract contract = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <UserStatusChangedContract>(info, 0); this.globalUserCache.ChangeUserStatus(contract.UserID, (UserStatus)contract.NewStatus); } if (informationType == InformationTypes.SystemNotify4AllOnline) { SystemNotifyContract contract = CompactPropertySerializer.Default.Deserialize <SystemNotifyContract>(info, 0); SystemNotifyForm form = new SystemNotifyForm(contract.Title, contract.Content); form.Show(); return; } if (informationType == InformationTypes.SystemNotify4Group) { SystemNotifyContract contract = CompactPropertySerializer.Default.Deserialize <SystemNotifyContract>(info, 0); SystemNotifyForm form = new SystemNotifyForm(contract.Title, contract.Content); form.Show(); return; } if (informationType == InformationTypes.RemoveMember) { //GGUser user = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize<GGUser>(info, 0); //this.globalUserCache.AddOrUpdateUser(user); string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; this.groupListBox.RemoveGroup(groupID); this.recentListBox1.RemoveUnit(this.globalUserCache.GetGroup(groupID)); GroupChatForm form = this.groupChatFormManager.GetForm(groupID); if (form != null) { form.Close(); } IGroup group = this.globalUserCache.GetGroup(groupID); group.NoSpeakList.Remove(UserID); this.globalUserCache.RemoveGroup(groupID); this.globalUserCache.CurrentUser.QuitGroup(groupID); MessageBoxEx.Show(string.Format("您已经被踢出群{0}({1})。", group.ID, group.Name)); return; } if (informationType == InformationTypes.AddMember) { string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; this.globalUserCache.CurrentUser.JoinGroup(groupID); GGGroup group = this.globalUserCache.GetGroup(groupID); group.NoSpeakList.Remove(UserID); this.groupListBox.AddGroup(group); GroupChatForm groupChatForm = this.GetGroupChatForm(group.ID); groupChatForm.AppendSysMessage("您已经成功加入群,可以开始聊天了..."); groupChatForm.Show(); groupChatForm.Focus(); return; } //if (informationType == InformationTypes.AddManager) //{ // string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; // string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; // GGGroup group = this.globalUserCache.GetGroup(groupID); // group.AddManager(UserID); // GroupChatForm groupChatForm = this.GetGroupChatForm(group.ID); // groupChatForm.AppendSysMessage("您已经成功加入群,可以开始聊天了..."); // groupChatForm.Show(); // groupChatForm.Focus(); // return; //} } catch (Exception ee) { GlobalResourceManager.Logger.Log(ee, "MainForm.HandleInformation", ESBasic.Loggers.ErrorLevel.Standard); MessageBox.Show(ee.Message); } } }