public void Load_statement_not_depending_on_entity_with_no_name_should_throw() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "Test_statement_invalid_missing_name.xml"); MapConfig config = new MapConfig(); Assert.Throws <MappingSerializationException>(() => config.Load(testMapfile)); }
public void Import() { FTWorldMap worldMap = this; string fileName = string.Format("Text/Map/{0}", worldMap.MapID); MapConfig data = new MapConfig(); data.Load(fileName); worldMap.MapID = data.MapID; worldMap.MapName = data.MapName; worldMap.MapType = data.MapType; worldMap.AllowPK = data.AllowPK; worldMap.AllowRide = data.AllowRide; worldMap.AllowTrade = data.AllowTrade; ImportEvents(data.MapEvents, worldMap); ImportDCFGByElement <FTBorn, MapBorn>(data.MapBorns, worldMap); ImportDCFGByElement <FTArea, MapArea>(data.MapAreas, worldMap); ImportDCFGByElement <FTAreaMine, MapAreaMine>(data.MapAreaMines, worldMap); ImportDCFGByElement <FTAreaMonster, MapAreaMonster>(data.MapAreaMonsters, worldMap); ImportDCFGByElement <FTBarrier, MapBarrier>(data.MapBarriers, worldMap); ImportDCFGByElement <FTMutiPoint, MapMutiPoint>(data.MapMutiPoints, worldMap); ImportDCFGByElement <FTNpc, MapNpc>(data.MapNpcs, worldMap); ImportDCFGByElement <FTPath, MapPath>(data.MapPaths, worldMap); ImportDCFGByElement <FTPortal, MapPortal>(data.MapPortals, worldMap); ImportDCFGByElement <FTStep, MapStep>(data.MapSteps, worldMap); ImportDCFGByElement <FTTimer, MapTimer>(data.MapTimers, worldMap); MapData = data; }
public void Parse_with_several_input_parameters() { string template = "select @{sel:a.Id}, @{sel:a.Name}, @{sel:a.City}, @{sel:a.AcceptNewAnimals} from @{a.TableName} where @{prop:a.Id} = @{prop:b.Id}"; string verify = "select Id as zoo_Id, Name as zoo_Name, City as zoo_City, AcceptNewAnimals as zoo_AcceptNewAnimals from zoos where $a_Id = $b_Id"; string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "TestFullMap.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); StatementMapParser parser = new StatementMapParser(); Dictionary <string, StatementInputParam> inputParams = new Dictionary <string, StatementInputParam> { { "a", new StatementInputParam() { Name = "a", Type = "WebZoo.Data.Zoo", ClrType = typeof(WebZoo.Data.Zoo) } }, { "b", new StatementInputParam() { Name = "b", Type = "WebZoo.Data.Animal", ClrType = typeof(WebZoo.Data.Animal) } } }; var statement = parser.Parse(new SqliteDialect(), config, inputParams, template); Console.WriteLine(statement.Body); Assert.AreEqual(verify, statement.Body); }
public void Load_xml_config_with_entity_non_existing_map_should_throw() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "Test002.data.xml"); MapConfig config = new MapConfig(); Assert.Throws <MappingException>(() => config.Load(testMapfile)); }
public void Load_generic_statement_without_operation_type_should_throw() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "Test_statement_invalid_statement_operationType.xml"); MapConfig config = new MapConfig(); Assert.Throws <MappingSerializationException>(() => config.Load(testMapfile)); }
static void Main(string[] args) { Console.WriteLine("加载mapConfig.json..."); MapConfig mapConfig = MapConfig.Load(); TileGenerator generator = new TileGenerator(mapConfig); generator.TileLoaded += new EventHandler <TileCoord>((sender, tileCoord) => { Console.WriteLine(string.Format("Tile : zoom : {0} x: {1} y :{2},已完成:{3}/{4}", tileCoord.Zoom, tileCoord.X, tileCoord.Y, generator.SuccessTileIndex, generator.TotalTile)); }); generator.Finished += new EventHandler((sender, e) => { Console.WriteLine(string.Format("完成:{0}/{1},失败:{2}!", generator.SuccessTileIndex, generator.TotalTile, generator.FailTiles)); //if (generator.FailTiles > 0) //{ // Console.WriteLine("是否尝试重新下载失败的瓦片?[Y/N]"); // string askYesNo = Console.ReadLine(); // if (askYesNo.Trim().ToUpper() =="Y") // { // generator.RetryFails(); // } //} }); Console.WriteLine("服务已启动......"); generator.Start(); Console.WriteLine("输入回车退出..."); Console.ReadKey(); generator.Close(); }
public void Load_simple_xml_config_should_have_valid_map_config() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "Test001.data.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); Assert.AreEqual(2, config.EntityConfigs.Count); }
public void EnterWorld(int mapID) { this.MapID = mapID; this.Init(); string fsPath = GTTools.Format("Text/Map/{0}", MapID); Config = new Cfg.Map.MapConfig(); Config.Load(fsPath); this.OnSceneStart(); }
public void Load_conventions_statement_without_name_should_default_to_naming_convention() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "Test_statement_valid.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); var zooInserts = config.UnprocessedStatements.Where(c => c.Name == "WebZoo.Data.Zoo_Insert").ToList(); Assert.AreEqual(1, zooInserts.Count); }
public void Load_conventions_statement_query_without_resul_map_should_default_type_of_entity_map_result() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "Test_statement_valid.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); var statement = config.UnprocessedStatements.Where(c => c.Name == "fakequery").First(); Assert.AreEqual("WebZoo.Data.Zoo", statement.ResultMap); }
public void Load_reference_dbType_should_be_valid() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "TestFullMap.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); var ent = config.GetEntityMap("WebZoo.Data.Animal"); var rel = ent.Relations["Zoo"]; Assert.AreEqual(System.Data.DbType.Int32, rel.DbType); }
public void Load_conventions_statement_insert_update_without_resul_map_should_default_integer_result() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "Test_statement_valid.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); var statement = config.UnprocessedStatements.Where(c => c.Name == "updateTest").First(); Assert.AreEqual(typeof(int).ToString(), statement.ResultMap); statement = config.UnprocessedStatements.Where(c => c.Name == "testInsert").First(); Assert.AreEqual(typeof(int).ToString(), statement.ResultMap); }
public void Load_conventions_statement_insert_update_without_InputParameterType_should_default_entity_result() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "Test_statement_valid.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); var statement = config.UnprocessedStatements.Where(c => c.Name == "updateTest").FirstOrDefault(); Assert.AreEqual("WebZoo.Data.Zoo", statement.InputParametersMap.Values.First()); statement = config.UnprocessedStatements.Where(c => c.Name == "testInsert").FirstOrDefault(); Assert.AreEqual("WebZoo.Data.Zoo", statement.InputParametersMap.Values.First()); }
public void Parse_non_existing_column_should_throw() { string template = "INSERT INTO @{TableName}(@{col:WaterPressure},@{col:City},@{col:AcceptNewAnimals}) VALUES(@{prop:Name},@{prop:City},@{prop:AcceptNewAnimals})"; string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "TestFullMap.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); var zooEntMap = config.EntityConfigs.Where(c => string.Equals(c.Name, "Zoo", StringComparison.Ordinal)) .FirstOrDefault(); StatementMapParser parser = new StatementMapParser(); Assert.Throws <GoliathDataException>(() => parser.Parse(new SqliteDialect(), zooEntMap, template, null)); }
public void Parse_with_db_parameters_parse_parameters() { string verify = "select * from zoos where Name = $p1 and AcceptAnimals = $p2;"; string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MappedStatementTests", "TestFullMap.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); Providers.Sqlite.SqliteProvider provider = new Providers.Sqlite.SqliteProvider(); config.MapStatements(provider.Name); StatementMap statement; config.MappedStatements.TryGetValue("querySupergloo", out statement); StatementMapParser parser = new StatementMapParser(); var compiled = parser.Parse(new SqliteDialect(), config, null, statement.Body, new QueryParam("p1", DbType.String), new QueryParam("p2", DbType.Boolean)); Console.WriteLine(compiled.Body.Trim()); Assert.AreEqual(verify, compiled.Body.Trim()); }
public void Parse_input_parameters_and_add_db_parameter_names_to_resulting_compiled_statement() { string verify = "INSERT INTO zoos(name, city, acceptanimals) VALUES($a_Name, $a_City, $a_AcceptAnimals);\nINSERT INTO zoos(name, city, acceptanimals) VALUES($b_Name, $b_City, $b_AcceptAnimals);"; string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MappedStatementTests", "TestFullMap.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); Providers.Sqlite.SqliteProvider provider = new Providers.Sqlite.SqliteProvider(); config.MapStatements(provider.Name); StatementMap statement; config.MappedStatements.TryGetValue("insertZoos", out statement); StatementMapParser parser = new StatementMapParser(); Dictionary <string, StatementInputParam> inputParams = new Dictionary <string, StatementInputParam> { { "a", new StatementInputParam() { Name = "a", Type = "WebZoo.Data.Zoo", ClrType = typeof(WebZoo.Data.Zoo) } }, { "b", new StatementInputParam() { Name = "b", Type = "WebZoo.Data.Zoo", ClrType = typeof(WebZoo.Data.Zoo) } } }; var compiled = parser.Parse(new SqliteDialect(), config, inputParams, statement.Body.Trim()); string[] verifySplit = verify.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); string[] bodySplit = compiled.Body.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); Console.WriteLine(bodySplit[0].Trim()); Assert.AreEqual(verifySplit[0], bodySplit[0].Trim()); Console.WriteLine(bodySplit[1].Trim()); Assert.AreEqual(verifySplit[1], bodySplit[1].Trim()); Assert.AreEqual(6, compiled.ParamPropertyMap.Count); Assert.IsTrue(compiled.ParamPropertyMap.Values.Where(c => c.QueryParamName == "a_Name").FirstOrDefault() != null); Assert.IsTrue(compiled.ParamPropertyMap.Values.Where(c => c.QueryParamName == "b_AcceptAnimals").FirstOrDefault() != null); }
public void Load_valid_map_file_return_list_of_valid_statements() { string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "TestFullMap.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); var statements = config.UnprocessedStatements.ToList(); Assert.AreEqual(6, statements.Count); foreach (var st in statements) { Assert.AreEqual("WebZoo.Data.Zoo", st.DependsOnEntity); } var statementWithParams = statements.Where(s => s.Name == "updateTest2").First(); Assert.AreEqual(3, statementWithParams.DbParametersMap.Count); }
public void Parse_valid_string_should_return_parsed_text() { string template = "INSERT INTO @{TableName}(@{sel:Name},@{sel:City},@{sel:AcceptNewAnimals}) VALUES(@{prop:Name},@{prop:City},@{prop:AcceptNewAnimals})"; string compiled = "INSERT INTO zoos(Name as zoo_Name,City as zoo_City,AcceptNewAnimals as zoo_AcceptNewAnimals) VALUES($Name,$City,$AcceptNewAnimals)"; string testMapfile = Path.Combine(SessionHelper.BaseDirectory, "TestFiles", "MapConfigTests", "TestFullMap.xml"); MapConfig config = new MapConfig(); config.Load(testMapfile); var zooEntMap = config.EntityConfigs.Where(c => string.Equals(c.Name, "Zoo", StringComparison.Ordinal)) .FirstOrDefault(); StatementMapParser parser = new StatementMapParser(); StatementInputParam inputParam = new StatementInputParam() { Name = "a", ClrType = typeof(WebZoo.Data.Zoo), Type = zooEntMap.FullName, Map = zooEntMap, IsMapped = true }; var statement = parser.Parse(new SqliteDialect(), zooEntMap, template, inputParam); Console.WriteLine(statement.Body); Assert.AreEqual(compiled, statement.Body); Assert.AreEqual(3, statement.ParamPropertyMap.Count); }
public override void Execute(AppOptionInfo opts, CodeGenRunner codeGenRunner) { Console.WriteLine("\n\nCreate Map..."); var providerFactory = new ProviderFactory(); ComplexType baseModel = null; var mapFileName = Path.Combine(opts.WorkingFolder, opts.MapFile); var baseMap = new MapConfig(); if (!string.IsNullOrWhiteSpace(opts.BaseModelXml) && File.Exists(opts.BaseModelXml)) { Console.WriteLine("\n\nRead base model."); baseMap.Load(opts.BaseModelXml); if (baseMap.ComplexTypes.Count > 0) { baseModel = baseMap.ComplexTypes[0]; codeGenRunner.Settings.BaseModel = baseModel.FullName; } } var rdbms = GetSupportedRdbms(opts); string[] whiteList; FilterSettings filterSettings = new FilterSettings(); if (!string.IsNullOrWhiteSpace(opts.Include)) { whiteList = opts.Include.Split(new string[] { ",", "|" }, StringSplitOptions.RemoveEmptyEntries); filterSettings.Exclude = false; filterSettings.TableFilterList = whiteList; } else { filterSettings.Exclude = true; filterSettings.TableFilterList = opts.ExcludedArray; } using (ISchemaDescriptor schemaDescriptor = providerFactory .CreateDbSchemaDescriptor(rdbms, codeGenRunner.Settings, filterSettings)) { var map = codeGenRunner.CreateMap(schemaDescriptor, opts.EntitiesToRename, baseModel, mapFileName); if (!string.IsNullOrWhiteSpace(opts.MappedStatementFile) && File.Exists(opts.MappedStatementFile)) { Console.WriteLine("Load mapped statements from {0} into {1}", opts.MappedStatementFile, mapFileName); map.LoadMappedStatements(opts.MappedStatementFile); CodeGenRunner.ProcessMappedStatements(map); } //let's try to read order from log if exists string primaOrda = Path.Combine(opts.WorkingFolder, PrimaOrdaFile); var previousOrderDict = new Dictionary <string, Tuple <int, string> >(); var orderCount = 0; if (File.Exists(primaOrda)) { using (var sr = new StreamReader(primaOrda)) { var contentLog = sr.ReadToEnd(); if (!string.IsNullOrWhiteSpace(contentLog)) { var split = contentLog.Split(new string[] { "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < split.Length; i++) { var tbName = split[i]; previousOrderDict.Add(tbName, Tuple.Create(i + 1, tbName)); } orderCount = split.Length; } } } map.MergeMap(baseMap); foreach (var ent in map.EntityConfigs) { ProcessMetadata(opts, ent); ProcessActivatedProperties(opts, ent); Tuple <int, string> tbOrder; if (previousOrderDict.TryGetValue(ent.FullName, out tbOrder)) { ent.Order = tbOrder.Item1; } else { previousOrderDict.Add(ent.FullName, Tuple.Create(ent.Order, ent.FullName)); orderCount = orderCount + 1; ent.Order = orderCount; } //process keygen if (!string.IsNullOrWhiteSpace(opts.DefaultKeygen)) { if (ent.PrimaryKey != null) { foreach (var k in ent.PrimaryKey.Keys) { if (string.IsNullOrWhiteSpace(k.KeyGenerationStrategy)) { k.KeyGenerationStrategy = opts.DefaultKeygen; } } } } foreach (var prop in ent) { ProcessMetadata(opts, ent, prop); ProcessActivatedProperties(opts, ent, prop); if (!string.IsNullOrWhiteSpace(opts.ComplexTypeMap)) { var key = string.Concat(ent.Name, ".", prop.Name); string complextType; if (opts.ComplexTypesTypeMap.TryGetValue(key, out complextType)) { prop.ComplexTypeName = complextType; prop.IsComplexType = true; opts.ComplexTypesTypeMap.Remove(key); } } } var unprocessedComplexTypes = opts.ComplexTypesTypeMap.Where(c => c.Key.StartsWith($"{ent.Name}.")).ToList(); if (unprocessedComplexTypes.Count > 0) { ProcessComplexTypes(unprocessedComplexTypes, ent, map); } } map.Save(mapFileName, true, true); using (var file = new StreamWriter(primaOrda)) { foreach (var tbOrder in previousOrderDict.Keys) { file.WriteLine(tbOrder); } } } }