Пример #1
0
        /// <summary>
        /// Deletes a relationship from the PackagePart. This is done based on the
        /// relationship's ID. The target PackagePart is not affected by this operation.
        /// </summary>
        /// <param name="id">The ID of the relationship to delete. An invalid ID will not
        /// throw an exception, but nothing will be deleted.</param>
        /// <exception cref="InvalidOperationException">If this part has been deleted</exception>
        /// <exception cref="InvalidOperationException">If the parent package has been closed or disposed</exception>
        /// <exception cref="IOException">If the package is readonly, it cannot be modified</exception>
        /// <exception cref="ArgumentNullException">If parameter "id" is null</exception>
        /// <exception cref="System.Xml.XmlException">If parameter "id" is not a valid Xsd Id</exception>
        public void DeleteRelationship(string id)
        {
            CheckInvalidState();
            _container.ThrowIfReadOnly();

            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            InternalRelationshipCollection.ThrowIfInvalidXsdId(id);

            EnsureRelationships();
            _relationships.Delete(id);
        }
Пример #2
0
        /// <summary>
        /// Retrieve a relationship per ID.
        /// </summary>
        /// <param name="id">The relationship ID.</param>
        /// <returns>The relationship with ID 'id' or null if not found.</returns>
        private PackageRelationship GetRelationshipHelper(string id)
        {
            CheckInvalidState();
            _container.ThrowIfWriteOnly();

            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            InternalRelationshipCollection.ThrowIfInvalidXsdId(id);

            EnsureRelationships();
            return(_relationships.GetRelationship(id));
        }
        //------------------------------------------------------
        //
        //  Public Constructors
        //
        //------------------------------------------------------

        #region Public Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sourceUri">Source Uri of the PackagePart or PackageRoot ("/") that owns the relationship</param>
        /// <param name="selectorType">PackageRelationshipSelectorType enum representing the type of the selectionCriteria</param>
        /// <param name="selectionCriteria">The actual string that is used to select the relationships</param>
        /// <exception cref="ArgumentNullException">If sourceUri is null</exception>
        /// <exception cref="ArgumentNullException">If selectionCriteria is null</exception>
        /// <exception cref="ArgumentOutOfRangeException">If selectorType Enumeration does not have a valid value</exception>
        /// <exception cref="System.Xml.XmlException">If PackageRelationshipSelectorType.Id and selection criteria is not valid Xsd Id</exception>
        /// <exception cref="ArgumentException">If PackageRelationshipSelectorType.Type and selection criteria is not valid relationship type</exception>
        /// <exception cref="ArgumentException">If sourceUri is not "/" to indicate the PackageRoot, then it must conform to the
        /// valid PartUri syntax</exception>
        public PackageRelationshipSelector(Uri sourceUri, PackageRelationshipSelectorType selectorType, string selectionCriteria)
        {
            if (sourceUri == null)
            {
                throw new ArgumentNullException("sourceUri");
            }

            if (selectionCriteria == null)
            {
                throw new ArgumentNullException("selectionCriteria");
            }

            //If the sourceUri is not equal to "/", it must be a valid part name.
            if (Uri.Compare(sourceUri, PackUriHelper.PackageRootUri, UriComponents.SerializationInfoString, UriFormat.UriEscaped, StringComparison.Ordinal) != 0)
            {
                sourceUri = PackUriHelper.ValidatePartUri(sourceUri);
            }

            //selectionCriteria is tested here as per the value of the selectorType.
            //If selectionCriteria is empty string we will throw the appropriate error message.
            if (selectorType == PackageRelationshipSelectorType.Type)
            {
                InternalRelationshipCollection.ThrowIfInvalidRelationshipType(selectionCriteria);
            }
            else
            if (selectorType == PackageRelationshipSelectorType.Id)
            {
                InternalRelationshipCollection.ThrowIfInvalidXsdId(selectionCriteria);
            }
            else
            {
                throw new ArgumentOutOfRangeException("selectorType");
            }

            _sourceUri         = sourceUri;
            _selectionCriteria = selectionCriteria;
            _selectorType      = selectorType;
        }