Exemple #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);
        }
Exemple #3
0
 private static void RegisterDefaultBoilerplates()
 {
     NewBoilerplateManage.Register(new CSharpMvcNewBoilerplate());
 }
Exemple #4
0
 private static void ParseAndExecute(string[] args)
 {
     Parser.Default.ParseArguments <GenOptions, NewOptions, DocOptions, BuildOptions, RunOptions, RestoreOptions, SqlMapOptions>(args)
     .WithParsed <GenOptions>(opts =>
     { //生成代码
         DoWhenNoArgs(opts);
     })
     .WithParsed <NewOptions>(opts =>
     { //创建新模板项目
         if (opts.Boilerplate == "" || opts.Boilerplate == null)
         {
             WriteMsg("` --b %` Boilerplate list: ");
             var listTemplateType = NewBoilerplateManage.Providers;
             foreach (var item in listTemplateType)
             {
                 WriteMsg(item.Name + "\t" + "(" + item.Description + ")");
             }
         }
         else
         {
             NewBoilerplateManage.Process(opts);
         }
     })
     .WithParsed <DocOptions>(opts =>
     { //生成数据库字典文档
         DocGenerator.Process(opts);
     })
     .WithParsed <SqlMapOptions>(opts =>
     { //生成数据库字典文档
         SqlmapHelpers.Export(opts);
     })
     .WithParsed <BuildOptions>(opts =>
     { //编译项目
         if (opts.LangType == LangType.none)
         {
             WriteMsg("` --l %` LangType list: ");
             var listTemplateType = EnumHelpers.GetAllItems(typeof(LangType));// NewBoilerplateManage.Providers;
             foreach (var item in listTemplateType)
             {
                 WriteMsg(item.Text + "\t" + "(" + item.Description + ")");
             }
         }
         else
         {
             CmdHelper.Run(CmdHelper.GetBuildCmd(opts));
         }
     })
     .WithParsed <RunOptions>(opts =>
     { //运行项目
         if (opts.LangType == LangType.none)
         {
             WriteMsg("` --l %` LangType list: ");
             var listTemplateType = EnumHelpers.GetAllItems(typeof(LangType));// NewBoilerplateManage.Providers;
             foreach (var item in listTemplateType)
             {
                 WriteMsg(item.Text + "\t" + "(" + item.Description + ")");
             }
         }
         else
         {
             CmdHelper.Run(CmdHelper.GetRunCmd(opts));
             //CmdHelper.RunCmd(CmdHelper.GetRunCmd(opts), true);
         }
     })
     .WithParsed <RestoreOptions>(opts =>
     {//还原项目包文件
     })
     .WithNotParsed(errs =>
     {
         foreach (var err in errs)
         {
             WriteError(err.ToString());
         }
     });
 }