Beispiel #1
0
        private void ConnectRemoteServers()
        {
            string s = SystemFile.ServerConfigFile;
            XmlDocument CfgXml = new XmlDocument();
            if (File.Exists(s))
            {
                CfgXml.Load(s);
                XmlNode aNode = CfgXml.DocumentElement.FirstChild;
                while (aNode != null)
                {
                    var serverType = aNode.LocalName;
                    if (string.Compare(serverType, "remoteserver", true) == 0)//IgnoreCase
                    {
                        bool active = aNode.Attributes["Active"] == null ? false : bool.Parse(aNode.Attributes["Active"].Value);
                        string ipAddress = aNode.Attributes["IpAddress"].InnerText;
                        try
                        {
                            string ip = aNode.Attributes["IpAddress"].Value;
                            int port = (aNode.Attributes["Port"] != null && aNode.Attributes["Port"].Value.Length > 0)
                                ? int.Parse(aNode.Attributes["Port"].Value) : 8989;
                            var rs = new RemoteServer(0, ip, port, active);
                            frmProgress frm = new frmProgress(rs.IpAddress, rs.Port, string.Format("Connect to {0}", rs));
                            frm.StartPosition = FormStartPosition.CenterScreen;
                            if (frm.ShowDialog() == DialogResult.OK)
                            {
                                Srvtools.LoginService service = frm.Module;
                                if (service != null)
                                {
                                    try
                                    {
                                        ServerConfig.RegisterRemoteServer(rs.IpAddress, rs.Port);
                                    }
                                    catch (Exception e)
                                    {
                                        //MessageBox.Show(e.Message);
                                        rs.Activated = false;
                                        ServerConfig.DeRegisterRemoteServer(rs.IpAddress, rs.Port);
                                    }
                                }
                                else
                                {
                                    rs.Activated = false;
                                    ServerConfig.DeRegisterRemoteServer(rs.IpAddress, rs.Port);
                                }
                            }
                        }
                        catch
                        {

                        }
                    }
                    aNode = aNode.NextSibling;
                }
            }
        }
Beispiel #2
0
        private static void LoadServerConfig()
        {
            string s = SystemFile.ServerConfigFile;
            XmlDocument CfgXml = new XmlDocument();
            if (File.Exists(s))
            {
                CfgXml.Load(s);
                XmlNode aNode = CfgXml.DocumentElement.FirstChild;
                while (aNode != null)
                {
                    string serverType = aNode.LocalName;
                    if (string.Compare(serverType, "ssotimeout", true) == 0)//IgnoreCase
                    {
                        SSOTimeOut = int.Parse(aNode.Attributes["Value"].InnerText);
                    }

                    if (string.Compare(serverType, "ssokey", true) == 0)//IgnoreCase
                    {
                        SSOKey = aNode.Attributes["Value"].InnerText;
                    }

                    if (string.Compare(serverType, "recordlockindatabase", true) == 0)//IgnoreCase
                    {
                        RecordLockInDatabase = string.Compare(aNode.Attributes["Value"].InnerText, bool.TrueString, true) == 0;
                    }

                    if (string.Compare(serverType, "localserver", true) == 0)//IgnoreCase
                    {
                        MaxUser = int.Parse(aNode.Attributes["MaxUser"].InnerText);
                        if (string.Compare(aNode.Attributes["IsMaster"].InnerText, "true", true) == 0)//IgnoreCase
                        {
                            IsMaster = true;
                        }
                        else
                        {
                            IsMaster = false;
                        }
                        MasterServerIP = aNode.Attributes["MasterServerIP"].InnerText;
                        if (aNode.Attributes["MasterServerKey"] != null)
                        {
                            MasterServerKey = aNode.Attributes["MasterServerKey"].InnerText;
                        }

                        SrvGL.MasterServerAddress = MasterServerIP;
                        SrvGL.ServerKey = MasterServerKey;
                    }
                    else if (string.Compare(serverType, "remoteserver", true) == 0)//IgnoreCase
                    {
                        string ipAddress = aNode.Attributes["IpAddress"].InnerText;
                        int port = 8989;
                        if (aNode.Attributes["Port"] != null && aNode.Attributes["Port"].InnerText != "")
                        {
                            port = int.Parse(aNode.Attributes["Port"].InnerText);
                        }
                        RemoteServer rs = new RemoteServer(0, ipAddress, port, false);

                        RemoteServers.Add(rs);
                    }

                    aNode = aNode.NextSibling;
                }
            }
        }