static void SocketTest()
        {
            int             count  = 1000;
            int             port   = 11111;
            Stopwatch       watch  = new Stopwatch();
            TcpSocketServer server = new TcpSocketServer(port);

            server.HandleRecMsg = (a, b, c) =>
            {
                b.Send(c);
            };
            server.StartServer();
            watch.Start();
            LoopHelper.Loop(count, () =>
            {
                //AutoResetEvent waitEvent = new AutoResetEvent(false);
                TcpSocketClient tcpSocketClient = new TcpSocketClient(port);
                tcpSocketClient.HandleRecMsg    = (a, b) =>
                {
                    Console.WriteLine($"收到时间:{DateTime.Now.ToString("HH:mm:ss:ffffff")}");
                    //waitEvent.Set();
                };
                tcpSocketClient.StartClient();
                Console.WriteLine($"发送时间:{DateTime.Now.ToString("HH:mm:ss:ffffff")}");
                tcpSocketClient.Send(new byte[] { 0X01 });
                //waitEvent.WaitOne();
                Thread.Sleep(1000);
            });
            watch.Stop();
            Console.WriteLine($"每次耗时:{(double)watch.ElapsedMilliseconds / count}ms");
        }
        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");
        }
示例#3
0
        static void Main(string[] args)
        {
            int port  = 11111;
            int count = 1;

            RPCServer rPCServer = new RPCServer(port);

            rPCServer.RegisterService <IHello, Hello>();
            rPCServer.Start();
            Stopwatch watch = new Stopwatch();

            var client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port);

            client.SayHello("Hello");

            watch.Start();
            LoopHelper.Loop(count, () =>
            {
                var res = client.SayHello("Hello");
                //Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")}客户端:{res}");
            });
            watch.Stop();

            Console.WriteLine($"耗时:{(double)watch.ElapsedMilliseconds/count}ms");

            Console.ReadLine();
        }
示例#4
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");
        }
        static void Main(string[] args)
        {
            Action <Exception> handleException = ex =>
            {
                Console.WriteLine(ex.Message);
            };
            int       port      = 9999;
            int       count     = 1000000;
            RPCServer rPCServer = new RPCServer(port);

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

            watch.Start();
            LoopHelper.Loop(count, () =>
            {
                client = RPCClientFactory.GetClient <IHello>("127.0.0.1", port);
            });
            watch.Stop();

            //var res = client.SayHello("Hello");
            //Console.WriteLine($"客户端:{res}");

            Console.WriteLine($"耗时:{watch.ElapsedMilliseconds}ms");

            Console.ReadLine();
            Console.WriteLine("完成");
            Console.ReadLine();
        }
示例#6
0
        public static void Execute(object obj)
        {
            var haoshenyin = (HaoShengYinObj)obj;

            LoopHelper.Count(50).Execute(() =>
            {
                var response = WxHttpRequestHelper.Get(haoshenyin.Url, haoshenyin.CookieStr);
                Console.WriteLine(response);
                Thread.Sleep(700);
            });
        }
示例#7
0
        public static void BaoJieExecute(object obj)
        {
            LoopHelper.Count(10).Execute(
                () =>
            {
                var baojieObj = (BaojieObj)obj;

                var url       = "http://app.weibopie.com/wxapp/LivingartistApp/www/index.php?a=CRFRedHire&m=sendWhich";
                var cookieStr = "BIGipServerpool_qiye=1510320320.20480.0000";

                var valueDict = new Dictionary <string, string>
                {
                    { "openid", baojieObj.OpenId },
                    { "passCode", "8096" }
                };
                //"ocJOVjs1avvXyOMIQXmzZyqiG1Kg"
                var headerList = new List <string>
                {
                    "Origin: http://app.weibopie.com",
                    baojieObj.Referer,
                    "Content-Type: application/x-www-form-urlencoded; charset=UTF-8"
                };

                var response = WxHttpRequestHelper.Post(url, valueDict, headerList, cookieStr);
                Console.WriteLine(response);

                LoopHelper.Count(2).Execute(() =>
                {
                    var getUrl =
                        "http://app.weibopie.com/wxapp/LivingartistApp/www/index.php?a=CRFRedHire&m=scoreNotice&openid=" +
                        baojieObj.OpenId;

                    var headerList2 = new List <string>
                    {
                        "Origin: http://app.weibopie.com",
                        baojieObj.Referer,
                        "Content-Type: application/x-www-form-urlencoded; charset=UTF-8"
                    };

                    var response2 = WxHttpRequestHelper.Get(getUrl, cookieStr, headerList2);
                    Console.WriteLine(response2);
                    Thread.Sleep(700);
                });
            }
                );
        }
示例#8
0
        public ActionResult GetChartData()
        {
            double length = 0;
            LinkedList <double> pointList = new LinkedList <double>();
            List <double>       rate      = new List <double>(10);

            LoopHelper.Loop(10, () =>
            {
                rate.Add(0);
            });
            double minutes = 60;
            double count   = 10.0 * 60 * 1000000 / 10;

            for (double i = 0; i < count; i++)
            {
                double s = 0.5861 * 1;
                length = length + s;
                double x = 0;
                if ((length / 20) % 1 < 0.5)
                {
                    x = length % 10;
                }
                else
                {
                    x = 10 - (length % 10);
                }
                rate[(int)x]++;
            }

            List <string> xData = new List <string>();
            List <double> yData = new List <double>();

            rate.ForEach((aValue, index) =>
            {
                xData.Add((index + 0.5).ToString());
                yData.Add(aValue);
            });
            var resData = new
            {
                XData = xData,
                YData = yData
            };

            return(Content(resData.ToJson()));
        }
示例#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
        static void Main(string[] args)
        {
            Base_UserBusiness base_UserBusiness = new Base_UserBusiness();
            List <Base_User>  insertList        = new List <Base_User>();

            LoopHelper.Loop(20, index =>
            {
                insertList.Add(new Base_User
                {
                    Id       = GuidHelper.GenerateKey(),
                    UserId   = GuidHelper.GenerateKey(),
                    UserName = $"名字{index}",
                    RealName = $"名字{index}"
                });
            });
            base_UserBusiness.Insert(insertList);

            Console.WriteLine("完成");
            Console.ReadLine();
        }