Skip to content

Commit 3b0d3af

Browse files
committed
1. Documentation
1 parent 670a183 commit 3b0d3af

File tree

9 files changed

+97
-1
lines changed

9 files changed

+97
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
namespace TextSearchEngine.DTO
22
{
3+
/// <summary>
4+
/// An in-memory representation of a file that holds both the file's filename and contents
5+
/// </summary>
36
public class FileRepresentation
47
{
8+
/// <summary>
9+
/// The file's filename
10+
/// </summary>
511
public string FileName { get; set; }
12+
/// <summary>
13+
/// An in-memory representation of the file's content
14+
/// </summary>
615
public string Contents { get; set; }
716
}
817
}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
namespace TextSearchEngine.Interfaces
22
{
3+
/// <summary>
4+
/// An interface to allow outputting and inputting information into the application
5+
/// </summary>
36
public interface IConsoleProvider
47
{
8+
/// <summary>
9+
/// Writes a line to the device and performs a carry return after writting it
10+
/// </summary>
11+
/// <param name="textToWrite">The text to write</param>
512
void WriteLine(string textToWrite);
613

14+
15+
/// <summary>
16+
/// Writes a line to the device
17+
/// </summary>
18+
/// <param name="textToWrite">The text to write</param>
719
void Write(string textToWrite);
820

21+
/// <summary>
22+
/// Reads the next keystroke performed on the input device
23+
/// </summary>
24+
/// <returns>A string representation of the stroken device's key</returns>
925
string ReadKey();
1026

27+
/// <summary>
28+
/// Reads the next line performed on the input device until a carry return is performed
29+
/// </summary>
30+
/// <returns>The line of text inputted from the device</returns>
1131
string ReadLine();
1232
}
1333
}

TextSearchEngine.Interfaces/IFileProvider.cs

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ namespace TextSearchEngine.Interfaces
55
{
66
public interface IFileProvider
77
{
8+
/// <summary>
9+
/// Returns a <seealso cref="IEnumerable{T}"/> of <seealso cref="FileRepresentation"/> of all the files inside a directory
10+
/// </summary>
11+
/// <param name="directory">The directory in which to enumerate the files</param>
12+
/// <returns><seealso cref="IEnumerable{T}"/> of <seealso cref="FileRepresentation"/></returns>
813
IEnumerable<FileRepresentation> GetFileRepresentationsFromDirectory(string directory);
914
}
1015
}

TextSearchEngine.Interfaces/IFileTextSearcher.cs

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
{
33
public interface IFileTextSearcher
44
{
5+
/// <summary>
6+
/// Counts the number of <paramref name="searchTerm"/> occurrences inside <paramref name="fileString"/>
7+
/// </summary>
8+
/// <param name="fileString">The file or file contents in which to perform the searchs</param>
9+
/// <param name="searchTerm">The search term</param>
10+
/// <returns>The amount of occurrences that <paramref name="searchTerm"/> occurs in the file/returns>
511
int SearchOccurrences(string fileString, string searchTerm);
612
}
713
}

TextSearchEngine.Library/ConsoleProviders/SystemConsoleProvider.cs

+19
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,42 @@
77

88
namespace TextSearchEngine.Library.ConsoleProviders
99
{
10+
/// <summary>
11+
/// A class to use the system console to output and input information from the application wherever it is needed
12+
/// </summary>
1013
public class SystemConsoleProvider : IConsoleProvider
1114
{
15+
/// <summary>
16+
/// Reads the next key pressed by the user, blocks execution until a key is pressed
17+
/// </summary>
18+
/// <returns>The string representation of the pressed key</returns>
1219
public string ReadKey()
1320
{
1421
return Console.ReadKey().KeyChar.ToString();
1522
}
1623

24+
/// <summary>
25+
/// Reads a line of text from the console, blocks execution until the enter key is pressed.
26+
/// </summary>
27+
/// <returns>The line of text written until the return key</returns>
1728
public string ReadLine()
1829
{
1930
return Console.ReadLine();
2031
}
2132

33+
/// <summary>
34+
/// Writes the <paramref name="textToWrite"/> string to the console
35+
/// </summary>
36+
/// <param name="textToWrite">The text to write</param>
2237
public void Write(string textToWrite)
2338
{
2439
Console.Write(textToWrite);
2540
}
2641

42+
/// <summary>
43+
/// Writes the <paramref name="textToWrite"/> string to the console and performs a carry return and line feed
44+
/// </summary>
45+
/// <param name="textToWrite">The text to write</param>
2746
public void WriteLine(string textToWrite)
2847
{
2948
Console.WriteLine(textToWrite);

TextSearchEngine.Library/FileProviders/SystemFileProvider.cs

+9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66

77
namespace TextSearchEngine.Library.FileProviders
88
{
9+
/// <summary>
10+
/// Retrieves the file/s in a directory through the native file system
11+
/// </summary>
912
public class SystemFileProvider : IFileProvider
1013
{
14+
/// <summary>
15+
/// Explores a directory, compiles a list of all the files inside it, reads them
16+
/// and creates a list of <seealso cref="FileRepresentation"/> from its contents and filename
17+
/// </summary>
18+
/// <param name="directory">The directory in which to search for files</param>
19+
/// <returns>A list of <seealso cref="FileRepresentation"/> with the associated contents and filename</returns>
1120
public IEnumerable<FileRepresentation> GetFileRepresentationsFromDirectory(string directory)
1221
{
1322
var files = System.IO.Directory.GetFiles(directory);

TextSearchEngine.Library/FileSearchEngines/FileSearchEngine.cs

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44

55
namespace TextSearchEngine.Library.FileSearchEngines
66
{
7+
/// <summary>
8+
/// An engine that given a directory, allows to perform any amount of text searchs within the text of all the files inside it
9+
/// </summary>
710
public class FileSearchEngine : IFileSearchEngine
811
{
912
private readonly IFileProvider fileProvider;
1013
private readonly IFileTextSearcher fileTextSearcher;
1114
private readonly IConsoleProvider consoleProvider;
1215

13-
private string exitString = "$end";
16+
/// <summary>
17+
/// A command that signals the engine to stop and end its execution
18+
/// </summary>
19+
private readonly string exitString = "$end";
1420

1521
[InjectionConstructor]
1622
public FileSearchEngine(IFileProvider fileProvider,
@@ -22,6 +28,11 @@ public FileSearchEngine(IFileProvider fileProvider,
2228
this.consoleProvider = consoleProvider;
2329
}
2430

31+
/// <summary>
32+
/// Starts the search engine in the directory specified by the <paramref name="searchDirectory"/> parameter and waits for user input.
33+
/// To stop the engine, type $end
34+
/// </summary>
35+
/// <param name="searchDirectory">The directory in which to perform the searchs</param>
2536
public void StartEngine(string searchDirectory)
2637
{
2738
var fileRepresentations = fileProvider.GetFileRepresentationsFromDirectory(searchDirectory);

TextSearchEngine.Library/FileTextSearchers/RegexFileTextSearcher.cs

+9
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33

44
namespace TextSearchEngine.Library.FileTextSearchers
55
{
6+
/// <summary>
7+
/// A class that uses Regex to search a given text in a string
8+
/// </summary>
69
public class RegexFileTextSearcher : IFileTextSearcher
710
{
11+
/// <summary>
12+
/// Counts the number of occurrences that the <paramref name="searchTerm"/> occurs in the content of the provided <paramref name="fileString"/>
13+
/// </summary>
14+
/// <param name="fileString">The string in which to search for the <paramref name="searchTerm"/> </param>
15+
/// <param name="searchTerm">The search term</param>
16+
/// <returns>The amount of occurrences that <paramref name="searchTerm"/> occurs in the file
817
public int SearchOccurrences(string fileString, string searchTerm)
918
{
1019
return Regex.Matches(fileString, searchTerm).Count;

TextSearchEngine.Library/Unity/ConfigureUnity.cs

+8
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@
1212

1313
namespace TextSearchEngine.Library.Unity
1414
{
15+
/// <summary>
16+
/// This class intends to expose a method which fills the container provided as a parameter with all of the dependencies
17+
/// that this class declares
18+
/// </summary>
1519
public static class ConfigureUnity
1620
{
21+
/// <summary>
22+
/// Registers all the dependencies this method declares in the container passed as the parameter of the method
23+
/// </summary>
24+
/// <param name="unityContainer">The container in which to declare dependencies</param>
1725
public static void ConfigureContainer(IUnityContainer unityContainer)
1826
{
1927
unityContainer.RegisterType<IConsoleProvider, SystemConsoleProvider>();

0 commit comments

Comments
 (0)