Exemplo n.º 1
0
 static void Main(string[] args)
 {
     client = new XRPCClient("localhost", 9090);
     client.Options.ParameterFormater = new JsonPacket();//default messagepack
     henry = client.Create <IAmount>("henry");
     ken   = client.Create <IAmount>("ken");
     Test();
     Console.Read();
 }
Exemplo n.º 2
0
        static async void Test(int concurrent, int requests)
        {
            mCount = 0;
            IAmountService henry = client.Create <IAmountService>("henry");
            IAmountService ken   = client.Create <IAmountService>("ken");

            Console.WriteLine($"[C:{concurrent}|R:{requests}]Testing ");
            List <Task> tasks = new List <Task>();
            double      start = BeetleX.TimeWatch.GetElapsedMilliseconds();

            for (int i = 0; i < concurrent; i++)
            {
                var task = Task.Run(async() =>
                {
                    for (int k = 0; k < requests; k++)
                    {
                        await henry.Income(10);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
                task = Task.Run(async() =>
                {
                    for (int k = 0; k < requests; k++)
                    {
                        await henry.Payout(10);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
                task = Task.Run(async() =>
                {
                    for (int k = 0; k < requests; k++)
                    {
                        await ken.Income(10);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
                task = Task.Run(async() =>
                {
                    for (int k = 0; k < requests; k++)
                    {
                        await ken.Payout(10);
                        System.Threading.Interlocked.Increment(ref mCount);
                    }
                });
                tasks.Add(task);
            }
            await Task.WhenAll(tasks.ToArray());

            double useTime = BeetleX.TimeWatch.GetElapsedMilliseconds() - start;

            Console.WriteLine($"Completed count:{mCount}|use time:{useTime}|rps:{(mCount / useTime * 1000d):###.00} |henry:{await henry.Get()},ken:{await ken.Get()}");
        }
Exemplo n.º 3
0
        static async void Test()
        {
            var api     = client.Create <IUserService>();
            var lresult = await api.Login("admin", "123456");

            Console.WriteLine(lresult);
            var result = await api.Add("henry", "*****@*****.**", "gz", "http://github.com");

            Console.WriteLine($"{result.Name}\t{result.EMail}\t{result.City}\t{result.Remark}");
            await api.Save();

            Console.WriteLine("save completed");
            User user = new User();

            user.ID     = Guid.NewGuid().ToString("N");
            user.Name   = "henry";
            user.EMail  = "*****@*****.**";
            user.City   = "GuangZhou";
            user.Remark = "http://github.com/ikende";
            result      = await api.Modify(user);

            Console.WriteLine($"{result.Name}\t{result.EMail}\t{result.City}\t{result.Remark}");
            var items = await api.List(5);

            foreach (var item in items)
            {
                Console.WriteLine($"{item.Name}\t{item.EMail}\t{item.City}\t{item.Remark}");
            }
        }
Exemplo n.º 4
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     XRPCClient = new XRPCClient("localhost", 9090, "test");
     XRPCClient.CertificateValidationCallback = (s, certificate, chain, sslPolicyErrors) => true;
     XRPCClient.Options.ParameterFormater     = new JsonPacket();
     dataService = XRPCClient.Create <IDataService>();
 }
Exemplo n.º 5
0
 static void Main(string[] args)
 {
     client = new XRPCClient("localhost", 9090);
     client.Options.ParameterFormater = new JsonPacket();//default messagepack
     dataService = client.Create <IDataService>();
     Test();
     Console.Read();
 }
Exemplo n.º 6
0
 static void Main(string[] args)
 {
     client = new XRPCClient("localhost", 9090, "test");
     client.CertificateValidationCallback = (s, certificate, chain, sslPolicyErrors) => true;
     client.Options.ParameterFormater     = new JsonPacket();//default messagepack
     dataService = client.Create <IDataService>();
     Test();
     Console.Read();
 }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            client          = new XRPCClient("192.168.2.18", 9090);
            client.PingTime = 5;
            client.Options.ParameterFormater = new JsonPacket();
            client.Register <IUser>(new Program());
            var user = client.Create <IUser>();

            user.Login("henry");
            System.Threading.Thread.Sleep(-1);
        }
Exemplo n.º 8
0
 static void Main(string[] args)
 {
     client = new XRPCClient("localhost", 9090);
     client.Connect();
     client.NetError = (c, e) =>
     {
         Console.WriteLine(e.Error.Message);
     };
     client.TimeOut = 10000;
     UserService    = client.Create <IUserService>();
     Test();
     Console.Read();
 }
Exemplo n.º 9
0
        static async void Hello()
        {
            var service = client.Create <IHelloWorld>();

            while (true)
            {
                Console.Write("enter name:");
                string name   = Console.ReadLine();
                var    result = await service.Hello(name);

                Console.WriteLine(result);
            }
        }
Exemplo n.º 10
0
        static async Task Main(string[] args)
        {
            client = new XRPCClient("localhost", 9090);
            client.Options.ParameterFormater = new JsonPacket();//default messagepack
            hello = client.Create <IHello>();
            while (true)
            {
                Console.Write("Enter you name:");
                var name   = Console.ReadLine();
                var result = await hello.Hello(name);

                Console.WriteLine(result);
            }
            Console.Read();
        }
Exemplo n.º 11
0
 public MainPage()
 {
     InitializeComponent();
     //定义XRPC SSL客户端
     mClient = new XRPCClient("192.168.1.18", 9090, "beetlex");
     mClient.CertificateValidationCallback = (s, certificate, chain, sslPolicyErrors) => true;
     mClient.Options.ParameterFormater     = new JsonPacket();
     //创建接口远程调用代理
     mUser = mClient.Create <IUser>();
     //定义委托给服务端调用
     mClient.AddDelegate <Func <Task <string> > >(() =>
     {
         return(Task.FromResult($"{Environment.OSVersion} {DateTime.Now}"));
     });
     //创建对应服务端的远程委托代理
     mGetTime = mClient.Delegate <Func <Task <string> > >();
 }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            BufferPool.BUFFER_SIZE = 1024 * 32;
            client          = new XRPCClient("192.168.2.19", 9090, 1);
            client.NetError = (c, e) =>
            {
                Console.WriteLine(e.Error.Message);
            };
            client.TimeOut = 10000;
            UserService    = client.Create <IUserService>();
            int thread = 1;

            if (args != null && args.Length > 0)
            {
                thread = int.Parse(args[0]);
            }
            Test(thread);
            while (true)
            {
                System.Threading.Thread.Sleep(1000);
                Console.WriteLine($"{DateTime.Now} {mCount:000,000,000,000}/RPS:{mCount - mLastCount:###,###,###}");
                mLastCount = mCount;
            }
        }
Exemplo n.º 13
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Random random = new Random();

            _client         = new XRPCClient("127.0.0.1", 9090);
            _client.TimeOut = 10000;
            _client.Connect();
            _client.NetError = (c, e) =>
            {
                Console.WriteLine(e.Error.Message);
            };
            var service = _client.Create <IHelloWorld>();

            while (true)
            {
                var result = await service.Hello();

                Console.WriteLine(result + "  " + DateTime.Now.ToString("s"));
                Thread.Sleep(random.Next(100));
            }

            Console.ReadKey();
        }
Exemplo n.º 14
0
 static XRPCHandler()
 {
     Client = new XRPCClient(Setting.SERVER_HOST, 50052, 3);
     Client.Connect();
     Greeter = Client.Create <XRPCModule.IGreeter>();
 }
Exemplo n.º 15
0
 public XRPCHandler()
 {
     Client = new XRPCClient("192.168.2.19", 9013, 3);
     Client.Connect();
     UserService = Client.Create <IUserService>();
 }
Exemplo n.º 16
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     XRPCClient = new XRPCClient("localhost", 9090);
     XRPCClient.Options.ParameterFormater = new JsonPacket();
     dataService = XRPCClient.Create <IDataService>();
 }
Exemplo n.º 17
0
 public XRPCHandler()
 {
     Client = new XRPCClient("192.168.2.19", 50052, 3);
     Client.Connect();
     Greeter = Client.Create <XRPCModule.IGreeter>();
 }