예제 #1
0
        public async Task RenderAsync(CancellationToken cancellationToken = default)
        {
            var mapper = new MainModelMapper();

            var synonymViewModels = Synonyms.Select(s => mapper.Map(s, SynonymTargets)).ToList();
            var synonymsVm        = new Synonyms(synonymViewModels);

            var renderedMain = await Formatter.RenderTemplateAsync(synonymsVm, cancellationToken).ConfigureAwait(false);

            var databaseName = !IdentifierDefaults.Database.IsNullOrWhiteSpace()
                ? IdentifierDefaults.Database + " Database"
                : "Database";
            var pageTitle     = "Synonyms · " + databaseName;
            var mainContainer = new Container(renderedMain, pageTitle, string.Empty);
            var renderedPage  = await Formatter.RenderTemplateAsync(mainContainer, cancellationToken).ConfigureAwait(false);

            if (!ExportDirectory.Exists)
            {
                ExportDirectory.Create();
            }
            var outputPath = Path.Combine(ExportDirectory.FullName, "synonyms.html");

            using var writer = File.CreateText(outputPath);
            await writer.WriteAsync(renderedPage.AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.FlushAsync().ConfigureAwait(false);
        }
예제 #2
0
        public async Task RenderAsync(CancellationToken cancellationToken = default)
        {
            var mapper = new MainModelMapper();

            var columns         = 0U;
            var constraints     = 0U;
            var indexesCount    = 0U;
            var tableViewModels = new List <Main.Table>();

            foreach (var table in Tables)
            {
                if (!RowCounts.TryGetValue(table.Name, out var rowCount))
                {
                    rowCount = 0;
                }

                var renderTable = mapper.Map(table, rowCount);

                var uniqueKeyLookup = table.GetUniqueKeyLookup();
                var uniqueKeyCount  = uniqueKeyLookup.UCount();

                var checksLookup = table.GetCheckLookup();
                var checksCount  = checksLookup.UCount();

                var indexesLookup = table.GetIndexLookup();
                var indexCount    = indexesLookup.UCount();
                indexesCount += indexCount;

                await table.PrimaryKey.IfSomeAsync(_ => constraints++).ConfigureAwait(false);

                constraints += uniqueKeyCount;
                constraints += renderTable.ParentsCount;
                constraints += checksCount;

                columns += renderTable.ColumnCount;

                tableViewModels.Add(renderTable);
            }

            var viewViewModels = Views.Select(mapper.Map).ToList();

            columns += (uint)viewViewModels.Sum(v => v.ColumnCount);

            var sequenceViewModels = Sequences.Select(mapper.Map).ToList();

            var synonymTargets    = new SynonymTargets(Tables, Views, Sequences, Synonyms, Routines);
            var synonymViewModels = Synonyms.Select(s => mapper.Map(s, synonymTargets)).ToList();

            var routineViewModels = Routines.Select(mapper.Map).ToList();

            var schemas = Tables.Select(t => t.Name)
                          .Union(Views.Select(v => v.Name))
                          .Union(Sequences.Select(s => s.Name))
                          .Union(Synonyms.Select(s => s.Name))
                          .Union(Routines.Select(r => r.Name))
                          .Select(n => n.Schema)
                          .Where(n => n != null)
                          .Distinct()
                          .Where(s => s != null)
                          .Select(s => s !)
                          .OrderBy(n => n)
                          .ToList();

            var templateParameter = new Main(
                Database.IdentifierDefaults.Database,
                DatabaseDisplayVersion ?? string.Empty,
                columns,
                constraints,
                indexesCount,
                schemas,
                tableViewModels,
                viewViewModels,
                sequenceViewModels,
                synonymViewModels,
                routineViewModels
                );

            var renderedMain = await Formatter.RenderTemplateAsync(templateParameter, cancellationToken).ConfigureAwait(false);

            var databaseName = !Database.IdentifierDefaults.Database.IsNullOrWhiteSpace()
                ? Database.IdentifierDefaults.Database + " Database"
                : "Database";
            var pageTitle     = "Home · " + databaseName;
            var mainContainer = new Container(renderedMain, pageTitle, string.Empty);
            var renderedPage  = await Formatter.RenderTemplateAsync(mainContainer, cancellationToken).ConfigureAwait(false);

            if (!ExportDirectory.Exists)
            {
                ExportDirectory.Create();
            }
            var outputPath = Path.Combine(ExportDirectory.FullName, "index.html");

            using var writer = File.CreateText(outputPath);
            await writer.WriteAsync(renderedPage.AsMemory(), cancellationToken).ConfigureAwait(false);

            await writer.FlushAsync().ConfigureAwait(false);
        }