예제 #1
0
        /// <summary>
        /// Custom Equals method.
        /// </summary>
        public override bool Equals(object o)
        {
            if (o.GetType() != typeof(ImageRequest))
            {
                return(false);
            }

            ImageRequest request = (ImageRequest)o;

            return(SourceUri.Equals(request.SourceUri) &&
                   CacheChoice.Equals(request.CacheChoice) &&
                   SourceFile.FullName.Equals(request.SourceFile.FullName));
        }
        //------------------------------------------------------
        //
        //  Public Methods
        //
        //------------------------------------------------------

        #region Public Methods

        /// <summary>
        /// This method returns the list of selected PackageRelationships as per the
        /// given criteria, from a part in the Package provided
        /// </summary>
        /// <param name="package">Package object from which we get the relationsips</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If package parameter is null</exception>
        public List <PackageRelationship> Select(Package package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            List <PackageRelationship> relationships = new List <PackageRelationship>(0);

            switch (SelectorType)
            {
            case PackageRelationshipSelectorType.Id:
                if (SourceUri.Equals(PackUriHelper.PackageRootUri))
                {
                    if (package.RelationshipExists(SelectionCriteria))
                    {
                        relationships.Add(package.GetRelationship(SelectionCriteria));
                    }
                }
                else
                {
                    if (package.PartExists(SourceUri))
                    {
                        PackagePart part = package.GetPart(SourceUri);
                        if (part.RelationshipExists(SelectionCriteria))
                        {
                            relationships.Add(part.GetRelationship(SelectionCriteria));
                        }
                    }
                }
                break;

            case PackageRelationshipSelectorType.Type:
                if (SourceUri.Equals(PackUriHelper.PackageRootUri))
                {
                    foreach (PackageRelationship r in package.GetRelationshipsByType(SelectionCriteria))
                    {
                        relationships.Add(r);
                    }
                }
                else
                {
                    if (package.PartExists(SourceUri))
                    {
                        foreach (PackageRelationship r in package.GetPart(SourceUri).GetRelationshipsByType(SelectionCriteria))
                        {
                            relationships.Add(r);
                        }
                    }
                }
                break;

            default:
                //Debug.Assert is fine here since the parameters have already been validated. And all the properties are
                //readonly
                Debug.Assert(false, "This option should never be called");
                break;
            }

            return(relationships);
        }