Esempio n. 1
0
        private static void StartServer(ConnectArgs arguments)
        {
            var server          = new SocketServer(arguments.Port);
            var connectionCount = 0;
            var messageCount    = 0;

            server.Listener.OnAccept().Subscribe((s) =>
            {
                Interlocked.Increment(ref connectionCount);
                s.OnMessage().Subscribe((d) => Interlocked.Increment(ref messageCount));
            });

            Observable.Interval(TimeSpan.FromSeconds(5)).TimeInterval()
            .Subscribe(_ =>
            {
                var rate                = Interlocked.Exchange(ref messageCount, 0) / 5.0;
                var current             = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("server: Active: ");
                Console.Write(connectionCount);
                Console.Write("\tMsg/sec: ");
                Console.WriteLine(rate);
                Console.ForegroundColor = current;
            });
        }
Esempio n. 2
0
        public static TestScenario Create(ConnectArgs commandline)
        {
            string scenario = commandline.Scenario;

            if (string.IsNullOrEmpty(scenario))
            {
                throw new ArgumentNullException("scenario");
            }

            var scenarios = Assembly.GetExecutingAssembly()
                            .GetTypes()
                            .Where(t => typeof(TestScenario).IsAssignableFrom(t) && t != typeof(TestScenario) && t.IsClass)
                            .ToArray();

            var type = scenarios.FirstOrDefault(t => t.Name.EndsWith(scenario, true, CultureInfo.InvariantCulture));

            if (type == null)
            {
                Console.WriteLine("Scenario {0} not found.", scenario);
                Console.WriteLine("Available scenarios: \n");
                foreach (var name in scenarios)
                {
                    Console.WriteLine("\t" + name.Name);
                }

                return(null);
            }

            Console.WriteLine("Executing scenario:" + type.Name);
            var instance = (TestScenario)Activator.CreateInstance(type);

            instance.ConnectArguments = commandline;
            return(instance);
        }
Esempio n. 3
0
        public static TestScenario Create(ConnectArgs commandline)
        {
            string scenario = commandline.Scenario;

            if (string.IsNullOrEmpty(scenario))
            {
                throw new ArgumentNullException("scenario");
            }

            var scenarios = Assembly.GetExecutingAssembly()
                                    .GetTypes()
                                    .Where(t => typeof(TestScenario).IsAssignableFrom(t) && t != typeof(TestScenario) && t.IsClass)
                                    .ToArray();

            var type = scenarios.FirstOrDefault(t => t.Name.EndsWith(scenario, true, CultureInfo.InvariantCulture));
            if (type == null)
            {
                Console.WriteLine("Scenario {0} not found.", scenario);
                Console.WriteLine("Available scenarios: \n");
                foreach (var name in scenarios)
                {
                    Console.WriteLine("\t" + name.Name);
                }

                return null;
            }

            Console.WriteLine("Executing scenario:" + type.Name);
            var instance = (TestScenario)Activator.CreateInstance(type);
            instance.ConnectArguments = commandline;
            return instance;
        }
Esempio n. 4
0
 public static bool IsServer(this ConnectArgs args)
 {
     return(String.Compare("server", args.Mode, true, CultureInfo.InvariantCulture) == 0);
 }
Esempio n. 5
0
 public static string CreateNetTcpAddress(this ConnectArgs args)
 {
     return("net.tcp://" + args.Server + ":" + args.Port);
 }
Esempio n. 6
0
 public ClientManager(ConnectArgs arguments)
 {
     this.arguments = arguments;
 }