Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Server\n");

            //start server and bind to its local and remote API
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, wc) =>
            {
                //Connect action
                c.OnOpen += () => Task.Run((Action)connected);

                //Receive action
                c.OnReceive += async msg => {
                    await c.SendAsync("Hi!");
                    //Stampo su console
                    Console.WriteLine("Client message: \n" + msg);

                    //Rispondo con ack
                    await c.SendAsync("I've received the following message: " + msg);

                    //Chiudo connessione
                    //await c.CloseAsync();
                };

                //Disconnect action
                c.OnClose += (s, d) => Task.Run((Action)disconnected);
            });

            //Waiting for connection closing
            AppExit.WaitFor(cts, t);
        }
Ejemplo n.º 2
0
        //if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address)
        //open Index.html to run the client
        static void Main(string[] args)
        {
            //generate js code
            File.WriteAllText($"./Site/{nameof(NumericService)}.js", RPCJs.GenerateCallerWithDoc <NumericService>());
            File.WriteAllText($"./Site/{nameof(TextService)}.js", RPCJs.GenerateCallerWithDoc <TextService>());

            //start server and bind its local and remote APIs
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, wc) =>
            {
                var path = wc.RequestUri.AbsolutePath;
                if (path == "/numericService")
                {
                    c.Bind(new NumericService());
                }
                else if (path == "/textService")
                {
                    c.Bind(new TextService());
                }
            });

            Console.Write("{0} ", nameof(MultiService));
            Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html"))
            {
                UseShellExecute = true
            });
            AppExit.WaitFor(cts, t);
        }
Ejemplo n.º 3
0
        private void CheckForCollision()
        {
            var head = this.snake.GetHead();

            if (this.frame.Points.Any(x => x.CoordinateX == head.CoordinateX && x.CoordinateY == head.CoordinateY))
            {
                AppExit.GameOver();
            }
        }
        //======================= #M002 PanelOpen =======================\\
        //  This method hided and unhide the panel used to add vehicles  \\
        //  - pnlAddVehicle : Name of the object on Design page          \\
        //  - bool pEnable : True = Shows panel, False = Hides i         \\
        //     Sample: PanelOpen(true) == Shows panel                    \\
        //===============================================================\\

        public String PanelOpen(String subMenu) //#M002
        {
            switch (subMenu)
            {
            case "OAddV":
                pnlAddVehicle.Left    = (this.ClientSize.Width - pnlAddVehicle.Width) / 2;
                pnlAddVehicle.Top     = (this.ClientSize.Height - pnlAddVehicle.Height) / 2;
                pnlAddVehicle.Enabled = true;
                pnlAddVehicle.Visible = true;
                break;

            case "CAddV":
                pnlAddVehicle.Enabled = false;
                pnlAddVehicle.Visible = false;
                break;

            case "OExt":
                if (carList.Count <= 0)
                {
                    var extBox = new AppExit();
                    extBox.Left = (this.ClientSize.Width - extBox.Width) / 2;
                    extBox.Top  = (this.ClientSize.Height - extBox.Height) / 2;
                    this.Controls.Add(extBox);
                    extBox.BringToFront();
                }
                else
                {
                    MessageBox.Show("There is still Cars parked.");
                }
                break;

            case "CExt":
                pnlAddVehicle.Enabled = false;
                pnlAddVehicle.Visible = false;
                break;

            case "OChkOut":
                pnlChckOut.Left    = (this.ClientSize.Width - pnlChckOut.Width) / 2;
                pnlChckOut.Top     = (this.ClientSize.Height - pnlChckOut.Height) / 2;
                pnlChckOut.Enabled = true;
                pnlChckOut.Visible = true;
                break;

            case "CChkOut":
                pnlChckOut.Enabled = false;
                pnlChckOut.Visible = false;
                break;
            }
            return(subMenu);
        }
Ejemplo n.º 5
0
        //if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address)
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Server\n");

            //start server and bind to its local and remote API
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, wc) =>
            {
                c.Bind <TaskAPI, IProgressAPI>(new TaskAPI());

                c.OnOpen  += () => Task.Run((Action)writeClientCount);
                c.OnClose += (s, d) => Task.Run((Action)writeClientCount);
            });

            Console.Write("{0} ", nameof(TestServer));
            AppExit.WaitFor(cts, t);
        }
Ejemplo n.º 6
0
        //if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address)
        //open Index.html to run the client
        static void Main(string[] args)
        {
            //generate js code
            File.WriteAllText($"./Site/{nameof(TaskAPI)}.js", RPCJs.GenerateCallerWithDoc <TaskAPI>());

            //start server and bind its local and remote API
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) =>
            {
                c.Bind <TaskAPI, IProgressAPI>(new TaskAPI());
                c.BindTimeout(TimeSpan.FromSeconds(1)); //close connection if there is no incommming message after X seconds
            });

            Console.Write("{0} ", nameof(ClientJs));
            Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html"))
            {
                UseShellExecute = true
            });
            AppExit.WaitFor(cts, t);
        }
Ejemplo n.º 7
0
        //if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address)
        //open Index.html to run the client
        static void Main(string[] args)
        {
            //generate js code (the API is empty)
            File.WriteAllText($"./Site/{nameof(PlatformInfo)}.js", RPCJs.GenerateCaller <PlatformInfo>());

            //start server and bind its local and remote API
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) =>
            {
                var pInfo = new PlatformInfo();
                c.Bind <PlatformInfo, IBrowserInfo>(pInfo);
                c.OnOpen += pInfo.InitializeAsync;
            });

            Console.Write("{0} ", nameof(ClientInfoJs));
            Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html"))
            {
                UseShellExecute = true
            });
            AppExit.WaitFor(cts, t);
        }
Ejemplo n.º 8
0
        //if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address)
        //open Index.html to run the client
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));

            Connection.MaxMessageSize = 1 * 1024 * 1024; //1MiB
            RPC.AddConverter(new JpgBase64Converter());

            //generate js code
            File.WriteAllText($"../../Site/{nameof(ImageProcessingAPI)}.js", RPCJs.GenerateCallerWithDoc <ImageProcessingAPI>());

            //start server and bind its local and remote API
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) => c.Bind(new ImageProcessingAPI()));

            Console.Write("{0} ", nameof(Serialization));
            Process.Start(new ProcessStartInfo(Path.GetFullPath("../../Site/Index.html"))
            {
                UseShellExecute = true
            });
            AppExit.WaitFor(cts, t);
        }
Ejemplo n.º 9
0
        //if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address)
        //open Index.html to run the client
        static void Main(string[] args)
        {
            //set message limit
            Connection.MaxMessageSize = Connection.Encoding.GetMaxByteCount(40);

            //generate js code
            File.WriteAllText($"./Site/{nameof(MessagingAPI)}.js", RPCJs.GenerateCaller <MessagingAPI>());

            //start server
            var cts = new CancellationTokenSource();
            var t   = Server.ListenAsync("http://localhost:8001/", cts.Token, (c, ws) =>
            {
                //set idle timeout
                c.BindTimeout(TimeSpan.FromSeconds(30));

                c.OnOpen  += async() => await c.SendAsync("Hello from server using WebSocketRPC");
                c.OnClose += (s, d) => Task.Run(() => Console.WriteLine("Connection closed: " + d));
                c.OnError += e => Task.Run(() => Console.WriteLine("Error: " + e.Message));

                c.OnReceive += async msg =>
                {
                    Console.WriteLine("Received: " + msg);

                    await c.SendAsync("Server received: " + msg);

                    if (msg.ToLower() == "close")
                    {
                        await c.CloseAsync(statusDescription: "Close requested by user.");
                    }
                };
            });

            Console.Write("{0} ", nameof(RawMsgJs));
            Process.Start(new ProcessStartInfo(Path.GetFullPath("./Site/Index.html"))
            {
                UseShellExecute = true
            });
            AppExit.WaitFor(cts, t);
        }
Ejemplo n.º 10
0
        public void Run()
        {
            DrawManager.DrawFrame(this.frame.Points);
            InitializeFood();

            while (true)
            {
                DrawManager.DrawSnake(this.snake.Body);
                var pointToClear = this.snake.Body.First();
                DrawManager.ClearPoint(pointToClear);

                DrawManager.WriteScore(this.score, this.level);
                if (this.counter == 0)
                {
                    this.counter = InitialCounter;
                    this.sleepTime--;
                    this.level++;
                    InitializeFood();
                }

                if (Console.KeyAvailable)
                {
                    var keyInput = Console.ReadKey();
                    if (keyInput.Key.Equals(ConsoleKey.Escape))
                    {
                        AppExit.Confirm();
                        DrawManager.DrawFrame(this.frame.Points);
                    }
                    GetDirection(keyInput);
                }
                Thread.Sleep(sleepTime);

                CheckForFood();
                CheckForCollision();
                this.snake.Move();

                this.counter--;
            }
        }
Ejemplo n.º 11
0
        //if access denied execute: "netsh http delete urlacl url=http://+:8001/" (delete for 'localhost', add for public address)
        static void Main(string[] args)
        {
            //Debug.Listeners.Add(new TextWriterTraceListener(Console.Out));

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Client\n");

            //start client and bind to its local API
            var cts = new CancellationTokenSource();
            var t   = Client.ConnectAsync("ws://localhost:8001/", cts.Token, c =>
            {
                c.Bind <ProgressAPI, ITaskAPI>(new ProgressAPI());
                c.OnOpen += async() =>
                {
                    var r = await RPC.For <ITaskAPI>().CallAsync(x => x.LongRunningTask(5, 3));
                    Console.WriteLine("\nResult: " + r.First());
                };
            },
                                          reconnectOnError: true);

            Console.Write("{0} ", nameof(TestClient));
            AppExit.WaitFor(cts, t);
        }
Ejemplo n.º 12
0
 public void OnAppExit()
 {
     AppExit?.Invoke();
 }
Ejemplo n.º 13
0
 private void Application_Exit(object sender, ExitEventArgs e)
 {
     AppExit?.Invoke(sender, e);
 }