Пример #1
0
        public Relationship AddStreamingRootPartToTree(string contentType, string relationshipType, string locationHint, ContentTypeAction ctypeAction)
        {
            Relationship relationship = this.AddStreamingPartToTree(contentType, relationshipType, locationHint, "/", ctypeAction);

            if (relationshipType == this._documentRootRelationshipType)
            {
                this._docRootLocation = relationship.RelatedPart;
            }
            return(relationship);
        }
Пример #2
0
 public Relationship AddStreamingPartToTree(string contentType, string relationshipType, string locationHint, XmlPart parent, ContentTypeAction ctypeAction)
 {
     return(this.AddStreamingPartToTree(contentType, relationshipType, locationHint, parent.Location, ctypeAction));
 }
Пример #3
0
        public Relationship AddStreamingPartToTree(string contentType, string relationshipType, string locationHint, string parentLocation, ContentTypeAction ctypeAction)
        {
            string      location    = this.UniqueLocation(locationHint);
            PhantomPart phantomPart = new PhantomPart();

            phantomPart.ContentType = contentType;
            phantomPart.Location    = location;
            this._parts.Add(phantomPart.Location, phantomPart);
            this._package.CreatePart(new Uri(WordOpenXmlUtils.CleanName(phantomPart.Location), UriKind.Relative), phantomPart.ContentType, CompressionOption.Normal);
            return(this.AddRelationship(location, relationshipType, parentLocation));
        }
Пример #4
0
        private Relationship AddPart(OoxmlPart part, string contentType, string relationshipType, string locationHint, string parentLocation, ContentTypeAction ctypeAction)
        {
            XmlPart xmlPart = new XmlPart();

            xmlPart.ContentType  = contentType;
            xmlPart.HydratedPart = part;
            if (locationHint.Contains("{0}"))
            {
                xmlPart.Location = this.UniqueLocation(locationHint);
            }
            else
            {
                xmlPart.Location = locationHint;
            }
            this._parts.Add(xmlPart.Location, xmlPart);
            this._package.CreatePart(new Uri(WordOpenXmlUtils.CleanName(xmlPart.Location), UriKind.Relative), xmlPart.ContentType, CompressionOption.Normal);
            return(this.AddRelationship(xmlPart.Location, relationshipType, parentLocation));
        }
Пример #5
0
        public Relationship AddImageToTree(ImageHash hash, string extension, string relationshipType, string locationHint, string parentLocation, ContentTypeAction ctypeAction, out bool newBlob)
        {
            PhantomPart phantomPart = new PhantomPart();

            phantomPart.ContentType = "image/" + extension;
            string text = default(string);

            if (this._blobPathsByUniqueId.TryGetValue(hash, out text))
            {
                phantomPart.Location = text;
                newBlob = false;
            }
            else
            {
                CompressionOption compressionOption = (CompressionOption)((extension == "jpg" || extension == "png" || extension == "gif") ? (-1) : 0);
                text = string.Format(CultureInfo.InvariantCulture, this.UniqueLocation(locationHint), extension);
                this._blobPathsByUniqueId[hash] = text;
                phantomPart.Location            = text;
                this._parts.Add(phantomPart.Location, phantomPart);
                this._package.CreatePart(new Uri(WordOpenXmlUtils.CleanName(phantomPart.Location), UriKind.Relative), phantomPart.ContentType, compressionOption);
                newBlob = true;
            }
            return(this.AddRelationship(phantomPart.Location, relationshipType, parentLocation));
        }
Пример #6
0
        public Relationship AddImageToTree(ImageHash hash, string extension, string relationshipType, string locationHint, string parentLocation, ContentTypeAction ctypeAction, out bool newBlob)
        {
            PhantomPart phantomPart = new PhantomPart();

            phantomPart.ContentType = "image/" + extension;
            if (_blobPathsByUniqueId.TryGetValue(hash, out string value))
            {
                phantomPart.Location = value;
                newBlob = false;
            }
            else
            {
                int num;
                switch (extension)
                {
                default:
                    num = 0;
                    break;

                case "jpg":
                case "png":
                case "gif":
                    num = -1;
                    break;
                }
                CompressionOption compressionOption = (CompressionOption)num;
                value = string.Format(CultureInfo.InvariantCulture, UniqueLocation(locationHint), extension);
                _blobPathsByUniqueId[hash] = value;
                phantomPart.Location       = value;
                _parts.Add(phantomPart.Location, phantomPart);
                _package.CreatePart(new Uri(WordOpenXmlUtils.CleanName(phantomPart.Location), UriKind.Relative), phantomPart.ContentType, compressionOption);
                newBlob = true;
            }
            return(AddRelationship(phantomPart.Location, relationshipType, parentLocation));
        }
Пример #7
0
 public Relationship AddPartToTree(OoxmlPart part, string contentType, string relationshipType, string locationHint, XmlPart parent, ContentTypeAction ctypeAction)
 {
     return(AddPart(part, contentType, relationshipType, locationHint, parent.Location, ctypeAction));
 }
Пример #8
0
        public Relationship AddRootPartToTree(OoxmlPart part, string contentType, string relationshipType, string locationHint, ContentTypeAction ctypeAction)
        {
            Relationship relationship = AddPart(part, contentType, relationshipType, locationHint, "/", ctypeAction);

            if (relationshipType == _documentRootRelationshipType)
            {
                _docRootLocation = relationship.RelatedPart;
            }
            return(relationship);
        }
Пример #9
0
        public Relationship AddImageToTree(string uniqueId, Stream data, string extension, string relationshipType, string locationHint, string parentLocation, ContentTypeAction ctypeAction)
        {
            bool         newBlob;
            Relationship relationship = _relationshipTree.AddImageToTree(uniqueId, extension, relationshipType, locationHint, parentLocation, ctypeAction, out newBlob);

            if (newBlob)
            {
                Stream stream = ((IStreambookModel)_workbookmodel).ZipPackage.GetPart(new Uri(Utils.CleanName(relationship.RelatedPart), UriKind.Relative)).GetStream();
                SupportClass.CopyStream(data, stream);
            }
            return(relationship);
        }
Пример #10
0
        public Relationship AddImageToTree(string uniqueId, Stream data, string extension, string relationshipType, string locationHint, string parentLocation, ContentTypeAction ctypeAction)
        {
            bool         flag         = default(bool);
            Relationship relationship = this._relationshipTree.AddImageToTree(uniqueId, extension, relationshipType, locationHint, parentLocation, ctypeAction, out flag);

            if (flag)
            {
                Package     zipPackage = ((IStreambookModel)this._workbookmodel).ZipPackage;
                PackagePart part       = zipPackage.GetPart(new Uri(Utils.CleanName(relationship.RelatedPart), UriKind.Relative));
                Stream      stream     = part.GetStream();
                SupportClass.CopyStream(data, stream);
            }
            return(relationship);
        }