The safe console class simple encapsulation.
示例#1
0
    private void _BaseMethodsTest()
    {
        Console.WriteLine("BaseMethods test:");

        using (Service svc = new Service("BaseMethodsTest"))
        {
            Console.WriteLine("DriveMode: {0}", svc.driveMode);
            Console.WriteLine("FPS: {0}", svc.fps);
            Console.WriteLine("frameInterval: {0}", svc.frameInterval);
            Console.WriteLine("isStarted: {0}", svc.isStarted);
            Console.WriteLine("svc type: {0}", svc.svcType);

            svc.fps = 1;
            Console.WriteLine("After set fps to 1, FPS: {0}, frameInterval: {1}", svc.fps, svc.frameInterval);

            try
            {
                svc.fps = LibConfig.commMaxServiceFPS + 10;
            }
            catch (Exception e)
            {
                Console.WriteLine("After set fps to {0}, exception occurred, right!", LibConfig.commMaxServiceFPS + 10);
                Console.WriteLine("exception:\n{0}", e);
            }
        }

        Console.WriteLine("Press any key to finish BaseMethods test...");
        Console.ReadKey();
    }
示例#2
0
    public void Run(string[] args)
    {
        Console.WriteLine("Core/Config/Ini test:");

        using (var ini = new Ini())
        {
            string file = "test_ini.ini";
            Console.WriteLine("Load config file: {0}", file);
            ini.LoadFromFile(file);

            var helloSection = ini["Hello"];
            Console.WriteLine("Hello section get: {0}", helloSection.sectionName);

            var unknownSection = ini.GetSection("sdfsafafas");
            Console.WriteLine("Get not exist section, return: {0}", unknownSection);

            Console.WriteLine("[Hello] Cfg1 = {0}", ini.GetValue <int>("Hello", "Cfg1"));
            Console.WriteLine("[Hello] Cfg2 = {0}", ini.GetValue <string>("Hello", "Cfg2"));
            Console.WriteLine("[Hello] Cfg3 = {0}", ini.GetValue <string>("Hello", "Cfg3"));
            Console.WriteLine("[Hello] Cfg4 = {0}", ini.GetValue <bool>("Hello", "Cfg4"));

            Console.WriteLine("[World] Cfg1 = {0}", ini.GetValue <int>("World", "Cfg1"));
            Console.WriteLine("[World] Cfg2 = {0}", ini.GetValue <string>("World", "Cfg2"));
            Console.WriteLine("[World] Cfg3 = {0}", ini.GetValue <string>("World", "Cfg3"));
            Console.WriteLine("[World] Cfg4 = {0}", ini.GetValue <bool>("World", "Cfg4"));
        }

        Console.WriteLine("Press any key to exit...");
        Console.ReadKey();
    }
示例#3
0
        public override void OnIdle(int idleTime)
        {
            if (_idleOutputTimes == 5)
            {
                return;
            }

            Console.WriteLine("Service [{0}] idle, idleTime: {1}", svc.svcName, idleTime);
            _idleOutputTimes += 1;
        }
示例#4
0
        public override void OnUpdate()
        {
            if (_updateOutputTimes == 5)
            {
                return;
            }

            Console.WriteLine("Service [{0}] update", svc.svcName);
            _updateOutputTimes += 1;
        }
示例#5
0
    public void Run(string[] args)
    {
        Console.WriteLine("Timer test:");

        using (Service svc = new Service("TimerTestSvc"))
        {
            svc.Start();

            Console.WriteLine("Press any key to pause TimerTest...");
            Console.ReadKey();
        }
    }
示例#6
0
    public void Run(string[] args)
    {
        Console.WriteLine("Comm/Service test:");

        // _BaseMethodsTest();
        _StartStopTest();
        // _ListenTest();
        // _ConnectTest();
        // _SendRecvTest();
        // _PreHandleTest();
        // _PacketExcTest();
        // _FrameExcTest();
        // _ExternalDriveTest();

        Console.WriteLine("Press any key to exit...");
        Console.ReadKey();
    }
    public void Run(string[] args)
    {
        Console.WriteLine("Core/Log/Logger test:");

        string logCfg = "Logger_Cfg.cfg";

        LoggerMgr.Init(logCfg);

        // Test Root logger.
        Log.enabledLogFileInfo = true;
        Log.Dbg("A debug message from Log.Dbg()...");
        Log.Info("A info message from Log.Info()...");
        Log.Warn("A warn message from Log.Warn()...");
        Log.Err("A error message from Log.Err()...");
        Log.Fatal("A fatal message from Log.Fatal()...");

        Log.Dbg <Log>("A debug message from Log.Dbg<Log>()...");
        Log.Info <Log>("A debug message from Log.Dbg<Log>()...");
        Log.Warn <Log>("A debug message from Log.Dbg<Log>()...");
        Log.Err <Log>("A debug message from Log.Dbg<Log>()...");
        Log.Fatal <Log>("A debug message from Log.Dbg<Log>()...");

        // Get test logger to test.
        var testLogger = LoggerMgr.Get("test");

        testLogger.Dbg("A debug message from testLogger.Dbg()...");
        testLogger.Info("A info message from testLogger.Info()...");
        testLogger.Warn("A warn message from testLogger.Warn()...");
        testLogger.Err("A error message from testLogger.Err()...");
        testLogger.Fatal("A fatal message from testLogger.Fatal()...");

        Console.WriteLine("Press any key to exit test...");
        Console.ReadKey();

        LoggerMgr.Destroy();
    }
示例#8
0
    private void _StartStopTest()
    {
        Console.WriteLine("Start/Stop service test:");

        using (Service svc = new Service("StartStopTest"))
        {
            svc.Start();
            Console.WriteLine("Start service, wait 2 seconds...");
            Thread.Sleep(2000);

            Console.WriteLine("Stop service...");
            svc.Stop();

            Console.WriteLine("ReStart service...");
            svc.Start(2);
            Thread.Sleep(5000);

            Console.WriteLine("Stop service...");
            svc.Stop();
        }

        Console.WriteLine("Press any key to finish Start/Stop service test...");
        Console.ReadKey();
    }
示例#9
0
 public override void OnInit()
 {
     Console.WriteLine("Service {0} init(By Facade)", svc.svcName);
     throw new Exception("Test Exception throw by OnInit!!!");
 }
示例#10
0
 public override void OnAsyncConnResult(AsyncConnResult asyncConnResult)
 {
     Console.WriteLine("Async-Connect result: {0}", asyncConnResult);
 }
示例#11
0
 public bool OnUnifyPrePacket(Packet packet)
 {
     Console.WriteLine("OnUnifyPrePacket: {0}", packet);
     return(true);
 }
示例#12
0
 public override void OnDestroy()
 {
     Console.WriteLine("Service[{0}] destroy", svc);
 }
示例#13
0
 public override void OnDestroy()
 {
     Console.WriteLine("Service {0} destroy(By Facade2)", svc.svcName);
 }
示例#14
0
 public void OnHandle(Packet packet)
 {
     Console.WriteLine("OnHandle, packet: {0}", packet);
 }
示例#15
0
 public bool OnPreHandle(Packet packet)
 {
     Console.WriteLine("OnPreHandle, packet: {0}", packet);
     return(true);
 }
示例#16
0
 public void OnBroadcastPacket(Packet packet)
 {
     Console.WriteLine("Recv broadcast packet: {0}", packet);
 }
示例#17
0
 public void OnMulticastPacket(Packet packet)
 {
     Console.WriteLine("Recv multicast-packet: {0}", packet);
 }
示例#18
0
 public override void OnUnHandledPacket(Packet packet)
 {
     Console.WriteLine("UnHandled packet: {0}", packet);
 }
示例#19
0
 public override void OnProtoReport(ProtoReport report)
 {
     Console.WriteLine("Proto report: {0}", report);
 }
示例#20
0
 public void OnFrameExc(Service svc, Exception e)
 {
     Console.WriteErrorLine("Service {0} exception raised, exception: {1}", svc.svcName, e);
 }
示例#21
0
 public override void OnInit()
 {
     Console.WriteLine("Service {0} init(By Facade2)", svc.svcName);
 }
示例#22
0
 public override void OnSessionDestroy(SessionDestroyInfo destroyInfo)
 {
     Console.WriteLine("Session destroy: {0}", destroyInfo);
 }
示例#23
0
 public override void OnInit()
 {
     Console.Write("Service[{0}] init", svc);
 }
示例#24
0
 private void _OnTimeout(Timer timer)
 {
     Console.WriteLine("Timeout handler called!");
 }
示例#25
0
 private void OnPacket(Packet packet)
 {
     Console.WriteLine("Recv packet: {0}", packet);
 }
示例#26
0
 public void OnFrameException(Service svc, Exception e)
 {
     Console.WriteLine("Frame exception: {0}", e);
 }
示例#27
0
 public void OnPacket(Packet packet)
 {
     Console.WriteLine("OnPacket: {0}", packet);
     throw new Exception("Test exception, Yep!");
 }
示例#28
0
 public override void OnSessionCreate(SessionInfo sessionInfo)
 {
     Console.WriteLine("New session create: {0}", sessionInfo);
 }
示例#29
0
 private void _OnCancel(Timer timer)
 {
     Console.WriteLine("Timer cancel handler called!");
 }
示例#30
0
 public void OnPacketExcHandler(PacketExceptionInfo excInfo)
 {
     Console.WriteLine("Packet exception, phase: {0}, packet: {1}, e: {2}", excInfo.phase, excInfo.packet, excInfo.exception);
 }