Ejemplo n.º 1
0
 public UnionAtomicCounterService Create(TransportProtocolType type)
 {
     if (cache.TryGetValue(type, out var service))
     {
         return(service);
     }
     else
     {
         var serviceNew = new UnionAtomicCounterService();
         cache.TryAdd(type, serviceNew);
         return(serviceNew);
     }
 }
Ejemplo n.º 2
0
        public static int MainInner()
        {
            DisplayTitle();

            var CmdLine = CommandLine.GetCmdLine();

            var UseOld             = false;
            var UseLoadTest        = false;
            var UsePerformanceTest = false;
            var UseStableTest      = false;

            foreach (var opt in CmdLine.Options)
            {
                if ((opt.Name.ToLower() == "?") || (opt.Name.ToLower() == "help"))
                {
                    DisplayInfo();
                    return(0);
                }
                else if (opt.Name.ToLower() == "old")
                {
                    UseOld = true;
                }
                else if (opt.Name.ToLower() == "load")
                {
                    UseLoadTest = true;
                }
                else if (opt.Name.ToLower() == "perf")
                {
                    UsePerformanceTest = true;
                }
                else if (opt.Name.ToLower() == "stable")
                {
                    UseStableTest = true;
                }
            }

            var argv = CmdLine.Arguments;
            TransportProtocolType     TransportProtocolType     = TransportProtocolType.Tcp;
            SerializationProtocolType SerializationProtocolType = SerializationProtocolType.Binary;
            int DefaultPort = 8001;

            if (argv.Length >= 1)
            {
                TransportProtocolType = (TransportProtocolType)Enum.Parse(typeof(TransportProtocolType), argv[0], true);
            }
            if (TransportProtocolType == TransportProtocolType.Tcp)
            {
                if (argv.Length >= 2)
                {
                    SerializationProtocolType = (SerializationProtocolType)Enum.Parse(typeof(SerializationProtocolType), argv[1], true);
                }
                if (SerializationProtocolType == SerializationProtocolType.Binary)
                {
                    DefaultPort = 8001;
                }
                else if (SerializationProtocolType == SerializationProtocolType.Json)
                {
                    DefaultPort = 8002;
                }
            }
            else if (TransportProtocolType == TransportProtocolType.Udp)
            {
                if (argv.Length >= 2)
                {
                    SerializationProtocolType = (SerializationProtocolType)Enum.Parse(typeof(SerializationProtocolType), argv[1], true);
                }
                if (SerializationProtocolType == SerializationProtocolType.Binary)
                {
                    DefaultPort = 8001;
                }
                else if (SerializationProtocolType == SerializationProtocolType.Json)
                {
                    DefaultPort = 8002;
                }
            }

            if (TransportProtocolType == TransportProtocolType.Tcp)
            {
                IPEndPoint RemoteEndPoint;
                if (argv.Length == 4)
                {
                    RemoteEndPoint = new IPEndPoint(IPAddress.Parse(argv[2]), int.Parse(argv[3]));
                }
                else if (argv.Length == 2)
                {
                    RemoteEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), DefaultPort);
                }
                else if (argv.Length == 0)
                {
                    RemoteEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), DefaultPort);
                }
                else
                {
                    DisplayInfo();
                    return(-1);
                }

                if (UseLoadTest)
                {
                    LoadTest.DoTestTcp(RemoteEndPoint, SerializationProtocolType);
                }
                else if (UsePerformanceTest)
                {
                    PerformanceTest.DoTestTcp(RemoteEndPoint, SerializationProtocolType);
                }
                else if (UseStableTest)
                {
                    StableTest.DoTestTcp(RemoteEndPoint, SerializationProtocolType);
                }
                else
                {
                    RunTcp(RemoteEndPoint, SerializationProtocolType, UseOld);
                }
            }
            else if (TransportProtocolType == TransportProtocolType.Udp)
            {
                IPEndPoint RemoteEndPoint;
                if (argv.Length == 4)
                {
                    RemoteEndPoint = new IPEndPoint(IPAddress.Parse(argv[2]), int.Parse(argv[3]));
                }
                else if (argv.Length == 2)
                {
                    RemoteEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), DefaultPort);
                }
                else
                {
                    DisplayInfo();
                    return(-1);
                }

                if (UseLoadTest)
                {
                    LoadTest.DoTestUdp(RemoteEndPoint, SerializationProtocolType);
                }
                else if (UsePerformanceTest)
                {
                    PerformanceTest.DoTestUdp(RemoteEndPoint, SerializationProtocolType);
                }
                else if (UseStableTest)
                {
                    StableTest.DoTestTcp(RemoteEndPoint, SerializationProtocolType);
                }
                else
                {
                    RunUdp(RemoteEndPoint, SerializationProtocolType, UseOld);
                }
            }
            else if (TransportProtocolType == TransportProtocolType.Http)
            {
                String UrlPrefix          = "http://localhost:8003/api/";
                String ServiceVirtualPath = "q";
                if (argv.Length == 3)
                {
                    UrlPrefix          = argv[1];
                    ServiceVirtualPath = argv[2];
                }
                else if (argv.Length == 1)
                {
                }
                else
                {
                    DisplayInfo();
                    return(-1);
                }

                if (UseLoadTest)
                {
                    LoadTest.DoTestHttp(UrlPrefix, ServiceVirtualPath);
                }
                else if (UsePerformanceTest)
                {
                    PerformanceTest.DoTestHttp(UrlPrefix, ServiceVirtualPath);
                }
                else if (UseStableTest)
                {
                    StableTest.DoTestHttp(UrlPrefix, ServiceVirtualPath);
                }
                else
                {
                    RunHttp(UrlPrefix, ServiceVirtualPath, UseOld);
                }
            }
            else
            {
                DisplayInfo();
                return(-1);
            }

            return(0);
        }