示例#1
0
        public void TestExportWithCurrentLanguage()
        {
            CultureInfo cultureInfo = CultureInfo.CurrentUICulture;
            SkylineDataSchema skylineDataSchema =
                new SkylineDataSchema(CreateMemoryDocumentContainer(LoadTestDocument()), SkylineDataSchema.GetLocalizedSchemaLocalizer());
            SkylineViewContext viewContext = new DocumentGridViewContext(skylineDataSchema);

            string testFile = Path.Combine(TestContext.TestDir, "TestExportWithCurrentLanguage.csv");
            char separator = TextUtil.GetCsvSeparator(cultureInfo);
            var dsvWriter = new DsvWriter(cultureInfo, separator);
            viewContext.ExportToFile(null, GetTestReport(skylineDataSchema), testFile, dsvWriter);
            string strExported = File.ReadAllText(testFile);
            var actualLines = strExported.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            var expectedLines = ExpectedInvariantReport.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

            var invariantHeaders = expectedLines[0].Split(',');
            var expectedHeaders =
                invariantHeaders.Select(header => ColumnCaptions.ResourceManager.GetString(header, cultureInfo) ?? header).ToArray();
            var actualHeaders = actualLines[0].Split(separator);
            CollectionAssert.AreEqual(expectedHeaders, actualHeaders);
            // If the language in English, then the exported report will be identical to the invariant report except for the headers
            if (cultureInfo.Name == "en-US")
            {
                CollectionAssert.AreEqual(expectedLines.Skip(1).ToArray(), actualLines.Skip(1).ToArray());
            }
        }
示例#2
0
 public void ExportToFile(Control owner, BindingListSource bindingListSource, String filename,
                          DsvWriter dsvWriter)
 {
     SafeWriteToFile(owner, filename, stream =>
     {
         var writer    = new StreamWriter(stream, new UTF8Encoding(false));
         bool finished = false;
         RunOnThisThread(owner, (cancellationToken, progressMonitor) =>
         {
             WriteData(progressMonitor, writer, bindingListSource, dsvWriter);
             finished = !progressMonitor.IsCanceled;
         });
         if (finished)
         {
             writer.Flush();
         }
         return(finished);
     });
 }
示例#3
0
        protected virtual void WriteDataWithStatus(IProgressMonitor progressMonitor, ref IProgressStatus status, TextWriter writer, BindingListSource bindingListSource, DsvWriter dsvWriter)
        {
            IList <RowItem>            rows       = Array.AsReadOnly(bindingListSource.Cast <RowItem>().ToArray());
            IList <PropertyDescriptor> properties = bindingListSource.GetItemProperties(new PropertyDescriptor[0]).Cast <PropertyDescriptor>().ToArray();

            dsvWriter.WriteHeaderRow(writer, properties);
            var rowCount     = rows.Count;
            int startPercent = status.PercentComplete;

            for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
            {
                if (progressMonitor.IsCanceled)
                {
                    return;
                }
                int percentComplete = startPercent + (rowIndex * (100 - startPercent) / rowCount);
                if (percentComplete > status.PercentComplete)
                {
                    status = status.ChangeMessage(string.Format(Resources.AbstractViewContext_WriteData_Writing_row__0___1_, (rowIndex + 1), rowCount))
                             .ChangePercentComplete(percentComplete);
                    progressMonitor.UpdateProgress(status);
                }
                dsvWriter.WriteDataRow(writer, rows[rowIndex], properties);
            }
        }
示例#4
0
        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);
        }