예제 #1
0
        public MainWindow(IAccesoUPVService service) : this()
        {
            _service = service;

            started = _service.VPN_UPV.IsReachable();

            notifyIcon = new System.Windows.Forms.NotifyIcon()
            {
                BalloonTipText  = "La aplicación ha sido minimizada. Use el icono de la barra de tareas para volver a mostrarla.",
                BalloonTipTitle = Title,
                Text            = Title,
                Icon            = new System.Drawing.Icon("Resources/app-icon.ico")
            };
            notifyIcon.MouseClick += NotifyIcon_MouseClick;

            BuildNotifyIconContextMenu();
            Started += (s, e) => BuildNotifyIconContextMenu();

            Start startPage = new Start(service);

            ContentFrame.Navigate(startPage);

            if (_service.StartMinimized)
            {
                WindowState = WindowState.Minimized;
                Loaded     += MetroWindow_StateChanged;
            }
        }
예제 #2
0
        public static async Task ConnectPortalDSIC(IAccesoUPVService service, ConnectionEventArgs e)
        {
            try
            {
                #region Conflicto con Disco W
                if (service.Disco_W.IsConnected)
                {
                    MessageBoxResult result = MessageBox.Show("No se puede acceder a la VPN del DSIC teniendo el Disco W conectado.\n"
                                                              + "Si continúa, este será desconectado automáticamente.\n\n"
                                                              + "¿Desea continuar?", "Conflicto entre conexiones", MessageBoxButton.OKCancel, MessageBoxImage.Warning);

                    if (result == MessageBoxResult.OK)
                    {
                        await service.Disco_W.DisconnectAsync();
                    }
                    else
                    {
                        throw new OperationCanceledException();
                    }
                }
                #endregion

                await e.ConnectionFunc();
            }
            catch (ArgumentNullException)
            {
                MessageBox.Show("No ha indicado ningún nombre para la VPN del DSIC. Indique uno en los ajustes.",
                                "Falta nombre",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
                OpenPreferences(service);
            }
        }
예제 #3
0
        public static async Task ConnectDrive(IAccesoUPVService service, ConnectionEventArgs e)
        {
            NetworkDrive networkDrive = e.Connectable as NetworkDrive;

            try
            {
                await e.ConnectionFunc();
            }
            catch (NotAvailableDriveException ex) when(ex.Letter == default)
            {
                MessageBox.Show(ex.Message, "Ninguna unidad disponible", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (NotAvailableDriveException ex)
            {
                string WARNING_W =
                    ex.Message + "\n" +
                    "(Continúe si prefiere que se elija la primera unidad disponible solo durante esta conexión).\n ";

                MessageBoxResult result = MessageBox.Show(WARNING_W, $"Unidad {ex.Letter} contiene disco",
                                                          MessageBoxButton.OKCancel, MessageBoxImage.Warning);

                if (result == MessageBoxResult.OK)
                {
                    networkDrive.Letter = default;
                    await e.ConnectionFunc().ContinueWith((t) => networkDrive.Letter = ex.Letter);
                }
            }
            catch (ArgumentNullException ex) when(ex.ParamName.Equals(nameof(networkDrive.Username)))
            {
                MessageBox.Show("No ha indicado ningún nombre de usuario. Indique uno en los ajustes.", "Falta usuario",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
                OpenPreferences(service);
            }
            catch (ArgumentNullException ex) when(ex.ParamName.Equals(nameof(networkDrive.Password)))
            {
                MessageBox.Show("No ha indicado ninguna contraseña. Indíquela en los ajustes.", "Falta contraseña",
                                MessageBoxButton.OK, MessageBoxImage.Warning);
                OpenPreferences(service);
            }
            catch (ArgumentOutOfRangeException ex) when(ex.ParamName.Equals(nameof(networkDrive.Address)))
            {
                /**
                 * We dont ask the user for the address, but the address depends on the username
                 * (which is, in fact, asked to the user). So we assume the error is because of the username.
                 */
                MessageBox.Show("Nombre de usuario incorrecto.", "Usuario incorrecto",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                OpenPreferences(service);
            }
            catch (ArgumentException ex) when(ex.ParamName.Equals(nameof(networkDrive.Password)))
            {
                MessageBox.Show("Contraseña incorrecta.", "Contraseña incorrecta",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                OpenPreferences(service);
            }
        }
예제 #4
0
        /// <summary>
        /// Tries to handle the CredentialsBugException, and returns if the connection process should be retried.
        /// </summary>
        /// <returns>Retry: If the connection process should be retried.</returns>
        private static async Task <bool> HandleCrendentialsError(IAccesoUPVService service, CredentialsBugException ex)
        {
            try
            {
                bool didAnything = await service.ResetUPVConnectionAsync();

                if (!didAnything)
                {
                    MessageBox.Show(ex.Message, "Error credenciales", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                return(didAnything);
            }
            catch (OperationCanceledException cancelledException)
            {
                const string CanceledReconnectionMessage =
                    "Cuidado, si cancela la operación de reconexión, el programa podría dejar de funcionar correctamente.\n\n" +
                    "¿Seguro que desea continuar?";

                bool cancelationHandled = false;
                while (!cancelationHandled)
                {
                    MessageBoxResult result = MessageBox.Show(CanceledReconnectionMessage, "Aviso", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                    if (result == MessageBoxResult.Yes)
                    {
                        throw cancelledException;
                    }
                    else
                    {
                        try
                        {
                            await service.VPN_UPV.ConnectAsync();

                            cancelationHandled = true;
                        }
                        // The cancelation message will be shown until the VPN is connected or the user says "Yes"
                        catch (OperationCanceledException) { }
                    }
                }
            }
            catch (TimeoutException tex)
            {
                MessageBox.Show(tex.Message, "El tiempo de espera ha expirado", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            return(false);
        }
예제 #5
0
        public static async Task ConnectWDrive(IAccesoUPVService service, ConnectionEventArgs e)
        {
            try
            {
                await ConnectDrive(service, e);
            }
            catch (CredentialsBugException ex)
            {
                bool retry = await HandleCrendentialsError(service, ex);

                if (retry)
                {
                    await ConnectWDrive(service, e);
                }
            }
        }
예제 #6
0
 public static void ConnectToSSH(IAccesoUPVService service, string server)
 {
     try
     {
         if (string.IsNullOrEmpty(service.User))
         {
             throw new ArgumentNullException();
         }
         SSHConnection.ConnectTo(server, service.User);
     }
     catch (ArgumentNullException)
     {
         MessageBox.Show("No ha indicado ningún nombre de usuario. Indique uno en los ajustes.", "Falta usuario",
                         MessageBoxButton.OK, MessageBoxImage.Warning);
         OpenPreferences(service);
     }
 }
예제 #7
0
        static void Main(string[] args)
        {
            // Service test calls
            IAccesoUPVService service = ServiceTest();

            // VPN test calls

            service.VPN_UPV.SetNameAuto();
            VPNTest(service.VPN_UPV);

            service.VPN_DSIC.SetNameAuto();
            VPNTest(service.VPN_DSIC);

            // Drive test calls

            Console.WriteLine("Press any key to start Drive testing...");
            Console.ReadKey();
            Console.Clear();

            try
            {
                if (!service.VPN_UPV.IsReachable())
                {
                    ConnectTest(service.VPN_UPV);
                }

                Console.Write("Type your user: "******"Press the drive letter: ");

                char letter = default;
                while (letter == default || !DriveLetterTools.IsValid(letter))
                {
                    if (letter != default)
                    {
                        Console.Write("Invalid input. Please try again: ");
                    }
                    letter = (char)Console.Read();
                    Console.WriteLine();
                }
                service.Disco_W.Letter = letter;

                Console.WriteLine("Type your domain:");
                foreach (var value in Enum.GetValues(typeof(UPVDomain)))
                {
                    Console.WriteLine($"{(int)value} - {(UPVDomain)value}");
                }
                Console.Write("Type here: ");
                service.Disco_W.Domain = (UPVDomain)int.Parse(Console.ReadLine());

                DriveTest(service.Disco_W);

                try
                {
                    Console.Write("Type your DSIC password: "******"DSIC Drive testing was canceled by the user.");
                };

                // Remote desktop test

                Console.WriteLine("Connecting to Linux Desktop...");
                RemoteDesktop.ConnectToLinuxDesktop();

                Console.WriteLine("Press any key when the Linux Desktop is closed");
                Console.ReadKey();

                Console.WriteLine("Connecting to Windows Desktop...");
                RemoteDesktop.ConnectToWindowsDesktop();

                Console.WriteLine("Press any key when the Windows Desktop is closed");
                Console.ReadKey();

                if (service.VPN_UPV.IsConnected)
                {
                    DisconnectTest(service.VPN_UPV);
                }
            }
            catch (OperationCanceledException)
            {
                Console.WriteLine("The VPN connection process was canceled by the user.\nDrive testing ended.");
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
예제 #8
0
 public static void OpenPreferences(IAccesoUPVService service)
 {
     new Preferences(service).ShowDialog();
 }
예제 #9
0
 public Start(IAccesoUPVService service) : this()
 {
     _service = service;
 }
예제 #10
0
 public Preferences(IAccesoUPVService service)
 {
     Service = service;
     InitializeComponent();
     Load();
 }
예제 #11
0
 public Start(IAccesoUPVService service)
 {
     _service = service;
     InitializeComponent();
 }
예제 #12
0
 public Main(IAccesoUPVService service)
 {
     Service = service;
     InitializeComponent();
 }
예제 #13
0
 public UPVPage(IAccesoUPVService service)
 {
     Service = service;
     InitializeComponent();
 }
예제 #14
0
 public Shutdown(IAccesoUPVService service) : this()
 {
     _service     = service;
     this.Loaded += Shutdown_Loaded;
 }