EnsureDoucmentStructure() { // if _xpsSignaturs is not null we have already initialized this // if (null != _documentStructure) { return; } PackageRelationship documentStructureRelationship = null; PackagePart documentStructurePart = null; foreach (PackageRelationship rel in _metroPart.GetRelationshipsByType(XpsS0Markup.StructureRelationshipName)) { if (documentStructureRelationship != null) { throw new InvalidDataException(SR.Get(SRID.ReachPackaging_MoreThanOneDocStructure)); } documentStructureRelationship = rel; } if (documentStructureRelationship != null) { Uri documentStructureUri = PackUriHelper.ResolvePartUri(documentStructureRelationship.SourceUri, documentStructureRelationship.TargetUri); if (CurrentXpsManager.MetroPackage.PartExists(documentStructureUri)) { documentStructurePart = CurrentXpsManager.MetroPackage.GetPart(documentStructureUri); _documentStructure = new XpsStructure(CurrentXpsManager, this, documentStructurePart); } } }
/// <summary> /// Initializes a new instance of the ReferenceRelationship. /// </summary> /// <param name="packageRelationship">The source PackageRelationship.</param> internal protected ReferenceRelationship(PackageRelationship packageRelationship) { Debug.Assert(packageRelationship != null); this.RelationshipType = packageRelationship.RelationshipType; this.Uri = packageRelationship.TargetUri; this.IsExternal = packageRelationship.TargetMode == TargetMode.External; this.Id = packageRelationship.Id; }
/// <summary> /// Deletes any relationship to the given signature from the signature origin /// </summary> /// <param name="r">relationship from origin</param> /// <param name="signatureUri">signatureUri</param> /// <returns>true</returns> private bool DeleteRelationshipToSignature(PackageRelationship r, Object signatureUri) { Uri uri = signatureUri as Uri; Debug.Assert(uri != null, "Improper use of delegate - context must be Uri"); // don't resolve if external if (r.TargetMode != TargetMode.Internal) throw new FileFormatException(SR.Get(SRID.PackageSignatureCorruption)); if (PackUriHelper.ComparePartUri(PackUriHelper.ResolvePartUri(r.SourceUri, r.TargetUri), uri) == 0) { OriginPart.DeleteRelationship(r.Id); // don't break early in case there are redundant relationships } return true; }
/// <summary> /// Deletes any relationship that is of the type that relates a Package to the Digital Signature Origin /// </summary> /// <param name="r"></param> /// <param name="context"></param> /// <returns></returns> private bool DeleteRelationshipOfTypePackageToOriginVisitor(PackageRelationship r, Object context) { Debug.Assert(Uri.Compare(r.SourceUri, PackUriHelper.PackageRootUri, UriComponents.SerializationInfoString, UriFormat.UriEscaped, StringComparison.Ordinal) == 0, "Logic Error: This visitor should only be called with relationships from the Package itself"); // don't resolve if external if (r.TargetMode != TargetMode.Internal) throw new FileFormatException(SR.Get(SRID.PackageSignatureCorruption)); Uri targetUri = PackUriHelper.ResolvePartUri(r.SourceUri, r.TargetUri); if (PackUriHelper.ComparePartUri(targetUri, _originPartName) == 0) _container.DeleteRelationship(r.Id); return true; }
/// <summary> /// Removes the certificate associated with the given signature if removing the signature would leave the /// certificate part orphaned. /// </summary> private bool DeleteCertificateIfReferenceCountBecomesZeroVisitor(PackageRelationship r, Object context) { // don't resolve if external if (r.TargetMode != TargetMode.Internal) throw new FileFormatException(SR.Get(SRID.PackageSignatureCorruption)); Uri certificatePartName = PackUriHelper.ResolvePartUri(r.SourceUri, r.TargetUri); if (CertificatePartReferenceCount(certificatePartName) == 1) // we are part of the calculation so one is the magic number _container.DeletePart(certificatePartName); // will not throw if part not found return true; }
private static void AddSignableItems(PackageRelationship relationship, ICollection<Uri> partsToSign, ICollection<PackageRelationshipSelector> relationshipsToSign) { var selector = new PackageRelationshipSelector(relationship.SourceUri, PackageRelationshipSelectorType.Id, relationship.Id); relationshipsToSign.Add(selector); if (relationship.TargetMode != TargetMode.Internal) { return; } var part = relationship.Package.GetPart( PackUriHelper.ResolvePartUri( relationship.SourceUri, relationship.TargetUri)); if (partsToSign.Contains(part.Uri)) { return; } partsToSign.Add(part.Uri); foreach (var childRelationship in part.GetRelationships()) { AddSignableItems(childRelationship, partsToSign, relationshipsToSign); } }
private PackageRelationship CreateRelationship (Uri targetUri, TargetMode targetMode, string relationshipType, string id, bool loading) { Package.CheckIsReadOnly (); Check.TargetUri (targetUri); Check.RelationshipTypeIsValid (relationshipType); Check.IdIsValid (id); if (id == null) id = NextId (); if (Relationships.ContainsKey (id)) throw new XmlException ("A relationship with this ID already exists"); PackageRelationship r = new PackageRelationship (id, Package, relationshipType, Uri, targetMode, targetUri); Relationships.Add (r.Id, r); if (!loading) WriteRelationships (); return r; }
internal PackageRelationship CreateRelationship (Uri targetUri, TargetMode targetMode, string relationshipType, string id, bool loading) { if (!loading) CheckIsReadOnly (); Check.TargetUri (targetUri); if (targetUri.IsAbsoluteUri && targetMode == TargetMode.Internal) throw new ArgumentException ("TargetUri cannot be absolute for an internal relationship"); Check.RelationshipTypeIsValid (relationshipType); Check.IdIsValid (id); if (id == null) id = NextId (); PackageRelationship r = new PackageRelationship (id, this, relationshipType, Uri, targetMode, targetUri); if (!PartExists (RelationshipUri)) CreatePartCore (RelationshipUri, RelationshipContentType, CompressionOption.NotCompressed).IsRelationship = true; Relationships.Add (r.Id, r); relationshipsCollection.Relationships.Add (r); if (!loading) { using (Stream s = GetPart (RelationshipUri).GetStream ()) WriteRelationships (relationships, s); } return r; }
internal Image(DocX document, PackageRelationship pr) { this.document = document; this.pr = pr; this.id = pr.Id; }
internal ExcelPivotTable(PackageRelationship rel, ExcelWorksheet sheet) : base(sheet.NameSpaceManager) { WorkSheet = sheet; PivotTableUri = PackUriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri); Relationship = rel; var pck = sheet._package.Package; Part=pck.GetPart(PivotTableUri); PivotTableXml = new XmlDocument(); LoadXmlSafe(PivotTableXml, Part.GetStream()); init(); TopNode = PivotTableXml.DocumentElement; Address = new ExcelAddressBase(GetXmlNodeString("d:location/@ref")); _cacheDefinition = new ExcelPivotCacheDefinition(sheet.NameSpaceManager, this); LoadFields(); //Add row fields. foreach (XmlElement rowElem in TopNode.SelectNodes("d:rowFields/d:field", NameSpaceManager)) { int x; if (int.TryParse(rowElem.GetAttribute("x"), out x) && x >= 0) { RowFields.AddInternal(Fields[x]); } else { rowElem.ParentNode.RemoveChild(rowElem); } } ////Add column fields. foreach (XmlElement colElem in TopNode.SelectNodes("d:colFields/d:field", NameSpaceManager)) { int x; if(int.TryParse(colElem.GetAttribute("x"),out x) && x >= 0) { ColumnFields.AddInternal(Fields[x]); } else { colElem.ParentNode.RemoveChild(colElem); } } //Add Page elements //int index = 0; foreach (XmlElement pageElem in TopNode.SelectNodes("d:pageFields/d:pageField", NameSpaceManager)) { int fld; if (int.TryParse(pageElem.GetAttribute("fld"), out fld) && fld >= 0) { var field = Fields[fld]; field._pageFieldSettings = new ExcelPivotTablePageFieldSettings(NameSpaceManager, pageElem, field, fld); PageFields.AddInternal(field); } } //Add data elements //index = 0; foreach (XmlElement dataElem in TopNode.SelectNodes("d:dataFields/d:dataField", NameSpaceManager)) { int fld; if (int.TryParse(dataElem.GetAttribute("fld"), out fld) && fld >= 0) { var field = Fields[fld]; var dataField = new ExcelPivotTableDataField(NameSpaceManager, dataElem, field); DataFields.AddInternal(dataField); } } }
public DocumentRelationship(PackageRelationship rel) { this.rel = rel; }
private static void ExtractPart(PackagePart packagePart, string targetDirectory, PackageRelationship relationship) { string stringPart = packagePart.Uri.ToString().TrimStart('/'); Uri partUri = new Uri(stringPart, UriKind.Relative); Uri uriFullFilePath = new Uri(new Uri(targetDirectory, UriKind.Absolute), partUri); List<string> str = new List<string>(); str.Add(partUri.OriginalString); str.Add(relationship.Id); fontName.Add(str); // Create the necessary directories based on the full part path if (!Directory.Exists(Path.GetDirectoryName(uriFullFilePath.LocalPath))) { Directory.CreateDirectory(Path.GetDirectoryName(uriFullFilePath.LocalPath)); } if (!File.Exists(uriFullFilePath.LocalPath)) { // Write the file from the part’s content stream. using (FileStream fileStream = File.Create(uriFullFilePath.LocalPath)) { packagePart.GetStream().CopyTo(fileStream); } } }
internal ExcelTable(PackageRelationship rel, ExcelWorksheet sheet) : base(sheet.NameSpaceManager) { WorkSheet = sheet; TableUri = PackUriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri); RelationshipID = rel.Id; var pck = sheet._package.Package; Part=pck.GetPart(TableUri); TableXml = new XmlDocument(); LoadXmlSafe(TableXml, Part.GetStream()); init(); Address = new ExcelAddressBase(GetXmlNodeString("@ref")); }
public PartStream(PackageRelationship rel, PackagePart part, Stream stream) { Rel = rel; Part = part; Stream = stream; }
internal Image(DocX document, PackageRelationship pr) { id = pr.Id; }