Ejemplo n.º 1
0
        public static void OutputEnum(Dictionary <string, TableMetaData> tables, GlobalConfiguration config, IProgressBar progress = null)
        {
            ResetProgress(progress);
            var path = Path.Combine(config.OutputBasePath, "Enum");

            Directory.CreateDirectory(path);

            BaseEnumGenerator g = new EnumGenerator(config);
            // 解析
            var i  = 0;
            var sb = new StringBuilder();

            foreach (var key in tables.Keys)
            {
                var table = tables[key];
                if (config.ExcludeTables != null && config.ExcludeTables.Any(p => p.Name == table.Name))
                {
                    continue;
                }

                foreach (var column in table.Columns)
                {
                    if (g.CanGenerateEnum(table, column))
                    {
                        sb.AppendLine(g.RenderEnumFor(table, column));
                        File.AppendAllText(Path.Combine(path, string.Format("{0}.cs", g.FileName)), sb.ToString());
                        sb.Clear();
                    }
                }
                PrintProgress(progress, ++i, tables.Count);
            }

            // 拷贝公用文件到指定目录
            DirHelper.CopyDirectory(Path.Combine("CopyFiles", "Enum"), path);
        }
Ejemplo n.º 2
0
        public static void OutputEnum(SQLMetaData config, bool enableProgress = true)
        {
            var path = Path.Combine(_basePath, "Enum");

            Directory.CreateDirectory(path);

            ConsoleProgressBar progress = null;

            if (enableProgress)
            {
                progress = GetProgressBar();
            }

            var sb = new StringBuilder();
            var g  = new EnumGenerator(config);
            // 解析
            var regex = new Regex(@"(?<=\[)[^\]]+(?=\])", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            for (int i = 0; i < config.Tables.Count; i++)
            {
                var table = config.Tables[i];
                if (config.ExceptTables.Contains(table.Name))
                {
                    continue;
                }

                foreach (var column in table.Columns)
                {
                    if (!string.IsNullOrWhiteSpace(column.Comment))
                    {
                        var match = regex.Match(column.Comment);
                        if (match.Success)
                        {
                            var comment   = match.Value.Replace(":", " ").Replace("、", " ").Replace("。", " ").Replace(";", " ").Replace(".", " ").Replace(";", " ").Replace(":", " ");
                            var tempname  = Regex.Replace(table.Name, @"\d", "").Replace("_", "");
                            var enum_name = string.Format("{0}_{1}_{2}", tempname, column.Name, "Enum");
                            if (_exist_enum.Contains(enum_name))
                            {
                                continue;
                            }
                            var arrs = comment.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            sb.Append(config.Model_HeaderNote);
                            sb.Append(string.Join(Environment.NewLine, config.Model_Using));
                            sb.AppendLine();
                            sb.AppendLine();
                            sb.AppendLine(string.Format("namespace {0}.{1}", _project, "GenEnum"));
                            sb.AppendLine("{");
                            sb.AppendLine(g.Get_Enum(enum_name, arrs));
                            sb.AppendLine("}");
                            File.AppendAllText(Path.Combine(path, string.Format("{0}.cs", enum_name)), sb.ToString());
                            sb.Clear();
                            _exist_enum.Add(enum_name);
                        }
                    }
                }

                if (progress != null)
                {
                    // 打印进度
                    ProgressPrint(progress, (i + 1), config.Tables.Count);
                }
            }

            // 拷贝公用文件到指定目录
            DirHelper.CopyDirectory(Path.Combine("CopyFiles", "Enum"), path);
        }