예제 #1
0
 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"));
 }
예제 #2
0
        public void ParseEmpty(string pattern)
        {
            var res = FileNamePattern.Parse(pattern);

            Assert.NotNull(res);
            Assert.Empty(res.Tokens);
            Assert.True(res.IsEmpty);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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));
        }
예제 #5
0
        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));
        }