public void InvalidPathChars(char pattern) { Assert.Throws <PatternSyntaxException>(() => FileNamePattern.Parse(pattern.ToString())); Assert.Throws <PatternSyntaxException>(() => FileNamePattern.Parse("pre" + pattern.ToString())); Assert.Throws <PatternSyntaxException>(() => FileNamePattern.Parse(pattern.ToString() + "post")); Assert.Throws <PatternSyntaxException>(() => FileNamePattern.Parse("pre" + pattern.ToString() + "post")); }
public void ParseEmpty(string pattern) { var res = FileNamePattern.Parse(pattern); Assert.NotNull(res); Assert.Empty(res.Tokens); Assert.True(res.IsEmpty); }
public void ParseTest(string pattern) { // var data = FileMetadata.DemoMetadata; var res = FileNamePattern.Parse(pattern); Assert.NotNull(res); Assert.NotEmpty(res.Tokens); Assert.False(res.IsEmpty); }
public static string GetFileNameFromPattern(FileMetadata info, string pattern) { if (pattern == null) { throw new ArgumentNullException(nameof(pattern)); } var parsedPattern = FileNamePattern.Parse(pattern); if (parsedPattern.IsEmpty) { throw new PatternSyntaxException(); } return(parsedPattern.FormatMetadata(info)); }
public JournalEntryFile GetEntryFromName(string name) { var entryDate = name.EndsWith(".md") ? FileNameWithExtensionPattern.Parse(name).Value : FileNamePattern.Parse(name).Value; var writer = _readerWriterFactory.CreateWriter(); var path = writer.GetJournalEntryFilePath(entryDate); var reader = _readerWriterFactory.CreateReader(path); return(new JournalEntryFile(reader)); }