Exemplo n.º 1
0
 static void Main(string[] args)
 {
     using (connection = new RouterVpnManagerConnection())
     {
         try
         {
             connection.Host = "192.168.3.1";
             connection.Connect();
             requests = new ControlledRequests(connection);
             requests.AddBroadcastListener(new Broadcasts());
             ListenForCommands();
         }
         catch (Exception e)
         {
             Console.WriteLine(e);
             throw;
         }
     }
 }
        public bool Connect()
        {
            if (MainPageController != null)
            {
                try
                {
                    if (!connection_.IsConnected)
                    {
                        MainPageController.LblStatus.Text      = "Connecting, Please Wait...";
                        MainPageController.LblStatus.TextColor = UIColor.Black;
                        connection_.Connect();
                        if (VpnSelectorDataSource != null)
                        {
                            VpnSelectorDataSource.PopulateVpns();
                        }

                        MainPageController.BtnSelectAVpn.Enabled = true;
                        MainPageController.LblStatus.Text        = "Connected";
                        MainPageController.LblStatus.TextColor   = UIColor.Green;
                        MainPageController.BtnConnect.SetTitle("DisconnectFromServer From Server", UIControlState.Normal);
                        connected_ = true;
                        return(true);
                    }
                    else
                    {
                        MainPageController.LblStatus.Text        = "Disconnecting, Please Wait...";
                        MainPageController.LblStatus.TextColor   = UIColor.Black;
                        MainPageController.BtnSelectAVpn.Enabled = false;
                        MainPageController.LblStatus.Text        = "Not Connected";
                        MainPageController.LblStatus.TextColor   = UIColor.Red;
                        MainPageController.BtnConnect.SetTitle("Connect To Server", UIControlState.Normal);
                        connected_ = false;
                        connection_.Dispose();
                        DeleteInstance();
                        return(false);
                    }
                }
                catch (SocketException ex)
                {
                    MainPageController.LblStatus.Text      = "Not Connected";
                    MainPageController.LblStatus.TextColor = UIColor.Red;
                    Global.BasicNotificationAlert("Unable To Connect", "We were unable to find the server", MainPageController, ex.ToString());
                    connected_ = false;
                    connection_.Dispose();
                    DeleteInstance();
                    return(false);
                }
                catch (Exception ex)
                {
                    MainPageController.LblStatus.Text      = "Not Connected";
                    MainPageController.LblStatus.TextColor = UIColor.Red;
                    Global.BasicNotificationAlert("Unable To Connect", "We were unable to process your request", MainPageController, ex.ToString());
                    connected_ = false;
                    return(false);
                }
            }
            else
            {
                Console.WriteLine("Can't find main controller");
                return(false);
            }
        }