Refactoring

pull/1/head
Ogoun 6 years ago
parent 4a0fd04513
commit c12a54f3b2

@ -14,6 +14,10 @@
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> </configuration>

@ -40,7 +40,7 @@ namespace ZeroLevel.Discovery
_exInbox.RegisterInbox<IEnumerable<ServiceEndpointsInfo>>("services", (_, __) => routeTable.Get()); _exInbox.RegisterInbox<IEnumerable<ServiceEndpointsInfo>>("services", (_, __) => routeTable.Get());
_exInbox.RegisterInbox<ExServiceInfo, InvokeResult>("register", (info, _, __) => routeTable.Append(info)); _exInbox.RegisterInbox<ExServiceInfo, InvokeResult>("register", (info, _, __) => routeTable.Append(info));
Log.Info($"TCP server started on port {socketPort}"); Log.Info($"TCP server started {_exInbox.Endpoint.Address}:{socketPort}");
} }
public override void StopAction() public override void StopAction()

@ -42,8 +42,8 @@
<Reference Include="Microsoft.Owin.Hosting, Version=4.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.Owin.Hosting, Version=4.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Owin.Hosting.4.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath> <HintPath>..\packages\Microsoft.Owin.Hosting.4.0.1\lib\net45\Microsoft.Owin.Hosting.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.4\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>C:\Users\a.bozhenov\source\repos\ZeroTests\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL"> <Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> <HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>

@ -1 +1 @@
e6d14b54c463a8096220ac67f9a339de12a3fb4a baf2f9d75e4982e81a51362dec180283f7786a6a

@ -7,6 +7,6 @@
<package id="Microsoft.Owin" version="4.0.1" targetFramework="net472" /> <package id="Microsoft.Owin" version="4.0.1" targetFramework="net472" />
<package id="Microsoft.Owin.Host.HttpListener" version="4.0.1" targetFramework="net472" /> <package id="Microsoft.Owin.Host.HttpListener" version="4.0.1" targetFramework="net472" />
<package id="Microsoft.Owin.Hosting" version="4.0.1" targetFramework="net472" /> <package id="Microsoft.Owin.Hosting" version="4.0.1" targetFramework="net472" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net472" /> <package id="Newtonsoft.Json" version="12.0.1" targetFramework="net472" />
<package id="Owin" version="1.0" targetFramework="net472" /> <package id="Owin" version="1.0" targetFramework="net472" />
</packages> </packages>

@ -29,7 +29,26 @@ namespace ZeroLevel.Services.Applications
var discoveryProtocol = _config.FirstOrDefault("discoveryProtocol", "socket"); var discoveryProtocol = _config.FirstOrDefault("discoveryProtocol", "socket");
_exchange = new Exchange(new DiscoveryClient(discoveryProtocol, discovery)); _exchange = new Exchange(new DiscoveryClient(discoveryProtocol, discovery));
}
private IExService _self_service = null;
private readonly object _self_create_lock = new object();
protected IExService Self
{
get
{
if (_self_service == null)
{
lock (_self_create_lock)
{
if (_self_service == null)
{
_self_service = _exchange.RegisterService(this);
}
}
}
return _self_service;
}
} }
#region Config #region Config

@ -28,10 +28,14 @@ namespace ZeroLevel.Services.Applications
{ {
InteraciveModeWorkingFlag.Reset(); InteraciveModeWorkingFlag.Reset();
OnStart(args); OnStart(args);
try
{
while (false == InteraciveModeWorkingFlag.WaitOne(2000)) while (false == InteraciveModeWorkingFlag.WaitOne(2000))
{ {
} }
} }
catch { }
}
#region IZeroService #region IZeroService

@ -16,5 +16,12 @@ namespace ZeroLevel.Network
/// Replier without request /// Replier without request
/// </summary> /// </summary>
void RegisterInbox<Tresp>(string inbox, Func<long, IZBackward, Tresp> handler); void RegisterInbox<Tresp>(string inbox, Func<long, IZBackward, Tresp> handler);
/*
DEFAULT INBOXES
*/
void RegisterInbox<T>(Action<T, long, IZBackward> handler);
void RegisterInbox<Treq, Tresp>(Func<Treq, long, IZBackward, Tresp> handler);
void RegisterInbox<Tresp>(Func<long, IZBackward, Tresp> handler);
} }
} }

@ -53,19 +53,23 @@ namespace ZeroLevel.Network
return port; return port;
} }
public static IPAddress GetNonLoopbackAddress() public static IPAddress GetNonLoopbackAddress(bool ignore_virtual_devices = true, bool ignore_docker_devices = true)
{ {
if (NetworkInterface.GetIsNetworkAvailable()) if (NetworkInterface.GetIsNetworkAvailable())
{ {
foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces()) foreach (var adapter in NetworkInterface.GetAllNetworkInterfaces())
{ {
if (adapter.Description.IndexOf("VirtualBox", StringComparison.OrdinalIgnoreCase) >= 0) if (adapter.OperationalStatus == OperationalStatus.Up)
{
if (ignore_virtual_devices && (adapter.Description.IndexOf("Virtual", StringComparison.OrdinalIgnoreCase) >= 0 || adapter.Name.IndexOf("Virtual", StringComparison.OrdinalIgnoreCase) >= 0))
continue;
if (ignore_docker_devices && (adapter.Description.IndexOf("Docker", StringComparison.OrdinalIgnoreCase) >= 0 || adapter.Name.IndexOf("Docker", StringComparison.OrdinalIgnoreCase) >= 0))
continue; continue;
if (adapter.NetworkInterfaceType != NetworkInterfaceType.Ethernet) if (adapter.NetworkInterfaceType != NetworkInterfaceType.Ethernet)
continue; continue;
foreach (UnicastIPAddressInformation address in adapter.GetIPProperties().UnicastAddresses) foreach (UnicastIPAddressInformation address in adapter.GetIPProperties().UnicastAddresses)
{ {
if (address.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) if (address.Address.AddressFamily == AddressFamily.InterNetwork)
{ {
if (!IPAddress.IsLoopback(address.Address)) if (!IPAddress.IsLoopback(address.Address))
{ {
@ -75,6 +79,7 @@ namespace ZeroLevel.Network
} }
} }
} }
}
return null; return null;
} }
} }

@ -66,21 +66,10 @@ namespace ZeroLevel.Network
_discoveryServerClient.ForceConnect(); _discoveryServerClient.ForceConnect();
if (_discoveryServerClient.Status == ZTransportStatus.Working) if (_discoveryServerClient.Status == ZTransportStatus.Working)
{ {
IEnumerable<ServiceEndpointsInfo> records = null;
try try
{ {
var ir = _discoveryServerClient.Request<IEnumerable<ServiceEndpointsInfo>>("services", response => records = response); var ir = _discoveryServerClient.Request<IEnumerable<ServiceEndpointsInfo>>("services", records =>
if (!ir.Success)
{ {
Log.Warning($"[DiscoveryClient] UpdateServiceListInfo. Error request to inbox 'services'. {ir.Comment}");
return;
}
}
catch (Exception ex)
{
Log.Error(ex, "[DiscoveryClient] UpdateServiceListInfo. Discrovery service response is absent");
return;
}
if (records == null) if (records == null)
{ {
Log.Warning("[DiscoveryClient] UpdateServiceListInfo. Discrovery response is empty"); Log.Warning("[DiscoveryClient] UpdateServiceListInfo. Discrovery response is empty");
@ -112,6 +101,18 @@ namespace ZeroLevel.Network
{ {
_lock.ExitWriteLock(); _lock.ExitWriteLock();
} }
});
if (!ir.Success)
{
Log.Warning($"[DiscoveryClient] UpdateServiceListInfo. Error request to inbox 'services'. {ir.Comment}");
return;
}
}
catch (Exception ex)
{
Log.Error(ex, "[DiscoveryClient] UpdateServiceListInfo. Discrovery service response is absent");
return;
}
} }
else else
{ {

@ -1 +1 @@
35db55177c262262ace2e47d49fa51ff7b48a736 44e8c5c8420f166261f61c4c11d319a8acdc2c79

Loading…
Cancel
Save

Powered by TurnKey Linux.