示例#1
0
        //public static Boolean IsSim()
        //{
        //    if (currentServerSet == null) return true;
        //    return currentServerSet == simServerSet;
        //}

        //public static void SetToSim()
        //{
        //    currentServerSet = simServerSet;
        //    SetSimOrRealServer(true);
        //}

        //public static void SetToReal()
        //{
        //    currentServerSet = realServerSet;
        //    SetSimOrRealServer(false);

        //}

        public static bool LoadXml()
        {
            if (Directory.Exists(CommonUtil.GetSettingPath() + "setting") == false)
            {
                Directory.CreateDirectory(CommonUtil.GetSettingPath() + "setting");
            }
            //从Setting目录中读取服务器列表文件
            string settingFile = CommonUtil.GetSettingPath() + "setting/ServerSettings.xml";

            if (File.Exists(settingFile) == false)
            {
                return(false);
            }
            //读取XML文件
            ServerSettingDoc.Load(settingFile);
            XmlNode node = ServerSettingDoc.SelectSingleNode("config");

            if (node == null)
            {
                return(false);
            }

            //simServerSet.Clear();
            _RealServerSet.Clear();


            ServerSettings tempServerSet = null;

            foreach (XmlNode node2 in node.ChildNodes)
            {
                if (node2.Name.ToLower() != "servers")
                {
                    continue;
                }

                tempServerSet    = _RealServerSet;
                CurrentServerSet = tempServerSet;

                foreach (XmlNode serverNode in node2.ChildNodes)
                {
                    if (serverNode.Name.ToLower() != "server")
                    {
                        continue;
                    }
                    foreach (XmlNode temp2 in serverNode.ChildNodes)
                    {
                        if (temp2.Attributes["name"] == null || temp2.Attributes["ip"] == null ||
                            temp2.Attributes["port"] == null || temp2.Attributes["selected"] == null)
                        {
                            Util.Log("LoadXml 格式错误:" + temp2.OuterXml);
                            continue;
                        }
                        ServerData sdata
                            = new ServerData(temp2.Attributes["name"].InnerText, temp2.Attributes["brokerID"].InnerText, temp2.Attributes["ip"].InnerText, temp2.Attributes["port"].InnerText, temp2.Attributes["selected"].InnerText);
                        if (serverNode.Attributes["type"].InnerText == "JY")
                        {
                            tempServerSet.JYserver.Add(sdata);
                            if (sdata.ServerSelected)
                            {
                                ServerData JYSstruct = new ServerData(sdata.ServerName, sdata.BrokerID, sdata.ServerIPadd, sdata.ServerPort);
                                tempServerSet.JYServerDetails = JYSstruct;
                            }
                        }
                        else if (serverNode.Attributes["type"].InnerText == "HQ")
                        {
                            tempServerSet.HQserver.Add(sdata);
                            if (sdata.ServerSelected)
                            {
                                ServerData HQSstruct = new ServerData(sdata.ServerName, sdata.BrokerID, sdata.ServerIPadd, sdata.ServerPort);
                                tempServerSet.HQServerDetails = HQSstruct;
                            }
                        }
                    }
                }
            }

            //if (tempServerSet!=null && (tempServerSet.JYServerDetails == null || tempServerSet.HQServerDetails == null))
            //{
            //    //给交易服务器测速
            //    SpeedTest(true);
            //}

            //LoadHQInfo();

            return(true);
        }
示例#2
0
        public static bool Update_Selected(SERVER_TYPE serverType, string sname, bool selected, bool isClearAll = false)
        {
            if (serverType == SERVER_TYPE.JY)
            {
                if (isClearAll == true)
                {
                    foreach (ServerData serverData in CurrentServerSet.JYserver)
                    {
                        serverData.ServerSelected = !selected;
                    }
                }
                foreach (ServerData serverData in CurrentServerSet.JYserver)
                {
                    if (serverData.ServerName.Equals(sname))
                    {
                        serverData.ServerSelected = selected;
                        if (selected)
                        {
                            ServerData JYSstruct = new ServerData(serverData.ServerName, serverData.BrokerID, serverData.ServerIPadd, serverData.ServerPort);
                            CurrentServerSet.JYServerDetails = JYSstruct;
                        }
                        XmlNode serverNode = GetServerNodeByAttribute(ServerSettingDoc, true);
                        if (serverNode == null)
                        {
                            continue;
                        }

                        foreach (XmlNode hostNode in serverNode.ChildNodes)
                        {
                            if (hostNode.Attributes["name"].Value.ToString() == sname)
                            {
                                //Util.Log("Change JY Selected Server:" + hostNode.Attributes["name"].Value + " selected=" + selected+" sname="+sname);
                                hostNode.Attributes["selected"].Value = selected.ToString();
                            }
                            else if (selected == true)
                            {
                                hostNode.Attributes["selected"].Value = (!selected).ToString();
                            }
                        }
                        //if (selected == true)
                        //{
                        //    SetConnectServerForFile();
                        //}
                        return(true);
                    }
                }
            }
            else if (serverType == SERVER_TYPE.HQ)
            {
                if (isClearAll == true)
                {
                    foreach (ServerData serverData in CurrentServerSet.HQserver)
                    {
                        serverData.ServerSelected = !selected;
                    }
                }

                foreach (ServerData serverData in CurrentServerSet.HQserver)
                {
                    if (serverData.ServerName.Equals(sname))
                    {
                        serverData.ServerSelected = selected;
                        if (selected)
                        {
                            ServerData HQSstruct = new ServerData(serverData.ServerName, serverData.BrokerID, serverData.ServerIPadd, serverData.ServerPort);
                            CurrentServerSet.HQServerDetails = HQSstruct;
                        }
                        XmlNode serverNode = GetServerNodeByAttribute(ServerSettingDoc, false);
                        if (serverNode == null)
                        {
                            continue;
                        }


                        foreach (XmlNode hostNode in serverNode.ChildNodes)
                        {
                            if (hostNode.Attributes["name"].Value.ToString() == sname)
                            {
                                //Util.Log("Change HQ Selected Server:" + hostNode.Attributes["name"].Value + " selected=" + selected + " sname=" + sname);
                                hostNode.Attributes["selected"].Value = selected.ToString();
                            }
                            else if (selected == true)
                            {
                                hostNode.Attributes["selected"].Value = (!selected).ToString();
                            }
                        }
                        //if (selected == true)
                        //{
                        //    SetConnectServerForFile();
                        //}
                        return(true);
                    }
                }
            }
            return(false);
        }