예제 #1
0
        public bool Build(string _codefilesavepath, string guid)
        {
            try
            {
                string templateFileName;//= Path.GetFileName(_template_name);
                string templateDirPath;
                templateFileFullPath = GetTemplateInfo(_template_name, out templateDirPath, out templateFileName);
                List <ITableSchema> allTables    = GetAllTableSchema(_setting, _tables, guid);
                ITableSchema        currentTable = allTables.Find(it => it.Name.Equals(_table_name));
                this.Constant.TemplateName = templateFileName;
                TemplateResolver th   = new TemplateResolver(templateDirPath);
                xUtils           util = new xUtils();
                th.Put("Tables", allTables);
                th.Put("Table", currentTable);
                th.Put("Utils", util);
                th.Put("Const", this.Constant);
                if (ContainRows(templateFileFullPath))
                {
                    var fac = DatabaseResolver.GetDataFactory(this._setting);
                    th.Put("Rows", fac.GetTableData(this._table_name).ToDynamic());
                }
                string text = th.BuildString(templateFileName);

                var    customerDefine = BlockCommentDictionary(text);
                string filename       = util.ToPascalCase(_table_name) + ".generate.cs";
                if (customerDefine.Count > 0 && customerDefine.ContainsKey("filename"))
                {
                    filename = customerDefine["filename"];
                }

                if (!Directory.Exists(_codefilesavepath))
                {
                    Directory.CreateDirectory(_codefilesavepath);
                }
                string fullsavefilename = _codefilesavepath + "/" + filename;
                if (File.Exists(fullsavefilename))
                {
                    File.Delete(fullsavefilename);
                }
                File.AppendAllText(fullsavefilename, text);
                return(true);
            }
            catch (Exception ex)
            {
                this.ExceptionMessage = ex.Message;
                LogText(string.Concat(Environment.NewLine, ex.StackTrace));
                return(false);
            }
        }
예제 #2
0
        private static List <ITableSchema> GetAllTableSchema(Entities.ConnectionSetting setting, string[] tables, string guid)
        {
            if (tableSchemas.Count > 0 && flag == guid)
            {
                return(tableSchemas);
            }
            flag = guid;
            int count = tables.Length;
            int step  = 100 % count == 0 ? 100 / count : 100 / count + 1;

            tableSchemas.Clear();
            foreach (string name in tables)
            {
                DataFactory  fac = DatabaseResolver.GetDataFactory(setting);
                ITableSchema its = fac.GetTableSchema(name);
                tableSchemas.Add(its);
                ExtendFunctions.OnProcess(step);
            }
            return(tableSchemas);
        }