static void WcfTest()
        {
            int threadCount = 4;
            int port        = 9999;
            int count       = 10000;
            int errorCount  = 0;

            WcfHost <IHello, Hello> wcfHost = new WcfHost <IHello, Hello>();

            wcfHost.StartHost();
            IHello client = WcfClient.GetService <IHello>("http://127.0.0.1:14725");

            client.SayHello("Hello");
            Stopwatch   watch = new Stopwatch();
            List <Task> tasks = new List <Task>();

            watch.Start();
            LoopHelper.Loop(threadCount, () =>
            {
                tasks.Add(Task.Run(() =>
                {
                    LoopHelper.Loop(count, index =>
                    {
                        var msg = client.SayHello("Hello" + index);
                        //Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:ffffff")}:{msg}");
                    });
                }));
            });
            Task.WaitAll(tasks.ToArray());
            watch.Stop();
            Console.WriteLine($"并发数:{threadCount},运行:{count}次,每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
        }
Пример #2
0
        static void WcfTest()
        {
            int count = int.MaxValue;

            WcfHost <IHello, Hello> wcfHost = new WcfHost <IHello, Hello>();

            wcfHost.StartHost();
            IHello client = WcfClient.GetService <IHello>("http://127.0.0.1:14725");

            client.SayHello("Hello");
            Stopwatch watch = new Stopwatch();

            watch.Start();
            LoopHelper.Loop(1, () =>
            {
                Task.Run(() =>
                {
                    LoopHelper.Loop(count, index =>
                    {
                        var msg = client.SayHello("Hello" + index);
                        Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:ffffff")}:{msg}");
                    });
                }).Wait();
            });
            watch.Stop();
            Console.WriteLine($"每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
        }
Пример #3
0
        static void Main(string[] args)
        {
            IHello hi = HelloFactory.GetThisPartyStarted();

            Console.WriteLine(hi.SayHello());
            Console.ReadKey();
        }
Пример #4
0
        public ActionResult Test()
        {
            IHello client = RPCClientFactory.GetClient <IHello>("127.0.0.1", 9999);
            var    res    = client.SayHello("aa");

            return(Content(res));
        }
Пример #5
0
        public void Test()
        {
            EmitHelper emit = new AssemblyBuilderHelper("HelloWorld.dll")
                              .DefineType("Hello", typeof(object), typeof(IHello))
                              .DefineMethod(typeof(IHello).GetMethod("SayHello"))
                              .Emitter;

            /*[a]*/ emit           /*[/a]*/
            // string.Format("Hello, {0}!", toWhom)
            //
            ./*[a]*/ ldstr/*[/a]*/ ("Hello, {0}!")
            ./*[a]*/ ldarg_1                   /*[/a]*/
            ./*[a]*/ call/*[/a]*/ (typeof(string), "Format", typeof(string), typeof(object))

            // Console.WriteLine("Hello, World!");
            //
            ./*[a]*/ call/*[/a]*/ (typeof(Console), "WriteLine", typeof(string))
            ./*[a]*/ ret/*[/a]*/ ()
            ;

            Type type = emit.Method.Type.Create();

            IHello hello = (IHello)TypeAccessor.CreateInstance(type);

            hello.SayHello("World");
        }
Пример #6
0
        private static async Task DoClientWork(IClusterClient client)
        {
            // example of calling grains from the initialized client
            IHello friend   = client.GetGrain <IHello>(0);
            var    response = await friend.SayHello("Good morning, my friend!");

            Console.WriteLine("\n\n{0}\n\n", response);
        }
 public void CallDependency()
 {
     if (helloservice == null)
     {
         throw new ArgumentException("hello service not available.");
     }
     helloservice.SayHello();
 }
Пример #8
0
        static void Main(string[] args)
        {
            IHello client = RPCClientFactory.GetClient <IHello>("127.0.0.1", 9999);
            var    msg    = client.SayHello("Hello");

            Console.WriteLine(msg);
            Console.ReadLine();
        }
Пример #9
0
        static void RpcTest()
        {
            int       port       = 9999;
            int       count      = 1;
            int       errorCount = 0;
            RPCServer rPCServer  = new RPCServer(port);

            rPCServer.HandleException = ex =>
            {
                Console.WriteLine(ExceptionHelper.GetExceptionAllMsg(ex));
            };
            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();
            IHello client = null;

            client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port);
            client.SayHello("aaa");
            Stopwatch   watch = new Stopwatch();
            List <Task> tasks = new List <Task>();

            watch.Start();
            LoopHelper.Loop(1, () =>
            {
                tasks.Add(Task.Run(() =>
                {
                    LoopHelper.Loop(count, () =>
                    {
                        string msg = string.Empty;
                        try
                        {
                            msg = client.SayHello("Hello");
                            Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}:{msg}");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ExceptionHelper.GetExceptionAllMsg(ex));
                        }
                    });
                }));
            });
            Task.WaitAll(tasks.ToArray());
            watch.Stop();
            Console.WriteLine($"每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
            Console.WriteLine($"错误次数:{errorCount}");
        }
Пример #10
0
        public ActionResult Index()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            IHello client = RPCClientFactory.GetClient <IHello>("127.0.0.1", 39999);

            client.SayHello("aa");
            stopwatch.Stop();
            return(Content(stopwatch.ElapsedMilliseconds.ToString()));
        }
Пример #11
0
 static void Main(string[] args)
 {
     using (ChannelFactory <IHello> channelFactoryHello = new ChannelFactory <IHello>("helloService"))
         using (ChannelFactory <IGoodbye> channelFactoryGoodbye = new ChannelFactory <IGoodbye>("goodbyeService"))
         {
             IHello   helloProxy   = channelFactoryHello.CreateChannel();
             IGoodbye goodbyeProxy = channelFactoryGoodbye.CreateChannel();
             Console.WriteLine(helloProxy.SayHello("Zhang San"));
             Console.WriteLine(goodbyeProxy.SayGoodbye("Li Si"));
         }
 }
Пример #12
0
 static void Main(string[] args)
 {
     using (ChannelFactory <IHello> helloFactory = new ChannelFactory <IHello>("helloService"))
         using (ChannelFactory <IGoodBye> goodbyeFactory = new ChannelFactory <IGoodBye>("goodbyeService"))
         {
             IHello   hello   = helloFactory.CreateChannel();
             IGoodBye goodBye = goodbyeFactory.CreateChannel();
             Console.WriteLine(hello.SayHello("z3"));
             Console.WriteLine(goodBye.SayGoodBye("w5"));
         }
     Console.Read();
 }
Пример #13
0
        public ActionResult Index()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            IHello client = RPCClientFactory.GetClient <IHello>("127.0.0.1", 39999);

            client.SayHello("aa");
            stopwatch.Stop();
            var ms = (double)stopwatch.ElapsedTicks / 10000;

            return(Content($"{ms}ms"));
        }
Пример #14
0
        public async Task SiloSayHelloTest()
        {
            long         id       = new Random().Next();
            const string greeting = "Bonjour";

            IHello grain = await Silo.CreateGrainAsync <HelloGrain>(id);

            // This will create and call a Hello grain with specified 'id' in one of the test silos.
            string reply = await grain.SayHello(greeting);

            Assert.NotNull(reply);
            Assert.Equal($"You said: '{greeting}', I say: Hello!", reply);
        }
Пример #15
0
        static void Main(string[] args)
        {
            IHello hello = null;

            string[] cities = { "Dorne", "Winterfell", "TheEyrie", "KingsLanding", "Dragonstone", "CasterlyRock" };

            foreach (string city in cities)
            {
                var type = Type.GetType(city + ".Hello" + city + "," + city);
                hello = (IHello)Activator.CreateInstance(type);
                hello.SayHello();
            }
        }
Пример #16
0
        static void Main(string[] args)
        {
            IHello client = RPCClientFactory.GetClient <IHello>("127.0.0.1", 9999);
            var    msg1   = client.SayHello("Hello1");

            Console.WriteLine(msg1);

            var msg2 = client.SayHello("Hello2");

            Console.WriteLine(msg2);

            decimal       prize        = 100.1M;
            IOrderService orderService = RPCClientFactory.GetClient <IOrderService>("127.0.0.1", 9999);
            var           sum1         = orderService.CalculateFinalOrderSum(500, prize);

            Console.WriteLine(sum1);

            var sum2 = orderService.CalculateFinalOrderSum(11000, 1000);

            Console.WriteLine(sum2);

            Console.ReadLine();
        }
Пример #17
0
        public async Task SiloSayHelloTest()
        {
            // The Orleans silo / client test environment is already set up at this point.

            long         id       = new Random().Next();
            const string greeting = "Bonjour";

            IHello grain = GrainFactory.GetGrain <IHello>(id);

            // This will create and call a Hello grain with specified 'id' in one of the test silos.
            string reply = await grain.SayHello(greeting);

            Assert.NotNull(reply);
            Assert.Equal($"You said: '{greeting}', I say: Hello!", reply);
        }
Пример #18
0
        public async Task SayHelloTest()
        {
            // The Orleans silo / client test environment is already set up at this point.

            const long   id       = 0;
            const string greeting = "Bonjour";

            IHello grain = GrainFactory.GetGrain <IHello>(id);

            // This will create and call a Hello grain with specified 'id' in one of the test silos.
            string reply = await grain.SayHello(greeting);

            Assert.IsNotNull(reply, "Grain replied with some message");
            string expected = string.Format("You said: '{0}', I say: Hello!", greeting);

            Assert.AreEqual(expected, reply, "Grain replied with expected message");
        }
Пример #19
0
        public async void NonSiloSayHelloTest()
        {
            // The mocked Orleans runtime is already set up at this point

            const long   id       = 0;
            const string greeting = "Bonjour";

            //Create a new instance of the grain. Notice this is the concrete grain type
            //that is being tested, not just the grain interface as with the silo test
            IHello grain = TestGrainFactory.CreateGrain <HelloGrain>(id);

            // This will directly call the grain under test.
            string reply = await grain.SayHello(greeting);

            Assert.NotNull(reply);
            Assert.Equal($"You said: '{greeting}', I say: Hello!", reply);
        }
Пример #20
0
        static void DotNettyRPCTest()
        {
            int       threadCount = 1;
            int       port        = 9999;
            int       count       = 10000;
            int       errorCount  = 0;
            RPCServer rPCServer   = new RPCServer(port);

            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();
            IHello client = null;

            client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port);
            client.SayHello("aaa");
            Stopwatch   watch = new Stopwatch();
            List <Task> tasks = new List <Task>();

            watch.Start();
            for (int i = 0; i < threadCount; i++)
            {
                tasks.Add(Task.Run(() =>
                {
                    for (int j = 0; j < count; j++)
                    {
                        string msg = string.Empty;
                        try
                        {
                            //msg = client.SayHello("Hello");
                            //Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff")}:{msg}");
                        }
                        catch (Exception ex)
                        {
                            errorCount++;
                            //Console.WriteLine(ExceptionHelper.GetExceptionAllMsg(ex));
                        }
                    }
                }));
            }
            Task.WaitAll(tasks.ToArray());
            watch.Stop();
            Console.WriteLine($"并发数:{threadCount},运行:{count}次,每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
            Console.WriteLine($"错误次数:{errorCount}");
        }
Пример #21
0
        public void Test()
        {
            AssemblyName asmName = new AssemblyName();

            asmName.Name = "HelloWorld";

            AssemblyBuilder asmBuilder =
                Thread.GetDomain().DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);

            ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule("HelloWorld");

            TypeBuilder typeBuilder = modBuilder.DefineType(
                "Hello",
                TypeAttributes.Public,
                typeof(object),
                new Type[] { typeof(IHello) });

            MethodBuilder methodBuilder = typeBuilder.DefineMethod("SayHello",
                                                                   MethodAttributes.Private | MethodAttributes.Virtual,
                                                                   typeof(void),
                                                                   new Type[] { typeof(string) });

            typeBuilder.DefineMethodOverride(methodBuilder, typeof(IHello).GetMethod("SayHello"));

            ILGenerator il = methodBuilder.GetILGenerator();

            // string.Format("Hello, {0} World!", toWhom)
            //
            /*[a]*/ il.Emit/*[/a]*/ (OpCodes.Ldstr, "Hello, {0} World!");
            /*[a]*/ il.Emit/*[/a]*/ (OpCodes.Ldarg_1);
            /*[a]*/ il.Emit/*[/a]*/ (OpCodes.Call, typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) }));

            // Console.WriteLine("Hello, World!");
            //
            /*[a]*/ il.Emit/*[/a]*/ (OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
            /*[a]*/ il.Emit/*[/a]*/ (OpCodes.Ret);

            Type type = typeBuilder.CreateType();

            IHello hello = (IHello)Activator.CreateInstance(type);

            hello.SayHello("Emit");
        }
Пример #22
0
        public async Task SayHelloTest()
        {
            // The Orleans silo / client test environment is already set up at this point.

            const long   id   = 0;
            const string name = "David";

            IHello grain = GrainFactory.GetGrain <IHello>(id);

            // This will create and call a Hello grain with specified 'id' in one of the test silos.
            string reply = await grain.SayHello(name);

            Console.WriteLine(reply);

            Assert.IsNotNull(reply, "Grain replied with some message");
            string expected = string.Format("Hello, David! Goodbye, David!", name);

            Assert.AreEqual(expected, reply, "Grain replied with expected message");
        }
Пример #23
0
        private static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                for (;;)
                {
                    IHello friend = ActorProxy.Create <IHello>(ActorId.NewId(), ApplicationName);
                    Console.WriteLine(@"\n\nFrom Actor {1}: {0}\n\n", friend.SayHello("Good morning!").Result, friend.GetActorId());
                    Thread.Sleep(50);
                }
            }
            else
            {
                IHello friend = ActorProxy.Create <IHello>(ActorId.NewId(), ApplicationName);
                Console.WriteLine(@"\n\nFrom Actor {1}: {0}\n\n", friend.SayHello("Good morning!").Result, friend.GetActorId());
            }

            Console.WriteLine(@"Press enter to exit ...");
            Console.ReadLine();
        }
Пример #24
0
        protected async void ButtonSayHello_Click(object sender, EventArgs e)
        {
            this.ReplyText.Text = "Talking to Orleans";

            IHello grainRef = GrainFactory.GetGrain <IHello>(0);

            try
            {
                string msg = await grainRef.SayHello(this.NameTextBox.Text);

                this.ReplyText.Text = "Orleans said: " + msg + " at " + DateTime.UtcNow + " UTC";
            }
            catch (Exception exc)
            {
                while (exc is AggregateException)
                {
                    exc = exc.InnerException;
                }

                this.ReplyText.Text = "Error connecting to Orleans: " + exc + " at " + DateTime.Now;
            }
        }
Пример #25
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILogger <Startup> logger, IHello hello)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();
            app.UseMvc(configureRoutes);

            app.Map("/test", testPipeline);
            app.Use(next => async context =>
            {
                await context.Response.WriteAsync("Before Hello: ");
                await next.Invoke(context);
            });

            app.Run(async(context) =>
            {
                logger.LogInformation("Response Served.");
                await context.Response.WriteAsync(hello.SayHello());
            });
        }
Пример #26
0
 public async Task <string> Hello()
 {
     return(await helloGrain.SayHello());
 }
Пример #27
0
        private static void runTests(IHello hello)
        {
            #region AddValue
            {
                Console.Write("  AddValue: ");
                check(5 == hello.AddValue(2, 3));
            }
            #endregion

            #region SayHello
            {
                Console.Write("  SayHello: ");
                check("Hello, Andy. It's Bob." == hello.SayHello("Andy"));
            }
            #endregion

            #region SayHello2
            {
                Console.Write("  SayHello2: ");
                string greeting;
                hello.SayHello2("Andy", out greeting);
                check("Hello, Andy. It's Bob." == greeting);
            }
            #endregion

            #region Message
            {
                Console.Write("  Message: ");
                string message = "Hello, Bob";
                bool result = hello.Message(ref message);
                check(result && ("Hello, Andy." == message));
            }
            #endregion

            #region MulComplex
            {
                Console.Write("  MulComplex: ");
                MyComplexNumber x = new MyComplexNumber(2, 3);
                MyComplexNumber y = new MyComplexNumber(5, 6);
                MyComplexNumber expected = new MyComplexNumber(x.re * y.re - x.im * y.im, x.re * y.im + x.im - y.re);

                MyComplexNumber result = hello.MulComplex(x, ref y);
                check(equal(result, expected) && equal(result, expected));
            }
            try
            {
                Console.Write("  MulComplexAsAny: ");
                MyComplexNumber x = new MyComplexNumber(2, 3);
                MyComplexNumber y = new MyComplexNumber(5, 6);
                MyComplexNumber expected = new MyComplexNumber(x.re * y.re - x.im * y.im, x.re * y.im + x.im - y.re);


                object result;
                bool success = hello.MulComplexAsAny(x, y, out result);
                MyComplexNumber complexNumber = (MyComplexNumber)result;

                check(success && equal(complexNumber, expected));
            }
            catch (System.Exception)
            {
                Console.WriteLine("__NOT RELEVANT__: Known issue with IIOP.NET marshalling <-> omniORB unmarshsalling of 'Any' type");
            }

            #endregion

            #region TimeTransfer
            {
                Console.Write("  DataTimeTransfer: ");

                DateTime dateTime = new DateTime(2016, 2, 8);
                long dataTimeValue = dateTime.ToFileTimeUtc();

                hello.DataTimeTransfer(ref dataTimeValue);

                DateTime fromServer = DateTime.FromFileTimeUtc(dataTimeValue);
                check(dateTime == fromServer);
            }
            #endregion

            #region Exception hadlers
            Console.WriteLine("  Install exceptions hadlers: Not relevant in iiop.net");
            #endregion

            #region System Exception
            try
            {
                Console.Write("  Catch NO_IMPLEMENT: ");
                hello.ThrowExceptions(0);
            }
            catch (NO_IMPLEMENT se)
            {
                check(1 == se.Minor);
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion

            #region Plain user exception
            try
            {
                Console.Write("  Catch plain user exception: ");
                hello.ThrowExceptions(1);
            }
            catch (UserExceptionS ue)
            {
                check(ue.Message.Contains("UserExceptionS"));
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion

            #region User exception with members
            try
            {
                Console.Write("  Catch user exception with members: ");
                hello.ThrowExceptions(2);
            }
            catch (UserExceptionExt ue)
            {
                check(ue.reason == "EXCEPTIONS_WORKS" && ue.codeError == 254);
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion

            #region Unknown exception
            try
            {
                Console.Write("  Catch unknown exception: ");
                hello.ThrowExceptions(4);
            }
            catch (omg.org.CORBA.UNKNOWN e)
            {
                check(e.Message.Contains("UNKNOWN"));
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion

            #region callback
            try
            {
                Console.WriteLine("  Callback: ");
                TestCallBack callback = new TestCallBack();
                check(hello.CallMe(callback) && callback.Greeting == "Hello from Server");
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion

            #region sequense
            try
            {
                Console.Write("  Sequence reversed: ");
                int[] array = { 1, 3, 5, 7, 10 };
                int[] reversed_arr = hello.Reverse(array);

                check(System.Linq.Enumerable.SequenceEqual(new int[] { 10, 7, 5, 3, 1 }, reversed_arr));
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion

            #region Pass single dimensional array
            try
            {
                Console.Write("  Pass single dimensional array: ");

                double[] x = { 1.0, 2.0, 3, 4.1};
                double[] y = { 2.0, 7.0, -0, -9};

                double[] expected = {
                    x[0] + y[0],
                    x[1] + y[1],
                    x[2] + y[2],
                    x[3] + y[3]
                };

                double[] result = hello.AddVectors(x, y);
                check(result[0] == expected[0] && result[1] == expected[1] && result[2] == expected[2] && result[3] == expected[3]);
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion

            #region Pass multi dimensional array
            try
            {
                Console.Write("  Pass multi dimensional array: ");

                double[,] x = {
                    { 1.0,  -2.0,  3, 4.1 },
                    { 2.0,   4.0, -6, 8.1 },
                    { -3.0, -5.0,  7,  -1 }
                };

                double[,] y = {
                    { 3.0,  -2.4,  3,  -0 },
                    { 6.0,   2.0, -7, 8.9 },
                    { -7.0, -1.0,  7,   1 }
                };

                double[,] expected = {
                    { x[0, 0] + y[0, 0], x[0, 1] + y[0, 1], x[0, 2] + y[0, 2], x[0, 3] + y[0, 3]},
                    { x[1, 0] + y[1, 0], x[1, 1] + y[1, 1], x[1, 2] + y[1, 2], x[1, 3] + y[1, 3]},
                    { x[2, 0] + y[2, 0], x[2, 1] + y[2, 1], x[2, 2] + y[2, 2], x[2, 3] + y[2, 3]}
                };

                double[,] result = hello.AddMatrixes(x, y);

                //check selectively
                check(result[0, 0] == expected[0, 0] && result[1,3] == expected[1, 3] && result[2, 0] == expected[2, 0] && result[2, 3] == expected[2, 3]);
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion

            #region Shutdown
            try
            {
                Console.Write("  Shutdown: ");
                hello.Shutdown();
                check(true);
            }
            catch (Exception)
            {
                check(false);
            }
            #endregion
        }
Пример #28
0
 private void ShowMessage(IHello hello)
 {
     MessageBox.Show($"{hello.SayHello()}\r\nThe answer is: {hello.AnswerEverything()}!");
 }
Пример #29
0
        public IActionResult Hello()
        {
            var hello = _iHelloService.SayHello();

            return(Ok(hello));
        }
Пример #30
0
 public void Say()
 {
     hello.SayHello();
 }