//------------------------------------------------------
        //
        //  Internal Members
        //
        //------------------------------------------------------
        #region Internal Members
        /// <summary>
        /// Constructor
        /// </summary>
        /// <remarks>For use by PackagePart</remarks>
        internal PackageRelationshipCollection(InternalRelationshipCollection relationships, string filter)
        {
            Debug.Assert(relationships != null, "relationships parameter cannot be null");

            _relationships = relationships;
            _filter        = filter;
        }
예제 #2
0
        //------------------------------------------------------
        //
        //  Internal Events
        //
        //------------------------------------------------------
        // None
        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
        #region Private Methods

        // lazy init
        private void EnsureRelationships()
        {
            if (_relationships == null)
            {
                // check here
                ThrowIfRelationship();

                // obtain the relationships from the PackageRelationship part (if available)
                _relationships = new InternalRelationshipCollection(this);
            }
        }
예제 #3
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));
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// Returns a collection of filtered Relationships that are
        /// owned by this PackagePart
        /// The relationshipType string is compared with the type of the relationships
        /// in a case sensitive and culture ignorant manner.
        /// </summary>
        /// <returns></returns>
        /// <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 write only, no information can be retrieved from it</exception>
        /// <exception cref="ArgumentNullException">If parameter "relationshipType" is null</exception>
        /// <exception cref="ArgumentException">If parameter "relationshipType" is an empty string</exception>
        public PackageRelationshipCollection GetRelationshipsByType(string relationshipType)
        {
            //These checks are made in the GetRelationshipsHelper as well, but we make them
            //here as we need to perform parameter validation
            CheckInvalidState();
            _container.ThrowIfWriteOnly();

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

            InternalRelationshipCollection.ThrowIfInvalidRelationshipType(relationshipType);

            return(GetRelationshipsHelper(relationshipType));
        }
        //------------------------------------------------------
        //
        //  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;
        }