当前位置: 首页>>代码示例>>C#>>正文


C# PackagePartName.IsRelationshipPartURI方法代码示例

本文整理汇总了C#中PackagePartName.IsRelationshipPartURI方法的典型用法代码示例。如果您正苦于以下问题:C# PackagePartName.IsRelationshipPartURI方法的具体用法?C# PackagePartName.IsRelationshipPartURI怎么用?C# PackagePartName.IsRelationshipPartURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PackagePartName的用法示例。


在下文中一共展示了PackagePartName.IsRelationshipPartURI方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddRelationship

        /**
         * Add a relationship to a part (except relationships part).
         * <p>
         * Check rule M1.25: The Relationships part shall not have relationships to
         * any other part. Package implementers shall enforce this requirement upon
         * the attempt to create such a relationship and shall treat any such
         * relationship as invalid.
         * </p>
         * @param targetPartName
         *            Name of the target part. This one must be relative to the
         *            source root directory of the part.
         * @param targetMode
         *            Mode [Internal|External].
         * @param relationshipType
         *            Type of relationship.
         * @param id
         *            Relationship unique id.
         * @return The newly created and added relationship
         * 
         * @throws InvalidFormatException
         *             If the URI point to a relationship part URI.
         * @see org.apache.poi.OpenXml4Net.opc.RelationshipSource#AddRelationship(org.apache.poi.OpenXml4Net.opc.PackagePartName,
         *      org.apache.poi.OpenXml4Net.opc.TargetMode, java.lang.String, java.lang.String)
         */
        public PackageRelationship AddRelationship(PackagePartName targetPartName,
                TargetMode targetMode, String relationshipType, String id)
        {
            container.ThrowExceptionIfReadOnly();

            if (targetPartName == null)
            {
                throw new ArgumentException("targetPartName");
            }
            //if (targetMode == null)
            //{
            //    throw new ArgumentException("targetMode");
            //}
            if (relationshipType == null)
            {
                throw new ArgumentException("relationshipType");
            }

            if (this.IsRelationshipPart || targetPartName.IsRelationshipPartURI())
            {
                throw new InvalidOperationException(
                        "Rule M1.25: The Relationships part shall not have relationships to any other part.");
            }

            if (relationships == null)
            {
                relationships = new PackageRelationshipCollection();
            }

            return relationships.AddRelationship(targetPartName.URI,
                    targetMode, relationshipType, id);
        }
开发者ID:ctddjyds,项目名称:npoi,代码行数:56,代码来源:PackagePart.cs

示例2: RemovePart

        /**
         * Remove a part in this package. If this part is relationship part, then
         * delete all relationships in the source part.
         * 
         * @param PartName
         *            The part name of the part to Remove.
         */
        public void RemovePart(PackagePartName PartName)
        {
            ThrowExceptionIfReadOnly();
            if (PartName == null || !this.ContainPart(PartName))
                throw new ArgumentException("PartName");

            // Delete the specified part from the package.
            if (this.partList.ContainsKey(PartName))
            {
                this.partList[PartName].IsDeleted = (true);
                this.RemovePartImpl(PartName);
                this.partList.Remove(PartName);
            }
            else
            {
                this.RemovePartImpl(PartName);
            }

            // Delete content type
            this.contentTypeManager.RemoveContentType(PartName);

            // If this part is a relationship part, then delete all relationships of
            // the source part.
            if (PartName.IsRelationshipPartURI())
            {
                Uri sourceURI = PackagingUriHelper
                        .GetSourcePartUriFromRelationshipPartUri(PartName.URI);
                PackagePartName sourcePartName;
                try
                {
                    sourcePartName = PackagingUriHelper.CreatePartName(sourceURI);
                }
                catch (InvalidFormatException)
                {
                    logger
                            .Log(POILogger.ERROR, "Part name URI '"
                                    + sourceURI
                                    + "' is not valid ! This message is not intended to be displayed !");
                    return;
                }
                if (sourcePartName.URI.Equals(
                        PackagingUriHelper.PACKAGE_ROOT_URI))
                {
                    ClearRelationships();
                }
                else if (ContainPart(sourcePartName))
                {
                    PackagePart part = GetPart(sourcePartName);
                    if (part != null)
                        part.ClearRelationships();
                }
            }

            this.isDirty = true;
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:62,代码来源:OPCPackage.cs

示例3: GetRelationshipPartName

        /**
         * Build a part name where the relationship should be stored ((ex
         * /word/document.xml -> /word/_rels/document.xml.rels)
         *
         * @param partName
         *            Source part Uri
         * @return the full path (as Uri) of the relation file
         * @throws InvalidOperationException
         *             Throws if the specified Uri is a relationshp part.
         */
        public static PackagePartName GetRelationshipPartName(
                PackagePartName partName)
        {
            if (partName == null)
                throw new ArgumentException("partName");

            if (PackagingUriHelper.PACKAGE_ROOT_URI.OriginalString == partName.URI
                    .OriginalString)
                return PackagingUriHelper.PACKAGE_RELATIONSHIPS_ROOT_PART_NAME;

            if (partName.IsRelationshipPartURI())
                throw new InvalidOperationException("Can't be a relationship part");

            String fullPath = partName.URI.OriginalString;
            String filename = GetFilename(partName.URI);
            fullPath = fullPath.Substring(0, fullPath.Length - filename.Length);
            fullPath = Combine(fullPath,
                    PackagingUriHelper.RELATIONSHIP_PART_SEGMENT_NAME);
            fullPath = Combine(fullPath, filename);
            fullPath = fullPath
                    + PackagingUriHelper.RELATIONSHIP_PART_EXTENSION_NAME;

            PackagePartName retPartName;
            try
            {
                retPartName = CreatePartName(fullPath);
            }
            catch (InvalidFormatException)
            {
                // Should never happen in production as all data are fixed but in
                // case of return null:
                return null;
            }
            return retPartName;
        }
开发者ID:WPG,项目名称:npoi,代码行数:45,代码来源:PackagingUriHelper.cs

示例4: AddRelationship

        /**
         * Add a relationship to the package (except relationships part).
         * 
         * Check rule M4.1 : The format designer shall specify and the format
         * producer shall Create at most one core properties relationship for a
         * package. A format consumer shall consider more than one core properties
         * relationship for a package to be an error. If present, the relationship
         * shall target the Core Properties part.
         * 
         * Check rule M1.25: The Relationships part shall not have relationships to
         * any other part. Package implementers shall enforce this requirement upon
         * the attempt to Create such a relationship and shall treat any such
         * relationship as invalid.
         * 
         * @param targetPartName
         *            Target part name.
         * @param targetMode
         *            Target mode, either Internal or External.
         * @param relationshipType
         *            Relationship type.
         * @param relID
         *            ID of the relationship.
         * @see PackageRelationshipTypes
         */
        public PackageRelationship AddRelationship(PackagePartName targetPartName,
                TargetMode targetMode, String relationshipType, String relID)
        {
            /* Check OPC compliance */

            // Check rule M4.1 : The format designer shall specify and the format
            // producer
            // shall Create at most one core properties relationship for a package.
            // A format consumer shall consider more than one core properties
            // relationship for a package to be an error. If present, the
            // relationship shall target the Core Properties part.
            if (relationshipType.Equals(PackageRelationshipTypes.CORE_PROPERTIES)
                    && this.packageProperties != null)
                throw new InvalidOperationException(
                        "OPC Compliance error [M4.1]: can't add another core properties part ! Use the built-in package method instead.");

            /*
             * Check rule M1.25: The Relationships part shall not have relationships
             * to any other part. Package implementers shall enforce this
             * requirement upon the attempt to Create such a relationship and shall
             * treat any such relationship as invalid.
             */
            if (targetPartName.IsRelationshipPartURI())
            {
                throw new InvalidOperationException(
                        "Rule M1.25: The Relationships part shall not have relationships to any other part.");
            }

            /* End OPC compliance */

            EnsureRelationships();
            PackageRelationship retRel = relationships.AddRelationship(
                    targetPartName.URI, targetMode, relationshipType, relID);
            this.isDirty = true;
            return retRel;
        }
开发者ID:JnS-Software-LLC,项目名称:npoi,代码行数:60,代码来源:OPCPackage.cs


注:本文中的PackagePartName.IsRelationshipPartURI方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。