AbstractFileParser.cs
Description du code
AbstractFileParser.cs est un fichier du projet BrolDev.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/broldev/src/.
Projet BrolDev : Librairie de composants réutilisables pour les applications BrolDev en CSharp.
Code source ou contenu du fichier
Code c# (AbstractFileParser.cs) (238 lignes)
using System; using System.ComponentModel; using System.IO; using be.gaudry.model.config; using be.gaudry.model.enums; namespace be.gaudry.model.file { /// <summary> /// Provides template to parse files and force to implement something to do on files /// </summary> public abstract class AbstractFileParser { #region declarations and constructors protected internal float progressMax, progressToDo; protected internal String startPath; protected internal bool includeSubFolders, includeHidden, preCalcProgress, validPreviousProgress; public AbstractFileParser() { progressToDo = 0F; progressMax = 0F; validPreviousProgress = false; includeSubFolders = true; includeHidden = false; preCalcProgress = true; "TargetInvocationException", "AbstractFileParser", "http://www.thescripts.com/forum/thread519073.html", "TargetInvocationException et utilisation pour e.Results" ) ); } #endregion #region properties /// <summary> /// True to search on the subfolders /// </summary> /// <remarks> /// Modifying this forces total size calculation if progress needed /// </remarks> public bool IncludeSubFolders { get { return includeSubFolders; } set { if (includeSubFolders != value) { //forces size calculation if progress needed validPreviousProgress = false; } includeSubFolders = value; } } /// <summary> /// True to search on the hidden files /// </summary> /// <remarks> /// Modifying this forces total size calculation if progress needed /// </remarks> public bool IncludeHiddenFiles { get { return includeHidden; } set { if (includeHidden != value) { //forces size calculation if progress needed validPreviousProgress = false; } includeHidden = value; } } public bool PreCalcProgress { get { return preCalcProgress; } set { preCalcProgress = value; } } /// <summary> /// Path of the root directory where to search /// </summary> /// <remarks> /// Modifying this forces total size calculation if progress needed /// </remarks> public String StartPath { get { return this.startPath; } set { if (startPath != value) { //forces size calculation if progress needed validPreviousProgress = false; } startPath = value; } } #endregion #region public methods public virtual long parse(BackgroundWorker bgw, DoWorkEventArgs e) { if (!validPreviousProgress) { // reset the progressMax if not valid because the searchMedia asynchroneous method will // add sizes along the search progressMax = 0F; if (preCalcProgress) { // Get progressMax before the first search, // or if a search parameter having a signification for the progressMax value has been modified bgw.ReportProgress((int)BGWORKER.currentInfo, "Lecture de la taille totale du répertoire"); progressMax = (float)FileHelper.getDirectoryLength(bgw, e, dirsInf, includeSubFolders); validPreviousProgress = true; } } //job may have been cancelled during the getDirectoryLength asynchroneous method if (!bgw.CancellationPending) { // Set the progressMax with the result of the search // the second search with the same basics search parameters // will able to display the progress //progressMax = browse(bgw, e, progressMax); progressToDo = progressMax; if (validPreviousProgress) { bgw.ReportProgress((int)BGWORKER.progressBarStyle_Block); } parseFiles(bgw, e, dirsInf, 0); } //job may have been cancelled during the searchMedia asynchroneous method if (!bgw.CancellationPending) { validPreviousProgress = true; bgw.ReportProgress((int)BGWORKER.currentInfo, "Lecture de la taille totale du répertoire"); } return (long)progressMax; } #endregion #region methods to implement /// <summary> /// Do something on each file /// </summary> /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param> /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param> /// <param name="fi">FileInfo to check</param> /// <param name="percent">(int) Progress percentage</param> /// <param name="subDirDeep">Deep of the directory in comparison with start directory</param> /// <returns> /// true if we must stop the parsing of current directory (ie. if we have a vob file, we don't check the other files in this directory) /// false otherwise ///</returns> protected abstract bool performOnFile(BackgroundWorker bgw, DoWorkEventArgs e, FileInfo fi, int percent, int subDirDeep); #endregion #region protected internal methods /// <summary> /// /// </summary> /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param> /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param> /// <param name="dirsInf">DirectoryInfo to get size</param> /// <param name="subDirDeep">Deep of the directory in comparison with start directory</param> protected internal void parseFiles(BackgroundWorker bgw, DoWorkEventArgs e, DirectoryInfo dirsInf, int subDirDeep) { if (bgw.CancellationPending) { e.Cancel = true; } else { bgw.ReportProgress((int)BGWORKER.currentInfo, dirsInf.Name); try { FileInfo[] filesInf = dirsInf.GetFiles(); foreach (FileInfo fi in filesInf) { progressToDo -= fi.Length; // add length to avoid calculate progressMax each time if (!validPreviousProgress) { progressMax += fi.Length; } if (perform(bgw, e, fi, subDirDeep)) { break; } } } catch (Exception) { } if (includeSubFolders) { try { subDirDeep++; foreach (DirectoryInfo dir in dirsInf.GetDirectories()) { parseFiles(bgw, e, dir, subDirDeep); } } catch (Exception) { } } } } /// <summary> /// /// </summary> /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param> /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param> /// <param name="fi">FileInfo</param> /// <param name="subDirDeep">Deep of the directory in comparison with start directory</param> /// <returns></returns> protected internal bool perform(BackgroundWorker bgw, DoWorkEventArgs e, FileInfo fi, int subDirDeep) { if (bgw.CancellationPending) { e.Cancel = true; return true; } else { int progressPercent = (validPreviousProgress) ? ((progressToDo <= progressMax) ? (int)((progressMax - progressToDo) / progressMax * 100) : 100) : 1; if (!IncludeHiddenFiles && ((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)) { bgw.ReportProgress(progressPercent, null); return false; } return performOnFile(bgw, e, fi, progressPercent, subDirDeep); } } #endregion } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1734984260 23/12/2024 21:04:20 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 16/10/2009, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/cs-broldev-source-rf-model/file/AbstractFileParser.cs.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.