public static void Integrate <A, B>(IReadOnlyStore <A> source, IStore <B> destination, IdMap <A, B> idMap) { var listA = source.List(); foreach (var id in listA) { if (!idMap.ContainsKey(id)) { TextReader reader = source.Get(id); B newId = destination.Store(reader); idMap.Add(id, newId); } } var syncA = idMap.Keys; foreach (var syncId in syncA) { if (!listA.Contains(syncId)) { B idB = idMap[syncId]; destination.Delete(idB); idMap.Remove(syncId); } } }
public static void Sync <A, B>(IStore <A> source, IStore <B> destination, IdMap <A, B> idMap) { Integrate(source, destination, idMap); Integrate(destination, source, idMap.Invert()); }