private static async Task ProcessFile(string fileName, IParseStrategy parseStrategy) { await using var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); using var streamReader = new StreamReader(fileStream); await parseStrategy.Parse(streamReader); }
private StreamReader GetParsedFileStream(IParseStrategy parseStrategy) { var fileParserFactory = new FileParserFactory(_searchFile, parseStrategy); var fileParser = fileParserFactory.Create(); var streamReader = fileParser.ParseFile(); return(streamReader); }
public void ParseStrategy_ReplaceCapitalLetters() { IParseStrategy parseStrategy = ParseStrategy.ReplaceCapitalLetters(); for (int i = 0; i < testStrings.Length; i++) { Assert.IsTrue(parseStrategy.Parse(testStrings[i]) == lowercaseResultStrings[i]); } }
public void ParseStrategy_ReplaceNonASCII() { IParseStrategy parseStrategy = ParseStrategy.ReplaceNonASCII(); for (int i = 0; i < testStrings.Length; i++) { Assert.IsTrue(parseStrategy.Parse(testStrings[i]) == asciiResultStrings[i]); } }
public void ParseStrategy_LeaveUnchanged() { IParseStrategy parseStrategy = ParseStrategy.LeaveUnchanged(); for (int i = 0; i < testStrings.Length; i++) { Assert.IsTrue(parseStrategy.Parse(testStrings[i]) == testStrings[i]); } }
private HtmlDocument GetHtmlResponse(IParseStrategy strategy) // Action<HttpRequestMessage> preRequestAction) { var request = new HttpRequestMessage(HttpMethod.Get, _url); strategy.PreRequestAction(request); var htmlString = _httpClient.SendAsync(request).Result.Content.ReadAsStringAsync().Result; var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(htmlString); return(htmlDocument); }
private HtmlNode ComputeStrategy(IParseStrategy strategy) { if (_urlValidation && !strategy.IsUrlValid(_url)) { return(null); } var htmlDocument = GetHtmlResponse(strategy); var productListHtml = strategy.Parser(htmlDocument); return(productListHtml); }
public IFileParser Create() { if (!File.Exists(FilePath)) throw new FileNotFoundException("The specified file was not found.", FilePath); if(Encoding == null) Encoding = System.Text.Encoding.Default; if(ParseStrategy == null) ParseStrategy = FileParsing.ParseStrategy.LeaveUnchanged(); string extension = Path.GetExtension(FilePath); if (extension == ".html" || extension == ".htm") return new HtmlFileParser(FilePath, Encoding, ParseStrategy); return new BaseFileParser(FilePath, Encoding, ParseStrategy); }
public IFileParser Create() { if (!File.Exists(FilePath)) { throw new FileNotFoundException("The specified file was not found.", FilePath); } if (Encoding == null) { Encoding = System.Text.Encoding.Default; } if (ParseStrategy == null) { ParseStrategy = FileParsing.ParseStrategy.LeaveUnchanged(); } string extension = Path.GetExtension(FilePath); if (extension == ".html" || extension == ".htm") { return(new HtmlFileParser(FilePath, Encoding, ParseStrategy)); } return(new BaseFileParser(FilePath, Encoding, ParseStrategy)); }
public LogParser(IParseStrategy strategy) { _strategy = strategy; }
public FileParserFactory(string filePath, IParseStrategy parseStrategy) { this.FilePath = filePath; this.ParseStrategy = parseStrategy; }
public FileParserFactory(string filePath, Encoding encoding, IParseStrategy parseStrategy) { this.FilePath = filePath; this.ParseStrategy = parseStrategy; this.Encoding = encoding; }
internal ParsedFileSearcheeProvider(string rootPath, IParseStrategy parseStrategy) { this._rootPath = rootPath; this._parseStrategy = parseStrategy; }
public BaseParseStrategy(IParseStrategy parseStrategy) { this.parseStrategy = parseStrategy; }
public ParseContext(IParseStrategy strategy) { this.Strategy = strategy; }
public BaseFileParser(string filePath, Encoding encoding, IParseStrategy parseStrategy) { this.filePath = filePath; this.encoding = encoding; this.parseStrategy = parseStrategy; }
public ReplaceNonASCIIStrategy(IParseStrategy parseStrategy) : base(parseStrategy) { }
public HtmlFileParser(string filePath, Encoding encoding, IParseStrategy parseStrategy) : base(filePath, encoding, parseStrategy) { }
/// <summary> /// Enables replacing non ascii letters with diacritic-less equivalents. /// </summary> /// <param name="parseStrategy">The parse strategy on which we deployed the function.</param> /// <returns> /// The parse strategy decorated using the ReplaceNonASCIIStrategy class. /// </returns> public static IParseStrategy ReplaceNonASCII(this IParseStrategy parseStrategy) { return(new ReplaceNonASCIIStrategy(parseStrategy)); }
/// <summary> /// Enables replacing uppercase letters with their lowercase equivalents using the decorator pattern. /// </summary> /// <param name="parseStrategy">The parse strategy on which we deployed the function.</param> /// <returns> /// The parse strategy decorated using the RemoveCapitalLettersStrategy class. /// </returns> public static IParseStrategy ReplaceCapitalLetters(this IParseStrategy parseStrategy) { return(new RemoveCapitalLettersStrategy(parseStrategy)); }
private StreamReader GetParsedFileStream(IParseStrategy parseStrategy) { var fileParserFactory = new FileParserFactory(_searchFile, parseStrategy); var fileParser = fileParserFactory.Create(); var streamReader = fileParser.ParseFile(); return streamReader; }
public RemoveCapitalLettersStrategy(IParseStrategy parseStrategy) : base(parseStrategy) { }