Exemple #1
0
        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);
        }