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)); }
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)); }
public void WritePart(string location) { PackagePart part = this._package.GetPart(new Uri(WordOpenXmlUtils.CleanName(location), UriKind.Relative)); StreamWriter streamWriter = new StreamWriter(part.GetStream()); ((XmlPart)this._parts[location]).HydratedPart.Write(streamWriter); streamWriter.Flush(); PhantomPart phantomPart = new PhantomPart(); phantomPart.ContentType = part.ContentType; phantomPart.Location = location; PhantomPart value = phantomPart; this._parts[location] = value; }
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)); }