コード例 #1
0
        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);
        }
コード例 #2
0
        private StreamReader GetParsedFileStream(IParseStrategy parseStrategy)
        {
            var fileParserFactory = new FileParserFactory(_searchFile, parseStrategy);

            var fileParser   = fileParserFactory.Create();
            var streamReader = fileParser.ParseFile();

            return(streamReader);
        }
コード例 #3
0
        public void ParseStrategy_ReplaceCapitalLetters()
        {
            IParseStrategy parseStrategy = ParseStrategy.ReplaceCapitalLetters();

            for (int i = 0; i < testStrings.Length; i++)
            {
                Assert.IsTrue(parseStrategy.Parse(testStrings[i]) == lowercaseResultStrings[i]);
            }
        }
コード例 #4
0
        public void ParseStrategy_ReplaceNonASCII()
        {
            IParseStrategy parseStrategy = ParseStrategy.ReplaceNonASCII();

            for (int i = 0; i < testStrings.Length; i++)
            {
                Assert.IsTrue(parseStrategy.Parse(testStrings[i]) == asciiResultStrings[i]);
            }
        }
コード例 #5
0
        public void ParseStrategy_LeaveUnchanged()
        {
            IParseStrategy parseStrategy = ParseStrategy.LeaveUnchanged();

            for (int i = 0; i < testStrings.Length; i++)
            {
                Assert.IsTrue(parseStrategy.Parse(testStrings[i]) == testStrings[i]);
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        private HtmlNode ComputeStrategy(IParseStrategy strategy)
        {
            if (_urlValidation && !strategy.IsUrlValid(_url))
            {
                return(null);
            }

            var htmlDocument    = GetHtmlResponse(strategy);
            var productListHtml = strategy.Parser(htmlDocument);

            return(productListHtml);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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));
        }
コード例 #10
0
 public LogParser(IParseStrategy strategy)
 {
     _strategy = strategy;
 }
コード例 #11
0
 public FileParserFactory(string filePath, IParseStrategy parseStrategy)
 {
     this.FilePath      = filePath;
     this.ParseStrategy = parseStrategy;
 }
コード例 #12
0
 public FileParserFactory(string filePath, Encoding encoding, IParseStrategy parseStrategy)
 {
     this.FilePath      = filePath;
     this.ParseStrategy = parseStrategy;
     this.Encoding      = encoding;
 }
コード例 #13
0
 internal ParsedFileSearcheeProvider(string rootPath, IParseStrategy parseStrategy)
 {
     this._rootPath      = rootPath;
     this._parseStrategy = parseStrategy;
 }
コード例 #14
0
 public BaseParseStrategy(IParseStrategy parseStrategy)
 {
     this.parseStrategy = parseStrategy;
 }
コード例 #15
0
 public ParseContext(IParseStrategy strategy)
 {
     this.Strategy = strategy;
 }
コード例 #16
0
 public FileParserFactory(string filePath, Encoding encoding, IParseStrategy parseStrategy)
 {
     this.FilePath = filePath;
     this.ParseStrategy = parseStrategy;
     this.Encoding = encoding;
 }
コード例 #17
0
 public BaseParseStrategy(IParseStrategy parseStrategy)
 {
     this.parseStrategy = parseStrategy;
 }
コード例 #18
0
ファイル: BaseFileParser.cs プロジェクト: kzemek/FileScanner
 public BaseFileParser(string filePath, Encoding encoding, IParseStrategy parseStrategy)
 {
     this.filePath = filePath;
     this.encoding = encoding;
     this.parseStrategy = parseStrategy;
 }
コード例 #19
0
 public ReplaceNonASCIIStrategy(IParseStrategy parseStrategy) : base(parseStrategy)
 {
 }
コード例 #20
0
ファイル: HtmlFileParser.cs プロジェクト: kzemek/FileScanner
 public HtmlFileParser(string filePath, Encoding encoding, IParseStrategy parseStrategy)
     : base(filePath, encoding, parseStrategy)
 {
 }
コード例 #21
0
 /// <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));
 }
コード例 #22
0
 /// <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));
 }
コード例 #23
0
ファイル: Search.cs プロジェクト: kzemek/FileScanner
        private StreamReader GetParsedFileStream(IParseStrategy parseStrategy)
        {
            var fileParserFactory = new FileParserFactory(_searchFile, parseStrategy);

            var fileParser = fileParserFactory.Create();
            var streamReader = fileParser.ParseFile();

            return streamReader;
        }
コード例 #24
0
 public RemoveCapitalLettersStrategy(IParseStrategy parseStrategy)
     : base(parseStrategy)
 {
 }
コード例 #25
0
ファイル: BaseFileParser.cs プロジェクト: kzemek/FileScanner
 public BaseFileParser(string filePath, Encoding encoding, IParseStrategy parseStrategy)
 {
     this.filePath      = filePath;
     this.encoding      = encoding;
     this.parseStrategy = parseStrategy;
 }
コード例 #26
0
ファイル: HtmlFileParser.cs プロジェクト: kzemek/FileScanner
 public HtmlFileParser(string filePath, Encoding encoding, IParseStrategy parseStrategy)
     : base(filePath, encoding, parseStrategy)
 {
 }
コード例 #27
0
 public FileParserFactory(string filePath, IParseStrategy parseStrategy)
 {
     this.FilePath = filePath;
     this.ParseStrategy = parseStrategy;
 }
コード例 #28
0
 public ReplaceNonASCIIStrategy(IParseStrategy parseStrategy)
     : base(parseStrategy)
 {
 }
コード例 #29
0
 public RemoveCapitalLettersStrategy(IParseStrategy parseStrategy) : base(parseStrategy)
 {
 }