Example #1
0
    public static void Enrich(
        Profile profile,
        ProfileEnrichment settings,
        IDictionary <string, string>?environmentVariables)
    {
        if (profile is null)
        {
            throw new ArgumentNullException(nameof(profile));
        }

        settings ??= new ProfileEnrichment();

        var variables = GetEnvironmentVariables(environmentVariables);

        foreach (var enricher in GetEnrichers(settings))
        {
            if (string.IsNullOrWhiteSpace(enricher.Name))
            {
                throw new InvalidOperationException($"Profile enricher of type '{enricher.GetType().FullName}' does not have a name.");
            }

            if (enricher.Enabled(variables))
            {
                enricher.Enrich(profile);
                profile.AddEnricher(enricher.Name);
            }
        }
    }
Example #2
0
    private static List <IProfileEnricher> GetEnrichers(ProfileEnrichment settings)
    {
        var enrichers = new List <IProfileEnricher>();

        if (settings.UseDefaultEnrichers)
        {
            enrichers.AddRange(_defaultEnrichers);
        }

        if (settings.Enrichers?.Count > 0)
        {
            enrichers.AddRange(settings.Enrichers);
        }

        return(enrichers);
    }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnsiConsoleSettings"/> class.
 /// </summary>
 public AnsiConsoleSettings()
 {
     Enrichment = new ProfileEnrichment();
 }