public virtual void testCreateMatcherForSuffix() { const string pattern = "helloworld"; var matcher = new FileNameMatcher(pattern, null); matcher.Append("hello"); FileNameMatcher childMatcher = matcher.CreateMatcherForSuffix(); Assert.AreEqual(false, matcher.IsMatch()); Assert.AreEqual(true, matcher.CanAppendMatch()); Assert.AreEqual(false, childMatcher.IsMatch()); Assert.AreEqual(true, childMatcher.CanAppendMatch()); matcher.Append("world"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); Assert.AreEqual(false, childMatcher.IsMatch()); Assert.AreEqual(true, childMatcher.CanAppendMatch()); childMatcher.Append("world"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); Assert.AreEqual(true, childMatcher.IsMatch()); Assert.AreEqual(false, childMatcher.CanAppendMatch()); childMatcher.Reset(); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); Assert.AreEqual(false, childMatcher.IsMatch()); Assert.AreEqual(true, childMatcher.CanAppendMatch()); childMatcher.Append("world"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); Assert.AreEqual(true, childMatcher.IsMatch()); Assert.AreEqual(false, childMatcher.CanAppendMatch()); }
public virtual void testCopyConstructor() { const string pattern = "helloworld"; var matcher = new FileNameMatcher(pattern, null); matcher.Append("hello"); var copy = new FileNameMatcher(matcher); Assert.AreEqual(false, matcher.IsMatch()); Assert.AreEqual(true, matcher.CanAppendMatch()); Assert.AreEqual(false, copy.IsMatch()); Assert.AreEqual(true, copy.CanAppendMatch()); matcher.Append("world"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); Assert.AreEqual(false, copy.IsMatch()); Assert.AreEqual(true, copy.CanAppendMatch()); copy.Append("world"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); Assert.AreEqual(true, copy.IsMatch()); Assert.AreEqual(false, copy.CanAppendMatch()); copy.Reset(); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); Assert.AreEqual(false, copy.IsMatch()); Assert.AreEqual(true, copy.CanAppendMatch()); copy.Append("helloworld"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); Assert.AreEqual(true, copy.IsMatch()); Assert.AreEqual(false, copy.CanAppendMatch()); }
private static void AssertFileNameMatch(string pattern, string input, char excludedCharacter, bool matchExpected, bool appendCanMatchExpected) { var matcher = new FileNameMatcher(pattern, excludedCharacter); matcher.Append(input); Assert.AreEqual(matchExpected, matcher.IsMatch()); Assert.AreEqual(appendCanMatchExpected, matcher.CanAppendMatch()); }
public IEnumerable <(string fileName, string accountName, DateTime dateCreation)> LoadFiles(FtpCredential ftpCred) { var ftpUrl = ftpCred.Url; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpUrl); request.Method = WebRequestMethods.Ftp.ListDirectory; request.Credentials = new NetworkCredential(ftpCred.UserName, ftpCred.UserPassword); using (var response = (FtpWebResponse)request.GetResponse()) { using (var responseStream = response.GetResponseStream()) { using (var reader = new StreamReader(responseStream)) { var fileName = ""; do { fileName = reader.ReadLine(); if (_fileNameMatcher.IsMatch(fileName)) { var account = _fileNameMatcher.ParseAccountName(fileName); DateTime?creationDate = null; if (_fileNameMatcher.IsTradeAsReport(fileName)) { creationDate = DateHelper.ParseDate(fileName, 1); } else { creationDate = DateHelper.ParseDate(fileName); } yield return(fileName, account, creationDate.Value); } } while (!string.IsNullOrEmpty(fileName)); } } } }
private static bool IsHostMatch(string pattern, string name) { FileNameMatcher fn; try { fn = new FileNameMatcher(pattern, null); } catch (InvalidPatternException) { return(false); } fn.Append(name); return(fn.IsMatch()); }
public virtual void testReset() { const string pattern = "helloworld"; var matcher = new FileNameMatcher(pattern, null); matcher.Append("helloworld"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); matcher.Reset(); matcher.Append("hello"); Assert.AreEqual(false, matcher.IsMatch()); Assert.AreEqual(true, matcher.CanAppendMatch()); matcher.Append("world"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); matcher.Append("to much"); Assert.AreEqual(false, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); matcher.Reset(); matcher.Append("helloworld"); Assert.AreEqual(true, matcher.IsMatch()); Assert.AreEqual(false, matcher.CanAppendMatch()); }
public bool IsIgnored(string path) { _matcher.Reset(); _matcher.Append(path); return(_matcher.IsMatch()); }
/// <summary>Returns true if a match was made.</summary> /// <remarks> /// Returns true if a match was made. /// <br /> /// This function does NOT return the actual ignore status of the /// target! Please consult /// <see cref="GetResult()">GetResult()</see> /// for the ignore status. The actual /// ignore status may be true or false depending on whether this rule is /// an ignore rule or a negation rule. /// </remarks> /// <param name="target">Name pattern of the file, relative to the base directory of this rule /// </param> /// <param name="isDirectory">Whether the target file is a directory or not</param> /// <returns> /// True if a match was made. This does not necessarily mean that /// the target is ignored. Call /// <see cref="GetResult()">getResult()</see> /// for the result. /// </returns> public virtual bool IsMatch(string target, bool isDirectory) { if (!target.StartsWith("/")) { target = "/" + target; } if (matcher == null) { if (target.Equals(pattern)) { //Exact match if (dirOnly && !isDirectory) { //Directory expectations not met return(false); } else { //Directory expectations met return(true); } } if ((target).StartsWith(pattern + "/")) { return(true); } if (nameOnly) { //Iterate through each sub-name string[] segments = target.Split("/"); for (int idx = 0; idx < segments.Length; idx++) { string segmentName = segments[idx]; if (segmentName.Equals(pattern) && DoesMatchDirectoryExpectations(isDirectory, idx , segments.Length)) { return(true); } } } } else { matcher.Append(target); if (matcher.IsMatch()) { return(true); } string[] segments = target.Split("/"); if (nameOnly) { for (int idx = 0; idx < segments.Length; idx++) { string segmentName = segments[idx]; //Iterate through each sub-directory matcher.Reset(); matcher.Append(segmentName); if (matcher.IsMatch() && DoesMatchDirectoryExpectations(isDirectory, idx, segments .Length)) { return(true); } } } else { //TODO: This is the slowest operation //This matches e.g. "/src/ne?" to "/src/new/file.c" matcher.Reset(); for (int idx = 0; idx < segments.Length; idx++) { string segmentName = segments[idx]; if (segmentName.Length > 0) { matcher.Append("/" + segmentName); } if (matcher.IsMatch() && DoesMatchDirectoryExpectations(isDirectory, idx, segments .Length)) { return(true); } } } } return(false); }