|
|
@ -1,5 +1,4 @@
|
|
|
|
using System;
|
|
|
|
using ZeroLevel.Network;
|
|
|
|
using ZeroLevel.Network;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZeroLevel.Services.Applications
|
|
|
|
namespace ZeroLevel.Services.Applications
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -11,19 +10,25 @@ namespace ZeroLevel.Services.Applications
|
|
|
|
public string Group { get; private set; }
|
|
|
|
public string Group { get; private set; }
|
|
|
|
public string Type { get; private set; }
|
|
|
|
public string Type { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected readonly IConfiguration _config;
|
|
|
|
protected readonly IConfigurationSet _configSet;
|
|
|
|
|
|
|
|
protected IConfiguration _config => _configSet?.Default;
|
|
|
|
|
|
|
|
|
|
|
|
protected Exchange Exchange { get; }
|
|
|
|
protected Exchange Exchange { get; }
|
|
|
|
|
|
|
|
|
|
|
|
protected BaseZeroExchangeService(IConfiguration configuration = null)
|
|
|
|
private BaseZeroExchangeService()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected BaseZeroExchangeService(IConfigurationSet configuration = null)
|
|
|
|
: base()
|
|
|
|
: base()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_config = configuration ?? Configuration.Default;
|
|
|
|
_configSet = configuration ?? Configuration.DefaultSet;
|
|
|
|
base.Name = ReadName(_config);
|
|
|
|
base.Name = ReadName();
|
|
|
|
this.Key = ReadKey(_config);
|
|
|
|
this.Key = ReadKey();
|
|
|
|
this.Version = ReadVersion(_config);
|
|
|
|
this.Version = ReadVersion();
|
|
|
|
this.Group = ReadServiceGroup(_config);
|
|
|
|
this.Group = ReadServiceGroup();
|
|
|
|
this.Type = ReadServiceType(_config);
|
|
|
|
this.Type = ReadServiceType();
|
|
|
|
|
|
|
|
|
|
|
|
var discovery = _config.First("discovery");
|
|
|
|
var discovery = _config.First("discovery");
|
|
|
|
|
|
|
|
|
|
|
@ -52,51 +57,62 @@ namespace ZeroLevel.Services.Applications
|
|
|
|
|
|
|
|
|
|
|
|
#region Config
|
|
|
|
#region Config
|
|
|
|
|
|
|
|
|
|
|
|
private string ReadName(IConfiguration configuration)
|
|
|
|
private string ReadName()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_config.Contains("ServiceName"))
|
|
|
|
return FindInConfig<string>(new[] { "ServiceName", "AppName" }, string.Empty, "service")
|
|
|
|
return _config.First("ServiceName");
|
|
|
|
?? this.GetType().Name;
|
|
|
|
if (_config.Contains("AppName"))
|
|
|
|
|
|
|
|
return _config.First("AppName");
|
|
|
|
|
|
|
|
return this.GetType().Name;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string ReadKey(IConfiguration configuration)
|
|
|
|
private string ReadKey()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_config.Contains("ServiceKey"))
|
|
|
|
return FindInConfig<string>(new[] { "ServiceKey", "AppKey" }, string.Empty, "service");
|
|
|
|
return _config.First("ServiceKey");
|
|
|
|
|
|
|
|
if (_config.Contains("AppKey"))
|
|
|
|
|
|
|
|
return _config.First("AppKey");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string ReadVersion(IConfiguration configuration)
|
|
|
|
private string ReadVersion()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_config.Contains("Version"))
|
|
|
|
return FindInConfig<string>(new[] { "Version", "AppVersion" }, string.Empty, "service")
|
|
|
|
return _config.First("Version");
|
|
|
|
?? "1.0";
|
|
|
|
if (_config.Contains("AppVersion"))
|
|
|
|
|
|
|
|
return _config.First("AppVersion");
|
|
|
|
|
|
|
|
return "1.0";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string ReadServiceGroup(IConfiguration configuration)
|
|
|
|
private string ReadServiceGroup()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_config.Contains("DiscoveryGroup"))
|
|
|
|
return FindInConfig<string>(new[] { "DiscoveryGroup", "ServiceGroup" }, string.Empty, "service")
|
|
|
|
return _config.First("DiscoveryGroup");
|
|
|
|
?? ExServiceInfo.DEFAULT_GROUP_NAME;
|
|
|
|
if (_config.Contains("ServiceGroup"))
|
|
|
|
|
|
|
|
return _config.First("ServiceGroup");
|
|
|
|
|
|
|
|
return ExServiceInfo.DEFAULT_GROUP_NAME;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private string ReadServiceType(IConfiguration configuration)
|
|
|
|
private string ReadServiceType()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_config.Contains("DiscoveryType"))
|
|
|
|
return FindInConfig<string>(new[] { "DiscoveryType", "ServiceType" }, string.Empty, "service")
|
|
|
|
return _config.First("DiscoveryType");
|
|
|
|
?? ExServiceInfo.DEFAULT_TYPE_NAME;
|
|
|
|
if (_config.Contains("ServiceType"))
|
|
|
|
|
|
|
|
return _config.First("ServiceType");
|
|
|
|
|
|
|
|
return ExServiceInfo.DEFAULT_TYPE_NAME;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected T FindInConfig<T>(string[] keys, params string[] sections)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var section in sections)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(section))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var key in keys)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_configSet.Default.Contains(key))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _configSet.Default.First<T>(key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (_configSet.ContainsSection(section))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var key in keys)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_configSet[section].Contains(key))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _configSet[section].First<T>(key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return default(T);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endregion Config
|
|
|
|
#endregion Config
|
|
|
|
|
|
|
|
|
|
|
|
public string Endpoint { get; private set; }
|
|
|
|
public string Endpoint { get; private set; }
|
|
|
|