-
Notifications
You must be signed in to change notification settings - Fork 0
/
PdfDocumentStampingAppBuilder.cs
169 lines (130 loc) · 6.22 KB
/
PdfDocumentStampingAppBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.IO;
using Autofac;
using Autofac.Extras.DynamicProxy;
using Castle.DynamicProxy;
using PdfDocumentStamperInterfaces;
using PdfDocumentStampingConsoleApp.ErrorHandling;
using PdfDocumentStampingConsoleApp.InputSources;
using PdfDocumentStampingConsoleApp.InputSources.Console;
using PdfDocumentStampingConsoleApp.Stamping.Commands.Sources;
using PdfDocumentStampingConsoleApp.Stamping.Objects.Barcodes;
using PdfDocumentStampingConsoleApp.Stamping.Objects.Barcodes._1D;
using PdfDocumentStampingConsoleApp.Stamping.Objects.Barcodes._1D.Generating;
using PdfDocumentStampingConsoleApp.Stamping.Objects.Barcodes._2D.QRCodes;
using PdfDocumentStampingConsoleApp.Stamping.Objects.Barcodes._2D.QRCodes.Generating;
using PdfDocumentStampingConsoleApp.Stamping.Objects.Images;
using PdfSharpPdfDocumentStamping;
using ILinearBarcodeGenerator = PdfDocumentStampingConsoleApp.Stamping.Objects.Barcodes._1D.Generating.ILinearBarcodeGenerator;
using IQRCodeGenerator = PdfDocumentStampingConsoleApp.Stamping.Objects.Barcodes._2D.QRCodes.Generating.IQRCodeGenerator;
namespace PdfDocumentStampingConsoleApp
{
internal partial class PdfDocumentStampingApp
{
public class PdfDocumentStampingAppBuilder
{
private ContainerBuilder containerBuilder = new ContainerBuilder();
public PdfDocumentStampingAppBuilder WithConsoleErrorHandling()
{
containerBuilder.Register(r => new ApplicationErrorHandler(Console.Out));
return this;
}
public PdfDocumentStampingAppBuilder WithCommandLineArgsStampingOptions(string[] args)
{
containerBuilder
.RegisterType<PdfDocumentStampingOptionsCommandLineArgs>()
.As<IPdfDocumentStampingOptionsInputSource>()
.WithParameter(new TypedParameter(typeof(string[]), args));
return this;
}
public PdfDocumentStampingAppBuilder WithStandardStampers()
{
WithStandardPdfDocumentBarcodeStampers();
WithStandardPdfDocumentImageStamper();
return this;
}
private PdfDocumentStampingAppBuilder WithStandardPdfDocumentBarcodeStampers()
{
WithStandardPdfDocumentLinearBarcodeStamper();
WithStandardPdfDocumentQRCodeStamper();
return this;
}
private PdfDocumentStampingAppBuilder WithStandardPdfDocumentLinearBarcodeStamper()
{
WithStandardLinearBarcodeGenerator();
WithStandardPdfDocumentStamper();
containerBuilder.RegisterType<StandardPdfDocumentLinearBarcodeStamper>().As<IPdfDocumentLinearBarcodeStamper>();
return this;
}
private PdfDocumentStampingAppBuilder WithStandardLinearBarcodeGenerator()
{
containerBuilder.RegisterType<StandardLinearBarcodeGenerator>().As<ILinearBarcodeGenerator>();
return this;
}
public PdfDocumentStampingAppBuilder WithStandardPdfDocumentQRCodeStamper()
{
WithStandardQRCodeGenerator();
WithStandardPdfDocumentStamper();
containerBuilder.RegisterType<StandardPdfDocumentQRCodeStamper>().As<IPdfDocumentQRCodeStamper>();
return this;
}
public PdfDocumentStampingAppBuilder WithStandardQRCodeGenerator()
{
containerBuilder.RegisterType<StandardQRCodeGenerator>().As<IQRCodeGenerator>();
return this;
}
public PdfDocumentStampingAppBuilder WithStandardPdfDocumentImageStamper()
{
WithStandardPdfDocumentStamper();
containerBuilder.RegisterType<StandardPdfDocumentImageStamper>().As<IPdfDocumentImageStamper>();
return this;
}
public PdfDocumentStampingAppBuilder WithStandardPdfDocumentStamper()
{
containerBuilder.RegisterType<PdfSharpPdfDocumentStamper>().As<IPdfDocumentStamper>();
return this;
}
public PdfDocumentStampingAppBuilder WithStandardStampingCommandSource()
{
WithStandardStampingCommandInputSource();
WithNoOpStampingCommandOutputSource();
containerBuilder.RegisterType<StandardStampingCommandSource>().As<IStampingCommandSource>();
return this;
}
public PdfDocumentStampingAppBuilder WithStandardStampingCommandInputSource()
{
containerBuilder.RegisterType<StandardStampingCommandInputSource>().As<IStampingCommandInputSource>();
return this;
}
public PdfDocumentStampingAppBuilder WithNoOpStampingCommandOutputSource()
{
containerBuilder.RegisterType<NoOpStampingCommandOutputSource>().As<IStampingCommandOutputSource>();
return this;
}
public PdfDocumentStampingApp Build()
{
var app = InternalBuildApp();
ResetAllDependencies();
return app;
}
private PdfDocumentStampingApp InternalBuildApp()
{
RegisterApp();
return ResolveApp();
}
private void RegisterApp()
{
containerBuilder
.RegisterType<PdfDocumentStampingApp>()
.EnableClassInterceptors()
.InterceptedBy(typeof(ApplicationErrorHandler));
}
private PdfDocumentStampingApp ResolveApp() => containerBuilder.Build().Resolve<PdfDocumentStampingApp>();
private void ResetAllDependencies()
{
containerBuilder = new ContainerBuilder();
}
}
public static readonly PdfDocumentStampingAppBuilder Builder = new PdfDocumentStampingAppBuilder();
}
}