Beispiel #1
0
        static async Task Run()
        {
            var client = new JsonHCS(new JsonHCS_Settings()
            {
                Timeout = 10000, ThrowOnFail = true, CatchErrors = false, AddJsonAcceptHeaders = true
            });
            JsonHCSProxyGenerator pg = new JsonHCSProxyGenerator(client, new SignalRPlugin(), new ActionResultPlugin(), new BasicPlugin());
            var proxy = pg.CreateClassProxy <ValuesController>("http://localhost:5000/");
            await Task.Delay(5000);

            for (int o = 0; o < 4; o++)
            {
                //Proxy speed comparison:
                Stopwatch s = new Stopwatch();
                s.Start();
                for (int i = 0; i < 400; i++)
                {
                    var all = await client.GetJsonAsync <IEnumerable <string> >("http://localhost:5000/api/values");

                    //Console.WriteLine(all.Count());
                    var one = await client.GetJsonAsync("http://localhost:5000/api/values/2");

                    //Console.WriteLine(one);
                    await client.PostAsync("http://localhost:5000/api/values", "Value");

                    //Console.WriteLine("Done");
                }
                s.Stop();
                Console.WriteLine("Direct:");
                Console.WriteLine(s.ElapsedMilliseconds);
                s.Reset();
                s.Start();
                for (int i = 0; i < 400; i++)
                {
                    var allrequest = await proxy.Get();

                    if (allrequest.IsSuccess)
                    {
                        var all = await allrequest.GetResultAsync();

                        //Console.WriteLine(all.Count());
                    }
                    var one = await(await proxy.Get(2)).GetResultAsync();
                    //Console.WriteLine(one);
                    var post = await proxy.Post("Value");

                    //Console.WriteLine(post.IsSuccess ? "Done" : "Failed");
                }
                s.Stop();
                Console.WriteLine("Proxy:");
                Console.WriteLine(s.ElapsedMilliseconds);
            }

            //SignalR plugin demo:
            var api = pg.CreateClassProxy <API>("http://localhost:5000/");
            var hub = await api.Connect();

            hub.On.Receive += On_Receive;
            var received = 0;

            using (hub.On.Message.Subscribe(s => { Console.WriteLine($"{DateTime.Now.TimeOfDay}: Subscription was updated to: {s}"); received++; }, () => Console.WriteLine($"{DateTime.Now.TimeOfDay}: Subscription closed!")))
            {
                Console.WriteLine($"{DateTime.Now.TimeOfDay}: Sending Test 1");
                await hub.Send.Broadcast("Test 1");

                Console.WriteLine($"{DateTime.Now.TimeOfDay}: Sending Test 2");
                await hub.Send.Broadcast("Test 2");

                Console.WriteLine($"{DateTime.Now.TimeOfDay}: Sending Test 3");
                await hub.Send.Broadcast("Test 3");

                while (received < 3)
                {
                    await Task.Delay(10);
                }
            }
        }
Beispiel #2
0
        API GetTestAPI()
        {
            JsonHCSProxyGenerator gen = new JsonHCSProxyGenerator(GetJsonHCS());

            return(gen.CreateClassProxy <API>("https://jsonplaceholder.typicode.com/"));
        }