示例#1
0
        private void Window_ContentRendered(object sender, EventArgs e)
        {
            //窗口呈现完成触发,已经显示了
            //窗口显示
            IsWindowShow = true;

            // udp测试
            // SendServerUdpData(0, "显示了窗体");

            // 是否显示更新日志,显示前进行判断该版本是否已经显示过了
            if (!UserClient.JsonSettings.IsNewVersionRunning)
            {
                UserClient.JsonSettings.IsNewVersionRunning = false;
                UserClient.JsonSettings.SaveToFile();
                MenuItem更新日志_Click(null, new RoutedEventArgs());
            }



            // 根据权限使能菜单
            if (UserClient.UserAccount.Grade < AccountGrade.Admin)
            {
                MenuItem公告管理.IsEnabled = false;
                MenuItem账户管理.IsEnabled = false;
                MenuItem注册账户.IsEnabled = false;
                MenuItem消息发送.IsEnabled = false;
            }


            if (UserClient.UserAccount.Grade < AccountGrade.SuperAdministrator)
            {
                MenuItem日志查看.IsEnabled = false;
                MenuItem远程更新.IsEnabled = false;
                MenuItem开发中心.IsEnabled = false;
                MenuItem系统配置.IsEnabled = false;
            }


            // 启动网络服务
            Net_Socket_Client_Initialization();
            // 启动定时器
            TimeTickInitilization();

            // 显示名称和加载头像
            AccountChip.Content    = UserClient.UserAccount.UserName;
            AccountPortrait.Source = AppWpfHelper.TranslateImageToBitmapImage(
                UserClient.PortraitManager.GetSmallPortraitByUserName(UserClient.UserAccount.UserName));

            SetShowRenderControl(UIControl_Home);
        }
示例#2
0
        /// <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.新头像更新)
            {
                UserClient.PortraitManager.UpdateSmallPortraitByName(data);
                if (IsWindowShow)
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        if (data == UserClient.UserAccount.UserName)
                        {
                            AccountPortrait.Source = AppWpfHelper.TranslateImageToBitmapImage(
                                UserClient.PortraitManager.GetSmallPortraitByUserName(data));
                        }
                        foreach (Views.Controls.UserClientRenderItem m in ClientsOnline.Children)
                        {
                            m.UpdatePortrait(data);
                        }
                    }));
                }
            }
        }