Example #1
0
        public void CompileTest()
        {
            var      classToGenerate = "GeneratedUser";
            string   generateClass   = generator.GenerateClass("Users", classToGenerate);
            Assembly assembly        = DbCompilerUtils.Compile(generateClass);
            Type     type            = assembly.GetType(generator.Namespace + "." + classToGenerate);

            ulong count = DbGateway.Instance.LoadCount(type);

            Assert.AreEqual(1, count);

            DbRecordInfo info1 = DbAttributesManager.GetRecordInfo(typeof(User));
            DbRecordInfo info2 = DbAttributesManager.GetRecordInfo(type);

            Assert.AreEqual(info1.TableName, info2.TableName, "TableName");


            DbFieldInfo pk = (info1 as DbIdentityRecordInfo).PrimaryKey;

            Assert.AreEqual(pk.FieldType, info2.Fields[0].FieldType);
            Assert.AreEqual(pk.Name, info2.Fields[0].Name);

            Assert.AreEqual(typeof(short), info2.Fields[1].FieldType);
            for (int i = 1; i < info2.Fields.Length - 1; i++)
            {
                Assert.AreEqual(info1.Fields[i], info2.Fields[i + 1], "Fields");
            }
        }
Example #2
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);
            }
        }