Added services description info
Added ZeroNetworkMonitor - show all services which connected to discovery
pull/1/head
a.bozhenov 5 years ago
parent e82a56a104
commit 7e4e26124a

@ -27,7 +27,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Processor", "TestPipeLine\P
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer", "TestPipeLine\Consumer\Consumer.csproj", "{931DEA89-42D1-4C06-9CB8-A3A0412093D6}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer", "TestPipeLine\Consumer\Consumer.csproj", "{931DEA89-42D1-4C06-9CB8-A3A0412093D6}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroLevel.SQL", "ZeroLevel.SQL\ZeroLevel.SQL.csproj", "{D25EC1F0-3BD2-409C-8A01-8C8339D5835C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ZeroLevel.SQL", "ZeroLevel.SQL\ZeroLevel.SQL.csproj", "{D25EC1F0-3BD2-409C-8A01-8C8339D5835C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZeroNetworkMonitor", "ZeroNetworkMonitor\ZeroNetworkMonitor.csproj", "{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -171,6 +173,18 @@ Global
{D25EC1F0-3BD2-409C-8A01-8C8339D5835C}.Release|x64.Build.0 = Release|Any CPU {D25EC1F0-3BD2-409C-8A01-8C8339D5835C}.Release|x64.Build.0 = Release|Any CPU
{D25EC1F0-3BD2-409C-8A01-8C8339D5835C}.Release|x86.ActiveCfg = Release|Any CPU {D25EC1F0-3BD2-409C-8A01-8C8339D5835C}.Release|x86.ActiveCfg = Release|Any CPU
{D25EC1F0-3BD2-409C-8A01-8C8339D5835C}.Release|x86.Build.0 = Release|Any CPU {D25EC1F0-3BD2-409C-8A01-8C8339D5835C}.Release|x86.Build.0 = Release|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Debug|x64.ActiveCfg = Debug|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Debug|x64.Build.0 = Debug|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Debug|x86.ActiveCfg = Debug|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Debug|x86.Build.0 = Debug|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Release|Any CPU.Build.0 = Release|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Release|x64.ActiveCfg = Release|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Release|x64.Build.0 = Release|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Release|x86.ActiveCfg = Release|Any CPU
{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -40,6 +40,9 @@ namespace ZeroLevel
public string Version { get; set; } public string Version { get; set; }
/// <summary> /// <summary>
/// Service port /// Service port
///
/// TODO move port out to new class for discovery service
///
/// </summary> /// </summary>
[DataMember] [DataMember]
public int Port { get; set; } public int Port { get; set; }

@ -1,4 +1,6 @@
using System; using System;
using System.Collections.Generic;
using ZeroLevel.Network.SDL;
namespace ZeroLevel.Network namespace ZeroLevel.Network
{ {
@ -26,6 +28,8 @@ namespace ZeroLevel.Network
bool ContainsHandlerInbox(string inbox); bool ContainsHandlerInbox(string inbox);
bool ContainsRequestorInbox(string inbox); bool ContainsRequestorInbox(string inbox);
IEnumerable<InboxServiceDescription> CollectInboxInfo();
event Action<ISocketClient> OnDisconnect; event Action<ISocketClient> OnDisconnect;
event Action<ExClient> OnConnect; event Action<ExClient> OnConnect;
} }

@ -16,6 +16,7 @@ namespace ZeroLevel.Network
void Remove(IPEndPoint endpoint); void Remove(IPEndPoint endpoint);
IEnumerable<KeyValuePair<string, IPEndPoint>> GetAll(); IEnumerable<KeyValuePair<string, IPEndPoint>> GetAll();
IEnumerable<string> GetKeys();
InvokeResult<IPEndPoint> Get(string key); InvokeResult<IPEndPoint> Get(string key);
InvokeResult<IEnumerable<IPEndPoint>> GetAll(string key); InvokeResult<IEnumerable<IPEndPoint>> GetAll(string key);

@ -5,6 +5,7 @@ using System.Net;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using ZeroLevel.Models; using ZeroLevel.Models;
using ZeroLevel.Network.SDL;
using ZeroLevel.Services.Serialization; using ZeroLevel.Services.Serialization;
namespace ZeroLevel.Network namespace ZeroLevel.Network
@ -654,17 +655,24 @@ namespace ZeroLevel.Network
#region Host service #region Host service
public IRouter UseHost() public IRouter UseHost()
{ {
return _cachee.GetServer(new IPEndPoint(IPAddress.Any, NetUtils.GetFreeTcpPort()), new Router()); return MakeHost(new IPEndPoint(IPAddress.Any, NetUtils.GetFreeTcpPort()));
} }
public IRouter UseHost(int port) public IRouter UseHost(int port)
{ {
return _cachee.GetServer(new IPEndPoint(IPAddress.Any, port), new Router()); return MakeHost(new IPEndPoint(IPAddress.Any, port));
} }
public IRouter UseHost(IPEndPoint endpoint) public IRouter UseHost(IPEndPoint endpoint)
{ {
return _cachee.GetServer(endpoint, new Router()); return MakeHost(endpoint);
}
private IRouter MakeHost(IPEndPoint endpoint)
{
var server = _cachee.GetServer(endpoint, new Router());
server.RegisterInbox<ServiceDescription>("__service_description__", _ => CollectServiceDescription());
return server;
} }
#endregion #endregion
@ -977,6 +985,22 @@ namespace ZeroLevel.Network
} }
#endregion #endregion
private ServiceDescription CollectServiceDescription()
{
return new ServiceDescription
{
ServiceInfo = this._owner?.ServiceInfo,
Inboxes = _cachee.ServerList
.SelectMany(se => se
.CollectInboxInfo()
.Select(i =>
{
i.Port = se.LocalEndpoint.Port;
return i;
}))
};
}
public void Dispose() public void Dispose()
{ {
if (_update_discovery_table_task != -1) if (_update_discovery_table_task != -1)

@ -0,0 +1,10 @@
namespace ZeroLevel.Network.SDL
{
public enum InboxKind
{
Handler = 0,
HandlerNoArgs = 1,
Reqeustor = 2,
ReqeustorNoArgs = 3,
}
}

@ -0,0 +1,50 @@
using ZeroLevel.Services.Serialization;
namespace ZeroLevel.Network.SDL
{
public class InboxServiceDescription
: IBinarySerializable
{
public int Port { get; set; }
/// <summary>
/// Inbox name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Invoke targer type name
/// </summary>
public string Target { get; set; }
/// <summary>
/// Inbox kind (handler or requestor)
/// </summary>
public InboxKind InboxKind { get; set; }
/// <summary>
/// Inbox Incoming data type
/// </summary>
public InboxType IncomingType { get; set; }
/// <summary>
/// Inbox Outcoming data type
/// </summary>
public InboxType OutcomingType { get; set; }
public void Deserialize(IBinaryReader reader)
{
this.Port = reader.ReadInt32();
this.Name = reader.ReadString();
this.Target = reader.ReadString();
this.InboxKind = (InboxKind)reader.ReadInt32();
this.IncomingType = reader.Read<InboxType>();
this.OutcomingType = reader.Read<InboxType>();
}
public void Serialize(IBinaryWriter writer)
{
writer.WriteInt32(this.Port);
writer.WriteString(this.Name);
writer.WriteString(this.Target);
writer.WriteInt32((int)this.InboxKind);
writer.Write<InboxType>(this.IncomingType);
writer.Write<InboxType>(this.OutcomingType);
}
}
}

@ -0,0 +1,30 @@
using System.Collections.Generic;
using ZeroLevel.Services.Serialization;
namespace ZeroLevel.Network.SDL
{
public class InboxType
: IBinarySerializable
{
/// <summary>
/// Type name
/// </summary>
public string Name { get; set; }
/// <summary>
/// Type fields (if composite type), top only
/// </summary>
public Dictionary<string, string> Fields { get; set; }
public void Deserialize(IBinaryReader reader)
{
this.Name = reader.ReadString();
this.Fields = reader.ReadDictionary<string, string>();
}
public void Serialize(IBinaryWriter writer)
{
writer.WriteString(this.Name);
writer.WriteDictionary(this.Fields);
}
}
}

@ -0,0 +1,24 @@
using System.Collections.Generic;
using ZeroLevel.Services.Serialization;
namespace ZeroLevel.Network.SDL
{
public class ServiceDescription
: IBinarySerializable
{
public ZeroServiceInfo ServiceInfo { get; set; }
public IEnumerable<InboxServiceDescription> Inboxes { get; set; }
public void Deserialize(IBinaryReader reader)
{
this.ServiceInfo = reader.Read<ZeroServiceInfo>();
this.Inboxes = reader.ReadCollection<InboxServiceDescription>();
}
public void Serialize(IBinaryWriter writer)
{
writer.Write<ZeroServiceInfo>(this.ServiceInfo);
writer.WriteCollection<InboxServiceDescription>(this.Inboxes);
}
}
}

@ -4,6 +4,7 @@ using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
using ZeroLevel.Network.SDL;
namespace ZeroLevel.Network namespace ZeroLevel.Network
{ {
@ -143,6 +144,7 @@ namespace ZeroLevel.Network
public bool ContainsInbox(string inbox) => _router.ContainsInbox(inbox); public bool ContainsInbox(string inbox) => _router.ContainsInbox(inbox);
public bool ContainsHandlerInbox(string inbox) => _router.ContainsHandlerInbox(inbox); public bool ContainsHandlerInbox(string inbox) => _router.ContainsHandlerInbox(inbox);
public bool ContainsRequestorInbox(string inbox) => _router.ContainsRequestorInbox(inbox); public bool ContainsRequestorInbox(string inbox) => _router.ContainsRequestorInbox(inbox);
public IEnumerable<InboxServiceDescription> CollectInboxInfo() => _router.CollectInboxInfo();
#endregion #endregion
} }
} }

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
using ZeroLevel.Network.SDL;
using ZeroLevel.Services.Invokation; using ZeroLevel.Services.Invokation;
using ZeroLevel.Services.Serialization; using ZeroLevel.Services.Serialization;
@ -122,6 +123,55 @@ namespace ZeroLevel.Network
} }
return null; return null;
} }
public InboxServiceDescription GetDescription(string name)
{
return new InboxServiceDescription
{
Name = name,
InboxKind = DetectKind(),
Target = _instance?.GetType()?.Name,
IncomingType = GetIncomingTypeDescription(),
OutcomingType = GetOutcomingTypeDescription()
};
}
private InboxType GetIncomingTypeDescription()
{
if (_typeReq == null) return null;
return new InboxType
{
Name = _typeReq.FullName,
Fields = _typeReq
.GetMembers(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.GetField | BindingFlags.GetProperty | BindingFlags.Instance)
.Where(m => m.MemberType == MemberTypes.Field || m.MemberType == MemberTypes.Property)
.Select(f => new KeyValuePair<string, string>(f.Name, (f.MemberType == MemberTypes.Property) ? (f as PropertyInfo).PropertyType.FullName : (f as FieldInfo).FieldType.FullName))
.ToDictionary(pair => pair.Key, pair => pair.Value)
};
}
private InboxType GetOutcomingTypeDescription()
{
if (_typeResp == null) return null;
return new InboxType
{
Name = _typeResp.FullName,
Fields = _typeResp
.GetMembers(BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.GetField | BindingFlags.GetProperty | BindingFlags.Instance)
.Where(m => m.MemberType == MemberTypes.Field || m.MemberType == MemberTypes.Property)
.Select(f => new KeyValuePair<string, string>(f.Name, (f.MemberType == MemberTypes.Property) ? (f as PropertyInfo).PropertyType.FullName : (f as FieldInfo).FieldType.FullName))
.ToDictionary(pair => pair.Key, pair => pair.Value)
};
}
private InboxKind DetectKind()
{
if (_typeResp == null)
{
return _noArguments ? InboxKind.HandlerNoArgs : InboxKind.Handler;
}
return _noArguments ? InboxKind.ReqeustorNoArgs : InboxKind.Reqeustor;
}
} }
private readonly Dictionary<string, List<MRInvoker>> _handlers = private readonly Dictionary<string, List<MRInvoker>> _handlers =
@ -291,6 +341,23 @@ namespace ZeroLevel.Network
return this; return this;
} }
#endregion #endregion
public IEnumerable<InboxServiceDescription> CollectInboxInfo()
{
var inboxes = new List<InboxServiceDescription>();
foreach (var handlers in _handlers)
{
foreach (var handler in handlers.Value)
{
inboxes.Add(handler.GetDescription(handlers.Key));
}
}
foreach (var requestor in _requestors)
{
inboxes.Add(requestor.Value.GetDescription(requestor.Key));
}
return inboxes;
}
} }
internal sealed class NullRouter internal sealed class NullRouter
@ -311,5 +378,6 @@ namespace ZeroLevel.Network
public bool ContainsInbox(string inbox) => false; public bool ContainsInbox(string inbox) => false;
public bool ContainsHandlerInbox(string inbox) => false; public bool ContainsHandlerInbox(string inbox) => false;
public bool ContainsRequestorInbox(string inbox) => false; public bool ContainsRequestorInbox(string inbox) => false;
public IEnumerable<InboxServiceDescription> CollectInboxInfo() => Enumerable.Empty<InboxServiceDescription>();
} }
} }

@ -242,72 +242,141 @@ namespace ZeroLevel.Network
} }
#region GET #region GET
public IEnumerable<string> GetKeys()
{
_lock.EnterReadLock();
try
{
return _tableByKey.Select(pair => pair.Key).ToArray();
}
finally
{
_lock.ExitReadLock();
}
}
public InvokeResult<IPEndPoint> Get(string key) public InvokeResult<IPEndPoint> Get(string key)
{ {
key = key.ToUpperInvariant(); key = key.ToUpperInvariant();
_lock.EnterReadLock();
try
{
if (_tableByKey.ContainsKey(key)) if (_tableByKey.ContainsKey(key))
{ {
if (_tableByKey[key].MoveNext()) if (_tableByKey[key].MoveNext())
return InvokeResult.Succeeding(_tableByKey[key].Current); return InvokeResult.Succeeding(_tableByKey[key].Current);
} }
}
finally
{
_lock.ExitReadLock();
}
return InvokeResult.Fault<IPEndPoint>($"No endpoints by key '{key}'"); return InvokeResult.Fault<IPEndPoint>($"No endpoints by key '{key}'");
} }
public InvokeResult<IEnumerable<IPEndPoint>> GetAll(string key) public InvokeResult<IEnumerable<IPEndPoint>> GetAll(string key)
{ {
key = key.ToUpperInvariant(); key = key.ToUpperInvariant();
_lock.EnterReadLock();
try
{
if (_tableByKey.ContainsKey(key)) if (_tableByKey.ContainsKey(key))
{ {
if (_tableByKey[key].MoveNext()) if (_tableByKey[key].MoveNext())
return InvokeResult.Succeeding(_tableByKey[key].GetCurrentSeq()); return InvokeResult.Succeeding(_tableByKey[key].GetCurrentSeq());
} }
}
finally
{
_lock.ExitReadLock();
}
return InvokeResult.Fault<IEnumerable<IPEndPoint>>($"No endpoints by key '{key}'"); return InvokeResult.Fault<IEnumerable<IPEndPoint>>($"No endpoints by key '{key}'");
} }
public IEnumerable<KeyValuePair<string, IPEndPoint>> GetAll() public IEnumerable<KeyValuePair<string, IPEndPoint>> GetAll()
{
_lock.EnterReadLock();
try
{ {
return _tableByKey.SelectMany(pair => pair.Value.Source.Select(s => new KeyValuePair<string, IPEndPoint>(pair.Key, s))); return _tableByKey.SelectMany(pair => pair.Value.Source.Select(s => new KeyValuePair<string, IPEndPoint>(pair.Key, s)));
} }
finally
{
_lock.ExitReadLock();
}
}
public InvokeResult<IPEndPoint> GetByType(string type) public InvokeResult<IPEndPoint> GetByType(string type)
{ {
type = type.ToUpperInvariant(); type = type.ToUpperInvariant();
_lock.EnterReadLock();
try
{
if (_tableByTypes.ContainsKey(type)) if (_tableByTypes.ContainsKey(type))
{ {
if (_tableByTypes[type].MoveNext()) if (_tableByTypes[type].MoveNext())
return InvokeResult.Succeeding(_tableByTypes[type].Current); return InvokeResult.Succeeding(_tableByTypes[type].Current);
} }
}
finally
{
_lock.ExitReadLock();
}
return InvokeResult.Fault<IPEndPoint>($"No endpoints by type '{type}'"); return InvokeResult.Fault<IPEndPoint>($"No endpoints by type '{type}'");
} }
public InvokeResult<IEnumerable<IPEndPoint>> GetAllByType(string type) public InvokeResult<IEnumerable<IPEndPoint>> GetAllByType(string type)
{ {
type = type.ToUpperInvariant(); type = type.ToUpperInvariant();
_lock.EnterReadLock();
try
{
if (_tableByTypes.ContainsKey(type)) if (_tableByTypes.ContainsKey(type))
{ {
if (_tableByTypes[type].MoveNext()) if (_tableByTypes[type].MoveNext())
return InvokeResult.Succeeding(_tableByTypes[type].GetCurrentSeq()); return InvokeResult.Succeeding(_tableByTypes[type].GetCurrentSeq());
} }
}
finally
{
_lock.ExitReadLock();
}
return InvokeResult.Fault<IEnumerable<IPEndPoint>>($"No endpoints by type '{type}'"); return InvokeResult.Fault<IEnumerable<IPEndPoint>>($"No endpoints by type '{type}'");
} }
public InvokeResult<IPEndPoint> GetByGroup(string group) public InvokeResult<IPEndPoint> GetByGroup(string group)
{ {
group = group.ToUpperInvariant(); group = group.ToUpperInvariant();
_lock.EnterReadLock();
try
{
if (_tableByGroups.ContainsKey(group)) if (_tableByGroups.ContainsKey(group))
{ {
if (_tableByGroups[group].MoveNext()) if (_tableByGroups[group].MoveNext())
return InvokeResult.Succeeding(_tableByGroups[group].Current); return InvokeResult.Succeeding(_tableByGroups[group].Current);
} }
}
finally
{
_lock.ExitReadLock();
}
return InvokeResult.Fault<IPEndPoint>($"No endpoints by group '{group}'"); return InvokeResult.Fault<IPEndPoint>($"No endpoints by group '{group}'");
} }
public InvokeResult<IEnumerable<IPEndPoint>> GetAllByGroup(string group) public InvokeResult<IEnumerable<IPEndPoint>> GetAllByGroup(string group)
{ {
group = group.ToUpperInvariant(); group = group.ToUpperInvariant();
_lock.EnterReadLock();
try
{
if (_tableByGroups.ContainsKey(group)) if (_tableByGroups.ContainsKey(group))
{ {
if (_tableByGroups[group].MoveNext()) if (_tableByGroups[group].MoveNext())
return InvokeResult.Succeeding(_tableByGroups[group].GetCurrentSeq()); return InvokeResult.Succeeding(_tableByGroups[group].GetCurrentSeq());
} }
}
finally
{
_lock.ExitReadLock();
}
return InvokeResult.Fault<IEnumerable<IPEndPoint>>($"No endpoints by group '{group}'"); return InvokeResult.Fault<IEnumerable<IPEndPoint>>($"No endpoints by group '{group}'");
} }
#endregion #endregion

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

@ -0,0 +1,9 @@
<Application x:Class="ZeroNetworkMonitor.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ZeroNetworkMonitor"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace ZeroNetworkMonitor
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

@ -0,0 +1,35 @@
<Window x:Class="ZeroNetworkMonitor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ZeroNetworkMonitor"
mc:Ignorable="d"
Title="MainWindow" Height="600" Width="1080" Loaded="Window_Loaded">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="27"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="199"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="150"/>
</Grid.ColumnDefinitions>
<Label Content="Discovery endpoint"/>
<TextBox x:Name="tbDiscovery" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<Button Content="Connect" Grid.Column="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Width="150" Click="Button_Click"/>
</Grid>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ListBox ItemsSource="{Binding}" x:Name="lbServices" MouseDoubleClick="LbServices_MouseDoubleClick"/>
</ScrollViewer>
<local:ServiceControlPanel x:Name="pService" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
</Grid>
</Grid>
</Window>

@ -0,0 +1,64 @@
using System;
using System.Collections.ObjectModel;
using System.Windows;
using ZeroLevel;
using ZeroLevel.Network;
namespace ZeroNetworkMonitor
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private ObservableCollection<string> _service_keys = new ObservableCollection<string>();
private IExchange _exchange;
private long _refresh_services_task = -1;
public ObservableCollection<string> Services
{
get { return _service_keys; }
}
public MainWindow()
{
InitializeComponent();
_exchange = Bootstrap.CreateExchange();
Injector.Default.Register<IExchange>(_exchange);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
_exchange.UseDiscovery(tbDiscovery.Text);
if (_refresh_services_task == -1)
{
_refresh_services_task = Sheduller.RemindEvery(TimeSpan.FromSeconds(5), () =>
{
Dispatcher.Invoke(() =>
{
var si = lbServices.SelectedItem;
_service_keys.Clear();
foreach (var s in _exchange.DiscoveryStorage.GetKeys())
{
_service_keys.Add(s);
};
lbServices.SelectedItem = si;
});
});
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
lbServices.ItemsSource = Services;
}
private void LbServices_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (lbServices.SelectedItem != null)
{
pService.UpdateView((string)lbServices.SelectedItem);
}
}
}
}

@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ZeroNetworkMonitor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZeroNetworkMonitor")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ZeroNetworkMonitor.Properties
{
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ZeroNetworkMonitor.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace ZeroNetworkMonitor.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}

@ -0,0 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>

@ -0,0 +1,57 @@
<UserControl x:Class="ZeroNetworkMonitor.ServiceControlPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ZeroNetworkMonitor"
mc:Ignorable="d"
d:DesignHeight="600" d:DesignWidth="900">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="81"/>
<RowDefinition Height="27"/>
<RowDefinition Height="*"/>
<RowDefinition Height="300"/>
</Grid.RowDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="27"/>
<RowDefinition Height="27"/>
<RowDefinition Height="27"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="Service Name" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<TextBlock x:Name="tbName" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<Label Grid.Row="1" Grid.Column="0" Content="Service Key" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<TextBlock x:Name="tbKey" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<Label Grid.Row="2" Grid.Column="0" Content="Version" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<TextBlock x:Name="tbVersion" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<Label Grid.Row="0" Grid.Column="2" Content="Service Type" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<TextBlock x:Name="tbType" Grid.Row="0" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<Label Grid.Row="1" Grid.Column="2" Content="Service Group" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
<TextBlock x:Name="tbGroup" Grid.Row="1" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>
</Grid>
<Label Grid.Row="1" Content="Inbox list"/>
<ListBox x:Name="lbInboxes" ItemsSource="{Binding}" Grid.Row="2" SelectionChanged="LbInboxes_SelectionChanged">
<ListBox.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBlock Text="["/>
<TextBlock Text="{Binding Port}"/>
<TextBlock Text="] "/>
<TextBlock Text="{Binding Name}"/>
</WrapPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Grid Grid.Row="3">
<TextBlock HorizontalAlignment="Stretch" TextWrapping="Wrap" x:Name="tbInboxDescription" VerticalAlignment="Stretch"/>
</Grid>
</Grid>
</UserControl>

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZeroLevel;
using ZeroLevel.Network;
using ZeroLevel.Network.SDL;
namespace ZeroNetworkMonitor
{
/// <summary>
/// Interaction logic for ServiceControlPanel.xaml
/// </summary>
public partial class ServiceControlPanel : UserControl
{
const string SDL_INBOX = "__service_description__";
private ServiceDescription _description;
public ServiceControlPanel()
{
InitializeComponent();
}
public void UpdateView(string serviceKey)
{
var exchange = Injector.Default.Resolve<IExchange>();
var client = exchange.GetConnection(serviceKey);
client.Request<ServiceDescription>(SDL_INBOX, desc =>
{
_description = desc;
UpdateDescriptionView();
});
}
private void UpdateDescriptionView()
{
if (_description != null)
{
Dispatcher.Invoke(() =>
{
tbGroup.Text = _description.ServiceInfo.ServiceGroup;
tbKey.Text = _description.ServiceInfo.ServiceKey;
tbName.Text = _description.ServiceInfo.Name;
tbType.Text = _description.ServiceInfo.ServiceType;
tbVersion.Text = _description.ServiceInfo.Version;
lbInboxes.ItemsSource = _description.Inboxes;
});
}
}
private void LbInboxes_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var inbox = lbInboxes.SelectedItem as InboxServiceDescription;
if (inbox != null)
{
var info = new StringBuilder();
info.AppendLine($"Inbox '{inbox.Name}' type: {inbox.InboxKind}");
info.AppendLine($"Target: '{inbox.Target}'");
if (inbox.InboxKind == InboxKind.Handler || inbox.InboxKind == InboxKind.Reqeustor)
{
info.AppendLine($"Incoming type: {inbox.IncomingType.Name}");
if (inbox.IncomingType.Fields != null && inbox.IncomingType.Fields.Any())
{
foreach (var field in inbox.IncomingType.Fields)
{
info.AppendLine($"\t{field.Key}: {field.Value}");
}
}
}
if (inbox.InboxKind == InboxKind.Reqeustor)
{
info.AppendLine($"Outcoming type: {inbox.OutcomingType.Name}");
if (inbox.OutcomingType.Fields != null && inbox.OutcomingType.Fields.Any())
{
foreach (var field in inbox.OutcomingType.Fields)
{
info.AppendLine($"\t{field.Key}: {field.Value}");
}
}
}
tbInboxDescription.Text = info.ToString();
}
}
}
}

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EECF6EA0-6D9C-4B69-9CA3-23357C04B84C}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ZeroNetworkMonitor</RootNamespace>
<AssemblyName>ZeroNetworkMonitor</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ServiceControlPanel.xaml.cs">
<DependentUpon>ServiceControlPanel.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="ServiceControlPanel.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ZeroLevel\ZeroLevel.csproj">
<Project>{06c9e60e-d449-41a7-9bf0-a829aaf5d214}</Project>
<Name>ZeroLevel</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading…
Cancel
Save

Powered by TurnKey Linux.