Example #1
0
        static void Main(string[] args)
        {
            //get confFile
            try
            {
                ReadConf rc = new ReadConf(DefaultConf.confPath);
                ClientInfo.confMap = rc.read();
            }
            catch (Exception)
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainWindow());

            /*TcpClient client = new TcpClient();
            client.Connect(IPAddress.Parse("127.0.0.1"), 33258);
            Protocol pro = new Protocol();
            pro.protoType = ProtoType.LOGIN;
            pro.param = new List<string>();
            pro.param.Add("Admin");
            pro.param.Add("liu355dq");
            NetworkStream ns = client.GetStream();
            IFormatter formatter = new BinaryFormatter();
            formatter.Serialize(ns, pro);
            Protocol returnPro = (Protocol)formatter.Deserialize(ns);
            Console.WriteLine(returnPro.data[0][0]);
            Console.WriteLine(returnPro.data[0][1]);
            Console.WriteLine("successful return");
            client.Close();*/
        }
Example #2
0
        static void Main()
        {
            //get confFile
            try
            {
                ReadConf rc = new ReadConf(DefaultConf.confPath);
                ClientInfo.confMap = rc.read();
            }
            catch (Exception)
            {
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new LoginForm());
        }
Example #3
0
        static void Main(string[] args)
        {
            ServerEntry entry = new ServerEntry();
            ServerEntry.GlobalInfo = new ServerInfo();
            //Step1;
            //首先呢,初始化conf文件,从中读取配置文件,进行相应功能的初始化
            //如果,此时,读取conf失败,就只能推出程序了
            try
            {
                ReadConf rc = new ReadConf(DefaultConf.confPath);
                ServerEntry.GlobalInfo.confMap = rc.read();
            }
            catch (Exception ex)
            {
                /*
                 *很可惜了,读取配置文件失败,退出程序
                 * */
                Console.WriteLine("Error:fail to get ./conf/DstConf.conf");
                return;
            }
            //Step2:
            //然后呢,初始化Log文件,即可以设置Log文件的大小
            //如果读取失败,则设定默认大小
            try
            {
                Log.open(ServerEntry.GlobalInfo.confMap.value(strConfKey.LogPath.ToString()));
                try{
                    Log.maxConfFile = int.Parse(ServerEntry.GlobalInfo.confMap.value(strConfKey.LogMaxPath.ToString())) * 1024 * 1024 * 8;
                }catch(Exception ex)
                {
                    Log.maxConfFile=int.Parse(DefaultConf.defaultLogMaxSize)*1024*1024*8;
                }
                try
                {
                    Log.isStdOut = bool.Parse(ServerEntry.GlobalInfo.confMap.value(strConfKey.LogStdOut.ToString()));
                }
                catch (Exception ex)
                {
                    Log.isStdOut = bool.Parse(DefaultConf.defaultLogStdOut.ToString()); //not to do just use the default value;
                }
            }
            catch (Exception ex)
            {
                try
                {
                    Log.open(DefaultConf.defaultLogPath);
                    Log.maxConfFile = int.Parse(DefaultConf.defaultLogMaxSize) * 1024 * 1024 * 8;
                }
                catch (Exception ex2)
                {
                    //如果仍然木有办法打开,只能返回了
                    Console.WriteLine("Error:fail to open log file!An inner error occur");
                    return;
                }
            }
            //Step3
            //获取数据库相关信息,以供数据库链接使用
            //数据库服务器的信息,存储在xml中
            Log.WriteLog(LogLevel.MSG,"Get the db info");
            try{
                Fetch_DbInfo_From_XML dbFetch = new Fetch_DbInfo_From_XML(ServerEntry.GlobalInfo.confMap.value(strConfKey.SqlInfoPath));
                ServerEntry.GlobalInfo.dbInfo = dbFetch.getDBInfoByDBName();
            }catch(Exception ex)
            {
                Log.WriteLog(LogLevel.ERR,"Fail to open the db_info_xml file");
                return;
            }

            //Step4
            //生成计时器线程
            //完成主要的监控动作
            Log.WriteLog(LogLevel.MSG,"Start the timer");
            try
            {
                //初始化Session
                 ServerEntry.GlobalInfo.session = new Session();
                //20秒更新一次

                entry.startTimer(20*1000);
                int maxCount = int.Parse(ServerEntry.GlobalInfo.confMap.value(strConfKey.TimeOut)) * 60 / 20;
                ServerEntry.GlobalInfo.session.MaxTime = maxCount;
            }
            catch (Exception ex)
            {
                Log.WriteLog(LogLevel.WARN,"Fail to fetch out of time in config file.Use default");
                entry.startTimer(int.Parse(DefaultConf.defaultTimeOut));
            }

            //Step7
            //初始化网络线程池并,开启网络监听
            int port;
            try
            {
                port = int.Parse(ServerEntry.GlobalInfo.confMap.value(strConfKey.ServerPort.ToString()));
            }catch(Exception ex)
            {
                Log.WriteLog(LogLevel.WARN,"Fail to fetch the server port.Use Default");
                port = int.Parse(DefaultConf.defaultServerPort);
            }
            entry.init(IPAddress.Any,port);
            Thread mainServerThread = new Thread(new ParameterizedThreadStart(ServerStart));
            mainServerThread.Start(entry);

            //循环,等待事件发生
            while (true)
            {
               String cmd=Console.ReadLine();
               if (cmd.Equals("quit"))
               {
                   entry.exit();
                   break;
               }
            }

            return;
        }