Example #1
0
        private static void DoWhenNoArgs(GenOptions options)
        {
            NewBoilerplateManage.DoGen(options.ConfigFile, options.Project, options.NameSpace, options.PrefixFilter, options.OnlyGenTable);


            Console.ReadLine();
            //IDatabase database = new Database(config, LogStatic, null);

            //try
            //{
            //    string outputPath = database.GenerateCode();
            //    LogStatic("Generate output: " + outputPath);

            //    if (System.IO.Directory.Exists(outputPath))
            //    {
            //        string v_OpenFolderPath = outputPath;
            //        System.Diagnostics.Process.Start("explorer.exe", v_OpenFolderPath);
            //    }

            //}
            //catch (Exception ex)
            //{
            //    LogStatic("Generate error: " + ex.Message, ex, MessageType.Error);
            //}


            //Console.ReadLine();
        }
        public static NewBoilerplateResult Process(NewOptions options)
        {
            NewBoilerplateResult result = null;
            //NewBoilerplateContenxt ctx = new NewBoilerplateContenxt();
            //ctx.Boilerplate = options.Boilerplate;

            var provider = Providers.FirstOrDefault(p => p.Name == options.Boilerplate);

            if (provider != null)
            {
                //ctx.BoilerplatPath = DbLoader.CombinePathWithAppDirectory(@"\Boilerplats\"+ ctx.Boilerplate);
                //ctx.ProjectName = options.Project;
                //ctx.ProjectOutputPath = DbLoader.CombinePathWithAppDirectory(@"\generate\" + ctx.ProjectName);

                //result = provider.Process(ctx);

                string config = DbLoader.CombinePathWithAppDirectory(@"Boilerplats\" + options.Boilerplate + @"\config.xml");
                NewBoilerplateManage.DoGen(config, options.Project, options.NameSpace, options.PrefixFilter, options.OnlyGenTable);


                string genDir = DbLoader.CombinePathWithAppDirectory(@"generate\" + options.Boilerplate);
                LogStatic("Starting copy resource to generate directory ......");
                LogStatic("Generate directory : " + genDir);

                string resourceDir = DbLoader.CombinePathWithAppDirectory(@"Boilerplats\" + options.Boilerplate + @"\resource");
                var    dirs        = Directory.GetDirectories(resourceDir, "*", SearchOption.TopDirectoryOnly);

                CurrentGenerateContext.ProjectName = options.Project;

                foreach (var dir in dirs)
                {
                    var    dirInfo     = new DirectoryInfo(dir);
                    var    dirname     = dirInfo.Name;// Path.GetDirectoryName(dir);
                    string realDirName = FormatSimpleTemplate(dirname);
                    string toDir       = Path.Combine(genDir, realDirName);
                    LogStatic("Copy directory resource " + dirname + " to " + toDir);

                    CopyDirectory(dir, toDir);
                    LogStatic("Finish copy directory.");
                }

                LogStatic("Finish copy resource to generate directory !");
            }
            else
            {
                LogStatic("Not find Boilerplate [" + options.Boilerplate + "] !", null, MessageType.Error);
            }

            return(result);
        }