IDirectoryBrowser.cs
上传用户:daihuo
上传日期:2018-11-13
资源大小:28k
文件大小:7k
源码类别:

C#编程

开发平台:

C#

  1. // ------------------------------------------------------------------------------------------------------------------//
  2. // Developed by: Jean-Christophe Grégoire
  3. // CodeProject profile: http://www.codeproject.com/script/Membership/Profiles.aspx?mid=496750
  4. // e-Mail address: dio@dioland.com
  5. // Initial Release Date: 01/01/2009
  6. // ------------------------------------------------------------------------------------------------------------------//
  7. using System;
  8. using System.Collections.ObjectModel;
  9. namespace System.Extensions.IO
  10. {
  11.     /// <summary>
  12.     /// Defines an engine that can read the contents of a disk folder and return
  13.     /// a list of folders and files having positive matches for one or multiple
  14.     /// <see cref="ISearchFilter{T}"/> objects using one of the various introspection
  15.     /// techniques defined by a <see cref="DirectoryBrowserSearchBehavior"/> object.
  16.     /// </summary>
  17.     /// <remarks>
  18.     /// The <see cref="ISearchFilter{T}"/> interface has been left generic enough to
  19.     /// permit any kind of search/comparison. Default concrete implementations like
  20.     /// <see cref="FileSystemInfoNameSearchFilter{T}"/> and
  21.     /// <see cref="FileSystemInfoAttributeSearchFilter{T}"/> are provided to validate
  22.     /// folders and files against pre-determined patterns and attributes but you could
  23.     /// perfectly make a new class also inheriting from the <see cref="SearchFilter{T}"/>
  24.     /// base class (to inherit  a Decorator behavior and allow stacking of multiple filters)
  25.     /// that would for example  be able to look inside files for a given string. Such a
  26.     /// sample implementation actually exists, the <see cref="FileInfoContentsSearchFilter"/>
  27.     /// shows a very basic implementation that can search for a particular string in files.
  28.     /// </remarks>
  29.     public interface IDirectoryBrowser
  30.     {
  31.         #region Properties
  32.         /// <summary>
  33.         /// Returns wether one of the three methods
  34.         /// <see cref="BrowseDirectory()"/>, <see cref="BrowseDirectory(DirectoryBrowserSearchBehavior)"/>
  35.         /// or <see cref="BrowseDirectory(DirectoryBrowserSearchBehavior,IDirectoryBrowserSearchFilters)"/>
  36.         /// has already been called.
  37.         /// </summary>
  38.         Boolean HasBrowsed
  39.         { get; }
  40.         /// <summary>
  41.         /// Gets or sets the disk folder that needs to be associated with this
  42.         /// <see cref="IDirectoryBrowser"/> instance. This is the folder that will be searched
  43.         /// when calling one of the three methods <see cref="BrowseDirectory()"/>,
  44.         /// <see cref="BrowseDirectory(DirectoryBrowserSearchBehavior)"/> or
  45.         /// <see cref="BrowseDirectory(DirectoryBrowserSearchBehavior,IDirectoryBrowserSearchFilters)"/>.
  46.         /// </summary>
  47.         String RootFolder
  48.         { get; set; }
  49.         /// <summary>
  50.         /// Returns wether the <see cref="Errors"/> property contains at least one
  51.         /// exception.
  52.         /// </summary>
  53.         Boolean HasErrors
  54.         { get; }
  55.         /// <summary>
  56.         /// Returns all exceptions that may have occured during the last browsing
  57.         /// operation. These exceptions include both exceptions that may have
  58.         /// occured while reading the contents of the <see cref="RootFolder"/>
  59.         /// and exceptions that may have occured in other <see cref="IDirectoryBrowser"/>
  60.         /// child objects for child folders.
  61.         /// </summary>
  62.         ReadOnlyCollection<Exception> Errors
  63.         { get;  }
  64.         #endregion
  65.         #region Methods
  66.         /// <summary>
  67.         /// Reads the contents of the <see cref="RootFolder"/> disk folder and returns
  68.         /// the list of all its direct child folders and files. Indeed, the browser mode
  69.         /// defaults to <see cref="DirectoryBrowserModes.ExcludeChildDirectories"/>; this
  70.         /// behavior is inherited from the <see cref="DirectoryBrowserSearchBehavior"/>
  71.         /// default constructor.
  72.         /// </summary>
  73.         /// <returns></returns>
  74.         IDirectoryBrowsingResults BrowseDirectory();
  75.         /// <summary>
  76.         /// Reads the contents of the <see cref="RootFolder"/> disk folder and returns
  77.         /// a list of folders and files using one of the various introspection
  78.         /// techniques defined by a <see cref="DirectoryBrowserSearchBehavior"/> object.
  79.         /// When no <see cref="ISearchFilter{T}"/> objects are provided via a
  80.         /// <see cref="IDirectoryBrowserSearchFilters"/> object, all files and folders are considered
  81.         /// as matching. Therefore, the <see cref="DirectoryBrowserSearchBehavior"/> can just be
  82.         /// used to include or exclude the contents of child folders.
  83.         /// </summary>
  84.         /// <param name="searchBehavior">
  85.         /// A <see cref="DirectoryBrowserSearchBehavior"/> object to specify wether child folders
  86.         /// should also be searched or not.
  87.         /// </param>
  88.         /// <returns></returns>
  89.         IDirectoryBrowsingResults BrowseDirectory(DirectoryBrowserSearchBehavior searchBehavior);
  90.         /// <summary>
  91.         /// Reads the contents of the <see cref="RootFolder"/> disk folder and returns
  92.         /// a list of folders and files having positive matches for one or multiple
  93.         /// <see cref="ISearchFilter{T}"/> objects using one of the various introspection
  94.         /// techniques defined by a <see cref="DirectoryBrowserSearchBehavior"/> object.
  95.         /// </summary>
  96.         /// <param name="searchBehavior">
  97.         /// A <see cref="DirectoryBrowserSearchBehavior"/> object to specify wether child folders
  98.         /// should also be searched or not. Child folders can be excluded or included idependently
  99.         /// using one or more <see cref="ISearchFilter{T}"/> objects, and they can be searched
  100.         /// to return all of their contents or just filtered contents when they match themselves
  101.         /// directory search criterias.
  102.         /// </param>
  103.         /// <param name="searchFilters">
  104.         /// A <see cref="IDirectoryBrowser"/> object encapsulating one <see cref="SearchFilter{DirectoryInfo}"/>
  105.         /// and one <see cref="SearchFilter{FileInfo}"/> for being able to process folders and files
  106.         /// independently. You are not restricted to the use of one single search filter for all folders and
  107.         /// another single search filter for all files, stacking multiple <see cref="ISearchFilter{T}"/> filter objects
  108.         /// for folders and/or files is possible when using a type deriving from <see cref="SearchFilter{T}"/>
  109.         /// because it implements a Decorator pattern. When a filter is null or empty, all folders/files are
  110.         /// considered as matching.
  111.         /// </param>
  112.         /// <returns></returns>
  113.         IDirectoryBrowsingResults BrowseDirectory(DirectoryBrowserSearchBehavior searchBehavior, IDirectoryBrowserSearchFilters searchFilters);
  114.         #endregion
  115.     }
  116. }