IOAccessFactory

by Daniel Marbach on December 29th, 2009
No notes
Syntax: C#
Show lines - Hide lines - Show in textbox - Download
  1. /// <summary>
  2. /// The IO access factory which implements <see cref="IIOAccessFactory"/>.
  3. /// </summary>
  4. public class IOAccessFactory : IIOAccessFactory
  5. {
  6. /// <summary>
  7. /// Creates the directory access layer.
  8. /// </summary>
  9. /// <returns>An instance implementing <see cref="IDirectoryAccess"/>.</returns>
  10. public IDirectoryAccess CreateDirectoryAccess()
  11. {
  12. return new DirectoryAccess();
  13. }
  14.  
  15. /// <summary>
  16. /// Creates the file access layer.
  17. /// </summary>
  18. /// <returns>An instance implementing <see cref="IFileAccess"/>.</returns>
  19. public IFileAccess CreateFileAccess()
  20. {
  21. return new FileAccess();
  22. }
  23.  
  24. /// <summary>
  25. /// Creates the path access layer.
  26. /// </summary>
  27. /// <returns>An instance implementing <see cref="IPathAccess"/>.</returns>
  28. public IPathAccess CreatePathAccess()
  29. {
  30. return new PathAccess();
  31. }
  32.  
  33. /// <summary>
  34. /// Creates the file info access.
  35. /// </summary>
  36. /// <param name="fileInfo">The file info.</param>
  37. /// <returns>An instance implementing <see cref="IFileInfoAccess"/>.</returns>
  38. public IFileInfoAccess CreateFileInfo(FileInfo fileInfo)
  39. {
  40. return new FileInfoAccess(fileInfo);
  41. }
  42.  
  43. /// <summary>
  44. /// Creates the file info access.
  45. /// </summary>
  46. /// <param name="pathToFile">The file path.</param>
  47. /// <returns>
  48. /// An instance implementing <see cref="IFileInfoAccess"/>.
  49. /// </returns>
  50. /// <exception cref="ArgumentNullException"><paramref name="pathToFile"/> is null.
  51. /// </exception>
  52. /// <exception cref="SecurityException">The caller does not have the required
  53. /// permission.</exception>
  54. /// <exception cref="ArgumentException">The file name is empty, contains only white
  55. /// spaces, or contains invalid characters.</exception>
  56. /// <exception cref="UnauthorizedAccessException">Access to
  57. /// <paramref name="pathToFile"/> is denied.</exception>
  58. /// <exception cref="PathTooLongException">The specified path, file name, or both
  59. /// exceed the system-defined maximum length. For example, on Windows-based
  60. /// platforms, paths must be less than 248 characters, and file names must be less
  61. /// than 260 characters.</exception>
  62. /// <exception cref="NotSupportedException"><paramref name="pathToFile"/> contains
  63. /// a colon (:) in the middle of the string.</exception>
  64. public IFileInfoAccess CreateFileInfo(string pathToFile)
  65. {
  66. return new FileInfoAccess(new FileInfo(pathToFile));
  67. }
  68.  
  69. /// <summary>
  70. /// Creates the directory info access.
  71. /// </summary>
  72. /// <param name="directoryInfo">The directory info.</param>
  73. /// <returns>An instance implementing <see cref="IDirectoryInfoAccess"/>.</returns>
  74. public IDirectoryInfoAccess CreateDirectoryInfo(DirectoryInfo directoryInfo)
  75. {
  76. return new DirectoryInfoAccess(directoryInfo);
  77. }
  78.  
  79. /// <summary>
  80. /// Creates the directory info access.
  81. /// </summary>
  82. /// <param name="pathToDirectory">The directory path.</param>
  83. /// <returns>
  84. /// An instance implementing <see cref="IDirectoryInfoAccess"/>.
  85. /// </returns>
  86. /// <exception cref="ArgumentNullException">path is null.</exception>
  87. /// <exception cref="SecurityException">The caller does not have the required
  88. /// permission.</exception>
  89. /// <exception cref="ArgumentException">path contains invalid characters.</exception>
  90. /// <exception cref="PathTooLongException">The specified path, file name, or both
  91. /// exceed the system-defined maximum length. For example, on Windows-based
  92. /// platforms, paths must be less than 248 characters, and file names must be less
  93. /// than 260 characters. The specified path, file name, or both are too long.
  94. /// </exception>
  95. public IDirectoryInfoAccess CreateDirectoryInfo(string pathToDirectory)
  96. {
  97. return new DirectoryInfoAccess(new DirectoryInfo(pathToDirectory));
  98. }
  99.  
  100. /// <summary>
  101. /// Creates the drive info.
  102. /// </summary>
  103. /// <param name="driveInfo">The drive info.</param>
  104. /// <returns>An instance implementing <see cref="IDriveInfoAccess"/>.</returns>
  105. public IDriveInfoAccess CreateDriveInfo(DriveInfo driveInfo)
  106. {
  107. return new DriveInfoAccess(driveInfo);
  108. }
  109.  
  110. /// <summary>
  111. /// Creates the drive info access.
  112. /// </summary>
  113. /// <param name="driveName">A valid drive path or drive letter. This can be either
  114. /// uppercase or lowercase, 'a' to 'z'. A null value is not valid.</param>
  115. /// <exception cref="ArgumentNullException">The drive letter cannot be null.
  116. /// </exception>
  117. /// <exception cref="ArgumentException">The first letter of
  118. /// <paramref name="driveName"/> is not an uppercase or lowercase letter from 'a'
  119. /// to 'z'. -or-
  120. /// <paramref name="driveName"/> does not refer to a valid drive.</exception>
  121. /// <returns>An instance implementing <see cref="IDriveInfoAccess"/>.</returns>
  122. public IDriveInfoAccess CreateDriveInfo(string driveName)
  123. {
  124. return new DriveInfoAccess(new DriveInfo(driveName));
  125. }
  126. }

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS