コード例 #1
0
 /// <summary>
 /// 生成代码文件
 /// </summary>
 /// <param name="td">元数据表定义</param>
 public void CreateAllFile(bool isCheck,TableDef td)
 {
     //生成模型代码文件
     this._CreateCodeFile(isCheck, eCreateCodeType.ModelCode, td);
     //生成操作方法代码
     if (_CurrentConf.OutputOperationSplite)
     {
         this._CreateCodeFile(isCheck, eCreateCodeType.ModelOperator, td);
     }
 }
コード例 #2
0
        public void Parsetest()
        {
            string template = "@(Model.Table.Name + \".cs\")";
            GlobalVariable par = new GlobalVariable();
            TableDef tb =new TableDef();
            tb.Name = "abc";
            string strExpected = "abc.cs";
            string result = RazorHelper.Parse(template, par, tb,"asfs");

            Assert.AreEqual(strExpected, result);
        }
コード例 #3
0
        public static string Parse(string template, GlobalVariable par, TableDef tab,string cacheName)
        {
            string result = "";

            //DynamicViewBag vb = new DynamicViewBag();
            //vb.GetDynamicMemberNames()

            TemplateServiceConfiguration config = new TemplateServiceConfiguration();
            config.BaseTemplateType = typeof(HtmlTemplateBase<>);
            TemplateService svc = new TemplateService(config);
            Razor.SetTemplateService(svc);

            result = Razor.Parse(template, new { GlobalVariable = par, Table = tab },cacheName);
            return result;
        }
コード例 #4
0
        public List<FieldDef> ObtainFields(TableDef td,string strFilter)
        {
            List<FieldDef> list = new List<FieldDef>();
            DataTable dtCol = SourceUtility.GetColumnDefinition(_strConn,strFilter);
            foreach(DataRow dr in dtCol.Rows)
            {
                FieldDef fd = new FieldDef();

                fd.Column_Id = int.Parse( dr["column_id"].ToString());
                fd.Table = td;
                fd.Name =  dr["Name"] as string ?? "";
                fd.Description = dr["Description"] as string ?? "";
                fd.RawType = dr["RawType"] as string ?? "";
                list.Add(fd);
            }

            return list;
        }
コード例 #5
0
        /// <summary>
        /// 根据输入条生成对应文件
        /// </summary>
        /// <param name="createType"></param>
        /// <param name="td"></param>
        /// <returns></returns>
        private void _CreateCodeFile(bool isCheck,eCreateCodeType createType, TableDef td)
        {
            //变化点2:
            string strOutputDir = "";
            string strFileName = "";
            string strNameSpace = "";
            string strCodeTemplate = "";

            switch (createType)
            {
                case eCreateCodeType.ModelCode:
                    strOutputDir = RazorHelper.Parse(_CurrentConf.OutputDirPattern, _CurrentPar, td,"OutputDir");
                    strFileName = RazorHelper.Parse(_CurrentConf.OutputFileNamePattern, _CurrentPar, td,"FileName");
                    strNameSpace = RazorHelper.Parse(_CurrentConf.OutputCodeNameSpacePattern, _CurrentPar, td,"CodeNameSpacePattern");
                    td.CodeNameSpace = strNameSpace;
                    strCodeTemplate = _CurrentConf.CodeTemplate;
                    td.FileName = string.Format("{0}{1}", strOutputDir, strFileName);
                    break;
                case eCreateCodeType.ModelOperator:
                    strOutputDir = RazorHelper.Parse(_CurrentConf.OutputOperationDirPattern, _CurrentPar, td,"OutputOperationDir");
                    strFileName = RazorHelper.Parse(_CurrentConf.OutputOperationFileNamePattern, _CurrentPar, td,"OutputOperationFileName");
                    strNameSpace = RazorHelper.Parse(_CurrentConf.OutputOperationCodeNameSpacePattern, _CurrentPar, td,"OutputOperationCodeNameSpace");
                    strCodeTemplate = _CurrentConf.OperatorTemplate;
                    td.OperationFileName = string.Format("{0}{1}", strOutputDir, strFileName);
                    td.OperationCodeNameSpace = strNameSpace;
                    break;
                default:
                    break;
            }
            string strFilePath = string.Format("{0}{1}", strOutputDir, strFileName);
            string strFileContent = RazorHelper.Parse(strCodeTemplate, _CurrentPar, td,createType.ToString());
            if (!isCheck)
            {
                FileHelper.WriteCodeToFile(strFilePath, strFileContent);
            }
        }
コード例 #6
0
 public List<TableDef> ObtainTables(string strFilter)
 {
     List<TableDef> list = new List<TableDef>();
     DataTable dtTab = SourceUtility.GetTableDefinition(_strConn,strFilter);
     foreach(DataRow dr in dtTab.Rows)
     {
         TableDef td = new TableDef();
         td.Object_Id = int.Parse(dr["object_id"].ToString());
         td.Name = (string ) dr["Name"];
         td.Schema = (string)dr["Schema"];
         string fieldFilter = string.Format("a.Object_Id={0}", td.Object_Id);
         List<FieldDef> fields = this.ObtainFields(td,fieldFilter);
         td.Fields = fields;
         list.Add(td);
     }
     return list;
 }