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

            while (obj != null && obj != lDeletedFiles)
            {
                if (obj.GetType() == typeof(System.Windows.Controls.ListViewItem))
                {
                    string deletedFileName = ((VersionListViewItem)lDeletedFiles.SelectedItem).sFilename;
                    string deletedFilePath = ((VersionListViewItem)lDeletedFiles.SelectedItem).sPath;

                    FileUtenteList fileUtenteList  = FileUtenteList.getInstance();
                    FileUtente[]   deletedFileList = fileUtenteList.Deleted;

                    foreach (FileUtente fu in deletedFileList)
                    {
                        if (fu.Nome == deletedFileName && fu.Path == deletedFilePath)
                        {
                            deletedFileUtente = fu;
                            break;
                        }
                    }

                    lDeletedFileVersions.Items.Clear();
                    foreach (DateTime fv in deletedFileUtente.Items)
                    {
                        lDeletedFileVersions.Items.Add(new FileVersionListViewItem(fv));
                    }
                    break;
                }
                obj = VisualTreeHelper.GetParent(obj);
            }
        }
Exemple #2
0
 public FileUtente this[int index]
 {
     get
     {
         if (__file_list[index] == null)
         {
             __file_list[index] = new FileUtente(__list_ids_files[index]);
         }
         return(__file_list[index]);
     }
     // set { }
 }
Exemple #3
0
        public void aggiornaDati(int newDim, DateTime newModTime, string newHash = null)
        {
            this.__dim        = newDim;
            this.__t_modifica = newModTime;
            if (newHash == null)
            {
                newHash = FileUtente.CalcolaSHA256(File.Open(this.__path_completo, FileMode.Open));
            }
            this.sha_contenuto = newHash;
            try
            {
                this.BeginTransaction();
                string[][] parameters = new string[2][];
                parameters[0] = new string[2] {
                    "@id_file", this.id.ToString()
                };
                parameters[1] = new string[2] {
                    "@timestamp_vers", this.__t_modifica.ToString("u")
                };
                this.ExecuteQuery(sql_add_version, parameters);

                //set <- UPDATE
                parameters    = new string[5][];
                parameters[0] = new string[2] {
                    "@dim", __dim.ToString()
                };
                parameters[1] = new string[2] {
                    "@t_modifica", __t_modifica.ToString("u")
                };
                parameters[2] = new string[2] {
                    "@sha_contenuto", sha_contenuto
                };
                parameters[3] = new string[2] {
                    "@id", id.ToString()
                };
                parameters[4] = new string[2] {
                    "@valido", __valido ? "TRUE" : "FALSE"
                };

                this.ExecuteQuery(sql_set_file_data, parameters);
                this.CommitTransaction();
            }
            catch
            {
                this.RollbackTransaction();
                throw;
            }
        }
Exemple #4
0
        public FileUtente CreaNuovo(string nome_file, string path, DateTime t_creazione, DateTime t_modifica, int dim, string sha_contenuto = null)
        {
            int      id = 0;
            DB_Table db = new DB_Table();

            sha_contenuto = sha_contenuto != null ? sha_contenuto : "";
            string[][] parameters = new string[6][];
            lock (this)
            {
                parameters[0] = new string[2] {
                    "@dim", dim.ToString()
                };
                parameters[1] = new string[2] {
                    "@t_modifica", t_modifica.ToString("u")
                };
                parameters[2] = new string[2] {
                    "@t_creazione", t_creazione.ToString("u")
                };
                parameters[3] = new string[2] {
                    "@sha_contenuto", sha_contenuto
                };
                parameters[4] = new string[2] {
                    "@nome_file", nome_file
                };
                parameters[5] = new string[2] {
                    "@path", path
                };

                db.ExecuteQuery(sql_nuovo_file, parameters);
                id = (int)db.getLastInsertedId();
                FileUtente fu = new FileUtente(id);
                fu.AggiungiVersione(t_modifica);
                this.__list_ids_files.Add(id);
                __file_list    = new FileUtente[__list_ids_files.Count];
                __deleted_list = new FileUtente[__list_deleted_ids.Count];
                return(fu);
            }
        }
        private void lDetails_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DependencyObject obj = (DependencyObject)e.OriginalSource;
            while (obj != null && obj != lDetails)
            {
                if (obj.GetType() == typeof(System.Windows.Controls.ListViewItem))
                {
                    string selectedFileName = ((VersionListViewItem)lDetails.SelectedItem).sFilename;
                    string selectedFilePath = ((VersionListViewItem)lDetails.SelectedItem).sPath;

                    FileUtenteList fileUtenteList = FileUtenteList.getInstance();
                    selectedFileUtente = fileUtenteList[selectedFileName, selectedFilePath];

                    lFileVersions.Items.Clear();
                    foreach (DateTime fv in selectedFileUtente.Items)
                    {
                        lFileVersions.Items.Add(new FileVersionListViewItem(fv));
                    }
                    break;
                }
                obj = VisualTreeHelper.GetParent(obj);
            }
        }
        public static void Check()
        {
            TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Central Europe Standard Time");

            if (!Directory.Exists(base_path))
            {
                return;
            }
            if (Monitor.TryEnter(syncLock))
            {
                try {
                    List <string[]>   files       = FileUtenteList.exploreFileSystem(base_path);
                    List <FileUtente> toBeDeleted = new List <FileUtente>();
                    FileUtenteList    list        = FileUtenteList.getInstance();
                    string[]          entry       = new string[2];
                    string            path_completo;
                    Command           c;

                    CultureInfo it = new CultureInfo("it-IT");
                    Thread.CurrentThread.CurrentCulture = it;

                    if (!init)
                    {
                        throw new ClientException("La classe per il controllo delle modifiche non è inizializzata correttamente.", ClientErrorCode.ControlloNonInizializzato);
                    }
                    if (!Command.Logged)
                    {
                        ComandoLogin login = new ComandoLogin(user, pwd);
                        login.esegui();
                    }
                    FileInfo finfo;
                    foreach (FileUtente fu in list)
                    {
                        //Check if still exists, and if its modified
                        entry[0] = fu.Nome;
                        entry[1] = fu.Path;
                        int index;
                        if ((index = files.FindIndex(fTest => (fTest[0] == entry[0] && fTest[1] == entry[1]))) >= 0)
                        {
                            files.RemoveAt(index);
                            //Il file selezionato esiste ancora...
                            path_completo = base_path + entry[1] + Path.DirectorySeparatorChar + entry[0];
                            finfo         = new FileInfo(path_completo);

                            DateTime dt   = TimeZoneInfo.ConvertTime(finfo.LastWriteTime, TimeZoneInfo.Local, tz);
                            DateTime tMod = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
                            tMod = tMod.AddTicks(-(tMod.Ticks % TimeSpan.TicksPerSecond));

                            if (DateTime.Compare(tMod, fu.TempoModifica) != 0)
                            {
                                FileStream fs      = File.Open(path_completo, FileMode.Open);
                                string     new_sha = FileUtente.CalcolaSHA256(fs);
                                if (new_sha != fu.SHA256Contenuto)
                                {
                                    fu.aggiornaDati((int)finfo.Length, finfo.LastWriteTime);
                                    c = new ComandoAggiornaContenutoFile(entry[0], entry[1], (int)finfo.Length,
                                                                         finfo.LastWriteTime, fu.SHA256Contenuto);
                                    c.esegui();
                                }
                            }
                        }
                        else
                        {
                            toBeDeleted.Add(fu);
                        }
                    }
                    //Cancelliamo
                    foreach (FileUtente _fu in toBeDeleted)
                    {
                        list.Delete(_fu.Id);
                        c = new ComandoEliminaFile(_fu.Nome, _fu.Path);
                        c.esegui();
                    }

                    //file nuovi
                    FileUtente fu2;
                    foreach (string[] n_file in files)
                    {
                        string file_path_completo = base_path + n_file[1] + Path.DirectorySeparatorChar + n_file[0];
                        finfo = new FileInfo(file_path_completo);
                        DateTime dt   = TimeZoneInfo.ConvertTime(finfo.LastWriteTime, TimeZoneInfo.Local, tz);
                        DateTime tMod = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
                        tMod = tMod.AddTicks(-(tMod.Ticks % TimeSpan.TicksPerSecond));
                        dt   = TimeZoneInfo.ConvertTime(finfo.CreationTime, TimeZoneInfo.Local, tz);
                        DateTime tCre = DateTime.SpecifyKind(dt, DateTimeKind.Utc);
                        tCre = tCre.AddTicks(-(tCre.Ticks % TimeSpan.TicksPerSecond));

                        FileStream fs      = File.Open(file_path_completo, FileMode.Open);
                        string     new_sha = FileUtente.CalcolaSHA256(fs);
                        fu2 = list.CreaNuovo(n_file[0], n_file[1], tCre, tMod, (int)finfo.Length, new_sha);
                        c   = new ComandoNuovoFile(n_file[0], n_file[1], (int)finfo.Length, tCre, tMod, new_sha);
                        c.esegui();
                    }
                }
                finally
                {
                    if (Monitor.IsEntered(syncLock))
                    {
                        Monitor.Exit(syncLock);
                    }
                }
            }
        }
        /// <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;
            }
        }