/// <summary> /// Initializes a new instance of the <see cref="GedcomxOutputStream"/> class. /// </summary> /// <param name="gedxOutputStream">The underlying data stream this GEDCOM X will be written to.</param> /// <param name="serializer">The serializer to use when adding objects to this GEDCOM X file.</param> public GedcomxOutputStream(Stream gedxOutputStream, IGedcomxEntrySerializer serializer) { this.serializer = serializer; this.gedxOutputStream = new ZipArchive(gedxOutputStream, ZipArchiveMode.Create, false, Encoding.UTF8); this.mf = new ManifestAttributes(this.gedxOutputStream); this.mf.MainAttributes.Put("Manifest-Version", "1.0"); }
/// <summary> /// Initializes a new instance of the <see cref="GedcomxFile"/> class. /// </summary> /// <param name="gedxFile">The GEDCOM X file.</param> /// <param name="deserializer">The deserializer to use for deserializing data streams from the file.</param> public GedcomxFile(FileInfo gedxFile, IGedcomxEntryDeserializer deserializer) { this.gedxFile = gedxFile; this.gedxArc = ZipFile.OpenRead(gedxFile.FullName); this.deserializer = deserializer; this.attributes = ManifestAttributes.Parse(this.gedxArc); }
/// <summary> /// Searches the specified zip file for the manifest file and returns the attribute declarations it contains. /// </summary> /// <param name="zip">The zip file to be evaluated.</param> /// <returns>A <see cref="ManifestAttributes"/> with the discovered manifest file attribute declarations.</returns> public static ManifestAttributes Parse(ZipArchive zip) { var result = new ManifestAttributes(zip); var manifest = zip.GetEntry(MANIFEST_FULLNAME); var tempAttributes = new List <ManifestAttribute>(); var mainAttributesParsed = false; ZipArchiveEntry entry = null; if (zip != null && zip.Entries != null) { foreach (var file in zip.Entries) { result.Add(file.FullName, null); } } if (manifest != null) { using (var stream = new StreamReader(manifest.Open())) { while (!stream.EndOfStream) { var line = stream.ReadLine(); var attribute = Parse(line); if (attribute != null) { tempAttributes.Add(attribute); } if (line == string.Empty) { var entryName = tempAttributes.FirstOrDefault(x => x.Name == "Name"); if ((entryName != null && !string.IsNullOrEmpty(entryName.Value)) || !mainAttributesParsed) { entry = entryName != null?zip.GetEntry(entryName.Value) : manifest; if (entry == manifest) { mainAttributesParsed = true; } if (entry != null) { result[entry.FullName] = tempAttributes.ToList(); // Make a copy so the reference won't clear this assignment tempAttributes.Clear(); } } } } } } return(result); }