/// <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);
        }
示例#2
0
        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();
        }
示例#3
0
        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);
        }
示例#4
0
 public Client(LiteServer server)
     : base(typeof(ClientChannel), new object[0], true)
 {
     this.aClient = new AClient(this);
     base.MultiThreadProcessing = true;
     this.System = new Wrapper(this);
 }
示例#5
0
        /// <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);
        }
示例#6
0
        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();
        }
示例#7
0
        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();
        }
        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);
        }