You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/TestApp/Program.cs

84 lines
2.5 KiB

5 years ago
using Newtonsoft.Json;
using System;
using System.Net;
using System.Threading;
5 years ago
using ZeroLevel;
5 years ago
using ZeroLevel.Logging;
using ZeroLevel.Network;
using ZeroLevel.Services.Serialization;
3 years ago
using ZeroLevel.Services.Trees;
namespace TestApp
{
5 years ago
public class TestQuery
{
public string Name { get; set; }
public int Age { get; set; }
public string[] Roles { get; set; }
}
internal static class Program
{
5 years ago
private static string Serialize(object instance)
{
return JsonConvert.SerializeObject(instance);
}
private static void Main(string[] args)
{
5 years ago
Configuration.Save(Configuration.ReadFromApplicationConfig());
5 years ago
Bootstrap.Startup<MyService>(args,
() => Configuration.ReadSetFromIniFile("config.ini"))
5 years ago
.EnableConsoleLog(LogLevel.System | LogLevel.FullDebug)
//.UseDiscovery()
.Run()
.WaitWhileStatus(ZeroServiceStatus.Running)
.Stop();
5 years ago
Bootstrap.Shutdown();
}
static void SimpleCSTest()
{
var server_router = new Router();
server_router.RegisterInbox<string>("test", (c, line) =>
{
Console.WriteLine(line);
});
server_router.RegisterInbox<string, string>("req", (c, line) =>
{
Console.WriteLine($"Request: {line}");
return line.ToUpperInvariant();
});
var server = new SocketServer(new System.Net.IPEndPoint(IPAddress.Any, 666), server_router);
var client_router = new Router();
var client = new SocketClient(new IPEndPoint(IPAddress.Loopback, 666), client_router);
var frm = FrameFactory.Create("req", MessageSerializer.SerializeCompatible("Hello world"));
while (Console.KeyAvailable == false)
{
client.Request(frm, data =>
{
var line = MessageSerializer.DeserializeCompatible<string>(data);
Console.WriteLine($"Response: {line}");
});
Thread.Sleep(2000);
}
}
3 years ago
public static double[] Generate(int vector_size)
{
var rnd = new Random((int)Environment.TickCount);
var vector = new double[vector_size];
for (int i = 0; i < vector_size; i++)
{
vector[i] = 50.0d - rnd.NextDouble() * 100.0d;
}
return vector;
}
}
5 years ago
}

Powered by TurnKey Linux.