internal void Load(OpenXmlPackage openXmlPackage, OpenXmlPart parent, Uri uriTarget, string id, Dictionary <Uri, OpenXmlPart> loadedParts) { if (uriTarget == null) { throw new ArgumentNullException("uriTarget"); } if (id == null) { throw new ArgumentNullException("id"); } if (openXmlPackage == null && parent == null) { throw new ArgumentNullException(ExceptionMessages.PackageRelatedArgumentNullException); } else if (parent != null && openXmlPackage != null && parent.OpenXmlPackage != openXmlPackage) { throw new ArgumentOutOfRangeException("parent"); } else if (parent != null && openXmlPackage == null) { openXmlPackage = parent.OpenXmlPackage; } this._openXmlPackage = openXmlPackage; //this._ownerPart = parent; Debug.Assert(loadedParts.ContainsKey(uriTarget)); this._uri = uriTarget; // TODO: should we delay load? PackagePart metroPart = this.OpenXmlPackage.Package.GetPart(uriTarget); if (this.IsContentTypeFixed && metroPart.ContentType != this.ContentType) { string errorMessage = String.Format(CultureInfo.CurrentUICulture, ExceptionMessages.InvalidPartContentType, metroPart.Uri.OriginalString, metroPart.ContentType, this.ContentType); OpenXmlPackageException e = new OpenXmlPackageException(errorMessage); //e.Data.Add("Part Uri", metroPart.Uri.OriginalString ); //e.Data.Add("Part Content Type", metroPart.ContentType); //e.Data.Add("Expected Content Type", this.ContentType); throw e; } this._metroPart = metroPart; // add the _uri to be reserved this.OpenXmlPackage.ReserveUri(this.ContentType, this.Uri); // load recursively RelationshipCollection relationshipCollection = new PackagePartRelationshipPropertyCollection(this.PackagePart); LoadReferencedPartsAndRelationships(openXmlPackage, this, relationshipCollection, loadedParts); }
/// <summary> /// FromPackage (static) /// </summary> public static OpenXmlDocument FromPackage(OpenXmlSDK.OpenXmlPackage package) { return(FromPackage(package.Package, null)); }
/// <summary> /// Initializes a new instance of the OpenXmlPackagePartIterator class using the supplied OpenXmlPackage class. /// </summary> /// <param name="package">The OpenXmlPackage to use to enumerate parts.</param> public OpenXmlPackagePartIterator(OpenXmlPackage package) { Debug.Assert(package != null); this._package = package; }
// create a new part in this package internal void CreateInternal(OpenXmlPackage openXmlPackage, OpenXmlPart parent, string contentType, string targetExt) { // openXmlPackage, parent can not be all null if (openXmlPackage == null && parent == null) { throw new ArgumentNullException(ExceptionMessages.PackageRelatedArgumentNullException); } else if (parent != null && openXmlPackage != null && parent.OpenXmlPackage != openXmlPackage) { throw new ArgumentOutOfRangeException("parent"); } else if (parent != null && openXmlPackage == null) { openXmlPackage = parent.OpenXmlPackage; } // throw exception to catch error in our code if (this._metroPart != null) { throw new InvalidOperationException(); } // set the _openXmlPackage so ThrowIfObjectDisposed( ) do not throw. this._openXmlPackage = openXmlPackage; Uri parentUri; if (parent != null) { parentUri = parent.Uri; } else { parentUri = new Uri("/", UriKind.Relative); } //OpenXmlPart parentPart = this._ownerPart; //Uri is auto generated to make sure it's unique string targetPath = this.GetTargetPath(this.TargetPath); if (targetPath == null) { targetPath = "."; } string targetFileExt = targetExt; if (!this.IsContentTypeFixed) { if (!this._openXmlPackage.PartExtensionProvider.TryGetValue(contentType, out targetFileExt)) { targetFileExt = targetExt; } } if (targetFileExt == null) { targetFileExt = this.TargetFileExtension; } this._uri = this._openXmlPackage.GetUniquePartUri(contentType, parentUri, targetPath, this.TargetName, targetFileExt); this._metroPart = this._openXmlPackage.CreateMetroPart(this._uri, contentType); }
/// <summary> /// Create an instance of OpenXmlPart according to the given relationship type. /// </summary> /// <param name="openXmlPackage">The container OpenXmlPackage.</param> /// <param name="relationshipType">The relationship type of the target part.</param> /// <param name="openXmlPart">The created instance of OpenXmlPart.</param> /// <remarks>This partial method will be generated by code generaotr.</remarks> static partial void CreatePartCore(OpenXmlPackage openXmlPackage, string relationshipType, ref OpenXmlPart openXmlPart);
// create a new part in this package private protected DataPart(OpenXmlPackage openXmlPackage, string contentType, string?extension) { _openXmlPackage = openXmlPackage; _uri = NewPartUri(openXmlPackage, contentType, extension); _metroPart = _openXmlPackage.CreateMetroPart(_uri, contentType); }
// create a new part in this package internal void CreateInternal(OpenXmlPackage openXmlPackage, string contentType, string extension) { this._openXmlPackage = openXmlPackage; this._uri = NewPartUri(openXmlPackage, contentType, extension); this._metroPart = this._openXmlPackage.CreateMetroPart(this._uri, contentType); }
// destroy itself (aka. dispose) internal void Destroy() { this.OpenXmlPackage.Package.DeletePart(this.Uri); this._openXmlPackage = null; }
internal void Destroy() { OpenXmlPackage.Package.DeletePart(Uri); _openXmlPackage = null; }
internal MediaDataPart(OpenXmlPackage openXmlPackage, string contentType, Uri partUri) : base(openXmlPackage, contentType, partUri) { }
internal MediaDataPart(OpenXmlPackage openXmlPackage, MediaDataPartType mediaDataPartType) : base(openXmlPackage, mediaDataPartType) { }
internal MediaDataPart(OpenXmlPackage openXmlPackage, string contentType, string?extension) : base(openXmlPackage, contentType, extension) { }
internal MediaDataPart(OpenXmlPackage openXmlPackage, PackagePart packagePart) : base(openXmlPackage, packagePart) { }