pull/1/head
a.bozhenov 5 years ago
parent 7db645b688
commit e82a56a104

@ -1,6 +1,4 @@
using System;
using System.Net;
using ZeroLevel;
using ZeroLevel;
namespace TestApp
{

@ -1,14 +1,38 @@
namespace ZeroLevel.Discovery
using System;
using Topshelf;
using static ZeroLevel.Bootstrap;
namespace ZeroLevel.Discovery
{
internal static class Program
{
private static void Main(string[] args)
{
Bootstrap.Startup<DiscoveryService>(args)
.Run()
.WaitWhileStatus(ZeroServiceStatus.Running)
.Stop();
Bootstrap.Shutdown();
IServiceExecution se = null;
HostFactory.Run(x =>
{
x.StartAutomatically();
x.Service<BootstrapFluent>(s =>
{
s.ConstructUsing(name => Bootstrap.Startup<DiscoveryService>(args));
s.WhenStopped(tc => { tc.Stop(); Bootstrap.Shutdown(); });
s.WhenStarted(tc => { se = tc.Run(); });
});
x.RunAsLocalSystem();
x.SetDescription("Discovery");
x.SetDisplayName("Discovery");
x.SetServiceName("Discovery");
x.OnException(ex =>
{
Log.Error(ex, "Service exception");
});
});
if (Environment.UserInteractive && args?.Length < 1)
{
se?.WaitWhileStatus(ZeroServiceStatus.Running);
}
}
}
}

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp2.2</TargetFramework>
<PublishDir>bin\Release\netcoreapp2.2\publish\</PublishDir>
</PropertyGroup>
</Project>

@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Topshelf" Version="4.2.1" />
</ItemGroup>
<ItemGroup>

@ -18,5 +18,8 @@ namespace ZeroLevel.SqlServer
int ExecuteNonResult(string query);
int ExecuteNonResult(string query, DbParameter[] par);
void LazySelect(string query, DbParameter[] par, Func<DbDataReader, bool> readHandler, int timeout);
T Read<T>(DbDataReader reader, int index);
T Read<T>(DbDataReader reader, string name);
}
}

@ -366,5 +366,16 @@ namespace ZeroLevel.SqlServer
}
}
#endregion
public T Read<T>(DbDataReader reader, int index)
{
if (reader[index] == DBNull.Value) return default(T);
return (T)Convert.ChangeType(reader[index], typeof(T));
}
public T Read<T>(DbDataReader reader, string name)
{
if (reader[name] == DBNull.Value) return default(T);
return (T)Convert.ChangeType(reader[name], typeof(T));
}
}
}

@ -46,20 +46,30 @@ namespace ZeroLevel.Services.Applications
public void ReadServiceInfo()
{
this.Name = ReadName();
this.Key = ReadKey();
this.Version = ReadVersion();
this.Group = ReadServiceGroup();
this.Type = ReadServiceType();
if (string.IsNullOrWhiteSpace(this.Name))
this.Name = ReadName();
if (string.IsNullOrWhiteSpace(this.Key))
this.Key = ReadKey();
if (string.IsNullOrWhiteSpace(this.Version))
this.Version = ReadVersion();
if (string.IsNullOrWhiteSpace(this.Group))
this.Group = ReadServiceGroup();
if (string.IsNullOrWhiteSpace(this.Type))
this.Type = ReadServiceType();
}
public void ReadServiceInfo(IConfigurationSet set)
{
this.Name = ReadName(set);
this.Key = ReadKey(set);
this.Version = ReadVersion(set);
this.Group = ReadServiceGroup(set);
this.Type = ReadServiceType(set);
if (string.IsNullOrWhiteSpace(this.Name))
this.Name = ReadName(set);
if (string.IsNullOrWhiteSpace(this.Key))
this.Key = ReadKey(set);
if (string.IsNullOrWhiteSpace(this.Version))
this.Version = ReadVersion(set);
if (string.IsNullOrWhiteSpace(this.Group))
this.Group = ReadServiceGroup(set);
if (string.IsNullOrWhiteSpace(this.Type))
this.Type = ReadServiceType(set);
}
private string ReadName(IConfigurationSet set = null)
@ -128,6 +138,7 @@ namespace ZeroLevel.Services.Applications
if (_state == ZeroServiceStatus.Running
|| _state == ZeroServiceStatus.Initialized)
{
ReadServiceInfo();
_exhange.UseDiscovery();
}
}
@ -137,6 +148,7 @@ namespace ZeroLevel.Services.Applications
if (_state == ZeroServiceStatus.Running
|| _state == ZeroServiceStatus.Initialized)
{
ReadServiceInfo();
_exhange.UseDiscovery(endpoint);
}
}
@ -146,6 +158,7 @@ namespace ZeroLevel.Services.Applications
if (_state == ZeroServiceStatus.Running
|| _state == ZeroServiceStatus.Initialized)
{
ReadServiceInfo();
_exhange.UseDiscovery(endpoint);
}
}

@ -15,6 +15,7 @@ namespace ZeroLevel.Network
IRouter UseHost(IPEndPoint endpoint);
IServiceRoutesStorage RoutesStorage { get; }
IServiceRoutesStorage DiscoveryStorage { get; }
ExClient GetConnection(string alias);
ExClient GetConnection(IPEndPoint endpoint);

@ -15,6 +15,8 @@ namespace ZeroLevel.Network
void Remove(IPEndPoint endpoint);
IEnumerable<KeyValuePair<string, IPEndPoint>> GetAll();
InvokeResult<IPEndPoint> Get(string key);
InvokeResult<IEnumerable<IPEndPoint>> GetAll(string key);
InvokeResult<IPEndPoint> GetByType(string type);

@ -20,6 +20,7 @@ namespace ZeroLevel.Network
private readonly ExClientServerCachee _cachee = new ExClientServerCachee();
public IServiceRoutesStorage RoutesStorage => _user_aliases;
public IServiceRoutesStorage DiscoveryStorage => _dicovery_aliases;
private readonly IZeroService _owner;
#region Ctor
@ -506,6 +507,7 @@ namespace ZeroLevel.Network
{
Sheduller.Remove(_register_in_discovery_table_task);
}
UpdateServiceListFromDiscovery();
_register_in_discovery_table_task = Sheduller.RemindEvery(TimeSpan.FromMilliseconds(500), _update_discovery_table_period, RegisterServicesInDiscovery);
_update_discovery_table_task = Sheduller.RemindEvery(TimeSpan.FromMilliseconds(750), _register_in_discovery_table_period, UpdateServiceListFromDiscovery);
}

@ -252,6 +252,7 @@ namespace ZeroLevel.Network
}
return InvokeResult.Fault<IPEndPoint>($"No endpoints by key '{key}'");
}
public InvokeResult<IEnumerable<IPEndPoint>> GetAll(string key)
{
key = key.ToUpperInvariant();
@ -262,6 +263,13 @@ namespace ZeroLevel.Network
}
return InvokeResult.Fault<IEnumerable<IPEndPoint>>($"No endpoints by key '{key}'");
}
public IEnumerable<KeyValuePair<string, IPEndPoint>> GetAll()
{
return _tableByKey.SelectMany(pair => pair.Value.Source.Select(s => new KeyValuePair<string, IPEndPoint>(pair.Key, s)));
}
public InvokeResult<IPEndPoint> GetByType(string type)
{
type = type.ToUpperInvariant();

@ -1,5 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using ZeroLevel.Services.Serialization;

Loading…
Cancel
Save

Powered by TurnKey Linux.