int LoadItems(XDocument doc, Func <string, NameDuplicateResolution> dupesResolver) { if (doc.Root == null) { return(0); } var itemNodes = new List <XElement>(); foreach (var itemElt in doc.Root.Elements("item")) { var name = itemElt.AttributeValue("name"); if (string.IsNullOrEmpty(name)) { continue; } if (items.ContainsKey(name)) { var resolution = dupesResolver(name); if (resolution == NameDuplicateResolution.Cancel) { return(0); } if (resolution == NameDuplicateResolution.Skip) { continue; } } itemNodes.Add(itemElt); } foreach (var itemElt in itemNodes) { var name = itemElt.AttributeValue("name"); var search = new UserDefinedSearch( this, name, filtersFactory.CreateFiltersList(itemElt, FiltersListPurpose.Search) ); items[name] = search; } return(itemNodes.Count); }
IUserDefinedSearch IUserDefinedSearches.AddNew() { string name; for (int num = 1;; ++num) { name = string.Format("New filter {0}", num); if (!items.ContainsKey(name)) { break; } } var search = new UserDefinedSearch( this, name, filtersFactory.CreateFiltersList(FilterAction.Exclude, FiltersListPurpose.Search) ); items[name] = search; changeHandlerInvoker.Invoke(); return(search); }