private void OnDeserialized(StreamingContext context = default(StreamingContext)) { Coverage = Coverage ?? new ObservableCollection <LandCoverItem>(); if (Coverage.Count == 0 || Coverage[0].Mapping == null) { Coverage.Clear(); foreach (var item in LandCoverTableService.GetTable("ESACCI LCCS")) { Coverage.Add(item.Clone()); } } }
private static emma.coverage[] CreateCoverage(bullseye.src src, emma.@class[] classes) { Coverage cov = new Coverage(); foreach (var cls in classes) { var covs = Utils.ParseCoverages((from item in cls.Items where item is emma.coverage select (emma.coverage) item).ToArray()); cov.Add(covs.ClassCovered, covs.ClassTotal); } return Utils.CreateCoverage(cov.Covered.ToString(), cov.Total.ToString(), src.fn_cov, src.fn_total, src.cd_cov, src.cd_total, "0", "0"); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.GetEntry(opfFilePath); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (Stream zipStream = _EpubFile.GetInputStream(zipEntry)) { using (MemoryStream memoryStream = new MemoryStream()) { byte[] buffer = new byte[4096]; // 4K is optimum StreamUtils.Copy(zipStream, memoryStream, buffer); memoryStream.Position = 0; contentOpf = XElement.Load(memoryStream); } } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null ? contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; UUID = contentOpf.Elements(xNamespace + "metadata").Elements() .FirstOrDefault(e => e.Name.LocalName == "identifier" && e.HasAttributes && e.Attribute("id") != null && e.Attribute("id").Value == uniqueIdentifier ).Value; foreach ( var metadataElement in contentOpf.Element(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase)); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (MemoryStream memoryStream = new MemoryStream()) { zipEntry.Extract(memoryStream); // Fix buggy "<?xml verison="1.1"?> // See http://stackoverflow.com/questions/912440/xdocument-cant-load-xml-with-version-1-1-in-c-sharp-linq byte[] b = memoryStream.ToArray(); for (int i = 0; i < 50; i++) { // Check for version="1.1" and replace if found if (b[i] == 0x76 && b[i + 1] == 0x65 && b[i + 2] == 0x72 && b[i + 3] == 0x73 && b[i + 4] == 0x69 && b[i + 5] == 0x6F && b[i + 6] == 0x6E && b[i + 7] == 0x3D && b[i + 8] == 0x22 && b[i + 9] == 0x31 && b[i + 10] == 0x2E && b[i + 11] == 0x31) { b[i + 11] = 0x30; } } using (MemoryStream fixedStream = new MemoryStream(b)) { contentOpf = XElement.Load(fixedStream); } b = null; } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attributes("id").FirstOrDefault() != null && e.Attribute("id").Value == uniqueIdentifier).Value; } catch { } foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
private void LoadEpubMetaDataFromOpfFile(string opfFilePath) { ZipEntry zipEntry = _EpubFile.Entries.FirstOrDefault(e => e.FileName.Equals(opfFilePath, StringComparison.InvariantCultureIgnoreCase)); if (zipEntry == null) { throw new Exception("Invalid epub file."); } XElement contentOpf; using (MemoryStream memoryStream = new MemoryStream()) { zipEntry.Extract(memoryStream); memoryStream.Position = 0; contentOpf = XElement.Load(memoryStream); } XNamespace xNamespace = contentOpf.Attribute("xmlns") != null?contentOpf.Attribute("xmlns").Value : XNamespace.None; string uniqueIdentifier = contentOpf.Attribute("unique-identifier").Value; try { UUID = contentOpf.Elements(xNamespace + "metadata").Elements().FirstOrDefault(e => e.Name.LocalName == "identifier" && e.Attribute("id").Value == uniqueIdentifier).Value; } catch { } foreach (var metadataElement in contentOpf.Elements(xNamespace + "metadata").Elements().Where(e => e.Value.Trim() != string.Empty)) { switch (metadataElement.Name.LocalName) { case "title": Title.Add(metadataElement.Value); break; case "creator": Creator.Add(metadataElement.Value); break; case "date": var attribute = metadataElement.Attributes().FirstOrDefault(a => a.Name.LocalName == "event"); if (attribute != null) { Date.Add(new DateData(attribute.Value, metadataElement.Value)); } break; case "publisher": Publisher.Add(metadataElement.Value); break; case "subject": Subject.Add(metadataElement.Value); break; case "source": Source.Add(metadataElement.Value); break; case "rights": Rights.Add(metadataElement.Value); break; case "description": Description.Add(metadataElement.Value); break; case "contributor": Contributer.Add(metadataElement.Value); break; case "type": Type.Add(metadataElement.Value); break; case "format": Format.Add(metadataElement.Value); break; case "identifier": ID.Add(metadataElement.Value); break; case "language": Language.Add(metadataElement.Value); break; case "relation": Relation.Add(metadataElement.Value); break; case "coverage": Coverage.Add(metadataElement.Value); break; } } LoadManifestSectionFromOpfFile(contentOpf, xNamespace); }
private emma.coverage[] ToCoverage() { var cov = new Coverage(); cov.Add(cd.Covered > 0 ? 1 : 0, 1); return Utils.CreateCoverage(cov, fn, cd, new Coverage()); }
private emma.report ConvertToEmma(bullseye.BullseyeCoverage dc) { var folders = new Dictionary<string, emma.package>(); // Create packages ForEachSrc(dc, (path, folder, src) => { if (!folders.ContainsKey(path)) { var package = new emma.package(); package.name = ConvertPathToPackageName(path); package.coverage = CreateCoverage(folder); package.srcfile = new emma.srcfile[0]; folders.Add(path, package); } var files = new List<emma.srcfile>(folders[path].srcfile); files.Add(Convert(src)); folders[path].srcfile = files.ToArray(); }); // Add classes to the package foreach (var package in folders.Values) { Coverage classesCov = new Coverage(); foreach (var src in package.srcfile) { var covs = Utils.ParseCoverages(src.coverage); classesCov.Add(covs.ClassCovered, covs.ClassTotal); } var packageCovs = Utils.ParseCoverages(package.coverage); package.coverage = Utils.CreateCoverage(classesCov.Covered, classesCov.Total, packageCovs.MethodCovered, packageCovs.MethodTotal, packageCovs.BlockCovered, packageCovs.BlockTotal, packageCovs.LineCovered, packageCovs.LineTotal); } return Utils.CreateReport(folders.Values); }