Esempio n. 1
0
        static void Main(string[] args)
        {
            var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "site");
            var engine = new BellyEngine(path);
            Console.CancelKeyPress += (sender, e) => {
                engine.Stop();
                while (engine.HasConnectedClients) {
                    Thread.Sleep(50);
                }
            };
            var browser = engine
                .OnConnected(() => Console.WriteLine("Client connected"))
                .OnDisconnected(() => Console.WriteLine("Client disconnected"))
                .OnSendException((ex) => Console.WriteLine(ex.ToString()))
                .On("hello-server", (m) => Console.WriteLine(m))
                .RespondTo("ping-server", (m, with) => with("pong from server"))
                .Start(new Point(100, 100));

            engine.WaitForFirstClientToConnect();
            engine.Send("hello-client", "hello world from server");
            Console.WriteLine(engine.Request("ping-client"));

            browser.BringToFront();

            while (engine.HasConnectedClients) {
                Thread.Sleep(50);
            }
        }
Esempio n. 2
0
        static void runBellyRub(string localConfig, bool headless, string path, bool leaveInBackground, string portString)
        {
            int port, channelPort;
            if (portString != null) {
                var portChunks = portString.Split(new[] {','});
                if (portChunks.Length > 0) {
                    if (!int.TryParse(portChunks[0], out port))
                        port = 0;
                } else {
                    port = 0;
                }
                if (portChunks.Length > 1) {
                    if (!int.TryParse(portChunks[1], out channelPort))
                        channelPort = 0;
                } else {
                    channelPort = 0;
                }
            } else {
                port = 0;
                channelPort = 0;
            }
            var site = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "site");
            var engine = new BellyEngine(site);
            Console.CancelKeyPress += (sender, e) => {
                engine.Stop();
                while (engine.HasConnectedClients) {
                    Thread.Sleep(50);
                }
            };
            Browser browser = null;
            if (headless) {
                if (port > 0) {
                    if (channelPort > 0)
                        engine.StartHeadless(port, channelPort);
                    else
                        engine.StartHeadless(port);
                } else {
                    engine.StartHeadless();
                } 
                Console.WriteLine("url: "+engine.ServerUrl);
                Console.WriteLine("waiting for client to connect..");
            } else {
                engine.OnSendException((ex) => Console.WriteLine(ex.ToString()));
                if (port > 0) {
                    if (channelPort > 0)
                        browser = engine.Start(port, channelPort, new Point(100,100));
                    else
                        browser = engine.Start(port, new Point(100,100));
                } else {
                    browser = engine.Start(new Point(100,100));
                } 
            } 

            var proxy = new BellyRubProxy(path, engine, browser);

            engine.WaitForFirstClientToConnect(60);
            if (!leaveInBackground && browser != null)
                browser.BringToFront(); 
            
            run(localConfig, path, proxy);
            proxy.SetClient(Client);
            if (headless) {
                Console.WriteLine("type exit to quit ContinuousTests");
                while (Console.ReadLine() != "exit") {
                    Thread.Sleep(10);
                }
            } else {
                while (engine.HasConnectedClients) {
                    Thread.Sleep(50);
                }
            }
            engine.Stop();
            exit();
        }