/// <summary> /// Map of values related to a single name for default property. /// It can be used to guess the use of a default property instead of simple tag /// </summary> /// <returns>an mepty map if any error occurred; the map with keys: default properties values (lower case); values, the related property name </returns> public static IDictionary <string, string> GetDefaultValuesRelatedToSingleKey(this IPropertiesRepository repo) { if (repo == null) { return(new Dictionary <string, string>()); } if (s_defValuesRelatedToSingleKey == null) { s_defValuesRelatedToSingleKey = new Dictionary <string, string>(); Dictionary <string, List <string> > defPropVal = repo.GetDefaultPropertiesValues(); foreach (string defPropKey in defPropVal.Keys) { List <string> values = defPropVal[defPropKey]; if (values != null) { foreach (string value in values) { string valueLower = value.ToLower(); // put an empty value to signal that the property value is linked to multiple keys if (s_defValuesRelatedToSingleKey.ContainsKey(valueLower)) { s_defValuesRelatedToSingleKey[valueLower] = string.Empty; } else { s_defValuesRelatedToSingleKey.Add(valueLower, defPropKey); } } } } //purge eventual values with multiple keys: List <string> keyToRemove = new List <string>(s_defValuesRelatedToSingleKey.Keys); foreach (string key in keyToRemove) { if (string.IsNullOrEmpty(s_defValuesRelatedToSingleKey[key])) { s_defValuesRelatedToSingleKey.Remove(key); } } } return(s_defValuesRelatedToSingleKey); }
/// <summary> /// Returns the set of default properties names and values: the complete collection of names and values that constitutes the /// default properties managed in Snip2Code. /// The first time they are fetched from DB, the other ones from in-memory cache. /// </summary> /// <returns>an empty set if any error occurred; the default properties names and values otherwise</returns> public static HashSet <string> GetDefaultPropertiesItems(this IPropertiesRepository repo) { if (repo == null) { return(new HashSet <string>()); } if (s_defPropertyItemsSet == null) { //init default properties if needed: Dictionary <string, List <string> > defPropertyValues = repo.GetDefaultPropertiesValues(); //fill all the list with the proper values: s_defPropertyItemsSet = new HashSet <string>(defPropertyValues.Keys, new IgnoreCaseComparer()); foreach (string key in defPropertyValues.Keys) { s_defPropertyItemsSet.UnionWith(defPropertyValues[key]); } } return(s_defPropertyItemsSet); }