bbv.Common.Bootstrapper Tutorial Part 6

The reporting mechanism allows creating a full report of the bootstrapping process. To be able to report the bootstrapping process the process must actually run and a reporter must be present. By default the bootstrapper uses a null reporter which does nothing with the report. But it is also possible to hook in a report generator which creates Visio, Enterprise Architect or … (you name it!) diagrams.

A custom reporter must implement the reporter interface IReporter. The reporter receives an IReportingContext which contains all necessary information about the bootstrapping process. The custom reporter must be passed upon the construction of the DefaultBootstrapper<TExtension>.

        new DefaultBootstrapper<ICustomExtension>( /* Input your IReporter */ )

The reporting context is structured like the following:

An example of a reporter which reports all into a string could look like:

        public class StringReporter : IReporter
        {
            private IReportingContext context;

            public void Report(IReportingContext context)
            {
                this.context = context;
            }

            public override string ToString()
            {
                return Dump(this.context);
            }

            private static string Dump(IReportingContext context)
            {
                var builder = new StringBuilder();

                context.Extensions.ForEach(e => Dump(e.Name, e.Description, builder, 0));

                Dump(context.Run, builder);
                Dump(context.Shutdown, builder);

                return builder.ToString();
            }

            private static void Dump(IExecutionContext executionContext, StringBuilder sb)
            {
                Dump(executionContext.Name, executionContext.Description, sb, 3);

                Dump(executionContext.Executables, sb);
            }

            private static void Dump(IEnumerable<IExecutableContext> executableContexts, StringBuilder sb)
            {
                foreach (IExecutableContext executableContext in executableContexts)
                {
                    Dump(executableContext.Name, executableContext.Description, sb, 6);

                    executableContext.Behaviors.ForEach(b => Dump(b.Name, b.Description, sb, 9));
                }
            }

            private static void Dump(string name, string description, StringBuilder sb, int indent)
            {
                sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "{0}[Name = {1}, Description = {2}]", string.Empty.PadLeft(indent), name, description));
            }
        }

Restrictions: In the version 1.0 of the bootstrapper there is a limitation for lazy resolved behaviors. Lazy resolved behaviors do not report as the actual behavior but as a LazyBehavior type. Hope I can resolve this in the feature version.

Happy reporting!

About the author

Daniel Marbach

Add comment

By Daniel Marbach

Recent Posts