/// <summary> /// Merges the map. /// </summary> /// <param name="config">The configuration.</param> /// <exception cref="GoliathDataException"> /// </exception> public void MergeMap(MapConfig config) { foreach (var entity in config.EntityConfigs) { if (EntityConfigs.Contains(entity.FullName)) { continue; } EntityConfigs.Add(entity); } foreach (var complexType in config.ComplexTypes) { if (ComplexTypes.Contains(complexType.FullName)) { continue; } ComplexTypes.Add(complexType); } config.MapStatements(config.Settings.Platform); MapStatements(Settings.Platform); LoadMappedStatements(config.MappedStatements); }
public ComplexType AddComplexType(string typeName) { var value = new ComplexType { Name = typeName }; ComplexTypes.Add(value); return(value); }
private Type CreateCompexType(ModuleBuilder builder, Random rand, string id) { var name = builder.Assembly.GetName().Name + ".ComplexType" + id; TypeBuilder typeBuilder = builder.DefineType(name, TypeAttributes.Public); // define 1~20 properties on the new complex type typeBuilder.DefineProperties( rand.Next(20) + 1, rand, primitiveTypes.Union(_complexTypes).ToArray()); var result = typeBuilder.CreateType(); ComplexTypes.Add(result); return(result); }
/// <summary> /// Create a group of types randomly /// </summary> /// <param name="count">number of the types to be created</param> /// <param name="rand">random generator</param> public void CreateTypes(int count, Random rand) { // create a random GUID in the form of 00000000000000000000000000000000 var uniqueName = InstanceCreator.CreateInstanceOf <Guid>(rand).ToString("N"); var assemblyName = new AssemblyName(uniqueName); AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess.RunAndSave); ModuleBuilder modelBuilder = assemblyBuilder.DefineDynamicModule( assemblyName.Name, assemblyName.Name + ".dll"); for (int i = 0; i < count; i++) { var choice = rand.Next(10); if (choice < 6) { // Entity type var newType = CreateEntityType(modelBuilder, rand, i.ToString()); CreateClientEntityType(modelBuilder, rand, newType); var controller = CreateControllerType(modelBuilder, newType); _controllerTypes.Add(controller); } else if (choice < 7) { // Enum type var newType = CreateEnumType(modelBuilder, rand, i.ToString()); ComplexTypes.Add(newType); } else { // Complex Type CreateCompexType(modelBuilder, rand, i.ToString()); } } this.Assembly = assemblyBuilder; }