Esempio n. 1
0
        public void ParseTest()
        {
            Match m = DbCodeGenerator.ParseSqlType("varchar(254)");

            Assert.IsTrue(m.Success);
            Assert.AreEqual("varchar", m.Groups[1].Value);
            Assert.AreEqual("254", m.Groups[2].Value);

            int count = m.Groups.Count;

            Assert.AreEqual(3, count);
        }
Esempio n. 2
0
        public void SetUp()
        {
            DbStructureGateway sgateway = DbStructureGateway.Instance;

            sgateway.DropTables(typeof(User).Assembly);
            sgateway.CreateTables(typeof(User).Assembly);

            TestData data = new TestData(sgateway.Accessor);
            long     user = data.CreateUser();

            generator = new DbCodeGenerator(sgateway)
            {
                Namespace = "ITCreatings.Ndb.GeneratedObjects"
            };
        }
Esempio n. 3
0
        public void GenerateClasses(string [] args)
        {
            string path      = args[3];
            string Namespace = (args.Length > 4) ? args[4] : null;

            var generator = new DbCodeGenerator(StructureGateway);

            if (!string.IsNullOrEmpty(Namespace))
            {
                generator.Namespace = Namespace;
            }

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            string[] Tables = StructureGateway.Accessor.LoadTables();
            foreach (string table in Tables)
            {
                string generatedClass = generator.GenerateClass(table);
                string filepath       = Path.Combine(path, table + ".cs");

                if (File.Exists(filepath))
                {
                    Console.WriteLine("Error: File {0} already exists", filepath);
                    continue;
                }

                using (var sw = File.CreateText(filepath))
                {
                    sw.Write(generatedClass);
                    sw.Close();
                }

                Console.WriteLine("Success: File {0} generated...", filepath);
            }
        }
Esempio n. 4
0
        public void GenerateEntityCodeTest_View()
        {
            IDbViewEntity view = (from v in new DbDatabaseEntity(new DbSourceEntity(this.m_dataSource, null, new SqlServerDatabaseEntityProvider()), "Xphter.Framework.Test", new SqlServerDataEntityProvider()).Views
                                  where v.Name.Equals("viewGeneration0", StringComparison.OrdinalIgnoreCase)
                                  select v).FirstOrDefault();

            CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
            DbCodeGenerator target   = new DbCodeGenerator(new SqlServerCodeProvider(), null, provider);
            CodeCompileUnit unit     = target.GenerateCompileUnit();

            target.GenerateEntityCode(target.GenerateNamespace(unit, this.m_entityNamespaceName), view);

            CodeGeneratorOptions options = new CodeGeneratorOptions();

            options.BlankLinesBetweenMembers = true;
            options.BracingStyle             = "Block";
            options.ElseOnClosing            = true;
            options.IndentString             = "  ";
            options.VerbatimOrder            = true;
            using (TextWriter writer = new StreamWriter(string.Format("{0}.{1}", target.GetEntityCodeFilename(view), provider.FileExtension), false, Encoding.UTF8)) {
                provider.GenerateCodeFromCompileUnit(unit, writer, options);
            }
        }