Wiki

Clone wiki

SortingV2 / TraceControl

Home

#TraceControl

The TraceControl project focuses on the trace modes of the service. It allows us to select which mode is active, as well as control the output from the gathered trace data.

By using an intermixing of meta factories, tracer types and formatters, we are able to create several different modes of trace data extraction

TraceMode Factory Type ITracer Type Formatter Output
NoTrace MetaFactory n/a n/a n/a
Count TraceMetaFactory CountTracerFormatted n/a to console
XML TraceMetaFactory Tracer default to xml file
XML Small TraceMetaFactory Tracer XmlSmall to xml file
HTML TraceMetaFactory Tracer HTML to html file
Count Data DataSetTraceMetaFactory CountTracerFormatted n/a to console
XML Small Data DataSetTraceMetaFactory Tracer XmlSmall to xml file

##TraceController The TraceController contains all of the available TraceModes, determines which trace mode is actually active, and acts as a central point from which to request the active set of factories.

###Properties ####public int Setting { get; } Returns the integer value indicating what trace mode is currently active.

###Methods ####public bool UpdateSetting(int newSetting) Selects a new trace mode to be active. This will cause a new tracer and factory set to be generated.

####public ITraceControl AddTraceMode(ITraceMode traceMode) Allows a new ITraceNode to be injected into the controller.

####public MetaFactory GetFactories() Retrieves the currently active factory set. This method will return the same set of factories (and tracer) until something causes the factories or tracer to be reset.

####public ITraceControl RefreshFactories() Forces a new set of factories to be generated.

####public string GetTraceData(string sortName, string dataOrder) Retrieves the trace data that will be displayed in the console. If the trace mode writes a file to disk, then the returned string will contain the file path and name written to.

##TraceModes The TraceModes are how we define which factory set, tracer type, formatter, and output is going to be used when a specific mode is selected. Each mode implements the ITraceMode.

##ITraceMode Each Trace Mode implements the ITraceMode interface. It is here we define the specific factory, tracer type and output that the trace mode will use.

###string Name { get; } The name of the trace mode.

###ITracer Tracer { get; } The tracer that will be used when the trace mode is active. Will be null if no tracer is active,

###NodeFormatter Formatter { get; } The formatter that will be used to format the trace data. Will be null if no formatter is used.

###string FileType { get; } Provides the file type extension for trace modes that write files to disk. Will be null If the trace mode does not write data to disk.

###MetaFactory Factories { get; } Returns the MetaFactory or TraceMetaFactory according to the trace mode. If the mode does trace data, then a new tracer will be created, as well as a new TraceMetaFactory that contains the tracer.

###string GetTraceData(string sortName, string dataOrder) Retrieves the trace data. If the trace mode writes to disk, then the file path and file name will be returned.

##Factory Types There are three different sets of factories used in the simulated service.

###MetaFactory Each of the factories that create functional versions of the DataSet or Sorting routines are contained inside the MetaFactory.

The MetaFactory has two constructors, one protected, and the other static. The protected constructor sets the various fields that contain the factories for the DataSet and Sorting classes.

The purpose of the static constructor is to contain all of the dependency injection necessary for the MetaFactory to be able to construct whatever needs to be constructed. For example, if we look at the code, then we will see that, in this case, that the InsertSortFactory is also used as a parameter for the QuickInsertSortFactory. Once all of the interdependencies are resolved, the protected constructor is called to create the MetaFactory proper.

Once constructed, all of the factories will be available via get only properties. Note: none of the properties are virtual.

Note: the MetaFactory is what would be used by default in a real service or application.

###TraceMetaFactory The TraceMetaFactory contains all of the factories that produce trace versions of the classes. We use the TraceMetaFactory when we want to trace every class that is used in the service call.

The TraceMetaFactory is derived from the MetaFactory. This allows the TraceMetaFactory to replace the MetaFactory, and thus transparently change which factories are being used during a service call.

Once again, there is a protected and static constructor. The protected constructor does two things: it calls the constructor of the MetaFactory class, and sets the ITracer instance. The static constructor, once again, creates all the necessary trace factories, resolves their interdependencies, and then calls the protected constructor to create the TraceMetaFactory.

Note: the ITracer is passed in as an argument of the the static constructor. This allows us to use different tracers as needed.

###DataSetTraceMetaFactory This factory set is a partial step between the MetaFactory and the TraceMetaFactory. Where as the TraceMetaFactory provides trace factories for every class, this factory set only provides tracing for the DataSet. All of the other factories provide the standard functional classes.

The purpose of this meta factory is to illustrate that we do not need to have tracing 100% on or off. Instead, we can have multiple levels of tracing.

##ITracer Types The TraceMetaFactory and DataSetTraceMetaFactory bot take an ITracer as an parameter during construction. This allows us to choose between different tracer types, and thus tailor the trace data that is collected.

###Tracer This is simply the Tracer class that is a default part of the Traceability library. It collects detailed data about each method and property called during execution of the service call.

###CountTracerFormatted This is a child version of the CountTracer that is part of the Traceability library. The child class extracts specific data from the CountTracer, formats it for console output, and then returns the formatted text as a string.

##Formatters The formatters are discussed in the Formatters page.

Updated