private PackageRelationship CreateRelationship(Uri targetUri, TargetMode targetMode, string relationshipType, string id, bool loading) { if (!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(string id, Package package, string relationshipType, Uri sourceUri, TargetMode targetMode, Uri targetUri) { Check.IdIsValid(id); Check.Package(package); Check.RelationshipTypeIsValid(relationshipType); Check.SourceUri(sourceUri); Check.TargetUri(targetUri); Id = id; Package = package; RelationshipType = relationshipType; SourceUri = sourceUri; TargetMode = targetMode; TargetUri = targetUri; }
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); }