/// <summary> /// Fills a C1MultiDocument or a C1PrintDocument passed to it with listings of /// all files in the specified directory and its subdirectories matching the specified mask. /// </summary> /// <param name="theDoc">A C1MultiDocument or a C1PrintDocument.</param> /// <param name="dir">Directory containing the files to list.</param> /// <param name="mask">The files mask (e.g. "*.cs").</param> /// <param name="pf">Progress form.</param> public void MakeMultiDocument(object theDoc, string dir, string mask, ProgressForm pf) { // Find out what kind of document we're creating: _mdoc = theDoc as C1MultiDocument; _sdoc = theDoc as C1PrintDocument; if (_mdoc == null && _sdoc == null) { throw new Exception("Unsupported document type."); } _dir = Path.GetFullPath(dir); _mask = mask; // Set up the document: if (_mdoc != null) { _mdoc.Clear(); _mdoc.DoEvents = true; } else { _sdoc.Clear(); _sdoc.DoEvents = true; SetupDoc(_sdoc); } // Show initial progress: pf.SetProgress(string.Format("Reading {0}...", _dir), 0); // For progress indicator only - get the list of all subdirectories: // long allDirsCount = Directory.GetDirectories(_dir, "*", SearchOption.AllDirectories).LongLength; // long allDirsIdx = 0; // Create TOC render object that will list directories and files: RenderToc toc = new RenderToc(); // Add a TOC directory entry in "directory added" event: DirAdded += (doc, dirRo, dirName, level) => { C1Anchor aDir = new C1Anchor(string.Format("d{0}", dirName.GetHashCode())); dirRo.Anchors.Add(aDir); // Add a TOC item for the directory (full name for root dir, own name for subdirs): string tocName = dirName == _dir ? dirName : Path.GetFileName(dirName); RenderTocItem rti = toc.AddItem(tocName, new C1Hyperlink(new C1LinkTargetAnchor(aDir.Name)), level); // Bold directory TOC entries: rti.Style.FontBold = true; // duplicate TOC entry in OUTLINE: OutlineNode outlineNode = new OutlineNode(dirName, dirRo); doc.Outlines.Add(outlineNode); // in this mode, all directory nodes are top-level // update overall progress: pf.SetProgress(string.Format("Reading {0}...", dirName)); if (pf.Cancelled) { throw new Exception("Directory scan aborted."); } return(outlineNode); }; // Add a TOC file entry in "file added" event: FileAdded += (doc, dirOutlineNode, fileRo, fileName, level) => { C1Anchor aFile = new C1Anchor(string.Format("f{0}", fileName.GetHashCode())); fileRo.Anchors.Add(aFile); string tocItemName = Path.GetFileName(fileName); toc.AddItem(tocItemName, new C1Hyperlink(new C1LinkTargetAnchor(aFile.Name)), level); // duplicate TOC entry in OUTLINE: if (dirOutlineNode == null) { doc.Outlines.Add(tocItemName, fileRo); // top-level entry } else { dirOutlineNode.Children.Add(tocItemName, fileRo); // nested entry } }; // Create the common index: RenderIndex index = new RenderIndex(); // Init keywords: Dictionary <string, IndexEntry> indexEntries = new Dictionary <string, IndexEntry>(); // For this sample, we will build an index of all KnownColor names: string[] colorNames = Enum.GetNames(typeof(KnownColor)); foreach (string keyword in colorNames) { indexEntries.Add(keyword, new IndexEntry(keyword)); } // Add an index entry for each key word in line: LineAdded += (lineRo, fileName, line, lineNo) => { var words = line.Split(s_delims, StringSplitOptions.RemoveEmptyEntries); C1Anchor a = null; foreach (string word in words) { if (indexEntries.ContainsKey(word)) { if (a == null) { a = new C1Anchor(string.Format("k{0}{1}", fileName.GetHashCode(), lineNo)); lineRo.Anchors.Add(a); } indexEntries[word].Occurrences.Add(new IndexEntryOccurrence(new C1LinkTargetAnchor(a.Name))); } } }; // Add listings of files to the document: ListDir(_dir, 1); // insert TOC at the top: RenderText tocHeader = new RenderText("Table of Contents"); tocHeader.Style.Spacing.Bottom = "3mm"; tocHeader.Style.TextAlignHorz = AlignHorzEnum.Center; tocHeader.Style.FontSize = 12; tocHeader.Style.FontBold = true; if (_mdoc != null) { C1PrintDocument docToc = new C1PrintDocument(); docToc.Body.Children.Add(tocHeader); docToc.Body.Children.Add(toc); _mdoc.Items.Insert(0, docToc); docToc = null; GC.Collect(); GC.WaitForPendingFinalizers(); } else { toc.BreakAfter = BreakEnum.Page; _sdoc.Body.Children.Insert(0, toc); _sdoc.Body.Children.Insert(0, tocHeader); } // insert word index at the bottom: RenderText indexHeader = new RenderText("Index of Known Colors"); indexHeader.Style.Spacing.Bottom = "3mm"; indexHeader.Style.TextAlignHorz = AlignHorzEnum.Center; indexHeader.Style.FontSize = 12; indexHeader.Style.FontBold = true; index.HeadingStyle.FontSize += 1; index.HeadingStyle.FontBold = true; index.HeadingStyle.Padding.All = "2mm"; // add index entries that have some occurrences: foreach (IndexEntry ie in indexEntries.Values) { if (ie.HasOccurrences) { index.Entries.Add(ie); } } if (_mdoc != null) { C1PrintDocument docIndex = new C1PrintDocument(); docIndex.Body.Children.Add(indexHeader); docIndex.Body.Children.Add(index); _mdoc.Items.Add(docIndex); docIndex = null; GC.Collect(); GC.WaitForPendingFinalizers(); } else { indexHeader.BreakBefore = BreakEnum.Page; _sdoc.Body.Children.Add(indexHeader); _sdoc.Body.Children.Add(index); } // we're done! pf.SetProgress(string.Format("Reading {0}...", _dir), 1); }
public static void CreateOutput(object sender, object selectedItem) { if (selectedItem is OutputCollectionViewModel outputCollectionViewModel) { CreateOutput(sender, outputCollectionViewModel.Parent); return; } if (!(selectedItem is GroupViewModel entityGroupViewModel)) { return; } var button = (Button)sender; var type = (string)button.CommandParameter; OutputBase entity; switch (type) { case nameof(RenderArrayHint): entity = RenderArrayHint.New(); break; case nameof(RenderNextDate): entity = RenderNextDate.New("Name", "0001-01-01", "Weekly"); break; case nameof(RenderIndex): entity = RenderIndex.New(); break; case nameof(RenderEntity): entity = RenderEntity.New(); break; case nameof(RenderLink): entity = RenderLink.New(); break; case nameof(RenderProperty): entity = RenderProperty.New("Display Name", "Property Name"); break; case nameof(RenderValue): entity = RenderValue.New("Name", "Value"); break; case nameof(RenderTypeName): entity = RenderTypeName.New("Name"); break; case nameof(RenderTaxPeriodDate): entity = RenderTaxPeriodDate.New("Name", "2020", "1"); break; case nameof(RenderConstant): entity = RenderConstant.New("Name", "Constant Name", typeof(DateTime)); break; case nameof(RenderTaxPeriod): entity = RenderTaxPeriod.New("Name", "Monthly", "0001-01-01"); break; case nameof(RenderDateAdd): entity = RenderDateAdd.New("Name", "0001-01-01", "Day", "1"); break; case nameof(RenderUniqueKeyFromLink): entity = RenderUniqueKeyFromLink.New("Name", "[Link]"); break; case nameof(Avg): entity = Avg.New("Name", "Property"); break; case nameof(Max): entity = Max.New("Name", "Property"); break; case nameof(Min): entity = Min.New("Name", "Property"); break; case nameof(Sum): entity = Sum.New("Name", "Property"); break; case nameof(Count): entity = Count.New("Name"); break; case nameof(ExpressionCalculator): entity = ExpressionCalculator.New("Name", "1 + 2 - 3 * 4 / 5", rounding: RoundingOption.NotSet); break; case nameof(Distinct): entity = Distinct.New("Name", "Property"); break; default: throw new ArgumentOutOfRangeException(); } entityGroupViewModel.Element.Outputs.Add(entity); var viewModelCollection = entityGroupViewModel.Children.OfType <OutputCollectionViewModel>().First(); var viewModel = new OutputViewModel(entity, viewModelCollection); viewModelCollection.Children.Add(viewModel); entityGroupViewModel.IsExpanded = true; viewModelCollection.IsExpanded = true; viewModel.IsSelected = true; viewModel.IsExpanded = true; }