/// <summary> /// 接收到服务器的字节数据的回调方法 /// </summary> /// <param name="state">网络连接对象</param> /// <param name="customer">用户自定义的指令头,用来区分数据用途</param> /// <param name="data">数据</param> private void Net_socket_client_AcceptString(AsyncStateOne state, NetHandle customer, string data) { if (customer == CommonHeadCode.MultiNetHeadCode.弹窗新消息) { if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { FormPopup fpp = new FormPopup(data, System.Drawing.Color.DodgerBlue, 10000); fpp.Show(); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.总在线信息) { //if (IsWindowShow) Dispatcher.Invoke(new Action(() => //{ // // ListBox_Onlines.ItemsSource = data.Split('#'); // ClientsOnline.Children.Clear(); // NetAccount[] accounts = JArray.Parse(data).ToObject<NetAccount[]>(); // foreach(var m in accounts) // { // Views.Controls.UserClientRenderItem userClient = new Views.Controls.UserClientRenderItem(); // userClient.SetClientRender(m); // ClientsOnline.Children.Add(userClient); // } //})); } else if (customer == CommonHeadCode.MultiNetHeadCode.关闭客户端) { if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { Close(); })); } } else if (customer == CommonHeadCode.SimplifyHeadCode.更新公告) { //此处应用到了同步类的指令头 if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { UserClient.Announcement = data; TextBlock_Announcement.Text = data; FormPopup fpp = new FormPopup(data, System.Drawing.Color.DodgerBlue, 10000); fpp.Show(); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.初始化数据) { //收到服务器的数据 JObject json = JObject.Parse(data); UserClient.DateTimeServer = json["Time"].ToObject <DateTime>(); List <string> chats = JArray.Parse(json["chats"].ToString()).ToObject <List <string> >(); StringBuilder sb = new StringBuilder(); chats.ForEach(m => { sb.Append(m + Environment.NewLine); }); if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { TextBlock_ServerTime.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm:ss"); TextBlock_FileCount.Text = json["FileCount"].ToObject <int>().ToString(); UIControls_Chat.AddChatsHistory(sb.ToString()); NetAccount[] accounts = JArray.Parse(json["ClientsOnline"].ToString()).ToObject <NetAccount[]>(); foreach (var m in accounts) { Views.Controls.UserClientRenderItem userClient = new Views.Controls.UserClientRenderItem(); userClient.SetClientRender(m); ClientsOnline.Children.Add(userClient); } })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.文件总数量) { if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { TextBlock_FileCount.Text = data; })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.留言版消息) { if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { UIControls_Chat?.DealwithReceive(data); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.新用户上线) { if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { Views.Controls.UserClientRenderItem userClient = new Views.Controls.UserClientRenderItem(); userClient.SetClientRender(JObject.Parse(data).ToObject <NetAccount>()); ClientsOnline.Children.Add(userClient); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.用户下线) { if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { Views.Controls.UserClientRenderItem item = null; foreach (Views.Controls.UserClientRenderItem m in ClientsOnline.Children) { if (m?.UniqueId == data) { item = m; } } if (item != null) { ClientsOnline.Children.Remove(item); } })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.新头像更新) { if (IsWindowShow) { Dispatcher.Invoke(new Action(() => { foreach (Views.Controls.UserClientRenderItem m in ClientsOnline.Children) { m.UpdatePortrait(data); } })); } } }
/// <summary> /// 接收到服务器的字节数据的回调方法 /// </summary> /// <param name="session">网络连接对象</param> /// <param name="customer">用户自定义的指令头,用来区分数据用途</param> /// <param name="data">数据</param> private void Net_socket_client_AcceptString(AppSession session, NetHandle customer, string data) { if (customer == CommonHeadCode.MultiNetHeadCode.弹窗新消息) { if (IsHandleCreated) { Invoke(new Action(() => { FormPopup fpp = new FormPopup(data, Color.DodgerBlue, 10000); fpp.Show(); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.总在线信息) { //if (IsHandleCreated) Invoke(new Action(() => //{ // // listBox1.DataSource = data.Split('#'); // NetAccount[] accounts = JArray.Parse(data).ToObject<NetAccount[]>(); // netClientOnline1.SetOnlineRender(accounts); //})); } else if (customer == CommonHeadCode.MultiNetHeadCode.关闭客户端) { if (IsHandleCreated) { Invoke(new Action(() => { Close(); })); } } else if (customer == CommonHeadCode.SimplifyHeadCode.更新公告) { //此处应用到了同步类的指令头 if (IsHandleCreated) { Invoke(new Action(() => { UserClient.Announcement = data; label_Announcement.Text = data; FormPopup fpp = new FormPopup(data, Color.DodgerBlue, 10000); fpp.Show(); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.初始化数据) { //收到服务器的数据 JObject json = JObject.Parse(data); UserClient.DateTimeServer = json["Time"].ToObject <DateTime>(); List <string> chats = JArray.Parse(json["chats"].ToString()).ToObject <List <string> >(); StringBuilder sb = new StringBuilder(); chats.ForEach(m => { sb.Append(m + Environment.NewLine); }); if (IsHandleCreated) { Invoke(new Action(() => { toolStripStatusLabel_time.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm:ss"); label_file_count.Text = json["FileCount"].ToObject <int>().ToString(); UIControls_Chat.AddChatsHistory(sb.ToString()); UserClient.LogNet?.WriteDebug("Online Clients : " + json["ClientsOnline"].ToString()); NetAccount[] accounts = JArray.Parse(json["ClientsOnline"].ToString()).ToObject <NetAccount[]>(); netClientOnline1.SetOnlineRender(accounts); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.文件总数量) { if (IsHandleCreated) { Invoke(new Action(() => { label_file_count.Text = data; })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.留言版消息) { if (IsHandleCreated) { Invoke(new Action(() => { UIControls_Chat?.DealwithReceive(data); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.新用户上线) { if (IsHandleCreated) { Invoke(new Action(() => { UserClient.LogNet?.WriteDebug("Online Event : " + data); netClientOnline1.ClientOnline(JObject.Parse(data).ToObject <NetAccount>()); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.用户下线) { if (IsHandleCreated) { Invoke(new Action(() => { netClientOnline1.ClinetOffline(data); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.新头像更新) { UserClient.PortraitManager.UpdateSmallPortraitByName(data); if (IsHandleCreated) { Invoke(new Action(() => { if (data == UserClient.UserAccount.UserName) { pictureBox1.Image = UserClient.PortraitManager.GetSmallPortraitByUserName(data); } netClientOnline1.ClientUpdatePortrait(data); })); } } }
/// <summary> /// 接收到服务器的字节数据的回调方法 /// </summary> /// <param name="state">网络连接对象</param> /// <param name="customer">用户自定义的指令头,用来区分数据用途</param> /// <param name="data">数据</param> private void Net_socket_client_AcceptString(AsyncStateOne state, int customer, string data) { if (customer == CommonHeadCode.MultiNetHeadCode.弹窗新消息) { if (IsHandleCreated) { Invoke(new Action(() => { FormPopup fpp = new FormPopup(data, Color.DodgerBlue, 10000); fpp.Show(); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.总在线信息) { if (IsHandleCreated) { Invoke(new Action(() => { listBox1.DataSource = data.Split('#'); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.关闭客户端) { if (IsHandleCreated) { Invoke(new Action(() => { Close(); })); } } else if (customer == CommonHeadCode.SimplifyHeadCode.更新公告) { //此处应用到了同步类的指令头 if (IsHandleCreated) { Invoke(new Action(() => { UserClient.Announcement = data; label_Announcement.Text = data; FormPopup fpp = new FormPopup(data, Color.DodgerBlue, 10000); fpp.Show(); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.初始化数据) { //收到服务器的数据 JObject json = JObject.Parse(data); UserClient.DateTimeServer = json["Time"].ToObject <DateTime>(); List <string> chats = JArray.Parse(json["chats"].ToString()).ToObject <List <string> >(); StringBuilder sb = new StringBuilder(); chats.ForEach(m => { sb.Append(m + Environment.NewLine); }); if (IsHandleCreated) { Invoke(new Action(() => { toolStripStatusLabel_time.Text = UserClient.DateTimeServer.ToString("yyyy-MM-dd HH:mm"); label_file_count.Text = json["FileCount"].ToObject <int>().ToString(); UIControls_Chat.AddChatsHistory(sb.ToString()); })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.文件总数量) { if (IsHandleCreated) { Invoke(new Action(() => { label_file_count.Text = data; })); } } else if (customer == CommonHeadCode.MultiNetHeadCode.留言版消息) { if (IsHandleCreated) { Invoke(new Action(() => { UIControls_Chat?.DealwithReceive(data); })); } } }