private void Add([NotNull] ServerInformation information) { var existing = _list.GetByIdOrDefault(information.Id); if (existing == null) { var entry = new ServerEntry(information); entry.SetOrigin(Key); entry.SetReferences(FileBasedOnlineSources.Instance.GetSourceKeys(entry)); _list.Add(entry); } else { existing.SetOrigin(Key); existing.UpdateValues(information); } }
private void Add([NotNull] IEnumerable <ServerInformation> informations) { if (_first) { _first = false; var newEntries = new List <ServerEntry>((informations as IReadOnlyList <ServerInformation>)?.Count ?? 300); foreach (var information in informations) { var existing = _list.GetByIdOrDefault(information.Id); if (existing == null) { var entry = new ServerEntry(information); entry.SetOrigin(Key); entry.SetReferences(FileBasedOnlineSources.Instance.GetSourceKeys(entry)); newEntries.Add(entry); } else { existing.SetOrigin(Key); existing.UpdateValues(information); OnlineManager.Instance.AvoidRemoval(existing); } } var target = _list as ChangeableObservableCollection <ServerEntry>; if (target == null || newEntries.Count < 10) { foreach (var entry in newEntries) { _list.Add(entry); } } else { target._AddRangeDirect(newEntries); } } else { var list = informations.ToIReadOnlyListIfItIsNot(); foreach (var information in list) { var existing = _list.GetByIdOrDefault(information.Id); if (existing == null) { var entry = new ServerEntry(information); entry.SetOrigin(Key); _list.Add(entry); } else { existing.SetOrigin(Key); existing.UpdateValues(information); OnlineManager.Instance.AvoidRemoval(existing); } } for (var i = _list.Count - 1; i >= 0; i--) { if (list.GetByIdOrDefault(_list[i].Id) == null) { var serverEntry = _list[i]; var empty = serverEntry.RemoveOrigin(_source.Id); if (empty) { if (OnlineManager.Instance.IsHolded(serverEntry)) { OnlineManager.Instance.RemoveWhenReleased(serverEntry); } else { _list.RemoveAt(i); } } } } } }