public void LoadEntities(List <EntityWithKey> entities, string storagePath, string path, bool useLock = false) { try { entityStructures = serializedStorageClient.GetEntityStructures(path); catalog = serializedStorageClient.GetCatalog(storagePath); logger.StartNewLog(); // Restore the entities and its dependencies. foreach (var entity in entities) { EntityStructure entityStructure = entityStructures.Find(entity.EntityName); if (entityStructure == null) { throw new TdsLogicException("The given entity/table name (" + entity.EntityName + ") is not found."); } InnerLoadEntity(entity.EntityName, entity.PrimaryKeyValues, storagePath, useLock); } dbClient.ExecuteTransaction(); } catch (Exception exception) { visitedEntities.Clear(); lockedEntities.Clear(); throw exception; } visitedEntities.Clear(); lockedEntities.Clear(); }
public void SaveEntityStructures(EntityStructures entityStructures, string path, bool overwrite) { if (!overwrite && File.Exists(path + "\\Structures.xml")) { throw new EntityStructureAlreadyExistsException(); } try { Serialize <EntityStructures>(entityStructures, path + "\\Structures.xml"); } catch (Exception exception) { throw exception; } }
public EntityStructures GetEntityStructures(string pathToFile) { EntityStructures entityStructures = null; try { entityStructures = Deserialize <EntityStructures>(pathToFile); } catch (Exception exception) { throw exception; } return(entityStructures); }
public EntityStructures GetDatabaseStructure() { EntityStructures structures = new EntityStructures(); try { foreach (var tableName in structureBuilder.GetTablesNames()) { StringBuilder builder = new StringBuilder(); builder.Append(tableName.Item1).Append(".").Append(tableName.Item2); EntityStructure structure = new EntityStructure(builder.ToString()); structureBuilder.SetTableAttributes(ref structure, tableName.Item1, tableName.Item2); structureBuilder.SetTablePrimaryKeys(ref structure, tableName.Item1, tableName.Item2); structureBuilder.SetTableForeignKeys(ref structure, tableName.Item1, tableName.Item2); structures.Add(structure); } //if a table has references to more than one table, it is considered a relationship table //we set the BelongsToMany fields in the referenced Tables foreach (var structure in structures.Structures) { //use hashset to escape multiple references to same table HashSet <string> referrencedTables = new HashSet <string>(); foreach (var foreignKey in structure.ForeignKeys) { if (structure.IsPrimaryKey(foreignKey.Key)) { referrencedTables.Add(foreignKey.Value.EntityName); } } if (referrencedTables.Count > 1) { foreach (var table in referrencedTables) { structures.Find(table).BelongsToMany.Add(structure.Name); } } } } catch { throw; } return(structures); }
public void SaveEntities(List <EntityWithKey> entities, string storageFolder, string pathToStructure, bool useLock = false, bool overwrite = false) { try { entityStructures = serializedStorageClient.GetEntityStructures(pathToStructure); catalog = serializedStorageClient.GetCatalog(storageFolder); serializedStorageClient.BeginTransaction(); logger.StartNewLog(); // Saves the entities and their dependencies. foreach (var entity in entities) { EntityStructure entityStructure = entityStructures.Find(entity.EntityName); if (entityStructure == null) { throw new TdsLogicException("The given entity/table name (" + entity.EntityName + ") is not found."); } InnerSaveEntity(entity.EntityName, entity.PrimaryKeyValues, storageFolder, useLock, overwrite); } serializedStorageClient.ExecuteTransaction(); serializedStorageClient.SaveCatalog(catalog, storageFolder); } catch (Exception exception) { visitedEntities.Clear(); lockedEntities.Clear(); throw exception; } visitedEntities.Clear(); lockedEntities.Clear(); }
/// <summary> /// Saves the entity structures to the given path. /// </summary> /// <param name="entityStructures">The given entity structures.</param> /// <param name="path">The path.</param> public void SaveEntityStructures(EntityStructures entityStructures, string path, bool overwrite = false) { serializedStorageStructureManager.SaveEntityStructures(entityStructures, path, overwrite); }
/// <summary> /// Saves the entity structures to the default path. /// </summary> /// <param name="entityStructures">The given entity structures.</param> public void SaveEntityStructures(EntityStructures entityStructures, bool overwrite = false) { serializedStorageStructureManager.SaveEntityStructures(entityStructures, defaultStoragePath, overwrite); }