public static void ReportToCsv(ReportSpec reportSpec, SrmDocument doc, string fileName, CultureInfo cultureInfo) { var documentContainer = new MemoryDocumentContainer(); Assert.IsTrue(documentContainer.SetDocument(doc, documentContainer.Document)); var skylineDataSchema = new SkylineDataSchema(documentContainer, new DataSchemaLocalizer(cultureInfo, cultureInfo)); var viewSpec = ReportSharing.ConvertAll(new[] { new ReportOrViewSpec(reportSpec) }, doc).First(); var viewContext = new DocumentGridViewContext(skylineDataSchema); using (var writer = new StreamWriter(fileName)) { IProgressStatus status = new ProgressStatus(); viewContext.Export(CancellationToken.None, new SilentProgressMonitor(), ref status, viewContext.GetViewInfo(ViewGroup.BUILT_IN, viewSpec), writer, viewContext.GetCsvWriter()); } }
/// <summary> /// Construct a new PersistedViews, migrating over the values from the old ViewSpecList /// and ReportSpecList properties. Views that are in use by an external tool get put in /// the External Tools group, and views that are /// </summary> public PersistedViews(ReportSpecList reportSpecList, ViewSpecList viewSpecList, ToolList toolList) { var viewItems = new List <ViewSpec>(); if (null != viewSpecList) { viewItems.AddRange(viewSpecList.ViewSpecs); } if (null != reportSpecList) { RevisionIndex = reportSpecList.RevisionIndex + 1; foreach (var newView in ReportSharing.ConvertAll(reportSpecList.Select(reportSpec => new ReportOrViewSpec(reportSpec)), new SrmDocument(SrmSettingsList.GetDefault()))) { if (viewItems.Any(viewSpec => viewSpec.Name == newView.Name)) { continue; } viewItems.Add(newView); } } var viewSpecLists = new Dictionary <ViewGroup, Dictionary <string, ViewSpec> >(); foreach (var viewItem in viewItems) { ViewGroup group; if (toolList.Any(tool => tool.ReportTitle == viewItem.Name)) { group = ExternalToolsGroup; } else { group = MainGroup; } Dictionary <string, ViewSpec> list; if (!viewSpecLists.TryGetValue(group, out list)) { list = new Dictionary <string, ViewSpec>(); viewSpecLists.Add(group, list); } if (!list.ContainsKey(viewItem.Name)) { list.Add(viewItem.Name, viewItem); } else { for (int i = 1;; i++) { string name = viewItem.Name + i; if (!list.ContainsKey(name)) { list.Add(name, viewItem.SetName(name)); break; } } } } foreach (var entry in viewSpecLists) { SetViewSpecList(entry.Key.Id, new ViewSpecList(entry.Value.Values)); } AddDefaults(); }