Class TextInteractor
Defines the TextInteractor.
Inherited Members
Namespace: TextInteractor
Assembly: TextInteractor.dll
Syntax
public class TextInteractor : TextFile
Constructors
| Improve this Doc View SourceTextInteractor(String)
Initializes a new instance of the TextInteractor class.
Declaration
public TextInteractor(string filePath)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | filePath | The path to the textFile. |
TextInteractor(String, ILogger)
Initializes a new instance of the TextInteractor class.
Declaration
public TextInteractor(string filePath, ILogger logger)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | filePath | The path to the textFile. |
| Microsoft.Extensions.Logging.ILogger | logger | Logger that is passed in. |
Methods
| Improve this Doc View SourceAddLine(String)
This method appends a line to the end of the text file.
Declaration
public void AddLine(string contents)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | contents | The string to be added to the end of the file. |
Close()
This method closes the text file for reading and writing. If file not open, nothing will happen.
Declaration
public override bool Close()
Returns
| Type | Description |
|---|---|
| System.Boolean | if the text file successfully closes.
|
Overrides
| Improve this Doc View SourceCompare(TextFile, String, Boolean, Boolean)
This method compares the text file with another text file.
Declaration
public override bool Compare(TextFile txtFile, string resultFilePath, bool ignoreWhitespace = false, bool caseInsensitive = false)
Parameters
| Type | Name | Description |
|---|---|---|
| TextFile | txtFile | Text file to compare. |
| System.String | resultFilePath | Text file that shows the comparison result when different. If there is a file name conflict, we will replace the file. |
| System.Boolean | ignoreWhitespace | Set to true if we are going to ignore whitespace during comparison. Default is false. |
| System.Boolean | caseInsensitive | Set to true if we are going to perform case insensitive comparison. Default is false. |
Returns
| Type | Description |
|---|---|
| System.Boolean | if the contents of the text files match.
|
Overrides
| Improve this Doc View SourceCompare(TextFile, String, Int32, Int32, Int32, Int32, Boolean, Boolean)
This method compares the text file with another text file specifying the top left and bottom right coordinates. If we consider the file to be a 2D matrix of characters, the startingLine and startingIndex would be the top left corner (x, y) respectively. The endingLine and endingIndex would be the bottom right coordinate on the bottom right corner.
Declaration
public override bool Compare(TextFile txtFile, string resultFilePath, int startingLine, int startingIndex, int endingLine, int endingIndex, bool ignoreWhitespace = false, bool caseInsensitive = false)
Parameters
| Type | Name | Description |
|---|---|---|
| TextFile | txtFile | The textfile that you want to compare with.TextFile. |
| System.String | resultFilePath | Text file that shows the comparison result when different. |
| System.Int32 | startingLine | The line index to start the comparison.System.Int32. |
| System.Int32 | startingIndex | The character index to start the comparison.System.Int32. |
| System.Int32 | endingLine | The line index to stop the comparison.System.Int32. |
| System.Int32 | endingIndex | The character index to end the comparison.System.Int32. |
| System.Boolean | ignoreWhitespace | Set to true if we are going to ignore whitespace during comparison. Default is false. |
| System.Boolean | caseInsensitive | Set to true if we are going to perform case insensitive comparison. Default is false. |
Returns
| Type | Description |
|---|---|
| System.Boolean | if the contents of the text file match.
|
Overrides
| Improve this Doc View SourceFind(String)
Find if string exist or not.
Declaration
public bool Find(string expectedString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | expectedString | The string to be found.System.String. |
Returns
| Type | Description |
|---|---|
| System.Boolean | if expectedString is foundSystem.Boolean.
|
Find(String, Int32)
This method tries to find the expected string in the specified line.
Declaration
public override bool Find(string expectedString, int lineNum)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | expectedString | String to be found. |
| System.Int32 | lineNum |
Returns
| Type | Description |
|---|---|
| System.Boolean | if the expected string is found at line.
|
Overrides
| Improve this Doc View SourceFindAndCount(String)
The FindAndCount.
Declaration
public int FindAndCount(string expectedString)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | expectedString | The string to be found and counted.System.String. |
Returns
| Type | Description |
|---|---|
| System.Int32 | The count of the expectedString in file System.Int32. |
FinishedReading()
This methods returns whether or not the reader is at the end of the text file.
Declaration
public override bool FinishedReading()
Returns
| Type | Description |
|---|---|
| System.Boolean | if the file has been finished reading.
|
Overrides
| Improve this Doc View SourceLineExactMatch(String, Int32)
The LineExactMatch.
Declaration
public bool LineExactMatch(string expectedString, int lineNum)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | expectedString | The expected string value of the corresponding line number.System.String. |
| System.Int32 | lineNum | The line numberSystem.Int32. |
Returns
| Type | Description |
|---|---|
| System.Boolean | The System.Boolean. |
Modify(Int32, String)
This methods modifies the textfile by replacing text in the text file.
Declaration
public override bool Modify(int replaceType, string args)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | replaceType | 0 means to replace once, 1 means to replaceAll, 2 means to replaceLine,3 means to replace regexSystem.Int32. |
| System.String | args | The argsSystem.String. |
Returns
| Type | Description |
|---|---|
| System.Boolean | if the modification was successful. System.Boolean.
|
Overrides
| Improve this Doc View SourceOpen()
This method opens the text file for reading and writing. If file is already open, nothing will happen.
Declaration
public override bool Open()
Returns
| Type | Description |
|---|---|
| System.Boolean | if the text file successfully opens.
|
Overrides
| Improve this Doc View SourceReadLine()
This method reads a line of characters in the file and returns the data as a string.
Declaration
public override string ReadLine()
Returns
| Type | Description |
|---|---|
| System.String | A string from the text file. |
Overrides
| Improve this Doc View SourceRestartReading()
This method resets the reader back to the beginning of the text file.
Declaration
public override void RestartReading()