Esempio n. 1
0
        /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            var mediaType = obj as MediaType;

            if (mediaType == null)
            {
                return(false);
            }

            return(Type.Equals(mediaType.Type, StringComparison.CurrentCultureIgnoreCase) &&
                   Subtype.Equals(mediaType.Subtype, StringComparison.CurrentCultureIgnoreCase) &&
                   (Suffix == null && mediaType.Suffix == null || (Suffix != null && mediaType.Suffix != null && Suffix.Equals(mediaType.Suffix, StringComparison.CurrentCultureIgnoreCase))));
        }
Esempio n. 2
0
        public bool Includes(MimeType other)
        {
            if (other == null)
            {
                return(false);
            }

            if (IsWildcardType)
            {
                // */* includes anything
                return(true);
            }
            else if (Type.Equals(other.Type))
            {
                if (Subtype.Equals(other.Subtype))
                {
                    return(true);
                }

                if (IsWildcardSubtype)
                {
                    // Wildcard with suffix, e.g. application/*+xml
                    var thisPlusIdx = Subtype.LastIndexOf('+');
                    if (thisPlusIdx == -1)
                    {
                        return(true);
                    }
                    else
                    {
                        // application/*+xml includes application/soap+xml
                        var otherPlusIdx = other.Subtype.LastIndexOf('+');
                        if (otherPlusIdx != -1)
                        {
                            var thisSubtypeNoSuffix = Subtype.Substring(0, thisPlusIdx);
                            var thisSubtypeSuffix   = Subtype.Substring(thisPlusIdx + 1);
                            var otherSubtypeSuffix  = other.Subtype.Substring(otherPlusIdx + 1);
                            if (thisSubtypeSuffix.Equals(otherSubtypeSuffix) && WILDCARD_TYPE.Equals(thisSubtypeNoSuffix))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 3
0
        public override bool Equals(object other)
        {
            if (this == other)
            {
                return(true);
            }

            if (!(other is MimeType))
            {
                return(false);
            }

            var otherType = (MimeType)other;

            return(Type.Equals(otherType.Type, StringComparison.InvariantCultureIgnoreCase) &&
                   Subtype.Equals(otherType.Subtype, StringComparison.InvariantCultureIgnoreCase) &&
                   ParametersAreEqual(otherType));
        }
Esempio n. 4
0
        public bool IsCompatibleWith(MimeType other)
        {
            if (other == null)
            {
                return(false);
            }

            if (IsWildcardType || other.IsWildcardType)
            {
                return(true);
            }
            else if (Type.Equals(other.Type))
            {
                if (Subtype.Equals(other.Subtype))
                {
                    return(true);
                }

                // Wildcard with suffix? e.g. application/*+xml
                if (IsWildcardSubtype || other.IsWildcardSubtype)
                {
                    var thisPlusIdx  = Subtype.LastIndexOf('+');
                    var otherPlusIdx = other.Subtype.LastIndexOf('+');
                    if (thisPlusIdx == -1 && otherPlusIdx == -1)
                    {
                        return(true);
                    }
                    else if (thisPlusIdx != -1 && otherPlusIdx != -1)
                    {
                        var thisSubtypeNoSuffix  = Subtype.Substring(0, thisPlusIdx);
                        var otherSubtypeNoSuffix = other.Subtype.Substring(0, otherPlusIdx);
                        var thisSubtypeSuffix    = Subtype.Substring(thisPlusIdx + 1);
                        var otherSubtypeSuffix   = other.Subtype.Substring(otherPlusIdx + 1);
                        if (thisSubtypeSuffix.Equals(otherSubtypeSuffix) &&
                            (WILDCARD_TYPE.Equals(thisSubtypeNoSuffix) || WILDCARD_TYPE.Equals(otherSubtypeNoSuffix)))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Esempio n. 5
0
 public bool Equals(MimeType other)
 {
     return(other != null && Type.Equals(other.Type) && Subtype.Equals(other.Subtype));
 }
Esempio n. 6
0
        public bool EqualsTypeAndSubtype(MimeType other)
        {
            if (other == null)
            {
                return(false);
            }

            return(Type.Equals(other.Type, StringComparison.InvariantCultureIgnoreCase) && Subtype.Equals(other.Subtype, StringComparison.InvariantCultureIgnoreCase));
        }
        public override Dictionary <string, object> ToUpdate(IMemoryCache memoryCache, out BaseModel updatedElement)
        {
            Dictionary <string, object> changes = new Dictionary <string, object>();

            BlobContent refInCache = null;

            if (Id != Guid.Empty)
            {
                refInCache = CacheHelper.GetBlobContentFromCache(memoryCache, Id);

                if (refInCache != null)
                {
                    if (Name != null && !Name.Equals(refInCache.Name))
                    {
                        changes.Add("Name", Name);
                    }
                    if (Description != null && !Description.Equals(refInCache.Description))
                    {
                        changes.Add("Description", Description);
                    }
                    if (!Sharing.Equals(refInCache.Sharing))
                    {
                        changes.Add("Sharing", Sharing);
                    }
                    if (!Type.Equals(refInCache.Type))
                    {
                        changes.Add("Type", Type);
                    }
                    if (!Subtype.Equals(refInCache.Subtype))
                    {
                        changes.Add("Subtype", Subtype);
                    }
                }
                else
                {
                    refInCache = this;

                    if (Name != null)
                    {
                        changes.Add("Name", Name);
                    }
                    if (Description != null)
                    {
                        changes.Add("Description", Description);
                    }
                    if (Sharing != null)
                    {
                        changes.Add("Sharing", Sharing);
                    }
                    if (Type != null)
                    {
                        changes.Add("Type", Type);
                    }
                    if (Subtype != null)
                    {
                        changes.Add("Subtype", Subtype);
                    }
                }
            }
            updatedElement = refInCache;
            return(changes);
        }