Ejemplo n.º 1
0
        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            base.OnOptionsItemSelected(item);
            if (item.ItemId == Resource.Id.option_start_stop)
            {
                if (tunnel.IsRunning)
                {
                    tunnel.Stop();
                }
                else
                {
                    tunnel.Start(new TunnelSettings("Loopback", 1500), new MonoBrick.NXT.Loopback <MonoBrick.NXT.Command, MonoBrick.NXT.Reply>());
                }
            }
            if (item.ItemId == Resource.Id.option_connect)
            {
                AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                dialog.SetTitle("Enter IP Address");
                EditText ipAddress = new EditText(this);
                dialog.SetView(ipAddress);
                dialog.SetPositiveButton("Connect", delegate(object sender, DialogClickEventArgs e) {
                    ProgressDialog progress = ProgressDialog.Show(this, "", "Connecting to client...");
                    Thread t = new Thread(
                        new ThreadStart(
                            delegate()
                    {
                        if (tunnel.ConnectToClient(ipAddress.Text))
                        {
                            RunOnUiThread(delegate() {
                                Toast.MakeText(ApplicationContext, "Successfully connected to client.", ToastLength.Short).Show();
                            });
                        }
                        else
                        {
                            RunOnUiThread(delegate() {
                                Toast.MakeText(ApplicationContext, "Failed to connect to client.", ToastLength.Short).Show();
                            });
                        }
                        progress.Dismiss();
                    }));
                    t.IsBackground = true;
                    t.Priority     = System.Threading.ThreadPriority.Normal;
                    t.Start();
                });
                dialog.SetNegativeButton("Cancel", delegate(object sender, DialogClickEventArgs e) {
                });
                dialog.Show();
            }

            if (item.ItemId == Resource.Id.option_exit)
            {
                //ApplicationContext.BindService(new Intent(this,typeof(TunnelService)), serviceConnection,Bind.AutoCreate);
            }
            return(true);
        }
Ejemplo n.º 2
0
        protected void OnConnectToClientClicked(object sender, EventArgs e)
        {
            if (tunnel.ClientsConnected > 0 || !tunnel.IsRunning)
            {
                return;
            }
            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            dialog.SetTitle("Enter IP Address");
            EditText ipAddress = new EditText(this);

            dialog.SetView(ipAddress);
            ISharedPreferences pref = GetSharedPreferences("clientSettings", 0);
            string             clientToConnectTo = pref.GetString("clientToConnectTo", "192.168.1.100");

            ipAddress.Text = clientToConnectTo;
            dialog.SetPositiveButton("Connect", delegate {
                // Save settings
                ISharedPreferencesEditor editor = pref.Edit();
                editor.PutString("clientToConnectTo", ipAddress.Text);
                editor.Commit();
                ProgressDialog progress = ProgressDialog.Show(this, "", "Connecting to client...");
                Thread t = new Thread(
                    new ThreadStart(
                        delegate()
                {
                    if (tunnel.ConnectToClient(ipAddress.Text))
                    {
                        RunOnUiThread(delegate() {
                            ShowToast("Successfully connected to client.", ToastLength.Short);
                        });
                    }
                    else
                    {
                        RunOnUiThread(delegate() {
                            ShowToast("Failed to connect to client.", ToastLength.Short);
                        });
                    }
                    progress.Dismiss();
                }));
                t.IsBackground = true;
                t.Priority     = System.Threading.ThreadPriority.Normal;
                t.Start();
            });
            dialog.SetNegativeButton("Cancel", delegate {
            });
            dialog.Show();
        }
		public static void Main2 (string[] args)
		{
				string connectToClient = "";	

				ConsoleKeyInfo cki;
				
			    TunnelSettings inConfig = new TunnelSettings();
				try
    			{
					inConfig = inConfig.LoadFromXML("settings.xml");
				}
				catch(Exception){
					ScreenPrint("Failed to read settings. Using default settings");
				}
				Arguments CommandLine = new Arguments(args);
				
			    if(CommandLine["connect"] != null){ 
					connectToClient = CommandLine["connect"];
				}				
				tunnel = new Tunnel();
				tunnel.LogEvent += ScreenPrint;
				try
    			{
					if(tunnel.Start(inConfig)){
					    Console.WriteLine("Press Q to quit");						
						Console.WriteLine("Press C to connect to client");
						Console.WriteLine("Press T to throw off all clients");
						if(connectToClient != "")
							tunnel.ConnectToClient(connectToClient);
						do 
	      				{
					        cki = Console.ReadKey(true);
					        if(cki.Key == ConsoleKey.C){
								tunnel.LogEvent -= ScreenPrint;
								Console.Write("Enter client IP-Address: ");
								tunnel.ConnectToClient(Console.ReadLine());
								tunnel.LogEvent += ScreenPrint;
							}
							if(cki.Key == ConsoleKey.T){
								tunnel.ThrowOffAllClients();
							}
	       				} while (cki.Key != ConsoleKey.Q);
						tunnel.Stop();
					}
 				}
			    catch(Exception e)
				{
					Console.WriteLine(e.Message);
				}
				finally
				{
					if(tunnel.IsRunning)
						tunnel.Stop();
				}
				TunnelSettings outConfig = inConfig;
				try{
					outConfig.SaveToXML("settings.xml");
				}
				catch{
				}
		}
Ejemplo n.º 4
0
        public static void Main2(string[] args)
        {
            string connectToClient = "";

            ConsoleKeyInfo cki;

            TunnelSettings inConfig = new TunnelSettings();

            try
            {
                inConfig = inConfig.LoadFromXML("settings.xml");
            }
            catch (Exception) {
                ScreenPrint("Failed to read settings. Using default settings");
            }
            Arguments CommandLine = new Arguments(args);

            if (CommandLine["connect"] != null)
            {
                connectToClient = CommandLine["connect"];
            }
            tunnel           = new Tunnel();
            tunnel.LogEvent += ScreenPrint;
            try
            {
                if (tunnel.Start(inConfig))
                {
                    Console.WriteLine("Press Q to quit");
                    Console.WriteLine("Press C to connect to client");
                    Console.WriteLine("Press T to throw off all clients");
                    if (connectToClient != "")
                    {
                        tunnel.ConnectToClient(connectToClient);
                    }
                    do
                    {
                        cki = Console.ReadKey(true);
                        if (cki.Key == ConsoleKey.C)
                        {
                            tunnel.LogEvent -= ScreenPrint;
                            Console.Write("Enter client IP-Address: ");
                            tunnel.ConnectToClient(Console.ReadLine());
                            tunnel.LogEvent += ScreenPrint;
                        }
                        if (cki.Key == ConsoleKey.T)
                        {
                            tunnel.ThrowOffAllClients();
                        }
                    } while (cki.Key != ConsoleKey.Q);
                    tunnel.Stop();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (tunnel.IsRunning)
                {
                    tunnel.Stop();
                }
            }
            TunnelSettings outConfig = inConfig;

            try{
                outConfig.SaveToXML("settings.xml");
            }
            catch {
            }
        }