Exemple #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            #region Generate and show QR

            //Find our local IP-address
            IPHostEntry host;
            string localIP = "";
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    localIP = ip.ToString();
                }
            }

            QRCodeGenerator.ShowQRCode(localIP + "/" + 1337, 120, 120, ImageFormat.Png);//120 are ok dimensions

            #endregion

            AndroidPhone phone = new AndroidPhone();
            DesktopController controller = new DesktopController(phone, new OsInterface());

            SerializeManager serializeManager = new SerializeManager();
            serializeManager.RegisterSerilizer(new TouchEventSerializer());
            serializeManager.RegisterSerilizer(new SensorEventSerializer());
            serializeManager.RegisterSerilizer(new StringSerializer());
            serializeManager.RegisterSerilizer(new HardwareButtonSerializer());

            IServer server = new Server(serializeManager);
            server.ConnectionTimeout = 5000;
            server.Start(1337);

            TouchDecoder decoder = new TouchDecoder();

            phone.Tap += () => controller.LeftClick();
            phone.Up += () => controller.mouseUp();
            phone.MultiTap += (x) => { if (x == 2) controller.RightClick(); };
            phone.Down += () => controller.mouseDown();
            phone.Move += (x, y) => controller.MoveMouse(moveSpeed(x), moveSpeed(y));
            phone.MulitiMove += (c, x, y) => controller.VerticalScroll(y * 10);

            phone.Pinch += (x) =>
            {
                InputSimulator.SimulateKeyDown(VirtualKeyCode.CONTROL);
                controller.VerticalScroll(x);
                InputSimulator.SimulateKeyUp(VirtualKeyCode.CONTROL);
            };

            int bytesRecived = 0;
            long totalbytesRecived = 0;
            System.Timers.Timer timer = new System.Timers.Timer(1000);
            timer.AutoReset = true;
            timer.Elapsed += (s,e) =>
            {

                Console.Title = "Total Recived: " + totalbytesRecived + " Current ByteRate: " + ((double)bytesRecived) / 1000;
                totalbytesRecived += bytesRecived;
                bytesRecived = 0;

            };
            timer.Start();

            server.Connected += (x, y) => Console.WriteLine("A connection was recived");
            server.Recived += (x, message) =>
            {
                if (message.Message is IPhoneMessage)
                {
                    phone.ProcessMessage((IPhoneMessage)message.Message);
                }
                else if(message.Message is String)
                {
                    controller.NetworkedText(message.Message.ToString());
                }
                else if (message.Message is HardwareButtonEvent)
                {
                    int id = ((HardwareButtonEvent)message.Message).ID;
                    if (id == HardwareButtonEvent.VOLUME_UP)
                        controller.IncreaseVolume();
                    else if (id == HardwareButtonEvent.VOLUME_DOWN)
                        controller.DecreaseVolume();
                    else
                        System.Diagnostics.Process.Start("http://www.google.com");
                }

            };
            server.Dissconnected += (x, y) => Console.WriteLine("Oh no we dced ;(");
        }
Exemple #2
0
 public Server(SerializeManager serializeManager)
 {
     this.connections = new ConcurrentDictionary<int, IServerConnection>();
     this.serializeManager = serializeManager;
     this.heartbeatInterval = 1000;
 }