internal virtual ZipPackageRelationship CreateRelationship(Uri targetUri, TargetMode targetMode, string relationshipType)
 {
     var rel = new ZipPackageRelationship();
     rel.TargetUri = targetUri;
     rel.TargetMode = targetMode;
     rel.RelationshipType = relationshipType;
     rel.Id = "rId" + (maxRId++).ToString();
     _rels.Add(rel);
     return rel;
 }
        internal virtual ZipPackageRelationship CreateRelationship(Uri targetUri, TargetMode targetMode, string relationshipType)
        {
            var rel = new ZipPackageRelationship();

            rel.TargetUri        = targetUri;
            rel.TargetMode       = targetMode;
            rel.RelationshipType = relationshipType;
            rel.Id = "rId" + (maxRId++).ToString();
            _rels.Add(rel);
            return(rel);
        }
예제 #3
0
        internal void ReadRelation(string xml, string source)
        {
            var doc = new XmlDocument();

            XmlHelper.LoadXmlSafe(doc, xml, Encoding.UTF8);

            foreach (XmlElement c in doc.DocumentElement.ChildNodes)
            {
                var target = c.GetAttribute("Target");
                var rel    = new ZipPackageRelationship();
                rel.Id = c.GetAttribute("Id");
                rel.RelationshipType = c.GetAttribute("Type");
                rel.TargetMode       = c.GetAttribute("TargetMode").Equals("external", StringComparison.OrdinalIgnoreCase) ? TargetMode.External : TargetMode.Internal;
                if (target.StartsWith("#"))
                {
                    rel.Target = c.GetAttribute("Target");
                }
                else
                {
                    try
                    {
                        rel.TargetUri = new Uri(c.GetAttribute("Target"), UriKind.RelativeOrAbsolute);
                    }
                    catch
                    {
                        //The URI is not a valid URI. Encode it to make i valid.
                        rel.TargetUri = new Uri(Uri.EscapeUriString("Invalid:URI " + c.GetAttribute("Target")), UriKind.RelativeOrAbsolute);
                        rel.Target    = c.GetAttribute("Target");
                    }
                }
                if (!string.IsNullOrEmpty(source))
                {
                    rel.SourceUri = new Uri(source, UriKind.Relative);
                }
                if (rel.Id.StartsWith("rid", StringComparison.OrdinalIgnoreCase))
                {
                    int id;
                    if (int.TryParse(rel.Id.Substring(3), out id))
                    {
                        if (id >= maxRId && id < int.MaxValue - 10000) //Not likly to have this high id's but make sure we have space to avoid overflow.
                        {
                            maxRId = id + 1;
                        }
                    }
                }
                _rels.Add(rel);
            }
        }
        internal void ReadRelation(string xml, string source)
        {
            var doc = new XmlDocument();
            XmlHelper.LoadXmlSafe(doc, xml, Encoding.UTF8);

            foreach (XmlElement c in doc.DocumentElement.ChildNodes)
            {
                var rel = new ZipPackageRelationship();
                rel.Id = c.GetAttribute("Id");
                rel.RelationshipType = c.GetAttribute("Type");
                rel.TargetMode = c.GetAttribute("TargetMode").ToLower() == "external" ? TargetMode.External : TargetMode.Internal;
                try
                {
                    rel.TargetUri = new Uri(c.GetAttribute("Target"), UriKind.RelativeOrAbsolute);
                }
                catch
                {
                    //The URI is not a valid URI. Encode it to make i valid.
                    rel.TargetUri = new Uri(Uri.EscapeUriString("Invalid:URI "+c.GetAttribute("Target")), UriKind.RelativeOrAbsolute);
                }
                if (!string.IsNullOrEmpty(source))
                {
                    rel.SourceUri = new Uri(source, UriKind.Relative);
                }
                if (rel.Id.ToLower().StartsWith("rid"))
                {
                    int id;
                    if (int.TryParse(rel.Id.Substring(3), out id))
                    {
                        if (id >= maxRId && id < int.MaxValue - 10000) //Not likly to have this high id's but make sure we have space to avoid overflow.
                        {
                            maxRId = id + 1;
                        }
                    }
                }
                _rels.Add(rel);
            }
        }
 internal bool TryGetRelationshipById(string id, out ZipPackageRelationship relationship)
 {
     return(_rels.TryGetRelationshipsById(id, out relationship));
 }