Ejemplo n.º 1
0
        public JournalIndex <T> CreateIndex <T>(DateRange range = null, ICollection <string> requiredTags = null, ICollection <string> optionalTags = null)
            where T : class, IJournalEntry
        {
            var index = new JournalIndex <T>();

            foreach (var file in _markdownFiles.FindAll())
            {
                var reader = _readerWriterFactory.CreateReader(file);
                if (range != null && !range.Includes(reader.EntryDate))
                {
                    continue;
                }

                var entry = reader.ToJournalEntry <T>();

                if (entry.Tags == null || entry.Tags.Count == 0)
                {
                    continue;
                }

                if (requiredTags != null && requiredTags.Count > 0 && !entry.Tags.ContainsAll(requiredTags))
                {
                    continue;
                }

                if (optionalTags != null && optionalTags.Count > 0 && !entry.Tags.ContainsAny(optionalTags))
                {
                    continue;
                }

                foreach (var tag in entry.Tags)
                {
                    if (index.Contains(tag))
                    {
                        index[tag].Entries.Add(entry);
                    }
                    else
                    {
                        var journalIndexEntry = new JournalIndexEntry <T>(tag, entry);
                        index.Add(journalIndexEntry);
                    }
                }
            }

            return(index);
        }
Ejemplo n.º 2
0
 protected override string GetKeyForItem(JournalIndexEntry <T> item) => item.Tag;