123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- using System;
- using System.IO;
- using System.Text;
- using System.Xml;
- namespace Wayne.Lib.IO
- {
- /// <summary>
- /// File system abstraction. Should be used instead of System.IO namespace, so we can
- /// mock the file system away in unit tests.
- /// </summary>
- public interface IFileSupport
- {
- /// <summary>
- /// Opens a file.
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="fileMode"></param>
- /// <param name="fileAccess"></param>
- /// <param name="fileShare"></param>
- /// <param name="retries"></param>
- /// <param name="delayBetweenRetries"></param>
- /// <returns></returns>
- [System.Diagnostics.DebuggerStepThrough]
- Stream Open(string fileName, FileMode fileMode, FileAccess fileAccess, FileShare fileShare, int retries, int delayBetweenRetries);
- /// <summary>
- /// Opens a file, using standard values for retries (100) and delayBetweenRetries(100)
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="fileMode"></param>
- /// <param name="fileAccess"></param>
- /// <param name="fileShare"></param>
- /// <returns></returns>
- Stream Open(string fileName, FileMode fileMode, FileAccess fileAccess, FileShare fileShare);
- /// <summary>
- /// Moves a file.
- /// </summary>
- /// <param name="sourceFileName"></param>
- /// <param name="destinationFileName"></param>
- /// <param name="retries"></param>
- /// <param name="delayBetweenRetries"></param>
- [System.Diagnostics.DebuggerStepThrough]
- void Move(string sourceFileName, string destinationFileName, int retries, int delayBetweenRetries);
- /// <summary>
- /// Moves a file, using standard values for retries (100) and delayBetweenRetries(100)
- /// </summary>
- /// <param name="sourceFileName"></param>
- /// <param name="destinationFileName"></param>
- [System.Diagnostics.DebuggerStepThrough]
- void Move(string sourceFileName, string destinationFileName);
- /// <summary>
- /// Moves a directory.
- /// </summary>
- /// <param name="sourceDirName"></param>
- /// <param name="destDirName"></param>
- /// <param name="retries"></param>
- /// <param name="delayBetweenRetries"></param>
- [System.Diagnostics.DebuggerStepThrough]
- void MoveDirectory(string sourceDirName, string destDirName, int retries, int delayBetweenRetries);
- /// <summary>
- /// Moves a directory, using standard values for retries (100) and delayBetweenRetries(100)
- /// </summary>
- /// <param name="sourceDirName"></param>
- /// <param name="destDirName"></param>
- [System.Diagnostics.DebuggerStepThrough]
- void MoveDirectory(string sourceDirName, string destDirName);
- /// <summary>
- /// Deletes a file
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="retries"></param>
- /// <param name="delayBetweenRetries"></param>
- [System.Diagnostics.DebuggerStepThrough]
- void Delete(string fileName, int retries, int delayBetweenRetries);
- /// <summary>
- /// Deletes a file, using standard values for retries (100) and delayBetweenRetries(100)
- /// </summary>
- /// <param name="fileName"></param>
- [System.Diagnostics.DebuggerStepThrough]
- void Delete(string fileName);
- /// <summary>
- /// Get- and set property for the SecureDelete support object. Needed to create backend to the secure delete function.
- /// </summary>
- ISecureDeleteSupport SecureDeleteSupport { get; set; }
- /// <summary>
- /// Gets or sets tha File support extension that can be different depending on the execution platform (WinCE or Win32)
- /// </summary>
- IFileSupportExtension FileSupportExtension { get; set; }
- /// <summary>
- /// Paths implementation ref.
- /// </summary>
- IPaths Paths { get;}
- /// <summary>
- /// Deletes a file securely.
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="sDeleteOK"></param>
- /// <param name="retries"></param>
- /// <param name="delayBetweenRetries"></param>
- void SecureDelete(string fileName, out bool sDeleteOK, int retries, int delayBetweenRetries);
- /// <summary>
- /// Deletes a file securely.
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="sDeleteOK"></param>
- void SecureDelete(string fileName, out bool sDeleteOK);
- /// <summary>
- /// Copy a file.
- /// </summary>
- /// <param name="sourceFileName"></param>
- /// <param name="destinationFileName"></param>
- /// <param name="overwrite"></param>
- void Copy(string sourceFileName, string destinationFileName, bool overwrite);
- /// <summary>
- /// Copies a file.
- /// </summary>
- /// <param name="sourceFileName"></param>
- /// <param name="destinationFileName"></param>
- /// <param name="overwrite"></param>
- /// <param name="retries"></param>
- /// <param name="delayBetweenRetries"></param>
- [System.Diagnostics.DebuggerStepThrough]
- void Copy(string sourceFileName, string destinationFileName, bool overwrite, int retries, int delayBetweenRetries);
- /// <summary>
- /// Read the lines of a text file into a byte array.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- byte[] LoadToByteArray(string fileName);
- /// <summary>
- /// Read the lines of a text file into a string.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- string LoadToString(string fileName);
- /// <summary>
- /// Read the lines of a text file into a string.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- /// <param name="encoding">The encoding.</param>
- string LoadToString(string fileName, System.Text.Encoding encoding);
- /// <summary>
- /// Read the lines of a text file into an array of strings.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- string[] LoadToStringArray(string fileName);
- /// <summary>
- /// Read the lines of a text file into an array of strings.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- /// <param name="encoding">The encoding.</param>
- string[] LoadToStringArray(string fileName, System.Text.Encoding encoding);
- /// <summary>
- /// Saves a text string to a file.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- /// <param name="text">The text to save.</param>
- void SaveToFile(string fileName, string text);
- /// <summary>
- /// Saves a text string to a file.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- /// <param name="lines">The lines to save.</param>
- void SaveToFile(string fileName, string[] lines);
- /// <summary>
- /// Saves a text string to a file.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- /// <param name="text">The text to save.</param>
- /// <param name="encoding">The encoding.</param>
- void SaveToFile(string fileName, string text, System.Text.Encoding encoding);
- /// <summary>
- /// Saves a text string to a file.
- /// </summary>
- /// <param name="fileName">The path and file name.</param>
- /// <param name="lines">The lines to save.</param>
- /// <param name="encoding">The encoding.</param>
- void SaveToFile(string fileName, string[] lines, System.Text.Encoding encoding);
- /// <summary>
- /// Loads the specified XML file into the XmlDocument.
- /// </summary>
- /// <param name="xmlDocument">The XmlDocument to load.</param>
- /// <param name="fileName">The path and file name.</param>
- void LoadXml(XmlDocument xmlDocument, string fileName);
- /// <summary>
- /// Loads the specified XML file into the XmlDocument.
- /// </summary>
- /// <param name="xmlDocument">The XmlDocument to load.</param>
- /// <param name="fileName">The path and file name.</param>
- /// <param name="encoding">The encoding.</param>
- void LoadXml(XmlDocument xmlDocument, string fileName, System.Text.Encoding encoding);
- /// <summary>
- /// Get creation time on a file.
- /// </summary>
- /// <param name="fileName"></param>
- DateTime GetCreationTime(string fileName);
- /// <summary>
- /// Set creation time on a file.
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="dateTime"></param>
- void SetCreationTime(string fileName, DateTime dateTime);
- /// <summary>
- /// Get last access time on a file.
- /// </summary>
- /// <param name="fileName"></param>
- DateTime GetLastAccessTime(string fileName);
- /// <summary>
- /// Set last access time on a file.
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="dateTime"></param>
- void SetLastAccessTime(string fileName, DateTime dateTime);
- /// <summary>
- /// Get last write time on the file.
- /// </summary>
- /// <param name="fileName"></param>
- DateTime GetLastWriteTime(string fileName);
- /// <summary>
- /// Set last write time on the file.
- /// </summary>
- /// <param name="fileName"></param>
- /// <param name="dateTime"></param>
- void SetLastWriteTime(string fileName, DateTime dateTime);
- /// <summary>
- /// Checks if the specified file exists.
- /// </summary>
- /// <param name="fileName"></param>
- /// <returns></returns>
- bool FileExists(string fileName);
- /// <summary>
- /// Checks if directory exists
- /// </summary>
- /// <param name="path"></param>
- /// <returns></returns>
- bool DirectoryExists(string path);
- /// <summary>
- /// Ensures the directory exists by trying to create it if it does not exist already.
- /// </summary>
- /// <param name="path"></param>
- /// <returns></returns>
- bool EnsureDirectoryExists(string path);
- /// <summary>
- /// Creates the specified directories if they do not exist.
- /// </summary>
- /// <param name="directoryName"></param>
- [Obsolete("Use EnsureDirectoryExists() instead.")]
- void EnsureDirectoriesExists(string directoryName);
- /// <summary>
- /// Removes a directory.
- /// </summary>
- /// <param name="path"></param>
- /// <param name="onlyIfEmpty"></param>
- /// <returns></returns>
- bool RemoveDirectory(string path, bool onlyIfEmpty);
- /// <summary>
- /// Copies a directory structure.
- /// </summary>
- /// <param name="sourceDir"></param>
- /// <param name="destinationDir"></param>
- /// <param name="recursive"></param>
- void CopyDirectory(string sourceDir, string destinationDir, bool recursive);
- /// <summary>
- /// Returns the names of files in the specified directory that match the specified search pattern.
- /// </summary>
- /// <param name="path">The directory to search.</param>
- /// <param name="searchPattern">The search string to match against the names of files in path. The parameter cannot end in two periods ("..") or contain two periods ("..") followed by System.IO.Path.DirectorySeparatorChar or System.IO.Path.AltDirectorySeparatorChar, nor can it contain any of the characters in System.IO.Path.InvalidPathChars.</param>
- /// <returns></returns>
- string[] GetFiles(string path, string searchPattern);
- /// <summary>
- /// Returns the names of files in the specified directory that match the specified search pattern.
- /// </summary>
- /// <param name="path">The directory to search.</param>
- /// <param name="searchPattern">The search string to match against the names of files in path. The parameter cannot end in two periods ("..") or contain two periods ("..") followed by System.IO.Path.DirectorySeparatorChar or System.IO.Path.AltDirectorySeparatorChar, nor can it contain any of the characters in System.IO.Path.InvalidPathChars.</param>
- /// <param name="recursive">Should the subdirectories be included in the search.</param>
- /// <returns></returns>
- string[] GetFiles(string path, string searchPattern, bool recursive);
- /// <summary>
- /// Returns the names of subdirectories in the specified directory.
- /// </summary>
- /// <param name="path">The directory to search.</param>
- /// <returns></returns>
- string[] GetDirectories(string path);
- /// <summary>
- /// Returns the subdirectories of the path
- /// </summary>
- /// <param name="path"></param>
- /// <param name="recursive">True if the method should get all subdirectories recursively.</param>
- /// <returns></returns>
- string[] GetDirectories(string path, bool recursive);
- /// <summary>
- /// Checks if the filename is valid.
- /// </summary>
- /// <param name="fileName"></param>
- /// <returns>True if the filename is valid otherwise false.</returns>
- bool IsValidFileName(string fileName);
- /// <summary>
- /// Checks if the filepath is valid
- /// </summary>
- /// <param name="pathName"></param>
- /// <returns>True if the filepath is valid otherwise false.</returns>
- bool IsValidPathName(string pathName);
- }
- }
|