Example #1
0
        protected override async Task OnHandlerAsync(ParameterHandlerInfo info)
        {
            var serializer = new NBinarySerializer();
            var service    = new SampleProvider();

            Core.Log.InfoBasic("Setting RPC Server");
            var rpcServer = new RPCServer(new DefaultTransportServer(20050, serializer));

            rpcServer.AddService(typeof(ISampleProvider), service);
            await rpcServer.StartAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("Setting RPC Client");
            var rpcClient = new RPCClient(new DefaultTransportClient("127.0.0.1", 20050, 1, serializer));

            var hClient = await rpcClient.CreateDynamicProxyAsync <ISampleProvider>().ConfigureAwait(false);

            var client = hClient.ActAs <ISampleProvider>();

            Core.Log.InfoBasic("GetSampleAsync");
            var sampleTsk = await client.GetSampleAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("DelayTestAsync");
            await client.DelayTestAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("GetSample");
            var sample = client.GetSample();

            Core.Log.InfoBasic("GetSample as Async");
            var sampleSimAsync = ((dynamic)hClient).GetSample2Async().Result;

            var pClient = await rpcClient.CreateProxyAsync <SampleProxy>().ConfigureAwait(false);

            Core.Log.InfoBasic("GetSampleAsync");
            var sampleTsk2 = await pClient.GetSampleAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("DelayTestAsync");
            await pClient.DelayTestAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("GetSample");
            var sample2 = pClient.GetSample();

            rpcClient.Dispose();
            await rpcServer.StopAsync().ConfigureAwait(false);
        }
Example #2
0
        protected override async Task OnHandlerAsync(ParameterHandlerInfo info)
        {
            var serializer = new NBinarySerializer();
            var service    = new SampleProvider();

            Core.Log.InfoBasic("Setting RPC Server");
            var rpcServer = new RPCServer(new DefaultTransportServer(20050, serializer));

            rpcServer.AddService(typeof(ISampleProvider), service);
            await rpcServer.StartAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("Setting RPC Client");
            var rpcClient = new RPCClient(new DefaultTransportClient("127.0.0.1", 20050, 1, serializer));

            var hClient = await rpcClient.CreateDynamicProxyAsync <ISampleProvider>().ConfigureAwait(false);

            var client = hClient.ActAs <ISampleProvider>();

            double perItemMs;

            try
            {
                var intEnumerable = await client.GetInt().ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Core.Log.Write(ex);
            }

            using (var watch = Watch.Create("GetSampleAsync"))
            {
                Sample res;
                for (var i = 0; i < 100000; i++)
                {
                    res = await client.GetSampleAsync().ConfigureAwait(false);
                }
                perItemMs = watch.GlobalElapsedMilliseconds / 100000;
            }
            Core.Log.InfoBasic($"GetSampleAsync per item: {perItemMs}ms");
            Console.ReadLine();

            Core.Log.InfoBasic("DelayTestAsync");
            await client.DelayTestAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("GetSample");
            var sample = client.GetSample();

            Core.Log.InfoBasic("GetSample as Async");
            var sampleSimAsync = ((dynamic)hClient).GetSample2Async().Result;

            Console.ReadLine();

            var pClient = await rpcClient.CreateProxyAsync <SampleProxy>().ConfigureAwait(false);

            using (var watch = Watch.Create("GetSampleAsync"))
            {
                Sample res;
                for (var i = 0; i < 100000; i++)
                {
                    res = await pClient.GetSampleAsync().ConfigureAwait(false);
                }
                perItemMs = watch.GlobalElapsedMilliseconds / 100000;
            }
            Core.Log.InfoBasic($"GetSampleAsync per item: {perItemMs}ms");
            Console.ReadLine();

            Core.Log.InfoBasic("DelayTestAsync");
            await pClient.DelayTestAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("GetSample");
            var sample2 = pClient.GetSample();

            rpcClient.Dispose();
            await rpcServer.StopAsync().ConfigureAwait(false);
        }
Example #3
0
        protected override async Task OnHandlerAsync(ParameterHandlerInfo info)
        {
            Core.Log.Warning("Starting RPC TEST");

            var serializer = new NBinarySerializer();
            var service    = new MyService();

            Core.Log.InfoBasic("Setting RPC Server");
            var rpcServer = new RPCServer(new DefaultTransportServer(20050, serializer));

            rpcServer.AddService(service);
            await rpcServer.StartAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("Setting RPC Client");
            var rpcClient = new RPCClient(new DefaultTransportClient("127.0.0.1", 20050, 1, serializer));

            var sw = Stopwatch.StartNew();

            //IHello test
            Core.Log.InfoBasic("IHello test");
            dynamic hClient = await rpcClient.CreateDynamicProxyAsync <IHello>().ConfigureAwait(false);

            var rtest = (string)hClient.SayHi("MyName");

            using (var watch = Watch.Create("IHello Time - SayHi | TestAsync"))
            {
                for (var i = 0; i < 5000; i++)
                {
                    var rHClient = (string)hClient.SayHi("MyName");
                }

                for (var i = 0; i < 5000; i++)
                {
                    var rHClient = await((Task <object>)hClient.TestAsync()).ConfigureAwait(false);
                }

                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 10000);
            }


            //IMyService test
            Core.Log.InfoBasic("IMyService test");
            dynamic dClient = await rpcClient.CreateDynamicProxyAsync <IMyService>().ConfigureAwait(false);

            using (var watch = Watch.Create("IMyService Time - GetAllAsync"))
            {
                for (var i = 0; i < 5000; i++)
                {
                    var aLst = await((Task <object>)dClient.GetAllAsync()).ConfigureAwait(false);
                }
                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 5000);
            }

            //Proxy class test
            Core.Log.InfoBasic("Proxy class test");
            var client = await rpcClient.CreateProxyAsync <MyServiceProxy>().ConfigureAwait(false);

            using (var watch = Watch.Create("Proxy class Time - GetAllAsync"))
            {
                for (var i = 0; i < 5000; i++)
                {
                    var resp = await client.GetAllAsync().ConfigureAwait(false);
                }
                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 5000);
            }

            using (var watch = Watch.Create("Parallel GetAllAsync Time"))
            {
                var rAwait = await Enumerable.Range(0, 50)
                             .Select(i => client.GetAllAsync())
                             .ConfigureAwait(false);

                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 100);
            }

            //Event test
            Core.Log.InfoBasic("Event test");
            using (var watch = Watch.Create("Event Test - AddSimplePersona"))
            {
                client.OnAddSimplePersona += (s, e) =>
                {
                    //Core.Log.Warning("On Add SimplePersona was fired!!!");
                };
                for (var i = 0; i < 5000; i++)
                {
                    client.AddSimplePersona(new SimplePerson {
                        Lastname = "Test", Firstname = "Test"
                    });
                }
                Core.Log.InfoBasic("Per Item: {0}", watch.GlobalElapsedMilliseconds / 5000);
            }

            var sTime = sw.Elapsed;

            Console.ReadLine();
            Core.Log.Warning("All Rpc Requests on: {0}", sTime);
            rpcClient.Dispose();
            await rpcServer.StopAsync().ConfigureAwait(false);

            Core.Log.InfoBasic("Test End.");
        }