public void WriteRow(TextWriter writer, char separator, IEnumerable <object> values) { string strSeparator = new string(separator, 1); var row = string.Join(strSeparator, values.Select(value => DsvWriter.ToDsvField(separator, FormatValue(value)))); writer.WriteLine(row); }
public DsvWriter GetDsvWriter(char separator) { DsvWriter dsvWriter = new DsvWriter(DataSchema.DataSchemaLocalizer.FormatProvider, separator); if (IsInvariantLanguage()) { dsvWriter.NumberFormatOverride = Formats.RoundTrip; } return(dsvWriter); }
private void RunScenario(string scenarioName) { RunUI(() => SkylineWindow.OpenSharedFile(TestFilesDir.GetTestPath(scenarioName + ".sky.zip"))); if (null != TestContext.TestRunResultsDirectory) { var directory = Path.Combine(TestContext.TestRunResultsDirectory, "GroupComparisonScenariosTest"); Directory.CreateDirectory(directory); string baseName = Path.Combine(directory, scenarioName); RunUI(() => SkylineWindow.ShareDocument(baseName + ".sky.zip", ShareType.COMPLETE)); foreach (var groupComparison in SkylineWindow.Document.Settings.DataSettings.GroupComparisonDefs) { String groupComparisonName = groupComparison.Name; FoldChangeGrid foldChangeGrid = ShowDialog <FoldChangeGrid>(() => SkylineWindow.ShowGroupComparisonWindow(groupComparisonName)); var reports = new[] { "GroupComparisonColumns" }; var dsvWriter = new DsvWriter(CultureInfo.InvariantCulture, ',') { NumberFormatOverride = Formats.RoundTrip }; foreach (String report in reports) { WaitForConditionUI(() => foldChangeGrid.DataboundGridControl.IsComplete && null != foldChangeGrid.FoldChangeBindingSource.GroupComparisonModel.Results && null != foldChangeGrid.DataboundGridControl.BindingListSource.ViewContext); // ReSharper disable AccessToForEachVariableInClosure RunUI(() => { foldChangeGrid.DataboundGridControl.ChooseView(report); }); // ReSharper restore AccessToForEachVariableInClosure WaitForConditionUI(() => foldChangeGrid.DataboundGridControl.IsComplete); String exportPath = Path.Combine(directory, scenarioName + "_" + groupComparisonName + "_" + report + ".csv"); RunUI(() => { var viewContext = (AbstractViewContext)foldChangeGrid.DataboundGridControl.NavBar.ViewContext; viewContext.ExportToFile(foldChangeGrid, foldChangeGrid.DataboundGridControl.BindingListSource, exportPath, dsvWriter); } ); } OkDialog(foldChangeGrid, foldChangeGrid.Close); } } }
private static string SeparateValues(char separator, IEnumerable <string> values) { var stringWriter = new StringWriter(); bool first = true; foreach (var value in values) { if (!first) { stringWriter.Write(separator); } first = false; stringWriter.Write(DsvWriter.ToDsvField(separator, value)); } return(stringWriter.ToString()); }
public void TestInvariantExport() { SkylineDataSchema skylineDataSchema = new SkylineDataSchema(CreateMemoryDocumentContainer(LoadTestDocument()), DataSchemaLocalizer.INVARIANT); SkylineViewContext viewContext = new DocumentGridViewContext(skylineDataSchema); string testFile = Path.Combine(TestContext.TestDir, "TestInvariantExport.csv"); var dsvWriter = new DsvWriter(CultureInfo.InvariantCulture, ','); viewContext.ExportToFile(null, GetTestReport(skylineDataSchema), testFile, dsvWriter); string strExported = File.ReadAllText(testFile); Assert.AreEqual(ExpectedInvariantReport, strExported); // Assert that the file written out was UTF8 encoding without any byte order mark byte[] bytesExported = File.ReadAllBytes(testFile); CollectionAssert.AreEqual(Encoding.UTF8.GetBytes(strExported), bytesExported); }
private void WriteAllAnnotations(CancellationToken cancellationToken, TextWriter textWriter, char separator) { string strSeparator = new string(separator, 1); var columns = new Columns(Document.Settings.DataSettings.AnnotationDefs); textWriter.WriteLine(string.Join(strSeparator, columns.GetColumnHeaders().Select(header => DsvWriter.ToDsvField(separator, header)))); foreach (var tuple in GetAllAnnotations()) { var annotations = tuple.Item2; if (annotations.IsEmpty) { continue; } var row = columns.GetRow(tuple.Item1, tuple.Item2); textWriter.WriteLine(string.Join(strSeparator, row.Select(value => DsvWriter.ToDsvField(separator, ValueToString(value))))); } }
public bool ExportToFile(Control owner, ViewInfo viewInfo, string fileName, DsvWriter dsvWriter) { try { return(SafeWriteToFile(owner, fileName, stream => { bool success = false; using ( var longWait = new LongWaitDlg { Text = Resources.ExportReportDlg_ExportReport_Generating_Report }) { var action = new Action <IProgressMonitor>(broker => { IProgressStatus status = new ProgressStatus(Resources.ExportReportDlg_ExportReport_Building_report); broker.UpdateProgress(status); using (var writer = new StreamWriter(stream)) { success = Export(broker, ref status, viewInfo, writer, dsvWriter); writer.Close(); } if (success) { broker.UpdateProgress(status.Complete()); } }); longWait.PerformWork(owner, 1500, action); } return success; })); } catch (Exception x) { Trace.TraceWarning("Error exporting to file: {0}", x); // Not L10N MessageDlg.ShowWithException(owner, string.Format(Resources.ExportReportDlg_ExportReport_Failed_exporting_to, fileName, x.Message), x); return(false); } }
protected static string ToCsvRow(IEnumerable <string> values) { StringBuilder stringBuilder = new StringBuilder(); bool anyValues = false; foreach (var value in values) { if (anyValues) { stringBuilder.Append(CSV_SEPARATOR_STRING); } anyValues = true; if (!string.IsNullOrEmpty(value)) { stringBuilder.Append(DsvWriter.ToDsvField(CSV_SEPARATOR_CHAR, value)); } } if (!anyValues) { // Return the empty string if there are zero rows of data return(string.Empty); } if (stringBuilder.Length == 0) { // Return the empty quoted string if there is one row of blank data, to // distinguish it from zero rows of data. // ReSharper disable LocalizableElement return("\"\""); // ReSharper restore LocalizableElement } return(stringBuilder.ToString()); }
public override string ToPersistedString() { return(string.Join(CSV_SEPARATOR_STRING, _values.Select(value => DsvWriter.ToDsvField(CSV_SEPARATOR_CHAR, value)))); }
public bool Export(IProgressMonitor progressMonitor, ref IProgressStatus status, ViewInfo viewInfo, TextWriter writer, DsvWriter dsvWriter) { progressMonitor = progressMonitor ?? new SilentProgressMonitor(); using (var bindingListSource = new BindingListSource()) { bindingListSource.SetViewContext(this, viewInfo); if (progressMonitor.IsCanceled) { return(false); } progressMonitor.UpdateProgress(status = status.ChangePercentComplete(5) .ChangeMessage(Resources.ExportReportDlg_ExportReport_Writing_report)); WriteDataWithStatus(progressMonitor, ref status, writer, bindingListSource, dsvWriter); if (progressMonitor.IsCanceled) { return(false); } writer.Flush(); progressMonitor.UpdateProgress(status = status.Complete()); } return(true); }
private string TabSeparate(params object[] values) { return(string.Join("\t", values.Select(value => DsvWriter.ToDsvField('\t', (value ?? string.Empty).ToString())))); }
public bool Export(CancellationToken cancellationToken, IProgressMonitor progressMonitor, ref IProgressStatus status, ViewInfo viewInfo, TextWriter writer, DsvWriter dsvWriter) { ViewLayout viewLayout = null; if (viewInfo.ViewGroup != null) { var viewLayoutList = GetViewLayoutList(viewInfo.ViewGroup.Id.ViewName(viewInfo.Name)); if (viewLayoutList != null) { viewLayout = viewLayoutList.DefaultLayout; } } return(Export(cancellationToken, progressMonitor, ref status, viewInfo, viewLayout, writer, dsvWriter)); }