Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 /// <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;
 }
Esempio n. 4
0
        // 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);
Esempio n. 6
0
 // 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);
 }
Esempio n. 7
0
 // 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);
 }
Esempio n. 8
0
        // destroy itself (aka. dispose)
        internal void Destroy()
        {
            this.OpenXmlPackage.Package.DeletePart(this.Uri);

            this._openXmlPackage = null;
        }
Esempio n. 9
0
        internal void Destroy()
        {
            OpenXmlPackage.Package.DeletePart(Uri);

            _openXmlPackage = null;
        }
Esempio n. 10
0
 internal MediaDataPart(OpenXmlPackage openXmlPackage, string contentType, Uri partUri)
     : base(openXmlPackage, contentType, partUri)
 {
 }
Esempio n. 11
0
 internal MediaDataPart(OpenXmlPackage openXmlPackage, MediaDataPartType mediaDataPartType)
     : base(openXmlPackage, mediaDataPartType)
 {
 }
Esempio n. 12
0
 internal MediaDataPart(OpenXmlPackage openXmlPackage, string contentType, string?extension)
     : base(openXmlPackage, contentType, extension)
 {
 }
Esempio n. 13
0
 internal MediaDataPart(OpenXmlPackage openXmlPackage, PackagePart packagePart)
     : base(openXmlPackage, packagePart)
 {
 }