Ejemplo n.º 1
0
        public async Task RenderAsync(CancellationToken cancellationToken = default)
        {
            var mapper = new TriggerModelMapper();

            var triggers   = Tables.SelectMany(t => t.Triggers.Select(tr => mapper.Map(t.Name, tr))).ToList();
            var triggersVm = new Triggers(triggers);

            var renderedTriggers = await Formatter.RenderTemplateAsync(triggersVm, cancellationToken).ConfigureAwait(false);

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

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

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

            await writer.FlushAsync().ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public async Task RenderAsync(CancellationToken cancellationToken = default)
        {
            var mapper = new TriggerModelMapper();

            var triggerTasks = Tables.SelectMany(table =>
            {
                var outputDirectory = Path.Combine(
                    ExportDirectory.FullName,
                    table.Name.ToSafeKey(),
                    "triggers"
                    );

                return(table.Triggers.Select(async trigger =>
                {
                    if (!Directory.Exists(outputDirectory))
                    {
                        _ = Directory.CreateDirectory(outputDirectory);
                    }

                    var triggerModel = mapper.Map(table.Name, trigger);
                    var outputPath = Path.Combine(outputDirectory, trigger.Name.ToSafeKey() + ".html");

                    var renderedTable = await Formatter.RenderTemplateAsync(triggerModel, cancellationToken).ConfigureAwait(false);

                    var pageTitle = trigger.Name.ToVisibleName() + " · Trigger · " + table.Name.ToVisibleName();
                    var container = new Container(renderedTable, pageTitle, "../../../");
                    var renderedPage = await Formatter.RenderTemplateAsync(container, cancellationToken).ConfigureAwait(false);

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

            await Task.WhenAll(triggerTasks).ConfigureAwait(false);
        }