Пример #1
0
        public void ConnectServer(NetClient client)
        {
            if (NetClientManager.ExistClient(client.ClientKey))
            {
                DisconnectServer(client.ClientKey);
            }
            NetClientManager.AddClient(client);

            LogHelper help = TableHelper.GetLogHelper(client.ClientKey);
            help.LogMessage(client.ClientKey, "Connect " + client.Database, LogType.NetWork);
        }
Пример #2
0
        public static void AddClient(NetClient clinet)
        {
            lock (mThreadLock)
            {
                if (mNetClients.ContainsKey(clinet.ClientKey))
                {
                    DeleteClient(clinet.ClientKey);
                }

                clinet.LastActiveTime = DateTime.Now;
                mNetClients[clinet.ClientKey] = clinet;
            }
        }
Пример #3
0
 /// <summary>
 /// 初始化远程对象
 /// </summary>
 /// <param name="config">Remoting配置文件</param>
 public static void InitServerProxy(string config, string dbname)
 {
     mDBName = dbname;
     mNetClient = GetClientInfo(config);
     mNetClient.Database = dbname;
     RemotingConfiguration.Configure(config, false);
     string remotingUrl = ConfigurationManager.AppSettings["RemotingSystem"];
     mRemotingSystem = (IRemotingSystem)Activator.GetObject(typeof(IRemotingSystem), remotingUrl);
     mRemotingSystem.ConnectServer(mNetClient);
     BroadcastSystem broadcastSystem = GetBroadcastSystem();
     broadcastSystem.AddConnectEventHandler(OnConnect);
     TableHelper.EnableRemoting(true);
     IsInit = true;
 }
Пример #4
0
 private static void CheckActive(DateTime time)
 {
     long time1 = time.Ticks;
     NetClient[] clients = new NetClient[mNetClients.Count];
     int index = 0;
     foreach (NetClient client in mNetClients.Values)
     {
         clients[index] = client;
         index++;
     }
     foreach (NetClient client in clients)
     {
         long time2 = client.LastActiveTime.Ticks;
         if (time1 - time2 > 10 * 4)
         {
             RemotingInterface.RemotingSystem.Instance.DisconnectServer(client.ClientKey);
         }
     }
 }
Пример #5
0
        private static NetClient GetClientInfo(string config)
        {
            string host = Dns.GetHostName();
            IPAddress[] ips = Dns.GetHostAddresses(host);
            string ip = ips[0].ToString();
            for (int i = 0; i < ips.Length; ++i)
            {
                if (ips[i].AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
                {
                    ip = ips[i].ToString();
                    break;
                }
            }

            string port = ConfigurationManager.AppSettings["port"];
            string tool = ConfigurationManager.AppSettings["tool"];
            NetClient client = new NetClient(ip, Convert.ToInt32(port), tool);
            client.HostName = host;
            return client;
        }
Пример #6
0
        private void LogToFile(string clientkey, string message, string time, LogType type)
        {
            lock (mFileLock)
            {
                string hostname = "Server";
                NetClient client = null;
                if (clientkey != null)
                {
                    client = NetClientManager.GetNetClient(clientkey);
                    if (client != null)
                    {
                        hostname = client.HostName;
                    }
                    else
                    {
                        hostname = clientkey;
                    }
                }
                else
                {
                    client = new NetClient(null, 0, null);
                    client.Database = "server";
                }

                string format = string.Format("{0, -12} {1} {2} {3}", type.ToString()+":", time, hostname, message);
                string filename = DateTime.Now.ToLongDateString();
                string filepath = string.Format(".//logs//{0}", client.Database.ToUpper());
                if (filename != mFileName || mFileStream == null || mFileWriter == null)
                {
                    CloseFile();
                    System.IO.Directory.CreateDirectory(filepath);
                    filepath = string.Format("{0}//{1}.txt", filepath, filename);
                    mFileName = filename;
                    mFileStream = new FileStream(filepath, FileMode.Append, FileAccess.Write);
                    mFileWriter = new StreamWriter(mFileStream);
                }
                mFileWriter.WriteLine(format);
                mLineCount++;
                if (mLineCount > mLineLimit)
                {
                    CloseFile();
                }
            }
        }
Пример #7
0
 public static void CheckConnect()
 {
     NetClient client = new NetClient("Server", 9898, "Server");
     client.HostName = "server";
     BroadcastSystem.BroadcastConnectEvent(client,
        new ConnectEventArgs(true, client.HostName));
 }