protected void AddSupportedFlavor(FilterFlavor flavor) { // Add flavor only when called from RegisterSupportedTypes if (supported_flavors == null) { throw new Exception("AddSupportedFlavor() should be only called from RegisterSupportedTypes()"); } supported_flavors.Add(flavor); }
// flav [larger wt] < flav [smaller wt] // for same wt, use hashcode (never return obj1 == obj2 unless they are actually same) public int Compare(object obj1, object obj2) { FilterFlavor flav1 = (FilterFlavor)obj1; FilterFlavor flav2 = (FilterFlavor)obj2; int ret = flav2.Weight.CompareTo(flav1.Weight); if (ret != 0) { return(ret); } else { return(obj1.GetHashCode() - obj2.GetHashCode()); } }
///////////////////////////////////////////////////////////////////////// static private ICollection CreateFilters(Uri uri, string extension, string mime_type) { SortedList matched_filters_by_flavor = FilterFlavor.NewHashtable(); foreach (FilterFlavor flavor in FilterFlavor.Flavors) { if (flavor.IsMatch(uri, extension, mime_type)) { Filter matched_filter = null; try { matched_filter = (Filter)Activator.CreateInstance((Type)FilterFlavor.FilterTable [flavor]); if (flavor.MimeType != null) { matched_filter.MimeType = flavor.MimeType; } if (flavor.Extension != null) { matched_filter.Extension = flavor.Extension; } } catch (Exception e) { continue; } matched_filters_by_flavor [flavor] = matched_filter; } } if (Debug) { foreach (DictionaryEntry entry in matched_filters_by_flavor) { FilterFlavor flav = (FilterFlavor)entry.Key; Filter filter = (Filter)entry.Value; Logger.Log.Debug("Found matching filter: {0}, Weight: {1}", filter, flav.Weight); } } return(matched_filters_by_flavor.Values); }