コード例 #1
0
        private void initDefault()
        {
            if (defaultTemplate != null)
            {
                return;
            }

            lock (this)
            {
                if (defaultTemplate == null)
                {
                    defaultTemplate = new CSharpTemplate();
                }
                else
                {
                    return;
                }

                razorEngine = new RazorEngine();

                beanTemplate   = GetTemplate <CSharpClass>(javaBeanTemplateRelatePath);
                daoTemplate    = GetTemplate <JavaDaoConfig>(javaDaoTemplateRelatePath);
                mapperTemplate = GetTemplate <JavaMapperConfig>(javaMapperTemplateRelatePath);

                codeTemplate = GetTemplate <JavaCodeConfig>(javaCodeTemplateRelatePath);

                defaultTemplate.beanTemplate        = beanTemplate;
                defaultTemplate.daoTemplate         = daoTemplate;
                defaultTemplate.mapperTemplate      = mapperTemplate;
                defaultTemplate.serviceTemplate     = codeTemplate;
                defaultTemplate.modelTemplate       = codeTemplate;
                defaultTemplate.serviceImplTemplate = codeTemplate;
                defaultTemplate.controllerTemplate  = codeTemplate;
            }
        }
コード例 #2
0
        internal CSharpTemplate Clone()
        {
            CSharpTemplate newTemplate = new CSharpTemplate();

            newTemplate.beanTemplate        = beanTemplate;
            newTemplate.daoTemplate         = daoTemplate;
            newTemplate.mapperTemplate      = mapperTemplate;
            newTemplate.modelTemplate       = modelTemplate;
            newTemplate.serviceTemplate     = serviceTemplate;
            newTemplate.serviceImplTemplate = serviceImplTemplate;
            newTemplate.controllerTemplate  = controllerTemplate;
            return(newTemplate);
        }
コード例 #3
0
        private CSharpTemplate GetTemplate(JavaCodeConfig javaCodeConfig)
        {
            initDefault();

            if (string.IsNullOrEmpty(javaCodeConfig.ServiceCodeTemplateFile) &&
                string.IsNullOrEmpty(javaCodeConfig.ServiceImplCodeTemplateFile) &&
                string.IsNullOrEmpty(javaCodeConfig.ControllerCodeTemplateFile))
            {
                return(defaultTemplate);
            }

            CSharpTemplate template = templateCache[javaCodeConfig];

            if (template != null)
            {
                return(template);
            }

            template = defaultTemplate.Clone();


            if (false == string.IsNullOrEmpty(javaCodeConfig.ServiceCodeTemplateFile))
            {
                template.serviceTemplate = GetTemplate <JavaCodeConfig>(GetTemplateFilePath(javaCodeConfig.ServiceCodeTemplateFile));
            }
            if (false == string.IsNullOrEmpty(javaCodeConfig.ServiceImplCodeTemplateFile))
            {
                template.serviceImplTemplate = GetTemplate <JavaCodeConfig>(GetTemplateFilePath(javaCodeConfig.ServiceImplCodeTemplateFile));
            }
            if (false == string.IsNullOrEmpty(javaCodeConfig.ControllerCodeTemplateFile))
            {
                template.controllerTemplate = GetTemplate <JavaCodeConfig>(GetTemplateFilePath(javaCodeConfig.ControllerCodeTemplateFile));
            }


            return(template);
        }
コード例 #4
0
        public void GenerateCode(JavaCodeConfig javaCodeConfig, JavaClass createdJavaBean)
        {
            CSharpTemplate template = GetTemplate(javaCodeConfig);
            IRazorEngineCompiledTemplate <RazorEngineTemplateBase <JavaCodeConfig> > codeTemplate = null;

            lock (this)
            {
                javaCodeConfig.JavaClass = createdJavaBean;

                string rootDir = String.Empty;

                string result = String.Empty;

                string fileName = string.Empty;

                Action action = () =>
                {
                    codeTemplate = null;
                    codeTemplate = codeTemplate ?? (javaCodeConfig.ForModel ? template.modelTemplate : null);
                    codeTemplate = codeTemplate ?? (javaCodeConfig.ForService ? template.serviceTemplate : null);
                    codeTemplate = codeTemplate ?? (javaCodeConfig.ForServiceImpl ? template.serviceImplTemplate : null);
                    codeTemplate = codeTemplate ?? (javaCodeConfig.ForController ? template.controllerTemplate : null);
                    if (codeTemplate == null)
                    {
                        Console.WriteLine("");
                    }



                    result = codeTemplate.Run(instance =>
                    {
                        instance.Model = javaCodeConfig;
                    });
                    Console.WriteLine(result);


                    string filePath = rootDir + Path.DirectorySeparatorChar + fileName + ".java";


                    if (File.Exists(filePath))
                    {
                        File.Delete(filePath);
                    }
                    File.WriteAllText(filePath, result, new UTF8Encoding(false));
                };

                if (javaCodeConfig.GeneralModel)
                {
                    javaCodeConfig.Reset();
                    javaCodeConfig.ForModel = true;
                    rootDir  = CodeUtil.PrepareCodeRoot(javaCodeConfig.ModelJavaDiretory, javaCodeConfig.ModelPackageName);
                    fileName = javaCodeConfig.ModelName;
                    action();
                }

                if (javaCodeConfig.GeneralService)
                {
                    javaCodeConfig.Reset();
                    javaCodeConfig.ForService = true;
                    rootDir  = CodeUtil.PrepareCodeRoot(javaCodeConfig.ModelJavaDiretory, javaCodeConfig.ServicePackageName);
                    fileName = javaCodeConfig.ServiceName;
                    action();
                }

                if (javaCodeConfig.GeneralServiceImpl)
                {
                    javaCodeConfig.Reset();
                    javaCodeConfig.ForServiceImpl = true;
                    rootDir  = CodeUtil.PrepareCodeRoot(javaCodeConfig.ModelJavaDiretory, javaCodeConfig.ServiceImplPackageName);
                    fileName = javaCodeConfig.ServiceImplName;
                    action();
                }

                if (javaCodeConfig.GeneralController)
                {
                    javaCodeConfig.Reset();
                    javaCodeConfig.ForController = true;
                    rootDir  = CodeUtil.PrepareCodeRoot(javaCodeConfig.ModelJavaDiretory, javaCodeConfig.ControllerPackageName);
                    fileName = javaCodeConfig.ControllerName;
                    action();
                }
            }
        }