Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

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

  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using be.gaudry.model.config;
  5. using be.gaudry.model.enums;
  6.  
  7. namespace be.gaudry.model.file
  8. {
  9. /// <summary>
  10. /// Provides template to parse files and force to implement something to do on files
  11. /// </summary>
  12. public abstract class AbstractFileParser
  13. {
  14.  
  15. #region declarations and constructors
  16. protected internal float progressMax, progressToDo;
  17. protected internal String startPath;
  18. protected internal bool includeSubFolders, includeHidden, preCalcProgress, validPreviousProgress;
  19. public AbstractFileParser()
  20. {
  21. progressToDo = 0F;
  22. progressMax = 0F;
  23. validPreviousProgress = false;
  24. includeSubFolders = true;
  25. includeHidden = false;
  26. preCalcProgress = true;
  27. SourcesManager.addSource(new Source(
  28. "TargetInvocationException",
  29. "AbstractFileParser",
  30. "http://www.thescripts.com/forum/thread519073.html",
  31. "TargetInvocationException et utilisation pour e.Results"
  32. )
  33. );
  34. }
  35. #endregion
  36.  
  37. #region properties
  38. /// <summary>
  39. /// True to search on the subfolders
  40. /// </summary>
  41. /// <remarks>
  42. /// Modifying this forces total size calculation if progress needed
  43. /// </remarks>
  44. public bool IncludeSubFolders
  45. {
  46. get { return includeSubFolders; }
  47. set
  48. {
  49. if (includeSubFolders != value)
  50. {
  51. //forces size calculation if progress needed
  52. validPreviousProgress = false;
  53. }
  54. includeSubFolders = value;
  55. }
  56. }
  57. /// <summary>
  58. /// True to search on the hidden files
  59. /// </summary>
  60. /// <remarks>
  61. /// Modifying this forces total size calculation if progress needed
  62. /// </remarks>
  63. public bool IncludeHiddenFiles
  64. {
  65. get { return includeHidden; }
  66. set
  67. {
  68. if (includeHidden != value)
  69. {
  70. //forces size calculation if progress needed
  71. validPreviousProgress = false;
  72. }
  73. includeHidden = value;
  74. }
  75. }
  76. public bool PreCalcProgress
  77. {
  78. get { return preCalcProgress; }
  79. set { preCalcProgress = value; }
  80. }
  81. /// <summary>
  82. /// Path of the root directory where to search
  83. /// </summary>
  84. /// <remarks>
  85. /// Modifying this forces total size calculation if progress needed
  86. /// </remarks>
  87. public String StartPath
  88. {
  89. get { return this.startPath; }
  90. set
  91. {
  92. if (startPath != value)
  93. {
  94. //forces size calculation if progress needed
  95. validPreviousProgress = false;
  96. }
  97. startPath = value;
  98. }
  99. }
  100. #endregion
  101.  
  102. #region public methods
  103. public virtual long parse(BackgroundWorker bgw, DoWorkEventArgs e)
  104. {
  105. DirectoryInfo dirsInf = new DirectoryInfo(startPath);
  106. if (!validPreviousProgress)
  107. {
  108. // reset the progressMax if not valid because the searchMedia asynchroneous method will
  109. // add sizes along the search
  110. progressMax = 0F;
  111. if (preCalcProgress)
  112. {
  113. // Get progressMax before the first search,
  114. // or if a search parameter having a signification for the progressMax value has been modified
  115. bgw.ReportProgress((int)BGWORKER.currentInfo, "Lecture de la taille totale du répertoire");
  116. progressMax = (float)FileHelper.getDirectoryLength(bgw, e, dirsInf, includeSubFolders);
  117. validPreviousProgress = true;
  118. }
  119. }
  120. //job may have been cancelled during the getDirectoryLength asynchroneous method
  121. if (!bgw.CancellationPending)
  122. {
  123. // Set the progressMax with the result of the search
  124. // the second search with the same basics search parameters
  125. // will able to display the progress
  126. //progressMax = browse(bgw, e, progressMax);
  127. progressToDo = progressMax;
  128. if (validPreviousProgress)
  129. {
  130. bgw.ReportProgress((int)BGWORKER.progressBarStyle_Block);
  131. }
  132. parseFiles(bgw, e, dirsInf, 0);
  133. }
  134. //job may have been cancelled during the searchMedia asynchroneous method
  135. if (!bgw.CancellationPending)
  136. {
  137. validPreviousProgress = true;
  138. bgw.ReportProgress((int)BGWORKER.currentInfo, "Lecture de la taille totale du répertoire");
  139. }
  140. return (long)progressMax;
  141. }
  142. #endregion
  143.  
  144. #region methods to implement
  145. /// <summary>
  146. /// Do something on each file
  147. /// </summary>
  148. /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param>
  149. /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param>
  150. /// <param name="fi">FileInfo to check</param>
  151. /// <param name="percent">(int) Progress percentage</param>
  152. /// <param name="subDirDeep">Deep of the directory in comparison with start directory</param>
  153. /// <returns>
  154. /// 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)
  155. /// false otherwise
  156. ///</returns>
  157. protected abstract bool performOnFile(BackgroundWorker bgw, DoWorkEventArgs e, FileInfo fi, int percent, int subDirDeep);
  158. #endregion
  159.  
  160. #region protected internal methods
  161. /// <summary>
  162. ///
  163. /// </summary>
  164. /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param>
  165. /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param>
  166. /// <param name="dirsInf">DirectoryInfo to get size</param>
  167. /// <param name="subDirDeep">Deep of the directory in comparison with start directory</param>
  168. protected internal void parseFiles(BackgroundWorker bgw, DoWorkEventArgs e, DirectoryInfo dirsInf, int subDirDeep)
  169. {
  170. if (bgw.CancellationPending)
  171. {
  172. e.Cancel = true;
  173. }
  174. else
  175. {
  176. bgw.ReportProgress((int)BGWORKER.currentInfo, dirsInf.Name);
  177. try
  178. {
  179. FileInfo[] filesInf = dirsInf.GetFiles();
  180. foreach (FileInfo fi in filesInf)
  181. {
  182. progressToDo -= fi.Length;
  183. // add length to avoid calculate progressMax each time
  184. if (!validPreviousProgress)
  185. {
  186. progressMax += fi.Length;
  187. }
  188. if (perform(bgw, e, fi, subDirDeep))
  189. {
  190. break;
  191. }
  192. }
  193. }
  194. catch (Exception) { }
  195. if (includeSubFolders)
  196. {
  197. try
  198. {
  199. subDirDeep++;
  200. foreach (DirectoryInfo dir in dirsInf.GetDirectories())
  201. {
  202. parseFiles(bgw, e, dir, subDirDeep);
  203. }
  204. }
  205. catch (Exception) { }
  206. }
  207. }
  208. }
  209. /// <summary>
  210. ///
  211. /// </summary>
  212. /// <param name="bgw">BackgroundWorker to perform cancel if needed, and report progress</param>
  213. /// <param name="e">DoWorkEventArgs to perform cancel if needed, and report progress</param>
  214. /// <param name="fi">FileInfo</param>
  215. /// <param name="subDirDeep">Deep of the directory in comparison with start directory</param>
  216. /// <returns></returns>
  217. protected internal bool perform(BackgroundWorker bgw, DoWorkEventArgs e, FileInfo fi, int subDirDeep)
  218. {
  219. if (bgw.CancellationPending)
  220. {
  221. e.Cancel = true;
  222. return true;
  223. }
  224. else
  225. {
  226. int progressPercent = (validPreviousProgress) ? ((progressToDo <= progressMax) ? (int)((progressMax - progressToDo) / progressMax * 100) : 100) : 1;
  227. if (!IncludeHiddenFiles && ((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden))
  228. {
  229. bgw.ReportProgress(progressPercent, null);
  230. return false;
  231. }
  232. return performOnFile(bgw, e, fi, progressPercent, subDirDeep);
  233. }
  234. }
  235. #endregion
  236.  
  237. }
  238. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/file/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1713547457 19/04/2024 19:24:17
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/broldev/src/model/file/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csAbstractFileParser.cs9.32 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csFileHelper.cs9.48 Ko31/10/2018 18:33:10-refusé-
Afficher le fichier .cs|.csAbstractFilesAndDirParser.cs2.97 Ko31/10/2018 18:33:10-refusé-

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.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 16/10/2009 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/cs-broldev-source-rf-model/file/AbstractFileParser.cs.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.