コード例 #1
0
ファイル: MsSqlDb.cs プロジェクト: smolsoft/DbRedmineDoc
        public DbObjectsList GetTables(DbObjectsList list)
        {
            foreach (DbObject d in GetTablesList(list))
            {
                // init tables as empty
                foreach (string name in setTable)
                {
                    d.AddTable(name);
                }

                // read FK cols
                Dictionary <string, string> FKs = GetFKsList(d);

                // read columns
                FillTable(T_COLUMNS, string.Format(qTableColumns, d.Name), (r, table) =>
                {
                    string colName = r.GetString(1);
                    d.AddTableRow(table, new (string, string)[]
                    {
                        ("col_i", r.GetInt32(0).ToString()),
                        ("col_name", colName),
                        ("col_type", r.GetString(2)),
                        ("col_size", r.IsDBNull(3) ? "" : r.GetInt32(3).ToString()),
                        ("col_fk", FKs.ContainsKey(colName) ? "FK: " + markup.MakeWikiLink(FKs[colName]) : "")
                    });
コード例 #2
0
        static void Main(string[] args)
        {
            // init config
            Config cfg = new Config();
            IConfigurationBuilder builder = new ConfigurationBuilder()
                                            .SetBasePath(Directory.GetCurrentDirectory())
                                            .AddJsonFile("config.json");

            var devEnvironmentVariable = Environment.GetEnvironmentVariable("NETCORE_ENVIRONMENT");
            var isDevelopment          = string.IsNullOrEmpty(devEnvironmentVariable) ||
                                         devEnvironmentVariable.ToLower() == "development";

            if (isDevelopment)
            {
                builder.AddUserSecrets <Program>();
            }

            IConfigurationSection configSection = builder.Build().GetSection("config");

            configSection.Bind(cfg);

            // init services
            IWiki   wiki   = new Redmine(cfg.RedmineKey, cfg.RedmineRoot);
            IMarkup markup = new TextileMarkup();

            // init DB adapters
            MsSqlDb    db  = new MsSqlDb(cfg.DbConnectionString, markup);
            GitSources git = new GitSources(cfg.GitRootPath, cfg.GitSourcesMask, markup);

            // init wiki sections
            DbObjectsList tables   = new DbObjectsList("Таблицы_AICS_AreaPassport", "table.txt");
            DbObjectsList routines = new DbObjectsList("Программы_AICS_AreaPassport", "routine.txt");

            // collect data
            db.GetTables(tables);
            db.GetRoutines(routines);
            git.AddCallers(routines);

            // save to wiki
            Task.WaitAll(
                SaveSection(tables, wiki),
                SaveSection(routines, wiki));
        }
コード例 #3
0
        private static async Task <bool> SaveSection(DbObjectsList list, IWiki wiki)
        {
            TemplateFiller tf = new TemplateFiller();

            // table of contents
            var section = await wiki.GetWikiPage(list.WikiSection);

            string toc = tf.FillTocTemplate(File.ReadAllText($"Templates/toc_{list.TemplateName}"), list,
                                            (desc, line) => !section.content.Contains(line));

            if (!string.IsNullOrEmpty(toc))
            {
                await wiki.SetWikiPage(list.WikiSection, section.content + Environment.NewLine + toc, null);
            }

            // pages for each object
            string template = File.ReadAllText($"Templates/{list.TemplateName}");

            foreach (var i in list)
            {
                var currentPage = await wiki.GetWikiPage(i.Name);

                if (string.IsNullOrEmpty(currentPage.content)) // create page
                {
                    await wiki.SetWikiPage(i.Name, tf.FillTemplate(template, i), list.WikiSection);
                }
                else if (i.LastUpdated > currentPage.updated) // update page
                {
                    await wiki.SetWikiPage(i.Name, tf.MergeTemplate(template, i, currentPage.content), list.WikiSection);
                }
                else
                {
                    ;// nothing changed - skip page
                }
            }
            return(true);
        }
コード例 #4
0
ファイル: GitSources.cs プロジェクト: smolsoft/DbRedmineDoc
        public DbObjectsList AddCallers(DbObjectsList list)
        {
            foreach (DbObject d in list)
            {
                d.AddTable("git_source");
                d["codeCalls"] = "0";
            }

            var files = GetFiles(projectRoot);

            char[] mustStartWith = new char[] { ' ', '[', '.' };
            char[] mustEndWith   = new char[] { ' ', ']', '(' };
            foreach (var file in files)
            {
                var    content = File.ReadAllText(file);
                string gitPath = file.Substring(projectRoot.Length);
                foreach (DbObject d in list)
                {
                    int    pos  = content.IndexOf(d.Name);
                    string prev = pos > 0 ? content.Substring(pos - 1, 1) : "";
                    string next = pos >= 0 && pos + d.Name.Length + 1 < content.Length ? content.Substring(pos + d.Name.Length, 1) : "";
                    if (pos > 0 && prev.Trim(mustStartWith) == "" && next.Trim(mustEndWith) == "")
                    {
                        d.AddTableRow("git_source", new (string, string)[] { ("file", markup.MakeSourceLink(gitPath)) });
コード例 #5
0
        public string FillTocTemplate(string template, DbObjectsList list, Func <DbObject, string, bool> include)
        {
            StringBuilder result = new StringBuilder(template);

            (string toReplace, string rowTemplate) = GetRowTemplate(template, "_toc_");
            result.Replace(toReplace, "");
            foreach (var i in list)
            {
                StringBuilder strRow = new StringBuilder(rowTemplate);
                foreach (var col in i.Keys)
                {
                    strRow.Replace(Place(col), i[col]);
                }
                string line = strRow.ToString();
                if (include(i, line))
                {
                    result.AppendLine(strRow.ToString());
                }
            }

            string resultBuilded = result.ToString();

            return(template.Length < resultBuilded.Length ? resultBuilded : string.Empty);
        }