public void Interpreter(TocYaml tocItemYamls, BuildContext context) { var tocTracker = context.GetSharedObject(Constants.Constants.ExtendedIdMappings) as ConcurrentDictionary <string, List <TocItemYaml> >; UpdateTocYaml(tocItemYamls, tocTracker); Save(tocItemYamls, null, "toc"); }
public Task RunAsync(BuildContext context) { var config = context.GetSharedObject(Constants.Config) as ConfigModel; if (config == null) { throw new ApplicationException(string.Format("Key: {0} doesn't exist in build context", Constants.Config)); } string outputPath = config.OutputPath; var changesDict = context.GetSharedObject(Constants.Changes) as Dictionary <string, HierarchyChange>; if (changesDict == null) { throw new ApplicationException(string.Format("Key: {0} doesn't exist in build context", Constants.Changes)); } TocYaml tocYaml = new TocYaml( from change in changesDict.Values where change.Parent == null let toc = FromHierarchyChange(changesDict, change, context) orderby toc.Name.ToLower() select toc); string tocFile = Path.Combine(outputPath, Constants.TocYamlFileName); using (var writer = new StreamWriter(tocFile)) { writer.WriteLine(Constants.YamlMime.TableOfContent); new YamlSerializer().Serialize(writer, tocYaml); } bool generateTocMDFile = config.GenerateTocMDFile; if (generateTocMDFile) { string tocMDFile = Path.Combine(outputPath, Constants.TocMDFileName); using (var writer = new StreamWriter(tocMDFile)) { foreach (var item in tocYaml) { WriteTocItemMD(writer, item, 1); } } } return(Task.FromResult(1)); }
public void UpdateTocYaml(TocYaml tocItemYamls, ConcurrentDictionary <string, List <TocItemYaml> > tocTracker) { if (tocItemYamls == null) { return; } foreach (var tocItem in tocItemYamls) { if (tocTracker.ContainsKey(tocItem.Uid)) { if (tocItem.Items == null) { tocItem.Items = new TocYaml(); } tocItem.Items.AddRange(tocTracker[tocItem.Uid]); } UpdateTocYaml(tocItem.Items, tocTracker); } }