示例#1
0
 public TypeSchemaGenerator(ITypeTableNameProvider tableNameProvider = null, Func <SchemaDefinition, TypeSchema, string> schemaTempPathProvider = null)
 {
     DefaultDataTypeBehavior    = DefaultDataTypeBehaviors.Exclude;
     TypeSchemaTempPathProvider = schemaTempPathProvider ?? ((sd, ts) => RuntimeSettings.AppDataFolder);
     SchemaManager      = new CuidSchemaManager(false);
     _tableNameProvider = tableNameProvider ?? new EchoTypeTableNameProvider();
 }
示例#2
0
        public static void GenerateDaoFromDbJs()
        {
            if (Arguments.Contains("root"))
            {
                DirectoryInfo rootDirectory = new DirectoryInfo(Arguments["root"]);
                if (!rootDirectory.Exists)
                {
                    Message.PrintLine("Specified root directory does not exist: {0}", ConsoleColor.Red, rootDirectory.FullName);
                    Environment.Exit(1);
                }

                FileInfo[] dbjs = rootDirectory.GetFiles("*.db.js", SearchOption.AllDirectories);
                if (dbjs.Length > 0)
                {
                    if (dbjs.Length > 1)
                    {
                        Message.PrintLine("Multiple *.db.js files found", ConsoleColor.Red);
                        if (!Arguments.Contains("s"))
                        {
                            Message.PrintLine("{0}", ConsoleColor.Yellow, dbjs.ToDelimited<FileInfo>(f => f.FullName, "\r\n"));
                            string answer = Prompt("Process each? [y N]", ConsoleColor.Yellow);
                            if (!answer.ToLowerInvariant().Equals("y"))
                            {
                                Exit(1);
                            }
                        }
                        else
                        {
                            Message.PrintLine("Processing each: {0}", ConsoleColor.Yellow,
                                dbjs.ToDelimited<FileInfo>(f => f.FullName, "\r\n\t"));
                        }
                    }

                    foreach (FileInfo file in dbjs)
                    {
                        try
                        {
                            Message.PrintLine("Processing {0}...", ConsoleColor.Yellow, file.FullName);
                            CuidSchemaManager manager = new CuidSchemaManager();

                            DirectoryInfo fileParent = file.Directory;
                            DirectoryInfo genToDir = GetTargetDirectory(file);

                            bool keep = Arguments.Contains("keep");

                            DirectoryInfo partialsDir = GetPartialsDir(genToDir);

                            SchemaManagerResult managerResult = null;
                            if (!Arguments.Contains("dll"))
                            {
                                bool compile = !keep;
                                managerResult = manager.GenerateDaoAssembly(file, compile, keep, genToDir.FullName,
                                    partialsDir.FullName);
                            }
                            else
                            {
                                managerResult = manager.GenerateDaoAssembly(file, new DirectoryInfo(Arguments["dll"]), keep,
                                    genToDir.FullName, partialsDir.FullName);
                            }

                            if (!managerResult.Success)
                            {
                                throw new Exception(managerResult.Message);
                            }

                            if (Arguments.Contains("sql"))
                            {
                                WriteSqlFile(managerResult);
                            }

                            Message.PrintLine(managerResult.Message, ConsoleColor.Green);
                            if (managerResult.DaoAssembly != null)
                            {
                                Message.PrintLine("Compiled to: {0}", managerResult.DaoAssembly.FullName, ConsoleColor.Yellow);
                            }
                        }
                        catch (Exception ex)
                        {
                            Message.PrintLine("{0}\r\n\r\n***\r\n{1}", ConsoleColor.Red, ex.Message, ex.StackTrace ?? "");
                            Pause("Press enter to exit\r\n");
                            Exit(1);
                        }
                    }

                    Pause("Press enter to exit...\r\n");
                }
                else
                {
                    Message.PrintLine("No *.db.js files were found", ConsoleColor.Yellow);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(Arguments["conn"]))
                {
                    Message.PrintLine("Please specify a connection name from the config or a directory to search",
                        ConsoleColor.Yellow);
                    Exit(1);
                }
                else
                {
                    Extract();
                }
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            SetArguments(args);

            if (Arguments.Contains("?"))
            {
                Usage(Assembly.GetExecutingAssembly());
                return;
            }
            else if (Arguments.Contains("examples"))
            {
                Out("For extraction:\r\n");
                Out("LaoTze /f:<file> /conn:<connectionNameFromConfig> /gen:<dirPath> /ns:<defaultNamespace> /dll:<assemblyName> [/v|/s]");
                Out("\r\n or To generate from *.db.js\r\n");
                Out("LaoTze /root:<project_root_to_search_for_database.db.js>\r\n");
                return;
            }

            if (Arguments.Contains("pause"))
            {
                Pause("Press a key to continue...");
            }

            if (Arguments.Contains("root"))
            {
                DirectoryInfo rootDirectory = new DirectoryInfo(Arguments["root"]);
                if (!rootDirectory.Exists)
                {
                    OutLineFormat("Specified root directory does not exist: {0}", ConsoleColor.Red, rootDirectory.FullName);
                    Pause();
                    Environment.Exit(1);
                }

                FileInfo[] dbjs = rootDirectory.GetFiles("*.db.js", SearchOption.AllDirectories);
                if (dbjs.Length > 0)
                {
                    if (dbjs.Length > 1)
                    {
                        OutLine("Multiple *.db.js files found", ConsoleColor.Red);
                        OutLineFormat("{0}", ConsoleColor.Yellow, dbjs.ToDelimited <FileInfo>(f => f.FullName, "\r\n"));
                        string answer = Prompt("Process each? [y N]", ConsoleColor.Yellow);
                        if (!answer.ToLowerInvariant().Equals("y"))
                        {
                            Exit(1);
                        }
                    }

                    foreach (FileInfo file in dbjs)
                    {
                        try
                        {
                            OutLineFormat("Processing {0}...", ConsoleColor.Yellow, file.FullName);
                            CuidSchemaManager manager = new CuidSchemaManager();

                            DirectoryInfo fileParent = file.Directory;
                            DirectoryInfo genToDir   = GetTargetDirectory(file);

                            bool keep = Arguments.Contains("keep");

                            DirectoryInfo partialsDir = GetPartialsDir(genToDir);

                            SchemaResult result = null;
                            if (!Arguments.Contains("dll"))
                            {
                                bool compile = !keep;
                                result = manager.GenerateDao(file, compile, keep, genToDir.FullName, partialsDir.FullName);
                            }
                            else
                            {
                                result = manager.GenerateDao(file, new DirectoryInfo(Arguments["dll"]), keep, genToDir.FullName, partialsDir.FullName);
                            }

                            if (!result.Success)
                            {
                                throw new Exception(result.Message);
                            }

                            if (Arguments.Contains("sql"))
                            {
                                WriteSqlFile(result);
                            }

                            OutLine(result.Message, ConsoleColor.Green);
                            if (result.DaoAssembly != null)
                            {
                                OutLineFormat("Compiled to: {0}", result.DaoAssembly.FullName, ConsoleColor.Yellow);
                            }
                        }
                        catch (Exception ex)
                        {
                            OutLineFormat("{0}\r\n\r\n***\r\n{1}", ConsoleColor.Red, ex.Message, ex.StackTrace ?? "");
                            Pause("Press enter to exit\r\n");
                            Exit(1);
                        }
                    }

                    Pause("Press enter to exit...\r\n");
                }
                else
                {
                    OutLine("No *.db.js files were found", ConsoleColor.Yellow);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(Arguments["conn"]))
                {
                    OutLine("Please specify a connection name from the config or a directory to search", ConsoleColor.Yellow);
                    Pause();
                }
                else
                {
                    Extract();
                }
            }
        }