C# Class SIL.Utils.MockFileOS

Mock version of IFileOS that lets us simulate existing files and directories.
Inheritance: IFileOS
Mostrar archivo Open project: sillsdev/FieldWorks Class Usage Examples

Public Methods

Method Description
AddExistingFile ( string filename ) : void

Adds the given filename to the collection of files that should be considered to exist.

AddFile ( string filename, string contents, Encoding encoding ) : void

Adds the given filename to the collection of files that should be considered to exist and set its contents so it can be read.

CreateFileContents ( bool fIncludeBOM, string sBookId ) : string

Create the simulated file contents, suitable for calling MakeFile or AddFile.

LockFile ( string filename ) : void

Simulates getting an exclusive (write) file lock on the file having the given filename.

MakeFile ( string contents ) : string

Adds a new "temp" file (with fully-qualified path and name) to the collection of files and sets its contents so it can be read. Encoding will be UTF8.

MakeFile ( string contents, Encoding encoding ) : string

Adds a new "temp" file (with fully-qualified path and name) to the collection of files and sets its contents so it can be read.

MakeSfFile ( Encoding encoding, bool fIncludeBOM, string sBookId ) : string

Create a mocked Standard Format file with \id line and file contents as specified.

MakeSfFile ( bool fIncludeBOM, string sBookId ) : string

Create a mocked Standard Format file with \id line and file contents as specified. Encoding will be UTF8.

MakeSfFile ( string sBookId ) : string

Create a mocked Standard Format file with \id line and file contents as specified. No BOM. Encoding will be UTF8.

Private Methods

Method Description
GetFileInfo ( string filename ) : MockFile

Gets the file info for the given filename (Using a case-insensitive lookup).

GetFileInfo ( string filename, FileLockType lockNeeded ) : MockFile

Gets the file info for the given filename (Using a case-insensitive lookup).

GetKey ( string filename ) : string

Gets the key for the file info for the given filename (Using a case-insensitive lookup).

IFileOS ( string filename ) : Stream

Gets the writer.

IFileOS ( string filename, FileMode mode ) : Stream
IFileOS ( string filename, Encoding encoding ) : TextReader

Opens a TextReader on the given file

IFileOS ( string filename, Encoding encoding ) : TextWriter

Gets the writer.

IFileOS ( string sPath ) : bool

Determines whether the specified file exists. Looks in m_existingFiles.Keys without making any adjustment for case or differences in normalization.

IFileOS ( string sPath ) : string[]

Gets the files in the given directory.

IFileOS ( string sPath, string searchPattern ) : string[]

Gets the files in the given directory.

IFileOS ( string filename ) : void

Deletes the given file. This should probably be made case-insensitive

IFileOS ( string source, string destination ) : void

Moves the specified source.

Method Details

AddExistingFile() public method

Adds the given filename to the collection of files that should be considered to exist.
public AddExistingFile ( string filename ) : void
filename string The filename (may or may not include path).
return void

AddFile() public method

Adds the given filename to the collection of files that should be considered to exist and set its contents so it can be read.
public AddFile ( string filename, string contents, Encoding encoding ) : void
filename string The filename (may or may not include path).
contents string The contents of the file
encoding System.Text.Encoding File encoding
return void

CreateFileContents() public static method

Create the simulated file contents, suitable for calling MakeFile or AddFile.
public static CreateFileContents ( bool fIncludeBOM, string sBookId ) : string
fIncludeBOM bool Indicates whether file contents should include the byte /// order mark
sBookId string The book id (if set, this will cause \id line to be written /// as the first line of the fiel)
return string

LockFile() public method

Simulates getting an exclusive (write) file lock on the file having the given filename.
public LockFile ( string filename ) : void
filename string The filename (must have been added previously).
return void

MakeFile() public method

Adds a new "temp" file (with fully-qualified path and name) to the collection of files and sets its contents so it can be read. Encoding will be UTF8.
public MakeFile ( string contents ) : string
contents string The contents of the file
return string

MakeFile() public method

Adds a new "temp" file (with fully-qualified path and name) to the collection of files and sets its contents so it can be read.
public MakeFile ( string contents, Encoding encoding ) : string
contents string The contents of the file
encoding System.Text.Encoding File encoding
return string

MakeSfFile() public method

Create a mocked Standard Format file with \id line and file contents as specified.
public MakeSfFile ( Encoding encoding, bool fIncludeBOM, string sBookId ) : string
encoding System.Text.Encoding File encoding
fIncludeBOM bool Indicates whether file contents should include the byte /// order mark
sBookId string The book id (if set, this will cause \id line to be written /// as the first line of the fiel)
return string

MakeSfFile() public method

Create a mocked Standard Format file with \id line and file contents as specified. Encoding will be UTF8.
public MakeSfFile ( bool fIncludeBOM, string sBookId ) : string
fIncludeBOM bool Indicates whether file contents should include the byte /// order mark
sBookId string The book id (if set, this will cause \id line to be written /// as the first line of the fiel)
return string

MakeSfFile() public method

Create a mocked Standard Format file with \id line and file contents as specified. No BOM. Encoding will be UTF8.
public MakeSfFile ( string sBookId ) : string
sBookId string The book id (if set, this will cause \id line to be written /// as the first line of the fiel)
return string