Esempio n. 1
0
        public async Task MultipleClientsWork(ChannelType type)
        {
            var proxy = await Init <ITestObject>(new TestObject(), type);

            ITestObject proxy2 = null;

            if (type == ChannelType.Tcp)
            {
                var client2 = new TcpRpcClientChannel(
                    new BinaryRpcSerializer(),
                    new RpcMessageFactory(),
                    IPAddress.Loopback,
                    11234);

                await client2.ConnectAsync();

                proxy2 = await client2.GetServerObjectAsync <ITestObject>();
            }
            else if (type == ChannelType.NamedPipe)
            {
                var client2 = new NamedPipeRpcClientChannel(
                    new BinaryRpcSerializer(),
                    new RpcMessageFactory(),
                    _pipeName);

                await client2.ConnectAsync();

                proxy2 = await client2.GetServerObjectAsync <ITestObject>();
            }



            var threads = new List <Task <bool> >();

            for (int i = 0; i < 10; i++)
            {
                int mi = i;
                threads.Add(new Task <bool>(delegate
                {
                    ITestObject pr = mi % 2 == 0 ? proxy : proxy2;

                    for (int j = 0; j < 100; j++)
                    {
                        if (pr.SimpleCalc(mi * 100, j) != mi * 100 + j)
                        {
                            return(false);
                        }
                    }
                    return(true);
                }));
            }

            foreach (var t in threads)
            {
                t.Start();
            }

            Assert.IsTrue(Task.WaitAll(threads.ToArray(), 20000));
            Assert.IsTrue(threads.TrueForAll(t => t.Result));
        }
Esempio n. 2
0
        static async Task Main(string[] args)
        {
            /*
             * var server = new TcpRpcServerChannel(
             *  new JsonRpcSerializer(),
             *  new RpcMessageFactory(),
             *  IPAddress.Loopback,
             *  11234);
             * server.ObjectRepository.RegisterSingleton(new TestObject());
             * await server.ListenAsync();*/


            /*var client = new TcpRpcClientChannel(
             *  new JsonRpcSerializer(),
             *  new RpcMessageFactory(),
             *  IPAddress.Loopback,
             *  11234);*/

            const LogLevel logLevel = LogLevel.Error;

            var client = new NamedPipeRpcClientChannel(
                new BinaryRpcSerializer(),
                new RpcMessageFactory(),
                "test",
                TokenImpersonationLevel.Impersonation,
                loggerFactory: LoggerFactory.Create(builder =>
                                                    builder
                                                    .AddFilter("AdvancedRpcLib", logLevel)
                                                    .AddConsole(o => o.LogToStandardErrorThreshold = logLevel)));

            await client.ConnectAsync(TimeSpan.FromSeconds(5));

            var testObj = await client.GetServerObjectAsync <ITestObject>();

            Console.WriteLine($"Remote user: {testObj.Username}");

            Console.WriteLine(testObj.SimpleCall());

            var sw = new Stopwatch();

            sw.Start();
            int j = 0;

            for (int i = 0; i < 1000; i++)
            {
                j += testObj.Calculate(2, 8);
            }
            sw.Stop();
            Console.WriteLine(sw.Elapsed);

            Console.ReadLine();
        }