public BackupDatabaseCommand(ICommandPerformer<string> exec, Document value) { this.backupFolder = value.Settings.Keys.Any(x => x == Keys.BackupFolder) ? value.Settings[Keys.BackupFolder] : null; this.restoreFolder = value.Settings.Keys.Any(x => x == Keys.RestoreFolder) ? value.Settings[Keys.RestoreFolder] : null; this.database = value.Name; this.commmandExecutor = exec; }
public InsertDataCommand(ICommandPerformer<string> exec, ICache cache, ITypeMapper mapper, EntityData value) { this.value = value; this.cache = cache; this.executor = exec; this.schema = cache.Pick<Document>(); this.nameSpace = schema.Settings[Keys.Namespace]; this.mapper = mapper; this.properties = schema.Entities.Single(x => x.Name == value.EntityName).Properties; }
public void WriteTest() { var strategy = A.Fake<IStrategy<Document>>(); var schemaWriter = new SchemaWriter(strategy); var database = new Document(); schemaWriter.Write(database); A.CallTo(() => strategy.Execute(A<Document>.Ignored)).MustHaveHappened(); }
public void ReadTest() { var db = new Document(); var jsonReader = A.Fake<IReadableRepository<Document>>(); A.CallTo(() => jsonReader.Read()).Returns(db); var reader = new SchemaJsonReader(jsonReader); var result = reader.Read(); Assert.AreEqual(db, result); }
public DeleteDatabaseCommand(ICommandPerformer<string> performaer, Document value) : base(performaer, value) { }
public void Execute() { var mapper = new TypeMapper(); var database = new Document(); database.Settings[Keys.Namespace] = "dbo"; if (generateUpdateSettings) { database.Settings[Keys.Update] = "true"; } database.Name = sqlConnectionBuilder.InitialCatalog; var tables = new List<Entity>(); ExecuteReader(string.Format(readTables, database.Name, database.Settings[Keys.Namespace]), (record) => { tables.Add(new Entity { Name = (string)record[0] }); }); foreach (var table in tables) { var columns = new List<Property>(); ExecuteReader(string.Format(readColumns, database.Name, database.Settings[Keys.Namespace], table.Name), (record) => { var pr = new Property { Name = (string)record[0], PropertyType = (string)record[1] + GetColumnLength(record) }; pr.Settings[Keys.IsNotSupportNull] = record[3].ToString() == "NO" ? "true" : "false"; columns.Add(pr); }); ExecuteReader(string.Format(readPrimaryColumn, database.Name, database.Settings[Keys.Namespace], table.Name), (record) => { columns.Single(x => x.Name == record[0].ToString()).Settings[Keys.IsPrimary] = "true"; }); ExecuteReader(string.Format(readIdentityColumn, database.Name, database.Settings[Keys.Namespace], table.Name), (record) => { columns.Single(x => x.Name == record[0].ToString()).Settings[Keys.Identity] = string.Format("({0},{1})", record[1], record[2]); }); var relations = new List<Relation>(); ExecuteReader(string.Format(readForeignKeys, database.Name, database.Settings[Keys.Namespace], table.Name), (record) => { relations.Add(new Relation { PrimaryEntity = table.Name, PrimaryProperty = record[1].ToString(), ForeignEntity = record[2].ToString(), ForeignProperty = record[3].ToString() }); }); table.Relations = relations; table.Properties = columns; } database.Entities = tables; WriteToFile(database); var databaseDescription = new DocumentDescription(); databaseDescription.DatabaseName = database.Name; databaseDescription.Settings[Keys.Iteration] = "1000"; databaseDescription.Settings[Keys.DateTimeFormat] = "yyyy-MM-dd HH:mm:ss"; databaseDescription.Settings[Keys.DateTimeMinValue] = "2010-01-01 00:00:00"; databaseDescription.Settings[Keys.DateTimeMaxValue] = "2020-01-01 00:00:00"; var entityDescriptions = new List<EntityDescription>(); foreach (var entity in database.Entities) { var entityDescription = new EntityDescription(); entityDescription.EntityName = entity.Name; entityDescription.NumberOfRecords = 1; var propertyDescriptions = new List<PropertyDescription>(); foreach (var property in entity.Properties) { var propertyDescription = new PropertyDescription(); propertyDescription.PropertyName = property.Name; propertyDescription.ValueProviderName = "ConstStringProvider"; var type = GetDefault(mapper.GetTypeForMap(property.PropertyType)); propertyDescription.Settings[Keys.Value] = type == null ? string.Empty : type.ToString(); propertyDescriptions.Add(propertyDescription); } entityDescription.PropertyDescriptions = propertyDescriptions; entityDescriptions.Add(entityDescription); } databaseDescription.EntityDescriptions = entityDescriptions; WriteToFile(databaseDescription); }
private void WriteToFile(Document database) { using (var f = File.CreateText("schema.json")) { f.Write(JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new WritablePropertiesOnlyResolver() })); } }
public CreateDatabaseCommand(ICommandPerformer<string> performaer, Document value) { this.database = value.Name; this.commmandExecutor = performaer; }