Example #1
0
        public void RegisterDuplicatedCommand_ArgumentException()
        {
            TcpAppServer server = new TcpAppServer();

            server.RegisterCommand("DummyCommand", "Dummy", null);
            Assert.Throws <ArgumentException>(() => { server.RegisterCommand("dummycommand", "Dummy", null); });
        }
Example #2
0
        public void Setup()
        {
            Server = new TcpAppServer();
            Server.Start(25000);
            Server.ClientSignedIn   += Server_ClientSignedIn;
            Server.ClientSigningOut += Server_ClientSigningOut;
            Server.RegisterCommand("Custom_1", "Custom Command.", Custom1Callback);
            Server.RegisterQueuedCommand("Delay", "Custom Delay", (TcpAppInputCommand sender) =>
            {
                //Each connection execute command from different thread
                int delay = Convert.ToInt32(sender.Command.Parameter("duration").Value);
                //TestContext.Progress.WriteLine(sender.Command.Parameter("client").Value + " Sleep " + delay.ToString());
                Thread.Sleep(delay);
                sender.Status        = TcpAppCommandStatus.OK;
                sender.OutputMessage = "Delay Tick";
            },
                                         TcpAppParameter.CreateParameter("client", "client name"),
                                         TcpAppParameter.CreateParameter("duration", "Duration in ms"));
            Server.RegisterCommand("DelayNoQueue", "Custom Delay", (TcpAppInputCommand sender) =>
            {
                //Each connection execute command from different thread
                int delay = Convert.ToInt32(sender.Command.Parameter("duration").Value);
                //TestContext.Progress.WriteLine(sender.Command.Parameter("client").Value + " Sleep " + delay.ToString());
                Thread.Sleep(delay);
                sender.Status        = TcpAppCommandStatus.OK;
                sender.OutputMessage = "MAIN";
            },
                                   TcpAppParameter.CreateParameter("client", "client name"),
                                   TcpAppParameter.CreateParameter("duration", "Duration in ms"));
            Server.RegisterPluginType(typeof(TcpAppServerSimpleMath));


            Client = new TcpAppClient("localhost", 25000);
            Tcp    = new TcpClient("localhost", 25000);
        }
        public void RegisterDuplicatedCommand_ArgumentException()
        {
            TcpAppServer server = new TcpAppServer(null);

            server.RegisterCommand("DummyCommand", "Dummy", null);
            server.RegisterCommand("dummycommand", "Dummy", null);
        }
Example #4
0
        public Form1()
        {
            InitializeComponent();
            Server = new TcpServer();
            Server.ServerStarted        += Server_StateChanged;
            Server.ServerStopped        += Server_StateChanged;
            Server.ClientConnected      += Server_ClientConnected;
            Server.ClientDisconnected   += Server_ClientDisconnected;
            propertyGrid1.SelectedObject = Server;

            AppServer = new TcpAppServer(this);
            AppServer.WelcomeMessage      = "Welcome to TCP Application Server. Copyright (C) Code Art Engineering.";
            AppServer.ClientConnected    += AppServer_ClientConnected;
            AppServer.ClientDisconnected += AppServer_ClientDisconnected;


            //TCP Application Server Customization Test
            AppServer.RegisterCommand("CustomFunction", "Dummy Custom Function", customFunctionCallback);
            AppServer.RegisterCommand("CustomFunction2", "Dummy Custom Function with Parameter", customFunction2Callback,
                                      new TcpAppParameter("P1", "Parameter 1"),
                                      new TcpAppParameter("P2", "Parameter 2, optional.", "10"));

            CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin SamplePlugin = new CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin();
            AppServer.RegisterPluginType("SamplePlugin", typeof(CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin));

            propertyGrid2.SelectedObject = AppServer;
        }
Example #5
0
        public void RegisterCommandWithParameterArray()
        {
            TcpAppServer server = new TcpAppServer();

            server.RegisterCommand("DummyCommand", "Dummy", null,
                                   TcpAppParameter.CreateParameter("P1", "Param 1"),
                                   TcpAppParameter.CreateParameter("P2", "Param 2"),
                                   TcpAppParameter.CreateParameterArray("PArr1", "Array Param 1", true)
                                   );
        }
Example #6
0
        public void RegisterCommandWithParameterArray_ArrayNotLastParam_ArgumentException()
        {
            TcpAppServer server = new TcpAppServer();

            Assert.Throws <ArgumentException>(() =>
            {
                server.RegisterCommand("DummyCommand", "Dummy", null,
                                       TcpAppParameter.CreateParameter("P1", "Param 1"),
                                       TcpAppParameter.CreateParameterArray("PArr1", "Array Param 1", true),
                                       TcpAppParameter.CreateParameter("P2", "Param 2")
                                       );
            });
        }
Example #7
0
        public Form1()
        {
            InitializeComponent();
            Server                       = new TcpServer();
            Server.MaxClients            = 5;
            Server.ServerStarted        += Server_StateChanged;
            Server.ServerStopped        += Server_StateChanged;
            Server.ClientConnected      += Server_ClientConnected;
            Server.ClientDisconnected   += Server_ClientDisconnected;
            propertyGrid1.SelectedObject = Server;

            AppServer = new TcpAppServer()
            {
                WelcomeMessage = "Welcome to TCP Application Server. Copyright (C) Code Art Engineering."
            };
            AppServer.MaxClients          = 5;
            AppServer.ExecutionTimeout    = 1000;
            AppServer.ClientConnected    += AppServer_ClientConnected;
            AppServer.ClientDisconnected += AppServer_ClientDisconnected;
            AppServer.ClientSignedIn     += AppServer_ClientInitialized;
            AppServer.ClientSigningOut   += AppServer_ClientSigningOut;
            tcpClientsList1.AssignObject(AppServer);
            tcpAppServerQueue1.AssignObject(AppServer);

            //TCP Application Server Customization Test
            AppServer.RegisterCommand("CustomFunction", "Dummy Custom Function", customFunctionCallback);
            AppServer.RegisterCommand("CustomFunction2", "Dummy Custom Function with Parameter", customFunction2Callback,
                                      TcpAppParameter.CreateParameter("P1", "Parameter 1"),
                                      TcpAppParameter.CreateOptionalParameter("P2", "Parameter 2, optional.", "10"));
            AppServer.RegisterCommand("SlowCommand", "Command which take 10 seconds to complete. Simulate blocking!", SlowCommand);
            AppServer.RegisterQueuedCommand("SlowCommandQ", "Command which take 10 seconds to complete. Run in queue. Simulate blocking!", SlowCommand);

            CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin SamplePlugin = new CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin();
            AppServer.RegisterPluginType(typeof(CodeArtEng.Tcp.Tests.TcpAppServerSamplePlugin));
            AppServer.RegisterPluginType(typeof(CodeArtEng.Tcp.Tests.TcpAppServerSimpleMath));

            propertyGrid2.SelectedObject = AppServer;
        }