public static ChangeSet EvaluateDiffWith3dmData(IFileDataTable table, IEnumerable table3dm, ref DataStore store) { Type tableObjectType = null; ChangeSet changes = new ChangeSet(); Dictionary <Guid, ModelComponent> table3dmCached = new Dictionary <Guid, ModelComponent>(); HashSet <Guid> objGuidsWithMatches = new HashSet <Guid>(); var i = table3dm.GetEnumerator(); while (i.MoveNext()) { ModelComponent comp = (ModelComponent)i.Current; if (tableObjectType == null) { tableObjectType = comp.GetType(); } //caching this for future use table3dmCached.Add(comp.Id, comp); //now doing the comparison if (table.Contains(comp.Id)) { objGuidsWithMatches.Add(comp.Id); ModelComponent obj = table.GetModelComponent(comp.Id); if (!obj.Equals(comp)) { //object has been modified Guid initialVersion; if (!table.ObjectHasAlias(comp.Id, out initialVersion)) { initialVersion = comp.Id; } //adding the new version of the object to the store Guid finalVersion = store.AddObject(comp, true); //create modification type change from initial version to final version changes.AddChange(ChangeType.Modification, tableObjectType, comp.Id, initialVersion, finalVersion); } } else { //create addition change changes.AddChange(ChangeType.Addition, tableObjectType, comp.Id); } } //finding the objects in the original tables whose matches were not found var deletedGuids = table.Objects.Except(objGuidsWithMatches); foreach (var deleted in deletedGuids) { changes.AddChange(ChangeType.Deletion, tableObjectType, deleted); } return(changes); }
/// <summary> /// Checks the accepting component to see if it is the type we are looking for, and if so, checks for the child given at construction. /// Updates the state of the visitor and ensures that it will not be evaluated again. /// </summary> /// <param name="component"></param> public override void Visit(ModelComponent component) { if (modelType.GetType().Equals(component.GetType()) && !evaluated) { foreach (ModelComponent mc in component.GetChildren()) { if (mc == child) { containsChild = true; break; } } evaluated = true; } }