Created
March 6, 2009 19:43
-
-
Save sonukapoor/75035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class RenderUnit | |
' 1 inch = 72 points | |
Public WidthPoints As Integer | |
Public HeightPoints As Integer | |
Public Items As IEnumerable | |
Public FileName As String | |
End Class | |
Public Interface IPDFLayout | |
Function Layout() As RenderUnit | |
End Interface | |
Public Interface IPDFLayoutHandler | |
Function GeneratePDF(ByVal renderUnit As RenderUnit) As String | |
End Interface | |
Public Class PDFGenerator | |
Private ReadOnly layout As IPDFLayout | |
Private ReadOnly layoutHandler As IPDFLayoutHandler | |
Private ReadOnly dataSource As IDataSource | |
Public Sub New(ByVal layout As IPDFLayout, ByVal layoutHandler As IPDFLayoutHandler, ByVal dataSource As IDataSource) | |
Me.layout = layout | |
Me.layoutHandler = layoutHandler | |
Me.dataSource = dataSource | |
End Sub | |
Public Function Generate() As String | |
Dim renderUnit As RenderUnit = layout.Layout() | |
renderUnit.Items = dataSource.GetData() | |
Return layoutHandler.GeneratePDF(renderUnit) | |
End Function | |
End Class | |
''''''''''''''''''''' REGISTRY ''''''''''''''''''''' | |
Imports StructureMap | |
Public Class MannequinRegistry | |
Inherits Configuration.DSL.Registry | |
Public Sub New() | |
ForRequestedType(Of IPDFLayout).TheDefault.Is.OfConcreteType(Of USCanadaLayout)() | |
ForRequestedType(Of IDataTransformer).TheDefault.Is.OfConcreteType(Of MannequinDataTransformer)().WithName("English").WithCtorArg("language").EqualTo("English") | |
ForRequestedType(Of IDataTransformer).TheDefault.Is.OfConcreteType(Of MannequinDataTransformer)().WithName("French").WithCtorArg("language").EqualTo("French") | |
ForRequestedType(Of IPDFLayoutHandler).TheDefault.Is.OfConcreteType(Of MannequinLayoutHandler)() | |
End Sub | |
End Class | |
''''''''''''''''''''' TRANSFORMER ''''''''''''''''''''' | |
Imports System.Collections.Generic | |
Public Class MannequinDataTransformer | |
Implements IDataTransformer | |
Private _language As String | |
Public Sub New(ByVal language As String) | |
_language = language | |
End Sub | |
Public Function Transform(ByVal datasource As IDataSource) As IDataSource Implements IDataTransformer.Transform | |
Dim items As Dictionary(Of String, Object)() = datasource.GetData() | |
Dim si As StyleInfo = Nothing | |
Dim alu As String = String.Empty | |
For Each item As Dictionary(Of String, Object) In items | |
alu = item("ALU") | |
si = PrintCards.GetDescriptionColorByALU(alu, _language) | |
item("Description") = si.Description | |
item("ColorName") = si.ColorName | |
item("Price") = PrintCards.GetPriceByALU(alu) | |
Next | |
Return datasource | |
End Function | |
End Class | |
''''''''''''''''''''' USAGE ''''''''''''''''''''' | |
<WebMethod()> _ | |
Public Function PrintCart(ByVal items As Dictionary(Of String, Object)(), ByVal language As String) As String | |
Dim layout As IPDFLayout = ObjectFactory.GetInstance(Of IPDFLayout)() | |
Dim layoutHandler As IPDFLayoutHandler = ObjectFactory.GetInstance(Of IPDFLayoutHandler)() | |
Dim dataSource As IDataSource = New MannequinDataSource(items) | |
Dim transformer As IDataTransformer = ObjectFactory.GetNamedInstance(Of IDataTransformer)(language) | |
dataSource = transformer.Transform(dataSource) | |
Dim generator As New PDFGenerator(layout, layoutHandler, dataSource) | |
Return generator.Generate() | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment