Beispiel #1
0
        public void Pack_and_unpack_manifest() {

            // Arrange
            string directory = Path.Combine(Path.GetTempPath(), StringUtil.CreateAlphaNumericKey(6));
            Directory.CreateDirectory(directory);
            List<XDoc> docs = new List<XDoc>();
            docs.Add(new XDoc("doc1").Attr("dataid", "a"));
            docs.Add(new XDoc("doc2").Attr("dataid", "b"));
            docs.Add(new XDoc("doc3").Attr("dataid", "c"));
            List<Tuplet<string, MemoryStream>> data = new List<Tuplet<string, MemoryStream>>();
            foreach(XDoc doc in docs) {
                string id = doc["@dataid"].AsText;
                data.Add(new Tuplet<string, MemoryStream>(id, new MemoryStream(doc.ToBytes())));
            }
            XDoc manifest = new XDoc("manifest")
                .Start("page").Attr("dataid", "a").End()
                .Start("page").Attr("dataid", "b").End()
                .Start("page").Attr("dataid", "c").End();

            // Act
            using(FilePackageWriter packageWriter = new FilePackageWriter(directory)) {
                foreach(Tuplet<string, MemoryStream> tuple in data) {
                    var item = new ExportItem(tuple.Item1, tuple.Item2, tuple.Item2.Length, new XDoc("item").Elem("path", "abc"));
                    packageWriter.WriteDataAsync(item, new Result()).Wait();
                }
                packageWriter.WriteManifest(manifest, new Result()).Wait();
            }

            XDoc manifest2;
            List<XDoc> docs2 = new List<XDoc>();
            using(FilePackageReader packageReader = new FilePackageReader(directory)) {
                manifest2 = packageReader.ReadManifest(new Result<XDoc>()).Wait();
                foreach(XDoc id in manifest2["*/@dataid"]) {
                    using(ImportItem item = packageReader.ReadData(new ImportItem(id.AsText, null, null), new Result<ImportItem>()).Wait()) {
                        using(StreamReader reader = new StreamReader(item.Data)) {
                            docs2.Add(XDocFactory.From(reader, MimeType.TEXT_XML));
                        }
                    }
                }
            }

            // Assert
            Assert.IsTrue(File.Exists(Path.Combine(directory, "package.xml")));
            Assert.AreEqual(ToCanonical(manifest), ToCanonical(manifest2));
            Assert.AreEqual(docs.Count, docs2.Count);
            foreach(var doc in docs) {
                Assert.IsTrue(docs2.Select(x => x == doc).Any());
            }
        }
Beispiel #2
0
 public static Result<ExportManager> CreateFileExportManagerAsync(Plug dekiApi, XDoc exports, string reltopath, string packageDirectory, Result<ExportManager> result) {
     FilePackageWriter filePackager = new FilePackageWriter(packageDirectory);
     return CreateAsync(dekiApi, exports, reltopath, filePackager, result);
 }
        public static Result <ExportManager> CreateFileExportManagerAsync(Plug dekiApi, XDoc exports, string reltopath, string packageDirectory, Result <ExportManager> result)
        {
            FilePackageWriter filePackager = new FilePackageWriter(packageDirectory);

            return(CreateAsync(dekiApi, exports, reltopath, filePackager, result));
        }