Esempio n. 1
0
        /// <summary>
        /// 从字符串数据加载配置
        /// </summary>
        /// <param name="content"></param>
        public override void LoadByString(string content)
        {
            JObject json = JObject.Parse(content);

            SystemVersion            = new SystemVersion(SoftBasic.GetValueFromJsonObject(json, nameof(SystemVersion), "1.0.0"));
            Announcement             = SoftBasic.GetValueFromJsonObject(json, nameof(Announcement), Announcement);
            Can_Account_Login        = SoftBasic.GetValueFromJsonObject(json, nameof(Can_Account_Login), Can_Account_Login);
            AllowUserMultiOnline     = SoftBasic.GetValueFromJsonObject(json, nameof(AllowUserMultiOnline), AllowUserMultiOnline);
            Account_Forbidden_Reason = SoftBasic.GetValueFromJsonObject(json, nameof(Account_Forbidden_Reason), Account_Forbidden_Reason);
            AllowLoginWhenFramewordVersionNotCheck = SoftBasic.GetValueFromJsonObject(json, nameof(AllowLoginWhenFramewordVersionNotCheck), AllowLoginWhenFramewordVersionNotCheck);



            if (json[nameof(SystemFactories)] != null)
            {
                SystemFactories = json[nameof(SystemFactories)].ToObject <List <string> >();
            }

            WhetherToEnableTrustedClientAuthentication = SoftBasic.GetValueFromJsonObject(json, nameof(WhetherToEnableTrustedClientAuthentication), false);

            if (json[nameof(TrustedClientList)] != null)
            {
                TrustedClientList = json[nameof(TrustedClientList)].ToObject <List <string> >();
            }

            ;
        }
        public void GetValueFromJsonObjectTest( )
        {
            JObject json = new JObject( );

            json.Add("A", new JValue("Abcdea234a"));

            Assert.AreEqual("Abcdea234a", SoftBasic.GetValueFromJsonObject(json, "A", ""));
        }
Esempio n. 3
0
        /// <summary>
        /// 从字符串数据加载配置
        /// </summary>
        /// <param name="content"></param>
        public override void LoadByString(string content)
        {
            JObject json = JObject.Parse(content);

            SystemVersion            = new SystemVersion(json.Property(nameof(SystemVersion)).Value.Value <string>());
            Announcement             = json.Property(nameof(Announcement)).Value.Value <string>();
            Can_Account_Login        = SoftBasic.GetValueFromJsonObject(json, nameof(Can_Account_Login), Can_Account_Login);
            Account_Forbidden_Reason = SoftBasic.GetValueFromJsonObject(json, nameof(Account_Forbidden_Reason), Account_Forbidden_Reason);
        }
        public void GetValueFromJsonObjectExample( )
        {
            #region GetValueFromJsonObjectExample

            JObject json = new JObject( );
            json.Add("A", new JValue("Abcdea234a"));

            Console.WriteLine("Abcdea234a", SoftBasic.GetValueFromJsonObject(json, "A", ""));

            // 输出 true

            #endregion
        }
Esempio n. 5
0
        public override void LoadByString(string content)
        {
            JObject json       = JObject.Parse(content);
            string  systemInfo = SoftBasic.GetValueFromJsonObject(json, nameof(SystemInfo), "");

            if (systemInfo == SystemInfo)
            {
                //文件匹配正确
                LoginName           = SoftBasic.GetValueFromJsonObject(json, nameof(LoginName), LoginName);
                IsNewVersionRunning = SoftBasic.GetValueFromJsonObject(json, nameof(IsNewVersionRunning), IsNewVersionRunning);
                Password            = SoftBasic.GetValueFromJsonObject(json, nameof(Password), Password);
                LoginTime           = SoftBasic.GetValueFromJsonObject(json, nameof(LoginTime), LoginTime);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 从字符串加载数据信息
        /// </summary>
        /// <param name="content"></param>
        public override void LoadByString(string content)
        {
            JObject json = JObject.Parse(content);

            OpcUaStringUrl                      = SoftBasic.GetValueFromJsonObject(json, nameof(OpcUaStringUrl), "");
            SecurityPolicyNone                  = SoftBasic.GetValueFromJsonObject(json, nameof(SecurityPolicyNone), false);
            SecurityPolicyBasic128_Sign         = SoftBasic.GetValueFromJsonObject(json, nameof(SecurityPolicyBasic128_Sign), false);
            SecurityPolicyBasic128_Sign_Encrypt = SoftBasic.GetValueFromJsonObject(json, nameof(SecurityPolicyBasic128_Sign_Encrypt), false);
            SecurityPolicyBasic256_Sign         = SoftBasic.GetValueFromJsonObject(json, nameof(SecurityPolicyBasic256_Sign), false);
            SecurityPolicyBasic256_Sign_Encrypt = SoftBasic.GetValueFromJsonObject(json, nameof(SecurityPolicyBasic256_Sign_Encrypt), false);
            SecurityAnonymous                   = SoftBasic.GetValueFromJsonObject(json, nameof(SecurityAnonymous), true);
            SecurityAccount                     = SoftBasic.GetValueFromJsonObject(json, nameof(SecurityAccount), false);
            UserName = SoftBasic.GetValueFromJsonObject(json, nameof(UserName), "admin");
            Password = SoftBasic.GetValueFromJsonObject(json, nameof(Password), "123456");
        }
Esempio n. 7
0
        /// <summary>
        /// [自校验] 从套接字中接收文件头信息
        /// </summary>
        /// <param name="socket"></param>
        /// <returns></returns>
        protected OperateResult <FileBaseInfo> ReceiveFileHeadFromSocket(Socket socket)
        {
            // 先接收文件头信息
            OperateResult <int, string> receiveString = ReceiveStringContentFromSocket(socket);

            if (!receiveString.IsSuccess)
            {
                return(new OperateResult <FileBaseInfo>( )
                {
                    Message = receiveString.Message
                });
            }

            // 判断文件是否存在
            if (receiveString.Content1 == 0)
            {
                socket?.Close( );
                LogNet?.WriteWarn(ToString( ), "对方文件不存在,无法接收!");
                return(new OperateResult <FileBaseInfo>( )
                {
                    Message = StringResources.FileNotExist
                });
            }

            OperateResult <FileBaseInfo> result = new OperateResult <FileBaseInfo>( );

            result.Content = new FileBaseInfo( );
            try
            {
                // 提取信息
                Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(receiveString.Content2);
                result.Content.Name   = SoftBasic.GetValueFromJsonObject(json, "FileName", "");
                result.Content.Size   = SoftBasic.GetValueFromJsonObject(json, "FileSize", 0L);
                result.Content.Tag    = SoftBasic.GetValueFromJsonObject(json, "FileTag", "");
                result.Content.Upload = SoftBasic.GetValueFromJsonObject(json, "FileUpload", "");
                result.IsSuccess      = true;
            }
            catch (Exception ex)
            {
                socket?.Close( );
                result.Message = "提取信息失败," + ex.Message;
            }

            return(result);
        }
Esempio n. 8
0
        public override void LoadByString(string content)
        {
            JObject json       = JObject.Parse(content);
            string  systemInfo = SoftBasic.GetValueFromJsonObject(json, nameof(SystemInfo), "");

            // 用户名不会因此更改
            LoginName = SoftBasic.GetValueFromJsonObject(json, nameof(LoginName), LoginName);

            if (systemInfo == SystemInfo)
            {
                //确认账户名及密码是本机的记录,而不是从其他电脑端拷贝过来的
                IsNewVersionRunning = SoftBasic.GetValueFromJsonObject(json, nameof(IsNewVersionRunning), IsNewVersionRunning);
                Password            = SoftBasic.GetValueFromJsonObject(json, nameof(Password), Password);
                LoginTime           = SoftBasic.GetValueFromJsonObject(json, nameof(LoginTime), LoginTime);
                IsThemeDark         = SoftBasic.GetValueFromJsonObject(json, nameof(IsThemeDark), IsThemeDark);
                PasswordOverdueDays = SoftBasic.GetValueFromJsonObject(json, nameof(PasswordOverdueDays), PasswordOverdueDays);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 用户账户验证的后台端
        /// </summary>
        private void ThreadCheckAccount()
        {
            //定义委托
            Action <string> message_show = delegate(string message)
            {
                label_status.Text = message;
            };
            Action start_update = delegate
            {
                //需要该exe支持,否则将无法是实现自动版本控制
                string update_file_name = Application.StartupPath + @"\软件自动更新.exe";
                try
                {
                    System.Diagnostics.Process.Start(update_file_name);
                    Environment.Exit(0);//退出系统
                }
                catch
                {
                    MessageBox.Show("更新程序启动失败,请检查文件是否丢失,联系管理员获取。");
                }
            };
            Action thread_finish = delegate
            {
                UISettings(true);
            };

            //延时
            Thread.Sleep(200);

            //请求指令头数据,该数据需要更具实际情况更改
            OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.维护检查);

            if (result.IsSuccess)
            {
                byte[] temp = Encoding.Unicode.GetBytes(result.Content);
                //例如返回结果为1说明允许登录,0则说明服务器处于维护中,并将信息显示
                if (result.Content != "1")
                {
                    if (IsHandleCreated)
                    {
                        Invoke(message_show, result.Content.Substring(1));
                    }
                    if (IsHandleCreated)
                    {
                        Invoke(thread_finish);
                    }
                    return;
                }
            }
            else
            {
                //访问失败
                if (IsHandleCreated)
                {
                    Invoke(message_show, result.Message);
                }
                if (IsHandleCreated)
                {
                    Invoke(thread_finish);
                }
                return;
            }



            //检查账户
            if (IsHandleCreated)
            {
                Invoke(message_show, "正在检查账户...");
            }
            else
            {
                return;
            }

            //延时
            Thread.Sleep(200);

            //===================================================================================
            //   根据实际情况校验,选择数据库校验或是将用户名密码发至服务器校验
            //   以下展示了服务器校验的方法,如您需要数据库校验,请删除下面并改成SQL访问验证的方式

            //包装数据
            JObject json = new JObject
            {
                { UserAccount.UserNameText, new JValue(textBox_userName.Text) },
                { UserAccount.PasswordText, new JValue(textBox_password.Text) },
                { UserAccount.LoginWayText, new JValue("winform") }
            };

            result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.账户检查, json.ToString());
            if (result.IsSuccess)
            {
                //服务器应该返回账户的信息
                UserAccount account = JObject.Parse(result.Content).ToObject <UserAccount>();
                if (!account.LoginEnable)
                {
                    //不允许登录
                    if (IsHandleCreated)
                    {
                        Invoke(message_show, account.ForbidMessage);
                    }
                    if (IsHandleCreated)
                    {
                        Invoke(thread_finish);
                    }
                    return;
                }
                UserClient.UserAccount = account;
            }
            else
            {
                //访问失败
                if (IsHandleCreated)
                {
                    Invoke(message_show, result.Message);
                }
                if (IsHandleCreated)
                {
                    Invoke(thread_finish);
                }
                return;
            }

            //登录成功,进行保存用户名称和密码
            UserClient.JsonSettings.LoginName = textBox_userName.Text;
            UserClient.JsonSettings.Password  = checkBox_remeber.Checked ? textBox_password.Text : "";
            UserClient.JsonSettings.LoginTime = DateTime.Now;
            UserClient.JsonSettings.SaveToFile();


            //版本验证
            if (IsHandleCreated)
            {
                Invoke(message_show, "正在验证版本...");
            }
            else
            {
                return;
            }

            //延时
            Thread.Sleep(200);

            result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.更新检查);
            if (result.IsSuccess)
            {
                //服务器应该返回服务器的版本号
                SystemVersion sv = new SystemVersion(result.Content);
                //系统账户跳过低版本检测
                if (UserClient.UserAccount.UserName != "admin")
                {
                    if (UserClient.CurrentVersion != sv)
                    {
                        //保存新版本信息
                        UserClient.JsonSettings.IsNewVersionRunning = true;
                        UserClient.JsonSettings.SaveToFile();
                        //和当前系统版本号不一致,启动更新
                        if (IsHandleCreated)
                        {
                            Invoke(start_update);
                        }
                        return;
                    }
                }
                else
                {
                    if (UserClient.CurrentVersion < sv)
                    {
                        //保存新版本信息
                        UserClient.JsonSettings.IsNewVersionRunning = true;
                        UserClient.JsonSettings.SaveToFile();
                        //和当前系统版本号不一致,启动更新
                        if (IsHandleCreated)
                        {
                            Invoke(start_update);
                        }
                        return;
                    }
                }
            }
            else
            {
                //访问失败
                if (IsHandleCreated)
                {
                    Invoke(message_show, result.Message);
                }
                if (IsHandleCreated)
                {
                    Invoke(thread_finish);
                }
                return;
            }


            //================================================================================
            //验证结束后,根据需要是否下载服务器的数据,或是等到进入主窗口下载也可以
            //如果有参数决定主窗口的显示方式,那么必要在下面向服务器请求数据
            //以下展示了初始化参数的功能
            if (IsHandleCreated)
            {
                Invoke(message_show, "正在下载参数...");
            }
            else
            {
                return;
            }

            //延时
            Thread.Sleep(200);


            result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.参数下载);
            if (result.IsSuccess)
            {
                //服务器返回初始化的数据,此处进行数据的提取,有可能包含了多个数据
                json = Newtonsoft.Json.Linq.JObject.Parse(result.Content);
                //例如公告数据
                UserClient.Announcement = SoftBasic.GetValueFromJsonObject(json, nameof(UserClient.Announcement), "");
            }
            else
            {
                //访问失败
                if (IsHandleCreated)
                {
                    Invoke(message_show, result.Message);
                }
                if (IsHandleCreated)
                {
                    Invoke(thread_finish);
                }
                return;
            }

            //启动主窗口
            if (IsHandleCreated)
            {
                Invoke(new Action(() =>
                {
                    DialogResult = DialogResult.OK;
                    return;
                }));
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 系统统一的登录模型
        /// </summary>
        /// <param name="message_show">信息提示方法</param>
        /// <param name="start_update">启动更新方法</param>
        /// <param name="thread_finish">线程结束后的复原方法</param>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="remember">是否记住登录密码</param>
        /// <param name="clientType">客户端登录类型</param>
        /// <returns></returns>
        public static bool AccountLoginServer(
            Action <string> message_show,
            Action start_update,
            Action thread_finish,
            string userName,
            string password,
            bool remember,
            string clientType
            )
        {
            message_show.Invoke("正在维护检查...");

            Thread.Sleep(200);

            // 请求指令头数据,该数据需要更具实际情况更改
            OperateResultString result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.维护检查);

            if (result.IsSuccess)
            {
                byte[] temp = Encoding.Unicode.GetBytes(result.Content);
                // 例如返回结果为1说明允许登录,0则说明服务器处于维护中,并将信息显示
                if (result.Content != "1")
                {
                    message_show.Invoke(result.Content.Substring(1));
                    thread_finish.Invoke();
                    return(false);
                }
            }
            else
            {
                // 访问失败
                message_show.Invoke(result.Message);
                thread_finish.Invoke();
                return(false);
            }



            // 检查账户
            message_show.Invoke("正在检查账户...");

            // 延时
            Thread.Sleep(200);

            //=======================================================================================
            //
            //   根据实际情况校验,选择数据库校验或是将用户名密码发至服务器校验
            //   以下展示了服务器校验的方法,如您需要数据库校验,请删除下面并改成SQL访问验证的方式
            //   如果还有其他数据一并传到服务器进行验证的,都在下面进行数据包装

            // 包装数据
            JObject json = new JObject
            {
                { UserAccount.UserNameText, new JValue(userName) },                                    // 用户名
                { UserAccount.PasswordText, new JValue(password) },                                    // 密码
                { UserAccount.LoginWayText, new JValue(clientType) },                                  // 登录方式
                { UserAccount.DeviceUniqueID, new JValue(UserClient.JsonSettings.SystemInfo) },        // 客户端唯一ID
                { UserAccount.FrameworkVersion, new JValue(SoftBasic.FrameworkVersion.ToString()) }    // 客户端框架版本
            };

            result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.账户检查, json.ToString());
            if (result.IsSuccess)
            {
                // 服务器应该返回账户的信息
                UserAccount account = JObject.Parse(result.Content).ToObject <UserAccount>();
                if (!account.LoginEnable)
                {
                    // 不允许登录
                    message_show.Invoke(account.ForbidMessage);
                    thread_finish.Invoke();
                    return(false);
                }
                UserClient.UserAccount = account;
            }
            else
            {
                // 访问失败
                message_show.Invoke(result.Message);
                thread_finish.Invoke();
                return(false);
            }

            // 登录成功,进行保存用户名称和密码
            UserClient.JsonSettings.LoginName = userName;
            UserClient.JsonSettings.Password  = remember ? password : "";
            UserClient.JsonSettings.LoginTime = DateTime.Now;
            UserClient.JsonSettings.SaveToFile();


            // 版本验证
            message_show.Invoke("正在验证版本...");

            // 延时
            Thread.Sleep(200);

            result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.更新检查);
            if (result.IsSuccess)
            {
                // 服务器应该返回服务器的版本号
                SystemVersion sv = new SystemVersion(result.Content);
                // 系统账户跳过低版本检测,该做法存在一定的风险,需要开发者仔细确认安全隐患
                if (UserClient.UserAccount.UserName != "admin")
                {
                    if (UserClient.CurrentVersion != sv)
                    {
                        // 保存新版本信息
                        UserClient.JsonSettings.IsNewVersionRunning = true;
                        UserClient.JsonSettings.SaveToFile();
                        // 和当前系统版本号不一致,启动更新
                        start_update.Invoke();
                        return(false);
                    }
                }
                else
                {
                    // 超级管理员可以使用超前版本进行登录
                    if (UserClient.CurrentVersion < sv)
                    {
                        // 保存新版本信息
                        UserClient.JsonSettings.IsNewVersionRunning = true;
                        UserClient.JsonSettings.SaveToFile();
                        // 和当前系统版本号不一致,启动更新
                        start_update.Invoke();
                        return(false);
                    }
                }
            }
            else
            {
                // 访问失败
                message_show.Invoke(result.Message);
                thread_finish.Invoke();
                return(false);
            }


            //
            // 验证结束后,根据需要是否下载服务器的数据,或是等到进入主窗口下载也可以
            // 如果有参数决定主窗口的显示方式,那么必要在下面向服务器请求数据
            // 以下展示了初始化参数的功能

            message_show.Invoke("正在下载参数...");

            // 延时
            Thread.Sleep(200);


            result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.参数下载);
            if (result.IsSuccess)
            {
                // 服务器返回初始化的数据,此处进行数据的提取,有可能包含了多个数据
                json = JObject.Parse(result.Content);
                // 例如公告数据和分厂数据
                UserClient.Announcement = SoftBasic.GetValueFromJsonObject(json, nameof(UserClient.Announcement), "");
                if (json[nameof(UserClient.SystemFactories)] != null)
                {
                    UserClient.SystemFactories = json[nameof(UserClient.SystemFactories)].ToObject <List <string> >();
                }
            }
            else
            {
                // 访问失败
                message_show.Invoke(result.Message);
                thread_finish.Invoke();
                return(false);
            }

            return(true);
        }
Esempio n. 11
0
        public ActionResult Login(FormCollection fc)
        {
            //请求指令头数据,该数据需要更具实际情况更改
            OperateResult <string> result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.维护检查);

            if (result.IsSuccess)
            {
                //例如返回结果为1说明允许登录,0则说明服务器处于维护中,并将信息显示
                if (result.Content != "1")
                {
                    return(Login(result.Message));
                }
            }
            else
            {
                //访问失败
                return(Login(result.Message));
            }

            //检查账户
            //包装数据
            JObject json = new JObject
            {
                { UserAccount.UserNameText, new JValue(fc["UserName"]) },
                { UserAccount.PasswordText, new JValue(fc["UserPassword"]) },
                { UserAccount.LoginWayText, new JValue("webApp") },
                { UserAccount.DeviceUniqueID, new JValue(UserClient.JsonSettings.SystemInfo) },        // 客户端唯一ID
                { UserAccount.FrameworkVersion, new JValue(SoftBasic.FrameworkVersion.ToString()) }    // 客户端框架版本
            };

            result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.账户检查, json.ToString());
            if (result.IsSuccess)
            {
                //服务器应该返回账户的信息
                UserAccount account = JObject.Parse(result.Content).ToObject <UserAccount>();
                if (!account.LoginEnable)
                {
                    //不允许登录
                    return(Login(account.ForbidMessage));
                }
                Session[SessionItemsDescription.UserAccount] = account;
                //UserClient.UserAccount = account;
            }
            else
            {
                //访问失败
                return(Login(result.Message));
            }


            result = UserClient.Net_simplify_client.ReadFromServer(CommonLibrary.CommonHeadCode.SimplifyHeadCode.更新检查);
            if (result.IsSuccess)
            {
                //服务器应该返回服务器的版本号
                SystemVersion sv = new SystemVersion(result.Content);
                //系统账户跳过低版本检测
                if (fc["UserName"] != "admin")
                {
                    if (UserClient.CurrentVersion != sv)
                    {
                        return(Login("当前版本号不正确,需要联系管理员更新服务器才允许登录。"));
                    }
                }
                else
                {
                    if (UserClient.CurrentVersion < sv)
                    {
                        return(Login("版本号过时,需要联系管理员更新服务器才允许登录。"));
                    }
                }
            }
            else
            {
                //访问失败
                return(Login(result.Message));
            }


            result = UserClient.Net_simplify_client.ReadFromServer(CommonHeadCode.SimplifyHeadCode.参数下载);
            if (result.IsSuccess)
            {
                //服务器返回初始化的数据,此处进行数据的提取,有可能包含了多个数据
                json = JObject.Parse(result.Content);
                //例如公告数据
                UserClient.Announcement = SoftBasic.GetValueFromJsonObject(json, nameof(UserClient.Announcement), "");
            }
            else
            {
                //访问失败
                //访问失败
                return(Login(result.Message));
            }

            //允许登录,并记录到Session
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 12
0
        /// <summary>
        /// 接收到来自客户端的数据,此处需要放置维护验证,更新验证等等操作
        /// </summary>
        /// <param name="object1">客户端的地址</param>
        /// <param name="object2">消息数据,应该使用指令头+数据组成</param>
        private void Net_simplify_server_ReceiveStringEvent(HuStateOne object1, string object2)
        {
            //如果此处充斥大量if语句,影响观感,则考虑进行指令头分类操作
            //必须返回结果,调用SendMessage(object1,[实际数据]);
            string head_code = object2.Substring(0, 4);

            if (head_code == CommonHeadCode.SimplifyHeadCode.维护检查)
            {
                net_simplify_server.SendMessage(object1, UserServer.ServerSettings.Can_Account_Login ? "1" : "0" +
                                                UserServer.ServerSettings.Account_Forbidden_Reason);
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.更新检查)
            {
                net_simplify_server.SendMessage(object1, UserServer.ServerSettings.SystemVersion.ToString());
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.参数下载)
            {
                Newtonsoft.Json.Linq.JObject json = new Newtonsoft.Json.Linq.JObject();
                json.Add(nameof(UserServer.ServerSettings.Announcement), new Newtonsoft.Json.Linq.JValue(UserServer.ServerSettings.Announcement));
                net_simplify_server.SendMessage(object1, json.ToString());
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.账户检查)
            {
                //此处使用的是组件自带的验证的方式,如果使用SQL数据库,另行验证
                Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(object2.Substring(4));
                //提取账户,密码
                string name     = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
                string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, "");
                net_simplify_server.SendMessage(object1, UserServer.ServerAccounts.CheckAccountJson(
                                                    name, password, ((System.Net.IPEndPoint)(object1._WorkSocket.RemoteEndPoint)).Address.ToString()));
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.更新公告)
            {
                UserServer.ServerSettings.Announcement = object2.Substring(4);
                //通知所有客户端更新公告
                net_socket_server.SendAllClients(object2);
                net_simplify_server.SendMessage(object1, "成功");
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.获取账户信息)
            {
                //返回服务器的账户信息
                net_simplify_server.SendMessage(object1, UserServer.ServerAccounts.GetAllAccountsJson());
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.更细账户信息)
            {
                //更新服务器的账户信息
                UserServer.ServerAccounts.LoadAllAccountsJson(object2.Substring(4));
                net_simplify_server.SendMessage(object1, "成功");
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.密码修改)
            {
                //更新服务器的账户密码
                //此处使用的是组件自带的验证的方式,如果使用SQL数据库,另行验证
                Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(object2.Substring(4));
                //提取账户,密码
                string name     = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
                string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, "");
                UserServer.ServerAccounts.UpdatePassword(name, password);
                net_simplify_server.SendMessage(object1, "成功");
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.网络日志查看)
            {
                net_simplify_server.SendMessage(object1, net_socket_server.LogReacord.GetLogText());
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.网络日志清空)
            {
                net_socket_server.LogReacord.ClearLogText();
                net_simplify_server.SendMessage(object1, "成功");
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.步日志查看)
            {
                net_simplify_server.SendMessage(object1, net_simplify_server.log_record.GetLogText());
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.步日志清空)
            {
                net_simplify_server.log_record.ClearLogText();
                net_simplify_server.SendMessage(object1, "成功");
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.更新日志查看)
            {
                net_simplify_server.SendMessage(object1, net_soft_update_Server.log_record.GetLogText());
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.更新日志清空)
            {
                net_soft_update_Server.log_record.ClearLogText();
                net_simplify_server.SendMessage(object1, "成功");
            }
            else if (head_code == CommonHeadCode.SimplifyHeadCode.注册账号)
            {
                bool result = UserServer.ServerAccounts.AddNewAccount(object2.Substring(4));
                net_simplify_server.SendMessage(object1, result ? "1" : "0");
            }
            else
            {
                net_simplify_server.SendMessage(object1, object2);
            }
        }
Esempio n. 13
0
 /****************************************************************************************************
 *
 *
 *    数据处理中心,同步信息中的所有的细节处理均要到此处来处理
 *
 *
 ****************************************************************************************************/
 /// <summary>
 /// A指令块,处理系统基础运行的消息
 /// </summary>
 /// <param name="state">网络状态对象</param>
 /// <param name="customer">用户自定义的指令头</param>
 /// <param name="data">实际的数据</param>
 private void DataProcessingWithStartA(AsyncStateOne state, int customer, string data)
 {
     if (customer == CommonHeadCode.SimplifyHeadCode.维护检查)
     {
         net_simplify_server.SendMessage(state, customer, "1");
         //UserServer.ServerSettings.Can_Account_Login ? "1" : "0" +
         //UserServer.ServerSettings.Account_Forbidden_Reason);
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.更新检查)
     {
         net_simplify_server.SendMessage(state, customer, UserServer.ServerSettings.SystemVersion.ToString());
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.参数下载)
     {
         JObject json = new JObject
         {
             { nameof(UserServer.ServerSettings.Announcement), new JValue(UserServer.ServerSettings.Announcement) }
         };
         net_simplify_server.SendMessage(state, customer, json.ToString());
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.账户检查)
     {
         //此处使用的是组件自带的验证的方式,如果使用SQL数据库,另行验证
         JObject json = JObject.Parse(data);
         //提取账户,密码
         string name     = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
         string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, "");
         net_simplify_server.SendMessage(state, customer, UserServer.ServerAccounts.CheckAccountJson(
                                             name, password, state.GetRemoteEndPoint().Address.ToString()));
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.更新公告)
     {
         UserServer.ServerSettings.Announcement = data;
         //通知所有客户端更新公告
         net_socket_server.SendAllClients(customer, data);
         net_simplify_server.SendMessage(state, customer, "成功");
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.获取账户)
     {
         //返回服务器的账户信息
         net_simplify_server.SendMessage(state, customer, UserServer.ServerAccounts.GetAllAccountsJson());
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.更细账户)
     {
         //更新服务器的账户信息
         UserServer.ServerAccounts.LoadAllAccountsJson(data);
         net_simplify_server.SendMessage(state, customer, "成功");
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.密码修改)
     {
         //更新服务器的账户密码,此处使用的是组件自带的验证的方式,如果使用SQL数据库,另行验证
         JObject json = JObject.Parse(data);
         //提取账户,密码
         string name     = SoftBasic.GetValueFromJsonObject(json, UserAccount.UserNameText, "");
         string password = SoftBasic.GetValueFromJsonObject(json, UserAccount.PasswordText, "");
         UserServer.ServerAccounts.UpdatePassword(name, password);
         net_simplify_server.SendMessage(state, customer, "成功");
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.更新版本)
     {
         try
         {
             UserServer.ServerSettings.SystemVersion = new SystemVersion(data);
             UserServer.ServerSettings.SaveToFile();
             toolStripStatusLabel_version.Text = UserServer.ServerSettings.SystemVersion.ToString();
             //记录数据
             RuntimeLogHelper.SaveInformation($"更改了版本号:{data}");
             net_simplify_server.SendMessage(state, customer, "1");
         }
         catch
         {
             net_simplify_server.SendMessage(state, customer, "0");
         }
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.注册账号)
     {
         bool result = UserServer.ServerAccounts.AddNewAccount(data);
         net_simplify_server.SendMessage(state, customer, result ? "1" : "0");
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.请求文件)
     {
         net_simplify_server.SendMessage(state, customer, net_simple_file_server.ToJsonString());
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.意见反馈)
     {
         AdviceLogHelper.SaveInformation(data);
         net_simplify_server.SendMessage(state, customer, "成功");
     }
     else if (customer == CommonHeadCode.SimplifyHeadCode.群发消息)
     {
         net_socket_server.SendAllClients(CommonHeadCode.MultiNetHeadCode.弹窗新消息, data);
         net_simplify_server.SendMessage(state, customer, "成功");
     }
     else
     {
         net_simplify_server.SendMessage(state, customer, data);
     }
 }