예제 #1
0
        public void ShouldBuildArchiveFromExistingFile()
        {
            var fieldMetaDataBuilder = FieldsMetaDataBuilder.Fields()
                                       .AutomaticallyIndex()
                                       .AddField(_ => _.Term(Terms.taxonID))
                                       .AddField(_ => _.Term(Terms.vernacularName))
                                       .AddField(_ => _.Term(Terms.language));
            var fileMetaData = CoreFileMetaDataBuilder.File("taxon.txt")
                               .FieldsEnclosedBy("\"")
                               .FieldsTerminatedBy(",")
                               .LinesTerminatedBy("\\n")
                               .IgnoreHeaderLines(1)
                               .Encoding(Encoding.UTF8)
                               .Index(0)
                               .RowType(RowTypes.Taxon)
                               .AddFields(fieldMetaDataBuilder);
            var fileBuider = FileBuilder.MetaData(fileMetaData)
                             .UseExistingFile("./resources/whales/whales.txt");

            ArchiveWriter.CoreFile(fileBuider, fileMetaData)
            .Build("whales.zip");

            Assert.True(File.Exists("whales.zip"));

            using (var archive = new ArchiveReader("whales.zip"))
            {
                var whales = archive.CoreFile
                             .DataRows
                             .Select(n => n[Terms.vernacularName]);
                Assert.Equal(new[] { "sperm whale", "cachalot", "gray whale" }, whales);
            }
        }
예제 #2
0
        public async Task ShouldBuildArchive()
        {
            var context = BuilderContext.Default;

            var occurrences = await fixture.GetOccurrencesAsync();

            var occurrenceMetaDataBuilder = fixture.OccurrenceFieldsMetaDataBuilder;
            var coreFileMetaDataBuilder   = CoreFileMetaDataBuilder.File("occurrence.txt")
                                            .IgnoreHeaderLines(1)
                                            .Encoding(Encoding.UTF8)
                                            .Index(0)
                                            .RowType(RowTypes.Occurrence)
                                            .AddFields(occurrenceMetaDataBuilder);
            var coreFileBuilder = FileBuilder.MetaData(coreFileMetaDataBuilder)
                                  .Context(context)
                                  .BuildRows(rowBuilder => BuildCoreRows(rowBuilder));

            var multimedia = await fixture.GetMultimediaAsync();

            var multimediaMetaDataBuilder    = fixture.MultimediaMetaDataBuilder;
            var extensionFileMetaDataBuilder = ExtensionFileMetaDataBuilder.File("multimedia.txt")
                                               .IgnoreHeaderLines(1)
                                               .Encoding(Encoding.UTF8)
                                               .CoreIndex(0)
                                               .RowType(RowTypes.Occurrence)
                                               .AddFields(multimediaMetaDataBuilder);
            var extensionFileBuilder = FileBuilder.MetaData(extensionFileMetaDataBuilder)
                                       .Context(context)
                                       .BuildRows(rowBuilder => BuildExtensionRows(rowBuilder));

            var archiveName = "archivexxx.zip";

            ArchiveWriter.CoreFile(coreFileBuilder, coreFileMetaDataBuilder)
            .Context(context)
            .AddExtensionFile(extensionFileBuilder, extensionFileMetaDataBuilder)
            .AddExtraFile("resources/ExtraData.txt")
            .Build(archiveName);

            Assert.True(File.Exists(archiveName));
            context.Cleanup();
        }