Ejemplo n.º 1
0
        public static void ValidateContentTypes(string[] contentTypes)
        {
            HashSet <string> valid = new HashSet <string>(StringComparer.CurrentCultureIgnoreCase);

            // Microsoft's standard Output-derived content types are listed in OutputClassifierProvider's
            // KnownContentTypes.  However, other custom content types can be registered.
            HashSet <string> knownOutputContentTypes = new HashSet <string>(
                OutputClassifierProvider.GetOutputContentTypes(),
                StringComparer.CurrentCultureIgnoreCase);

            if (contentTypes != null)
            {
                foreach (string contentType in contentTypes
                         .Where(s => !string.IsNullOrEmpty(s))
                         .Select(s => s.Trim())
                         .Where(s => s.Length > 0))
                {
                    // Only add types that are known to be valid (or add them all if there are no known types).
                    if (knownOutputContentTypes.Count == 0 || knownOutputContentTypes.Contains(contentType))
                    {
                        valid.Add(contentType);
                    }
                }
            }

            if (valid.Count == 0)
            {
                throw new ArgumentException("You must specify one of the registered Output content types: " +
                                            string.Join(", ", knownOutputContentTypes.OrderBy(s => s)));
            }
        }
Ejemplo n.º 2
0
 public static HashSet <string> GetKnownOutputContentTypes()
 {
     // Microsoft's standard Output-derived content types are listed in OutputClassifierProvider's
     // KnownContentTypes.  However, other custom content types can be registered.
     return(new HashSet <string>(
                OutputClassifierProvider.GetOutputContentTypes(),
                StringComparer.CurrentCultureIgnoreCase));
 }