From 9d037896863c4df94f57171c8a1a29b344a66694 Mon Sep 17 00:00:00 2001 From: "a.bozhenov" Date: Fri, 5 Jul 2019 19:33:56 +0300 Subject: [PATCH] Fix --- TestApp/MyService.cs | 9 ++++++--- TestApp/Program.cs | 10 ++++------ TestApp/config.ini | 1 - ZeroLevel.Discovery/DiscoveryService.cs | 2 +- ZeroLevel.Discovery/Program.cs | 6 +++++- ZeroLevel/Services/Bootstrap.cs | 3 +++ ZeroLevel/Services/Network/SocketClient.cs | 9 +++++---- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/TestApp/MyService.cs b/TestApp/MyService.cs index 459f2f0..6008688 100644 --- a/TestApp/MyService.cs +++ b/TestApp/MyService.cs @@ -31,7 +31,8 @@ namespace TestApp StoreConnection("mytest", new IPEndPoint(IPAddress.Loopback, 8800)); StoreConnection("mymeta", new IPEndPoint(IPAddress.Loopback, 8801)); - Sheduller.RemindEvery(TimeSpan.FromSeconds(1), () => + int count = 0; + Sheduller.RemindWhile(TimeSpan.FromSeconds(1), () => { var client = ConnectToService("mytest"); client.Send("pum"); @@ -42,10 +43,12 @@ namespace TestApp s => Log.Info($"Response: {s}")); client.Request("now", s => Log.Info($"Response date: {s}")); client.Request(BaseSocket.DEFAULT_REQUEST_WITHOUT_ARGS_INBOX, s => Log.Info($"Response ip: {s}")); + count++; + return count > 3; }); - + Sheduller.RemindEvery(TimeSpan.FromSeconds(3), () => - { + { var client = ConnectToService("mymeta"); client.Request("metainfo", info => { diff --git a/TestApp/Program.cs b/TestApp/Program.cs index 6dab700..589882e 100644 --- a/TestApp/Program.cs +++ b/TestApp/Program.cs @@ -1,6 +1,4 @@ -using System; -using System.Net; -using ZeroLevel; +using ZeroLevel; namespace TestApp { @@ -8,10 +6,10 @@ namespace TestApp { private static void Main(string[] args) { - Bootstrap.Startup(args, + Bootstrap.Startup(args, () => Configuration.ReadSetFromIniFile("config.ini")) - //.ReadServiceInfo() - //.UseDiscovery() + .EnableConsoleLog(ZeroLevel.Services.Logging.LogLevel.System | ZeroLevel.Services.Logging.LogLevel.FullDebug) + .UseDiscovery() .Run() .WaitWhileStatus(ZeroServiceStatus.Running) .Stop(); diff --git a/TestApp/config.ini b/TestApp/config.ini index 6382ac9..7cb9cec 100644 --- a/TestApp/config.ini +++ b/TestApp/config.ini @@ -8,7 +8,6 @@ ServiceType=site [log] path=logs -console=true [webapi] port=8183 diff --git a/ZeroLevel.Discovery/DiscoveryService.cs b/ZeroLevel.Discovery/DiscoveryService.cs index b2e1caa..8576566 100644 --- a/ZeroLevel.Discovery/DiscoveryService.cs +++ b/ZeroLevel.Discovery/DiscoveryService.cs @@ -21,7 +21,7 @@ namespace ZeroLevel.Discovery Injector.Default.Register(routeTable); var socketPort = Configuration.Default.First("socketport"); _exInbox = UseHost(socketPort); - _exInbox.RegisterInbox>("services", (_, __) => routeTable.Get()); + _exInbox.RegisterInbox>("services", (_) => routeTable.Get()); _exInbox.RegisterInbox("register", (client, info) => routeTable.Append(info, client)); } diff --git a/ZeroLevel.Discovery/Program.cs b/ZeroLevel.Discovery/Program.cs index e316dcf..47ae75c 100644 --- a/ZeroLevel.Discovery/Program.cs +++ b/ZeroLevel.Discovery/Program.cs @@ -4,7 +4,11 @@ { private static void Main(string[] args) { - Bootstrap.Startup(args); + Bootstrap.Startup(args) + .Run() + .WaitWhileStatus(ZeroServiceStatus.Running) + .Stop(); + Bootstrap.Shutdown(); } } } \ No newline at end of file diff --git a/ZeroLevel/Services/Bootstrap.cs b/ZeroLevel/Services/Bootstrap.cs index cc94c7c..b5540d5 100644 --- a/ZeroLevel/Services/Bootstrap.cs +++ b/ZeroLevel/Services/Bootstrap.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Net; using System.Reflection; +using ZeroLevel.Services.Logging; namespace ZeroLevel { @@ -38,6 +39,8 @@ namespace ZeroLevel public BootstrapFluent ReadServiceInfo() { _service?.ReadServiceInfo(); return this; } public BootstrapFluent ReadServiceInfo(IConfigurationSet config) { _service?.ReadServiceInfo(config); return this; } + public BootstrapFluent EnableConsoleLog(LogLevel level = LogLevel.FullStandart) { Log.AddConsoleLogger(level); return this; } + public ZeroServiceStatus Status { get { return _service.Status; } } public IServiceExecution Run() { _service.Start(); return this; } public IServiceExecution Stop() diff --git a/ZeroLevel/Services/Network/SocketClient.cs b/ZeroLevel/Services/Network/SocketClient.cs index c95de9c..2efef54 100644 --- a/ZeroLevel/Services/Network/SocketClient.cs +++ b/ZeroLevel/Services/Network/SocketClient.cs @@ -40,7 +40,7 @@ namespace ZeroLevel.Network public SocketClient(IPEndPoint ep, IRouter router) { - _router = router; + _router = router; Endpoint = ep; _parser.OnIncoming += _parser_OnIncoming; _sendThread = new Thread(SendFramesJob); @@ -59,9 +59,9 @@ namespace ZeroLevel.Network _parser.OnIncoming += _parser_OnIncoming; _sendThread = new Thread(SendFramesJob); _sendThread.IsBackground = true; - _sendThread.Start(); - _stream.BeginRead(_buffer, 0, DEFAULT_RECEIVE_BUFFER_SIZE, ReceiveAsyncCallback, null); + _sendThread.Start(); Working(); + _stream.BeginRead(_buffer, 0, DEFAULT_RECEIVE_BUFFER_SIZE, ReceiveAsyncCallback, null); } #region API @@ -295,7 +295,8 @@ namespace ZeroLevel.Network _parser.Push(_buffer, count); _last_rw_time = DateTime.UtcNow.Ticks; } - if (Status == SocketClientStatus.Working) + if (Status == SocketClientStatus.Working + || Status == SocketClientStatus.Initialized) { _stream.BeginRead(_buffer, 0, DEFAULT_RECEIVE_BUFFER_SIZE, ReceiveAsyncCallback, null); }