Ejemplo n.º 1
0
        public void GenCode(TableInfo tableInfo)
        {
            NVelocityHelper nVelocityHelper = new NVelocityHelper(FilePathHelper.TemplatesPath);
            string          tableName       = tableInfo.TableName;

            string path = string.Format(@"{0}", TemplateParas.TemplateName);
            var    dic  = GetNVelocityVars();

            dic.Add("tableInfo", tableInfo);

            string str = nVelocityHelper.GenByTemplate(path, dic);


            string title = tableName + "." + (TemplateParas.CodeLanguage + "").ToLower();

            if (!string.IsNullOrEmpty(TemplateParas.SaveFileName))
            {
                title = TemplateParas.SaveFileName;
                title = nVelocityHelper.GenByStr(title, dic);
            }
            if (TemplateParas.IsShowGenCode)
            {
                CodeShow(title, str);
            }
            else
            {
                FileHelper.Write(TemplateParas.SaveFilePath + title, new[] { str }, SaveFileEncoding);
            }
        }
Ejemplo n.º 2
0
        public void GenCode()
        {
            NVelocityHelper nVelocityHelper = new NVelocityHelper(FilePathHelper.TemplatesPath);
            string          path            = string.Format(@"{0}", TemplateParas.TemplateName);
            var             dic             = GetNVelocityVars();
            string          str             = nVelocityHelper.GenByTemplate(path, dic);
            string          title           = "";

            if (!string.IsNullOrEmpty(TemplateParas.SaveFileName))
            {
                title = TemplateParas.SaveFileName;
                title = nVelocityHelper.GenByStr(title, dic);
            }
            if (TemplateParas.IsShowGenCode)
            {
                CodeShow(title, str);
            }
            else
            {
                FileHelper.Write(TemplateParas.SaveFilePath + title, new[] { str }, SaveFileEncoding);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 生成指定单一文件
        /// </summary>
        /// <param name="o"></param>
        public void GenCode(object[] o, string language)
        {
            NVelocityHelper nVelocityHelper = new NVelocityHelper(FilePathHelper.TemplatesPath);
            Header          header          = o[0] as Header;
            Trailer         trailer         = o[0] as Trailer;
            Message         message         = o[0] as Message;
            Component       component       = o[0] as Component;
            FieldDic        field           = o[0] as FieldDic;
            string          tableName       = "";

            string path = string.Format(@"{0}", TemplateParas.TemplateName);
            //var dic = new Dictionary<string, object>();
            var dic = GetNVelocityVars();

            if (header != null)
            {
                tableName = "header";
                dic.Add("header", o[0]);
            }
            if (trailer != null)
            {
                tableName = "trailer";
                dic.Add("trailer", o[0]);
            }
            if (message != null)
            {
                tableName = message.Name;
                dic.Add("messages", o);
            }
            if (component != null)
            {
                tableName = component.Name;
                dic.Add("components", o);
            }
            if (field != null)
            {
                tableName = field.Name;
                dic.Add("fields", o);
            }

            FixHelper.FieldDics = FieldDics;
            dic.Add("FixHelper", new FixHelper());
            //dic.Add("codeGenHelper", new CodeGenHelper());
            string str   = nVelocityHelper.GenByTemplate(path, dic);
            string title = tableName + "." + (TemplateParas.CodeLanguage + "").ToLower();


            if (!string.IsNullOrEmpty(TemplateParas.SaveFileName))
            {
                title = TemplateParas.SaveFileName;
                title = nVelocityHelper.GenByStr(title, dic);
            }

            if (TemplateParas.IsShowGenCode)
            {
                CodeShow(title, str);
            }
            else
            {
                FileHelper.Write(TemplateParas.SaveFilePath + title, new[] { str }, SaveFileEncoding);
            }
        }