private static FileState ParseFile(File3dm file, DataStore store, RvcVersion version, out ChangeSet changes) { FileState state = null; List <IFileDataTable> parsedTableList = new List <IFileDataTable>(); //opening the store, and the file and comparing the contents List <Type> memberTypes; List <string> tableNames; List <IEnumerable> tables3dm = GetAllTables(file, out memberTypes, out tableNames); ChangeSet fileChanges = new ChangeSet(); for (int i = 0; i < tables3dm.Count; i++) { ChangeSet tableChanges; IFileDataTable parsedTable = TableUtil.ParseTableData(tables3dm[i], tableNames[i], memberTypes[i], version, store, out tableChanges); parsedTableList.Add(parsedTable); fileChanges = ChangeSet.Merge(fileChanges, tableChanges); } //populating the file state state = new FileState(store, version.AddDownStreamVersion(fileChanges)); foreach (var table in parsedTableList) { state.Tables.Add(table); } changes = fileChanges; return(state); }
public bool RollbackChange(IChange change) { IFileDataTable matchingTable = GetMatchingTable(change.ObjectType); if (matchingTable == null) { return(false); } return(matchingTable.RollbackChange(change)); }
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); }
public static IFileDataTable ParseTableData(IEnumerable table3dm, string tableName, Type dataType, RvcVersion version, DataStore store, out ChangeSet changes) { IFileDataTable refTable = version.State.GetMatchingTable(dataType, tableName); if (refTable == null) { refTable = CreateTableInstance(dataType); version.State.Tables.Add(refTable); version.State.Store = store; } changes = EvaluateDiffWith3dmData(refTable, table3dm, ref store); return(refTable.ApplyChangeSet(changes)); }
public IFileDataTable GetMatchingTable(IFileDataTable table) { return(GetMatchingTable(table.MemberType, table.Name)); }