public void ShouldGenerateModelFromScripts2()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts2");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            var brandTable = new Table("brand", ImmutableList.Create(
                                           new Column("id", "int", false, false, true),
                                           new Column("name", "string", false, false, false),
                                           new Column("logo", "string", true, false, false),
                                           new Column("archived", "bool", true, false, false),
                                           new Column("color", "string", false, false, false),
                                           new Column("external_id", "string", true, false, false)
                                           ), ImmutableSortedSet.Create("id"));
            var bbbTable = new Table("bbbb", ImmutableList.Create(
                                         new Column("id", "int", false, false, true),
                                         new Column("name", "string", false, false, false),
                                         new Column("logo", "string", true, false, false)
                                         ), ImmutableSortedSet.Create("id"));

            actual.Tables.ShouldDeepEqual(ImmutableList.Create(bbbTable, brandTable));
        }
        public void ShouldGenerateModelFromScripts5()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts5");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            var userProfile = new Table("user_profile", ImmutableList.Create(
                                            new Column("id", "int", false, false, true),
                                            new Column("firstName", "string", false, false, false),
                                            new Column("lastName", "string", false, false, false),
                                            new Column("password", "string", false, false, false),
                                            new Column("algorithm", "int", false, false, false),
                                            new Column("balance", "decimal", false, false, false),
                                            new Column("salt", "string", false, false, false),
                                            new Column("disabled", "bool", false, false, false),
                                            new Column("groupId", "string", false, false, false),
                                            new Column("latitude", "decimal", true, false, false)
                                            ), ImmutableSortedSet.Create("id"));
            var userGroup = new Table("user_group", ImmutableList.Create(
                                          new Column("id", "string", false, false, false)
                                          ), ImmutableSortedSet.Create("id"));
            var userRole = new Table("role", ImmutableList.Create(
                                         new Column("id", "string", false, false, false)
                                         ), ImmutableSortedSet.Create("id"));
            var userGroupRole = new Table("user_group_role", ImmutableList.Create(
                                              new Column("groupId", "string", false, false, false),
                                              new Column("roleId", "int", false, false, false)
                                              ), ImmutableSortedSet.Create("groupId", "roleId"));

            actual.Tables.ShouldDeepEqual(ImmutableList.Create(userRole, userGroup, userGroupRole, userProfile));
        }
        static void Main(string[] args)
        {
            const string connectionString = "Data Source=dev-app3.abax.local;Initial Catalog=ETS;User Id=T2F_Web;password=ets;MultipleActiveResultSets=True";

            var schema = DbSchemaReader.ReadTableSchema(() => new SqlConnection(connectionString), "dbo.GpsTrip");

//            var properties = schema.Select(PropertyDefinitionFactory.FromDbColumnInfo).ToArray();

//            Console.WriteLine(properties.Length);
        }
        public async Task Initialize()
        {
            Log.Debug("Initializing single table queue gateway");

            var schema = await DbSchemaReader.ReadTableSchema(_connectionFactory, _tableName).ConfigureAwait(false);

            _properties  = schema.Where(x => x.Name.ToLower() != "rownumber").Select(FromDbColumnInfo).ToArray();
            _messageType = MessageTypeProvider.BuildMessageType(new MessageTypeDefinition(_type, _properties));

            Log.Debug("Initialization complete");
        }
        public async Task Initialize()
        {
            Log.Debug("Initializing JSON table queue gateway");

            var schema = (await DbSchemaReader.ReadTableSchema(_connectionFactory, _tableName).ConfigureAwait(false)).ToArray();

            ExpectColumnType(schema, _columnNames.Timestamp, typeof(DateTime));
            ExpectColumnType(schema, _columnNames.MessageType, typeof(string));
            ExpectColumnType(schema, _columnNames.Payload, typeof(string));

            Log.Debug("Initialization complete");
        }
        public void ShouldGenerateModelFromScripts13()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts13");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            var table = new Table("user_grid_state", ImmutableList.Create(
                                      new Column("id", "int", false, false, true),
                                      new Column("filter_expression", "string", true, false, false),
                                      new Column("shared_view_id", "int", true, false, false),
                                      new Column("is_sharded", "bool", false, false, false)
                                      ), ImmutableSortedSet.Create("id"));

            actual.Tables.ShouldDeepEqual(ImmutableList.Create(table));
        }
        public void ShouldGenerateModelFromScripts4()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts4");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            var bbbTable = new Table("bbbb", ImmutableList.Create(
                                         new Column("name", "string", false, false, false),
                                         new Column("lobo", "string", true, false, false),
                                         new Column("jiji", "int", false, false, false),
                                         new Column("tartuffe", "int", true, false, false)
                                         ), ImmutableSortedSet <string> .Empty);

            actual.Tables.ShouldDeepEqual(ImmutableList.Create(bbbTable));
        }
        public void ShouldGenerateModelFromScripts12()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts12");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            var tenant_saml = new Table("tenant_saml", ImmutableList.Create(
                                            new Column("new_tenant_id", "string", false, false, false),
                                            new Column("is_enabled", "bool", false, false, false),
                                            new Column("identity_provider_metadata", "string", false, false, false),
                                            new Column("default_group_id", "int", true, false, false),
                                            new Column("default_culture_id", "string", true, false, false)
                                            ), ImmutableSortedSet.Create("new_tenant_id"));

            actual.Tables.ShouldDeepEqual(ImmutableList.Create(tenant_saml));
        }
        public void ShouldGenerateModelFromScripts7()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts7");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            Assert.AreEqual(8, actual.Tables.Count());
            Assert.AreEqual(2, actual.Tables.First(t => t.Name == "group_type").Columns.Count);
            Assert.AreEqual(8, actual.Tables.First(t => t.Name == "group_type_available_scope").Columns.Count);
            Assert.AreEqual(3, actual.Tables.First(t => t.Name == "role").Columns.Count);
            Assert.AreEqual(5, actual.Tables.First(t => t.Name == "user_group").Columns.Count);
            Assert.AreEqual(30, actual.Tables.First(t => t.Name == "user_profile").Columns.Count);
            Assert.AreEqual(2, actual.Tables.First(t => t.Name == "user_group_role").Columns.Count);
            Assert.AreEqual(6, actual.Tables.First(t => t.Name == "user_scope_access").Columns.Count);
            Assert.AreEqual(10, actual.Tables.First(t => t.Name == "user_grid_state").Columns.Count);
        }
        public void ShouldGenerateModelFromScripts10()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts10");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            var contract = new Table("contract", ImmutableList.Create(
                                         new Column("id", "string", false, false, false)
                                         ), ImmutableSortedSet <string> .Empty);

            var other = new Table("other", ImmutableList.Create(
                                      new Column("id", "int", false, false, true),
                                      new Column("contract_id", "int", false, false, false)
                                      ), ImmutableSortedSet.Create("id"));

            actual.Tables.ShouldDeepEqual(ImmutableList.Create(contract, other));
        }
        public void ShouldGenerateModelFromScripts8()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts8");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            var contract = new Table("contract", ImmutableList.Create(
                                         new Column("id", "int", false, false, true),
                                         new Column("code", "string", false, false, false),
                                         new Column("created_by", "string", false, false, false),
                                         new Column("creation_date", "DateTime", false, false, false),
                                         new Column("last_modified_by", "string", true, false, false),
                                         new Column("last_modification_date", "DateTime", true, false, false),
                                         new Column("pyjame", "int", true, false, false)
                                         ), ImmutableSortedSet.Create("id"));

            actual.Tables.ShouldDeepEqual(ImmutableList.Create(contract));
        }
        public void ShouldGenerateModelFromScripts6()
        {
            var testProjectDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "../../../");
            var scriptsPath          = Path.Combine(testProjectDirectory, "Scripts6");

            var dbSchemaReader = new DbSchemaReader();

            var actual = dbSchemaReader.Read(scriptsPath, new TaskLoggingHelper(GetTask(), "build"));

            var tenant = new Table("tenant", ImmutableList.Create(
                                       new Column("id", "int", false, false, true),
                                       new Column("name", "string", true, false, false),
                                       new Column("groupId", "int", false, false, false)
                                       ), ImmutableSortedSet.Create("id"));
            var userGroup = new Table("lamorosso", ImmutableList.Create(
                                          new Column("id", "int", false, true, false),
                                          new Column("name", "string", true, false, false)
                                          ), ImmutableSortedSet.Create("id"));

            actual.Tables.ShouldDeepEqual(ImmutableList.Create(userGroup, tenant));
        }
Exemple #13
0
        public void ConfigureServices(IServiceCollection services)
        {
            ModuleBuilder moduleBuilder   = ClrTypeBuilder.GetModuleBuilder();
            List <Type>   connectionTypes = new List <Type>();

            foreach (var connection in this.Connections)
            {
                var          connectionString = connection.Value;
                var          tables           = DbSchemaReader.GetSchemata(connectionString);
                List <Entry> entrys           = new List <Entry>();
                foreach (var table in tables)
                {
                    var modelType = moduleBuilder.CreateModelType(connection.Key, table);
                    entrys.Add(new Entry(modelType, table));
                }
                _entrys.Add(connection.Key, entrys);
                var dbcontextType = moduleBuilder.CreateDbContextType(connection.Key, entrys);
                Action <DbContextOptionsBuilder> optionsAction = options => options.UseSqlServer(connection.Value);
                MethodInfo addDbContextmethod =
                    typeof(EntityFrameworkServiceCollectionExtensions).
                    GetMethods(BindingFlags.Public | BindingFlags.Static).
                    FirstOrDefault(mi => mi.Name == "AddDbContext" && mi.GetGenericArguments().Count() == 1).
                    MakeGenericMethod(new Type[] { dbcontextType });
                addDbContextmethod.Invoke(null, new object[] { services, optionsAction, ServiceLifetime.Scoped, ServiceLifetime.Scoped });
                foreach (var entry in entrys)
                {
                    var controllerType = moduleBuilder.CreateControllerType(
                        connection.Key,
                        entry.Type,
                        dbcontextType);

                    connectionTypes.Add(controllerType);
                }
            }

            services.AddMvc().
            SetCompatibilityVersion(CompatibilityVersion.Version_2_1).
            ConfigureApplicationPartManager(p => p.FeatureProviders.Add(new EmitTypeControllerFeatureProvider(connectionTypes)));
            services.AddOData();
        }