/// <summary> /// Initializes a basic <see cref="LiteServer{TUser}"/> with the specified <typeparamref name="TLiteServerUser"/>. /// </summary> /// <typeparam name="TLiteServerUser">Server's user type.</typeparam> /// <param name="builder">A <see cref="ILiteBuilder"/> to add server.</param> /// <param name="configure">Delegate to configure a <see cref="LiteServerOptions"/>.</param> /// <returns>The <see cref="ILiteBuilder"/>.</returns> public static ILiteBuilder AddLiteServer <TLiteServerUser>(this ILiteBuilder builder, Action <LiteServerOptions> configure) where TLiteServerUser : LiteServerUser { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddSingleton <ILiteServer <TLiteServerUser>, LiteServer <TLiteServerUser> >(serviceProvider => { var liteServerOptions = new LiteServerOptions(); configure(liteServerOptions); var server = new LiteServer <TLiteServerUser>(liteServerOptions, serviceProvider); return(server); }); builder.Services.AddHostedService(serviceProvider => { var serverInstance = serviceProvider.GetRequiredService <ILiteServer <TLiteServerUser> >(); return(new LiteServerHostedService <TLiteServerUser>(serverInstance)); }); return(builder); }
static void Main(string[] args) { var certificate = new X509Certificate2("GriffinNetworkingTemp.pfx", "mamma"); var config = new LiteServerConfiguration(); config.Modules.AddAuthentication(new HashAuthenticationModule(new FakeFetcher())); config.Modules.AddAuthorization(new MustAlwaysAuthenticate()); var server = new LiteServer(config); server.Start(IPAddress.Loopback, 0); var client = new CqsClient(() => new DataContractMessageSerializer()); client.Authenticator = new HashClientAuthenticator(new NetworkCredential("jonas", "mamma")); client.StartAsync(IPAddress.Loopback, server.LocalPort).Wait(); client.ExecuteAsync(new HelloWorld()).Wait(); var listener = new HttpListener(); listener.ChannelFactory = new SecureTcpChannelFactory(new ServerSideSslStreamBuilder(certificate)); listener.ClientConnected += OnConnect; listener.MessageReceived = OnMessage; listener.BodyDecoder = new CompositeIMessageSerializer(); listener.Start(IPAddress.Any, 8083); Console.ReadLine(); }
public void Setup() { var root = new CompositionRoot(); root.Build(); var module = new CqsModule { CommandBus = CqsBus.CmdBus, QueryBus = CqsBus.QueryBus, RequestReplyBus = CqsBus.RequestReplyBus, EventBus = CqsBus.EventBus }; var config = new LiteServerConfiguration(); config.DecoderFactory = () => new MicroMessageDecoder(new JsonMessageSerializer()); config.EncoderFactory = () => new MicroMessageEncoder(new JsonMessageSerializer()); config.Modules.AddAuthentication(new AuthenticationModule()); config.Modules.AddHandler(module); _server = new LiteServer(config); }
public Client(LiteServer server) : base(typeof(ClientChannel), new object[0], true) { this.aClient = new AClient(this); base.MultiThreadProcessing = true; this.System = new Wrapper(this); }
/// <summary> /// Initializes a basic <see cref="LiteServer{TUser}"/> with the specified <typeparamref name="TLiteServerUser"/>. /// </summary> /// <typeparam name="TLiteServerUser">Server's user type.</typeparam> /// <param name="hostBuilder">Current host builder.</param> /// <param name="builder">LiteServer builder.</param> /// <returns>The <see cref="IHostBuilder"/>.</returns> public static IHostBuilder UseLiteServer <TLiteServerUser>(this IHostBuilder hostBuilder, Action <HostBuilderContext, LiteServerBuilderOptions> builder) where TLiteServerUser : LiteServerUser { if (hostBuilder is null) { throw new ArgumentNullException(nameof(hostBuilder)); } hostBuilder.ConfigureServices((hostContext, services) => { services.AddSingleton <ILiteServer <TLiteServerUser>, LiteServer <TLiteServerUser> >(serviceProvider => { var liteServerBuilder = new LiteServerBuilderOptions(); builder(hostContext, liteServerBuilder); var configuration = new LiteServerConfiguration(liteServerBuilder.Host, liteServerBuilder.Port, liteServerBuilder.Backlog, liteServerBuilder.ClientBufferSize); var server = new LiteServer <TLiteServerUser>(configuration, liteServerBuilder.PacketProcessor, serviceProvider); return(server); }); services.AddHostedService(serviceProvider => { var serverInstance = serviceProvider.GetRequiredService <ILiteServer <TLiteServerUser> >(); return(new LiteServerHostedService <TLiteServerUser>(serverInstance)); }); }); return(hostBuilder); }
static void Main(string[] args) { LiteServer server = new LiteServer(539); server.onClientConnect += (LiteCode.Server.Client client) => { ITest test = client.aClient.GetSharedClass<ITest>("test"); Stopwatch sw = Stopwatch.StartNew(); int calls = 0; int CallsPerSec = 0; while(true) { test.TestDelegate("test", (string assd) => { }); calls++; CallsPerSec++; if(sw.ElapsedMilliseconds >= 1000) { Console.WriteLine("milliseconds: " + sw.ElapsedMilliseconds + ", calls: " + calls + ", Calls Per Sec: " + CallsPerSec); CallsPerSec = 0; sw = Stopwatch.StartNew(); } } /*test.TestDelegate(":O", new TestDel((string val) => { calls++; CallsPerSec++; if(sw.ElapsedMilliseconds > 1000) { Console.WriteLine("milliseconds: " + sw.ElapsedMilliseconds + ", calls: " + calls + ", Calls Per Sec: " + CallsPerSec); CallsPerSec = 0; sw = Stopwatch.StartNew(); } }));*/ }; Console.WriteLine("Providing remote code at port 539"); Process.GetCurrentProcess().WaitForExit(); }
static void Main(string[] args) { LiteServer server = new LiteServer(539); server.onClientConnect += (LiteCode.Server.Client client) => { ITest test = client.aClient.GetSharedClass <ITest>("test"); Stopwatch sw = Stopwatch.StartNew(); int calls = 0; int CallsPerSec = 0; while (true) { test.TestDelegate("test", (string assd) => { }); calls++; CallsPerSec++; if (sw.ElapsedMilliseconds >= 1000) { Console.WriteLine("milliseconds: " + sw.ElapsedMilliseconds + ", calls: " + calls + ", Calls Per Sec: " + CallsPerSec); CallsPerSec = 0; sw = Stopwatch.StartNew(); } } /*test.TestDelegate(":O", new TestDel((string val) => * { * calls++; * CallsPerSec++; * * if(sw.ElapsedMilliseconds > 1000) * { * Console.WriteLine("milliseconds: " + sw.ElapsedMilliseconds + ", calls: " + calls + ", Calls Per Sec: " + CallsPerSec); * CallsPerSec = 0; * sw = Stopwatch.StartNew(); * } * }));*/ }; Console.WriteLine("Providing remote code at port 539"); Process.GetCurrentProcess().WaitForExit(); }