예제 #1
0
        /// <summary>
        /// classe ricorsiva che scandisce tutto il tree di directory e chiama un delegato sui singoli file
        /// </summary>
        /// <param name="root"></param>
        private void WalkDirectoryTree(System.IO.DirectoryInfo root, doOnFile_d doOnFile)
        {
            System.IO.FileInfo[]      files   = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                //files = root.GetFiles("*.*");
                files = root.GetFiles();
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                // da gestire il caso che non ho privilegi sufficienti ???
                MyLogger.print(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                MyLogger.print(e.Message);
                throw;
            }


            //e se file fosse null ma ci fossero sotto cartelle?? non devo ritornare!!
            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                    //Console.WriteLine(fi.FullName);
                    doOnFile(fi);
                }
            }

            // Now find all the subdirectories under this directory.
            subDirs = root.GetDirectories();

            foreach (System.IO.DirectoryInfo dirInfo in subDirs)
            {
                // Resursive call for each subdirectory.
                WalkDirectoryTree(dirInfo, doOnFile);
            }
        }
예제 #2
0
        /// <summary>
        /// costruttore
        /// </summary>
        /// <param name="path">path della cartella da monitorare</param>
        public DirMonitor(string path, SessionManager sm)
        {
            myDir = new System.IO.DirectoryInfo(path);

            if (!myDir.Exists)
            {
                throw new System.IO.DirectoryNotFoundException(path);
            }

            try
            {
                dim = new DirImageManager(myDir, sm);
            }
            catch (InitialBackupNeededException ibne)
            {
                //TODO! ATTENZIONE, COME INTERROMPO L'APPLICAZIONE METRE STA FACENDO L'INITIAL BACKUP ????? al momento solo tra un file e l'altro

                //non c'è ancora nessun backup sul server, impossibile scaricare una dirImage.
                //devo fare un initial backup completo. terminato quello bisogna riscaricare la dirImage
                completeFileList = new List <RecordFile>();

                //salvo vecchio delegato
                var buf = this.doOnFile;
                this.doOnFile = addAllFiles;

                //crea elenco completo file in root dir e subdirs
                WalkDirectoryTree(myDir, doOnFile);

                //rimetto delegato di prima
                this.doOnFile = buf;

                //effettua backup completo di tutti i file
                sm.sendInitialBackup(completeFileList);
                completeFileList = null;

                //se la cartella è vuota la new DirImageManager continua a fallire, viene rilanciata l'eccezione InitialBackupNeededException
                try
                {
                    //riscarico la dirImage
                    dim = new DirImageManager(myDir, sm);
                }
                catch (InitialBackupNeededException) { throw new EmptyDirException(); }
            }
            doOnFile = checkFile;
            init();
        }
예제 #3
0
        /// <summary>
        /// costruttore
        /// </summary>
        /// <param name="path">path della cartella da monitorare</param>
        public DirMonitor(string path, SessionManager sm)
        {
            myDir = new System.IO.DirectoryInfo(path);

            if (!myDir.Exists)
                throw new System.IO.DirectoryNotFoundException(path);

            try
            {
                dim = new DirImageManager(myDir, sm);
            }
            catch(InitialBackupNeededException ibne)
            {
                //TODO! ATTENZIONE, COME INTERROMPO L'APPLICAZIONE METRE STA FACENDO L'INITIAL BACKUP ????? al momento solo tra un file e l'altro

                //non c'è ancora nessun backup sul server, impossibile scaricare una dirImage.
                //devo fare un initial backup completo. terminato quello bisogna riscaricare la dirImage
                completeFileList = new List<RecordFile>();

                //salvo vecchio delegato
                var buf = this.doOnFile;
                this.doOnFile = addAllFiles;

                //crea elenco completo file in root dir e subdirs
                WalkDirectoryTree(myDir, doOnFile);

                //rimetto delegato di prima
                this.doOnFile = buf;

                //effettua backup completo di tutti i file
                sm.sendInitialBackup(completeFileList);
                completeFileList = null;

                //se la cartella è vuota la new DirImageManager continua a fallire, viene rilanciata l'eccezione InitialBackupNeededException
                try
                {
                    //riscarico la dirImage
                    dim = new DirImageManager(myDir, sm);
                }
                catch (InitialBackupNeededException) { throw new EmptyDirException(); }
            }
            doOnFile = checkFile;
            init();
        }
예제 #4
0
        /// <summary>
        /// classe ricorsiva che scandisce tutto il tree di directory e chiama un delegato sui singoli file
        /// </summary>
        /// <param name="root"></param>
        private void WalkDirectoryTree(System.IO.DirectoryInfo root, doOnFile_d doOnFile)
        {
            System.IO.FileInfo[] files = null;
            System.IO.DirectoryInfo[] subDirs = null;

            // First, process all the files directly under this folder
            try
            {
                //files = root.GetFiles("*.*");
                files = root.GetFiles();
            }
            // This is thrown if even one of the files requires permissions greater
            // than the application provides.
            catch (UnauthorizedAccessException e)
            {
                // da gestire il caso che non ho privilegi sufficienti ???
                MyLogger.print(e.Message);
            }

            catch (System.IO.DirectoryNotFoundException e)
            {
                MyLogger.print(e.Message);
                throw;
            }

            //e se file fosse null ma ci fossero sotto cartelle?? non devo ritornare!!
            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    // In this example, we only access the existing FileInfo object. If we
                    // want to open, delete or modify the file, then
                    // a try-catch block is required here to handle the case
                    // where the file has been deleted since the call to TraverseTree().
                    //Console.WriteLine(fi.FullName);
                    doOnFile(fi);
                }
            }

            // Now find all the subdirectories under this directory.
            subDirs = root.GetDirectories();

            foreach (System.IO.DirectoryInfo dirInfo in subDirs)
            {
                // Resursive call for each subdirectory.
                WalkDirectoryTree(dirInfo, doOnFile);
            }
        }