Example #1
0
        private void lDeletedFileVersions_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DependencyObject obj = (DependencyObject)e.OriginalSource;

            while (obj != null && obj != lDeletedFiles)
            {
                if (obj.GetType() == typeof(System.Windows.Controls.ListViewItem))
                {
                    DateTime deletedVersion = ((FileVersionListViewItem)lDeletedFileVersions.SelectedItem).sTimestamp;

                    foreach (DateTime fv in deletedFileUtente.Items)
                    {
                        if (deletedVersion == fv)
                        {
                            deletedFileVersion = fv;
                        }
                    }

                    MessageBoxResult res = System.Windows.MessageBox.Show("Do you want to restore file \"" + deletedFileUtente.Nome + "\" with version " + deletedVersion + " ?", "Restore system", System.Windows.MessageBoxButton.YesNo);

                    if (res == MessageBoxResult.Yes)
                    {
                        try
                        {
                            if (Command.Logged == true)
                            {
                                ControlloModifiche.StopTimer();
                                Command getVersComm = new ComandoScaricaFile(deletedFileUtente.Nome, deletedFileUtente.Path, deletedFileVersion);
                                getVersComm.esegui();
                                this.GetDelFiles();
                                ControlloModifiche.Inizializza();
                            }
                            else
                            {
                                Command loginComm = new ComandoLogin(connectionSettings.readSetting("account", "username"), connectionSettings.readSetting("account", "password"));
                                loginComm.esegui();
                            }
                        }
                        catch (ServerException ex)
                        {
                            System.Windows.MessageBox.Show("Restore failed\n" + ex.Message, "Restoring system", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;
                }
                obj = VisualTreeHelper.GetParent(obj);
            }
        }
        private void lFileVersions_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DependencyObject obj = (DependencyObject)e.OriginalSource;
            while (obj != null && obj != lDetails)
            {
                if (obj.GetType() == typeof(System.Windows.Controls.ListViewItem))
                {
                    DateTime selectedVersion = ((FileVersionListViewItem)lFileVersions.SelectedItem).sTimestamp;

                    foreach (DateTime fv in selectedFileUtente.Items)
                    {
                        if (selectedVersion == fv)
                            selectedFileVersion = fv;
                    }

                    MessageBoxResult res = System.Windows.MessageBox.Show("Do you want to restore file \"" + selectedFileUtente.Nome + "\" with version of " + selectedVersion + " ?", "Restore system", System.Windows.MessageBoxButton.YesNo);

                    if (res == MessageBoxResult.Yes)
                    {
                        try
                        {
                            if (Command.Logged == true)
                            {
                                ControlloModifiche.StopTimer();
                                Command getVersComm = new ComandoScaricaFile(selectedFileUtente.Nome, selectedFileUtente.Path, selectedFileVersion);
                                getVersComm.esegui();
                                this.GetFiles();
                                ControlloModifiche.Inizializza();
                            }
                            else
                            {
                                Command loginComm = new ComandoLogin(connectionSettings.readSetting("account", "username"), connectionSettings.readSetting("account", "password"));
                                loginComm.esegui();
                            }
                        }
                        catch (ServerException ex)
                        {
                            System.Windows.MessageBox.Show("Restore failed\n" + ex.Message, "Restoring system", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                    break;
                }
                obj = VisualTreeHelper.GetParent(obj);
            }
        }
        /// <summary>
        /// In ordine questa funzione:
        ///  - Cancella il contenuto della cartella base_path
        ///  - Cancella il database e lo ricrea con le tabelle vuote
        ///  - Scarica la lista dei path relativi
        ///  - Per ogni path, ricrea le cartelle e scarica i file con le loro versioni
        /// </summary>
        public static void RestoreAsLastStatusOnServer()
        {
            bool tmp = checker.Enabled;

            checker.Enabled = false;
            Log l = Log.getLog();

            lock (syncLock)
            {
                //Puliamo la cartella...
                if (Directory.Exists(base_path))
                {
                    Directory.Delete(base_path, recursive: true);
                }
                try
                {
                    DB_Table.RebuildDB();
                    Directory.CreateDirectory(base_path);

                    ComandoListFolders c = new ComandoListFolders();
                    c.esegui();
                    FileUtenteList flist = FileUtenteList.getInstance();
                    foreach (string path_rel in c.Paths)
                    {
                        string[] directories = path_rel.Split('\\');
                        string   tmp_path    = base_path;
                        foreach (string dir in directories)
                        {
                            tmp_path += dir + "\\";
                            if (!Directory.Exists(tmp_path))
                            {
                                Directory.CreateDirectory(tmp_path);
                            }
                        }
                        ComandoListDir c2 = new ComandoListDir(path_rel);
                        c2.esegui();
                        foreach (string nome_file in c2.FileNames)
                        {
                            ComandoListVersions c_vers = new ComandoListVersions(nome_file, path_rel);
                            c_vers.esegui();
                            DateTime[]         versions  = c_vers.Versions;
                            DateTime           last_vers = versions.Max();
                            ComandoScaricaFile c_scarica = new ComandoScaricaFile(nome_file, path_rel, last_vers);
                            c_scarica.esegui();
                            FileUtente fu = flist.CreaNuovo(nome_file, path_rel, last_vers, last_vers, c_scarica.Dim, c_scarica.SHAContenuto);
                            foreach (DateTime dt in versions)
                            {
                                if (dt != last_vers)
                                {
                                    fu.AggiungiVersione(dt);
                                }
                            }
                        }
                    }
                }
                catch (ServerException e)
                {
                    l.log(e.Message);
                    throw;
                }
                checker.Enabled = tmp;
            }
        }
        /// <summary>
        /// In ordine questa funzione:
        ///  - Cancella il contenuto della cartella base_path
        ///  - Cancella il database e lo ricrea con le tabelle vuote
        ///  - Scarica la lista dei path relativi
        ///  - Per ogni path, ricrea le cartelle e scarica i file con le loro versioni
        /// </summary>
        public static void RestoreAsLastStatusOnServer()
        {
            bool tmp = checker.Enabled;
            checker.Enabled = false;
            Log l = Log.getLog();

            lock (syncLock)
            {
                //Puliamo la cartella...
                if(Directory.Exists(base_path))
                    Directory.Delete(base_path, recursive: true);
                try
                {
                    DB_Table.RebuildDB();
                    Directory.CreateDirectory(base_path);

                    ComandoListFolders c = new ComandoListFolders();
                    c.esegui();
                    FileUtenteList flist = FileUtenteList.getInstance();
                    foreach (string path_rel in c.Paths)
                    {
                        string[] directories = path_rel.Split('\\');
                        string tmp_path = base_path;
                        foreach(string dir in directories)
                        {
                            tmp_path += dir + "\\";
                            if(!Directory.Exists(tmp_path))
                            {
                                Directory.CreateDirectory(tmp_path);
                            }
                        }
                        ComandoListDir c2 = new ComandoListDir(path_rel);
                        c2.esegui();
                        foreach (string nome_file in c2.FileNames)
                        {
                            ComandoListVersions c_vers = new ComandoListVersions(nome_file, path_rel);
                            c_vers.esegui();
                            DateTime[] versions = c_vers.Versions;
                            DateTime last_vers = versions.Max();
                            ComandoScaricaFile c_scarica = new ComandoScaricaFile(nome_file, path_rel, last_vers);
                            c_scarica.esegui();
                            FileUtente fu = flist.CreaNuovo(nome_file,path_rel, last_vers, last_vers, c_scarica.Dim, c_scarica.SHAContenuto);
                            foreach (DateTime dt in versions)
                            {
                                if(dt != last_vers)
                                    fu.AggiungiVersione(dt);
                            }
                        }
                    }
                }
                catch (ServerException e)
                {
                    l.log(e.Message);
                    throw;
                }
                checker.Enabled = tmp;
            }
        }