Difference between revisions of "Tabulation Script"
m (add breadscrump) |
m |
||
Line 1: | Line 1: | ||
− | [[New Report Design 2009]] => [[Tabulation Script]] | + | [[New Report Design - 2009]] => [[Tabulation Script]] |
== Tabulation Script == | == Tabulation Script == |
Revision as of 08:29, 30 July 2009
New Report Design - 2009 => Tabulation Script
Contents
Tabulation Script
Tabulation Script is a CGScript library allowing user to create diagram/report. It's also capable of setting stylesheet (both external and internal).
Some classes
- CGScript_System_Report: CGScript library implementation, contains all entry points to diagram/report generation process
- TabulationModuleUtilities: contains utility methods
- DiagramUtilities: also contains utility methods
- TabulationDiagram: wrapper class for the REAL report diagram
- TabulationConfiguration: contains all result of tabulation diagram (the name ??!!!!)
Understanding tabulation script processing
The processing of tabulation script can be understand as below:
- Create new Interpreter (which create also an instance of TabulationConfiguration as properties named TabulationConfig )
- Run the tabulation script => the result diagrams (if any) is stored inside DiagramCharts variable of TabulationConfiguration
- If has to show result, get the result diagram objects from DiagramCharts and set to session
- Show a SPECIFIC viewer that takes diagram objects from session and draw on screen (why do we need a SPECIFIC viewer?)
Injecting new processing with least impact
Moving script location
Due to the fact that tabulation script belongs to REPORT DOMAIN rather RUNTIME DOMAIN, it MUST be in the same assembly with REPORT. And to not change so much at the same time, the file CGScript_System_Report is 'copied' to CatGlobe.Report assembly under folder Script. The namespace was also changed to CatGlobe.Framework.Report.Script.
CGScript engine is designed to hide all unnecessary information from the outside (good point). But we need references to some internal classes in order to implement a CGScriptLibrary. Thus, the CatGlobe assembly must be internal visible to CatGlobe.Report.
And, there must be a factory method for getting Interpreter that can support for report:
public static class ScriptLibraryHelper
{
public static Interpreter GetReportInterpreter(this DataCacheSpecification dataCache)
{
return new Interpreter(new[] { CGScript_System_Report.Instance })
{
DataCacheSpecification = dataCache,
};
}
}
That's mean, with a appropriate using statement, we can create report's interpreter as below:
DataCacheSpecification dcs = DataCacheSpecification.GetBy(1);
Interpreter cgsEngine = dcs.GetReportInterpreter();
Point of injections
TabulationDiagram
As shown in processing of tabulation script section above, the main idea of TabulationDiagram is that it is created with enough information for generating a domain's diagram instance, but that instance is created whenever needed only.
So, to inject our processing with least painful, I decided to create a diagram creating delegate. The delegate type is declared in DiagramUtility class (CatGlobe assembly) but the implementation is inside CatGlobe.Report assembly. After all, the instance of the delegate will be passed to CatGlobe from CatGlobe.Report during execution of a tabulation script. And the TabulationDiabram is changed as below:
public Diagram InternalDiagram
{
get
{
if (this.internalDiagram == null)
this.CreateInternalDiagram();
return this.internalDiagram;
}
set { this.internalDiagram = value; }
}
private void CreateInternalDiagram()
{
...
InternalDiagram = DiagramFactoryMethod != null
? DiagramFactoryMethod(this.ReportTemplate, this.ChartName, DiagramType.CrossDiagram, this.ChartType, string.Empty, this.Parameter)
: DiagramUtilities.CreateDiagram(this.ReportTemplate
, this.CrossStruct
, this.ChartName
, this.Generator.Header
, this.Generator.Title
, this.Generator.Parameter.ChartType
, DiagramType.CrossDiagram
, subtitle1, string.Empty, string.Empty);
...
}
It can be understood as if there is a custom diagram generating delegate, use that. Otherwise, use the default method.
CatGlobe.Report's code
First of all, we need an implementation of the diagram generating delegate:
// CatGlobe.Report assembly
public static class DomainDiagramFactory
{
public static Domain.Reports.Diagram CreateDiagram(
ReportTemplate template, string chartName, DiagramType diagramType,
ChartType chartType, string weight, Parameter parameter)
}
Then, we need to transfer above delegate instance to CatGlobe assembly;
internal sealed class CGScript_System_Report : CGScriptLibrary
{
private static int CreateDiagram(List<Axis> columns, List<Axis> rows, FunctionIdentifier function)
{
...
TabulationDiagram diagram = TabulationModuleUtilities.CreateDiagramObject(crossStruct, config, DomainDiagramFactory.CreateDiagram);
...
}
}
Document revisions
Version No. | Date | Changed By | Description |
0.1 | 23.07.2009 | Nguyen Trung Chinh | Create the first version |