Пример #1
0
        /**
         *
         * return:
         *  4: generic error in the client
         *  3: generic error in the server
         *  2: already logged
         *  1: wrong username or password
         *  0: login successful
         */
        internal int loginProcedureAsync(string clientID, string password)
        {
            TcpClient client    = null;
            SslStream sslStream = null;
            //string challenge = null;
            int result = 4; // initialize the result with the worst condition

            if (clientID == null || password == null || clientID.Length <= 0 || password.Length <= 0)
            {
                return(1);
            }

            try
            {
                /* Create a TCP/IP client socket and connect to the server */
                Client.ConnectServer(Properties.Settings.Default.machineName, Properties.Settings.Default.serverCertificateName, Properties.Settings.Default.PORT, out client, out sslStream /*, out challenge*/);

                /* Start login procedure */
                result = Client.Login(sslStream /*, challenge*/, clientID, password);
            }
            catch (Exception e)
            {
                Console.WriteLine("Eccezione inaspettata in loginProcedureAsync(). Messaggio " + e.Message);
                Console.WriteLine(e.StackTrace);
                result = 4;
            }
            finally
            {
                if (sslStream != null)
                {
                    sslStream.Close();
                }
                if (client != null)
                {
                    client.Close();
                }
            }

            return(result);
        }
Пример #2
0
        /**
         * return:
         *  - false if logout is not performed
         */
        internal bool logoutProcedure(string clientID)
        {
            TcpClient client    = null;
            SslStream sslStream = null;
            bool      result    = false;

            if (clientID == null)
            {
                return(false);
            }

            try
            {
                /* Create a TCP/IP client socket and connect to the server */
                Client.ConnectServer(Properties.Settings.Default.machineName, Properties.Settings.Default.serverCertificateName, Properties.Settings.Default.PORT, out client, out sslStream);

                /* Start login procedure */
                result = Client.Logout(sslStream, clientID);
            }
            catch (Exception e)
            {
                Console.WriteLine("Eccezione inaspettata in logoutProcedure(). Messaggio " + e.Message);
                Console.WriteLine(e.StackTrace);
                result = false;
            }
            finally
            {
                if (sslStream != null)
                {
                    sslStream.Close();
                }
                if (client != null)
                {
                    client.Close();
                }
            }

            return(result);
        }
Пример #3
0
        internal void updateBackupList()
        {
            if (Interlocked.Read(ref backgroundRunning) == TRUE)
            {
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    showAlertDialog(ALERT_DIALOG_TITLE, ALERT_DIALOG_MESSAGE);
                }));
                return;
            }


            Interlocked.Exchange(ref backgroundRunning, TRUE);

            TcpClient client    = null;
            SslStream sslStream = null;

            //string challenge = null;

            //show loading
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                //clear tree view
                DataContext = null;

                //UpdateProgressText.Text = "Recupero della lista di backup...";

                BackupListProgressBar.IsIndeterminate = true;
                BackupListProgressBar.Visibility      = Visibility.Visible;

                BackupListAdvProgressBar.IsIndeterminate = true;
                BackupListAdvProgressBar.Visibility      = Visibility.Visible;

                noBackupAdvanced.Visibility = Visibility.Hidden;
                NoBackupImage.Visibility    = Visibility.Hidden;
                NoBackupText.Visibility     = Visibility.Hidden;
                RetryText.Visibility        = Visibility.Hidden;
            }));

            try
            {
                /* Create a TCP/IP client socket and connect to the server */
                Client.ConnectServer(Properties.Settings.Default.machineName, Properties.Settings.Default.serverCertificateName, Properties.Settings.Default.PORT, out client, out sslStream);

                /* Request backup list from the server */
                List <BackupRecord> backupList = Client.GetBackupList(sslStream, Preferences.UserID.GetValue(), Preferences.SessionID.GetValue(), null);

                //no backup records
                if (backupList.Count <= 0)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        UpdateProgressText.Text = "";

                        //clear backup lists
                        simpleObsBackupCollection.Clear();
                        advObsBackupCollection.Clear();

                        //refresh UI
                        BackupListProgressBar.IsIndeterminate = false;
                        BackupListProgressBar.Visibility      = Visibility.Hidden;

                        BackupListAdvProgressBar.IsIndeterminate = false;
                        BackupListAdvProgressBar.Visibility      = Visibility.Hidden;

                        //UpdateProgressText.Text = "Lista di backup aggiornata";

                        noBackupAdvanced.Visibility = Visibility.Visible;
                        NoBackupImage.Visibility    = Visibility.Visible;
                        NoBackupText.Visibility     = Visibility.Visible;
                        RetryText.Visibility        = Visibility.Visible;

                        //last backup labels
                        TileLastBackupLabel.Visibility = Visibility.Hidden;
                        TileLastBackupDate.Text        = "";
                        TileLastBackupDate.Visibility  = Visibility.Hidden;
                    }));

                    lock (locker)
                    {
                        Interlocked.Exchange(ref backgroundRunning, FALSE);
                        System.Threading.Monitor.PulseAll(locker);
                    }
                    return;
                }


                //show available backups
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    //clear backup lists
                    simpleObsBackupCollection.Clear();
                    advObsBackupCollection.Clear();

                    //refresh UI
                    BackupListProgressBar.IsIndeterminate = false;
                    BackupListProgressBar.Visibility      = Visibility.Hidden;

                    BackupListAdvProgressBar.IsIndeterminate = false;
                    BackupListAdvProgressBar.Visibility      = Visibility.Hidden;

                    foreach (BackupRecord record in backupList)
                    {
                        simpleObsBackupCollection.Add(new BackupListItem(record, this, false));
                        advObsBackupCollection.Add(new BackupListItem(record, this, true));
                    }

                    //UpdateProgressText.Text = "Lista di backup aggiornata";

                    //update tile last backup info
                    TileLastBackupLabel.Visibility = Visibility.Visible;
                    TileLastBackupDate.Visibility  = Visibility.Visible;
                    TileLastBackupDate.Text        = simpleObsBackupCollection.First <BackupListItem>().backupRecord.getDateString();
                }));
                Console.WriteLine("task terminato!");
            }
            catch (SessionAuthenticationException sae)
            {
                Preferences.DeleteAll();
                Console.WriteLine("Errore nell'autenticazione con il server. Messaggio: " + sae.Message);
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    LoginWindow l = new LoginWindow("Operazione fallita. Qualcun altro potrebbe aver effettuato l'accesso da un altro dispositivo.");
                    l.Show();
                    Close();
                }));
            }
            catch (Exception e)
            {
                //UI update
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    //show error on status bar
                    UpdateProgressText.Text = "Errore durante la ricezione della lista di backup";

                    //clear backup lists
                    simpleObsBackupCollection.Clear();
                    advObsBackupCollection.Clear();

                    //refresh UI
                    BackupListProgressBar.IsIndeterminate = false;
                    BackupListProgressBar.Visibility      = Visibility.Hidden;

                    BackupListAdvProgressBar.IsIndeterminate = false;
                    BackupListAdvProgressBar.Visibility      = Visibility.Hidden;

                    noBackupAdvanced.Visibility = Visibility.Visible;
                    NoBackupImage.Visibility    = Visibility.Visible;
                    NoBackupText.Visibility     = Visibility.Visible;
                    RetryText.Visibility        = Visibility.Visible;
                }));

                Console.WriteLine("Errore nell recupero della lista di backup. " + e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                if (sslStream != null)
                {
                    sslStream.Close();
                }
                if (client != null)
                {
                    client.Close();
                }

                lock (locker)
                {
                    Interlocked.Exchange(ref backgroundRunning, FALSE);
                    System.Threading.Monitor.PulseAll(locker);
                }
            }
        }
Пример #4
0
        /*
         * create a new backup (should use in a new thread)
         */
        internal bool newBackupProcedureAsync(bool autoBackground)
        {
            if (Interlocked.Read(ref backgroundRunning) == TRUE)
            {
                if (!autoBackground)
                {
                    Application.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        showAlertDialog(ALERT_DIALOG_TITLE, ALERT_DIALOG_MESSAGE);
                    }));
                }

                return(false);
            }

            Interlocked.Exchange(ref backgroundRunning, TRUE);

            //Console.WriteLine("Inizio operazione di background automatico in corso...");
            bool result;

            //update UI
            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                if (!autoBackground)
                {
                    UpdateProgressText.Text = "Operazione di backup in corso...";
                }
                else
                {
                    UpdateProgressText.Text = "Operazione di backup automatico in corso...";
                }

                //start animation before disabling Tile!
                arrowImage.Visibility = Visibility.Visible;
                ((Storyboard)Resources["Storyboard"]).Begin();

                BackupTile.IsEnabled = false;
            }));


            TcpClient client    = null;
            SslStream sslStream = null;

            //Start doing work
            Console.WriteLine("Inizio operazione di backup...");

            try
            {
                /* Create a TCP/IP client socket and connect to the server */
                Client.ConnectServer(Properties.Settings.Default.machineName, Properties.Settings.Default.serverCertificateName, Properties.Settings.Default.PORT, out client, out sslStream);

                /* Create the new backup on the server */
                bool closeConnection = true;
                Client.NewBackup(sslStream, Preferences.UserID.GetValue(), Preferences.SessionID.GetValue(), closeConnection, this);

                //update UI - backup completed
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    if (!autoBackground)
                    {
                        UpdateProgressText.Text = "Backup completato";
                    }
                    else
                    {
                        UpdateProgressText.Text = "Backup automatico completato";
                    }
                }));

                result = true;
            }
            catch (EmptyBackupFolderException e)
            {
                //update UI - error
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    UpdateProgressText.Text = "Impossibile effettuare il backup di una cartella vuota";
                }));

                result = false;
            }
            catch (Exception e)
            {
                Console.WriteLine("Errore nell'esecuzione del backup. " + e.Message);
                Console.WriteLine(e.StackTrace);

                //update UI - error
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    UpdateProgressText.Text = "Errore durante il backup";
                }));

                result = false;
            }
            finally
            {
                if (sslStream != null)
                {
                    sslStream.Close();
                }
                if (client != null)
                {
                    client.Close();
                }

                //update UI
                Application.Current.Dispatcher.Invoke(new Action(() => {
                    ((Storyboard)Resources["Storyboard"]).Stop();
                    BackupTile.IsEnabled         = true;
                    arrowImage.Visibility        = Visibility.Hidden;
                    UpdateProgressBar.Visibility = Visibility.Hidden;
                }));

                lock (locker)
                {
                    Interlocked.Exchange(ref backgroundRunning, FALSE);
                    System.Threading.Monitor.PulseAll(locker);
                }
            }

            return(result);
        }
Пример #5
0
        internal void retreiveBackupFilesTask(List <myFileInfo> requestedFilesList)
        {
            if (requestedFilesList.LongCount <myFileInfo>() <= 0)
            {
                return;
            }

            if (Interlocked.Read(ref backgroundRunning) == TRUE)
            {
                return;
            }

            Interlocked.Exchange(ref backgroundRunning, TRUE);

            TcpClient client    = null;
            SslStream sslStream = null;

            try
            {
                //update UI
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    UpdateProgressText.Text = "Operazione di recupero in corso...";
                }));

                /* Create a TCP/IP client socket and connect to the server */
                Client.ConnectServer(Properties.Settings.Default.machineName, Properties.Settings.Default.serverCertificateName, Properties.Settings.Default.PORT, out client, out sslStream);

                /* Retrieve backup from the server */
                Client.GetBackup(sslStream, Preferences.UserID.GetValue(), Preferences.SessionID.GetValue(), requestedFilesList, this);

                //update UI
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    UpdateProgressText.Text = "Operazione di recupero terminata";
                }));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Errore nell'esecuzione del backup. " + ex.Message);
                Console.WriteLine(ex.StackTrace);

                //update UI
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    UpdateProgressText.Text = "Errore durante il recupero dei file";
                }));
            }
            finally
            {
                if (sslStream != null)
                {
                    sslStream.Close();
                }
                if (client != null)
                {
                    client.Close();
                }

                lock (locker)
                {
                    Interlocked.Exchange(ref backgroundRunning, FALSE);
                    System.Threading.Monitor.PulseAll(locker);
                }

                //update UI
                Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    UpdateProgressBar.Visibility = Visibility.Hidden;
                }));
            }
        }