-
Notifications
You must be signed in to change notification settings - Fork 1
/
FDFErrors.vb
179 lines (179 loc) · 8.91 KB
/
FDFErrors.vb
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
170
171
172
173
174
175
176
177
178
179
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Web
Imports System.Web.Mail
Imports System.Diagnostics.Process
Imports System.Data.OleDb
Imports System.Data
Namespace FDFApp
Public Class FDFErrors
Implements IDisposable
Public ThrowErrors As Boolean = True
Public Sub ThrowError(ByVal err As Exception)
If ThrowErrors Then
Throw err
End If
End Sub
Enum FDFErc
FDFErcOK = 0
FDFErcInternalError = 1 'Internal FDF Library error */
FDFErcBadParameter = 2 ' One or more of the parameters passed to the function are invalid */
FDFErcFileSysErr = 3 ' Some error using the file system,including file not found"
FDFErcBadFDF = 4 ' The FDF file being opened/parsed is invalid */
FDFErcFieldNotFound = 5 '- The field whose name was passed in parameter "fieldName" does not exist in the FDF */
FDFErcNoValue = 6 ' The field whose value was requested has no value */
FDFErcEnumStopped = 7 ' Enumeration was stopped by FDFEnumValuesProc by returning false */
FDFErcCantInsertField = 8 ' The field whose name was passed in parameter "fieldName" can't be inserted into the FDF. This might happen, for example, if you try to insert "a.b" into an FDF that already has a field such as "a.b.c" in it. Or, conversely, if you try to insert "a.b.c" into an FDF that already has "a.b" */
FDFErcNoOption = 9 ' The requested element in a field's /Opt key does not exist, or the field has no /Opt key */
FDFErcNoFlags = 10 ' The field has no /F or /Ff keys */
FDFErcBadPDF = 11 ' The PDF passed as parameter to FDFSetAP is invalid, or doesn't contain pageNum */
FDFErcBufTooShort = 12 ' The buffer passed as parameter is too short for the length of the data that the function wants to return in it */
FDFErcNoAP = 13 ' The field has no /AP key */
FDFErcIncompatibleFDF = 14 ' Cannot mix "classic" and "template-based" FDF (see FDFAddTemplate) */
FDFErcNoAppendSaves = 15 ' The FDF does not include a /Differences key */
FDFErcValueIsArray = 16 ' The value of this field is an array. Use FDFGetNthValue */
FDFErcEmbeddedFDFs = 17 ' The FDF that you passed as parameter is a container for one or more FDFs embedded within it. Use FDFOpenFromEmbedded to gain access to each embedded FDF */
FDFErcNoMoreFDFs = 18 ' Returned by FDFOpenFromEmbedded when parameter iWhich >= to the number of embedded FDFs (including the case when the passed FDF does not contain any embedded FDFs) */
FDFErcInvalidPassword = 19 ' Returned by FDFOpenFromEmbedded when the embedded FDF is encrypted, and the correct password to open it was not provided */
FDFErcLast = 20 ' Unknown
FDFErcUnknown = 50 ' Unknown
End Enum
Private Function ReturnErrCodeStr(ByVal intCode As Integer) As String
Select Case intCode
Case 0
Return "FDFErcOK"
Case 1
Return "FDFErcInternalError"
Case 2
Return "FDFErcBadParamete"
Case 3
Return "FDFErcFileSysErr"
Case 4
Return "FDFErcBadFDF"
Case 5
Return "FDFErcFieldNotFound"
Case 6
Return "FDFErcNoValue"
Case 7
Return "FDFErcEnumStopped"
Case 8
Return "FDFErcCantInsertField"
Case 9
Return "FDFErcNoOption"
Case 10
Return "FDFErcNoFlags"
Case 11
Return "FDFErcBadPDF"
Case 12
Return "FDFErcBufTooShort"
Case 13
Return "FDFErcNoAP"
Case 14
Return "FDFErcIncompatibleFDF"
Case 15
Return "FDFErcNoAppendSaves"
Case 16
Return "FDFErcValueIsArray"
Case 17
Return "FDFErcEmbeddedFDFs"
Case 18
Return "FDFErcNoMoreFDFs"
Case 19
Return "FDFErcInvalidPassword"
Case 20
Return "FDFErcLast"
Case 50
Return "FDFErcUnknown"
Case Else
Return "FDFErcUnknown"
End Select
End Function
Structure FDFError
Dim FDFError As FDFErc
Dim FDFError_Msg As String
Dim FDFError_Module As String
Dim FDFError_Number As Integer
Dim FDFError_Code As String
End Structure
Private _FDFErrors As New System.Collections.Generic.List(Of FDFError)
Public Sub FDFAddError(ByVal FDFErrCode As FDFErc, ByVal FDFErrMessage As String, ByVal FDFErrModule As String, ByVal FDFErrNumber As Integer)
If Not _FDFErrors Is Nothing Then
Dim e As New FDFError
e.FDFError = FDFErrCode
e.FDFError_Module = FDFErrModule
e.FDFError_Number = FDFErrNumber
e.FDFError_Msg = FDFErrMessage
e.FDFError_Code = ReturnErrCodeStr(FDFErrNumber)
_FDFErrors.Add(e)
End If
End Sub
Public Sub FDFAddError(ByVal FDFErrCode As FDFErc, ByVal FDFException As Exception)
If Not _FDFErrors Is Nothing Then
Dim e As New FDFError
e.FDFError = FDFErrCode
e.FDFError_Module = FDFException.TargetSite.DeclaringType.ToString & "." & FDFException.TargetSite.Name.ToString
e.FDFError_Number = 0
e.FDFError_Msg = FDFException.Message
_FDFErrors.Add(e)
End If
If ThrowErrors And FDFErrCode <> FDFErc.FDFErcOK Then
ThrowError(FDFException)
End If
End Sub
Public Function FDFHasErrors() As Boolean
If _FDFErrors.Count > 0 Then
Return True
End If
Return False
End Function
Public Sub ResetErrors()
_FDFErrors = New System.Collections.Generic.List(Of FDFError)
End Sub
Public Property FDFErrors() As FDFError()
Get
If _FDFErrors.Count > 0 Then
Return _FDFErrors.ToArray
Else
Return New FDFError() {}
End If
End Get
Set(ByVal Value As FDFError())
_FDFErrors = New System.Collections.Generic.List(Of FDFError)
_FDFErrors.AddRange(Value)
End Set
End Property
Public Function FDFErrorsStr(Optional ByVal HTMLFormat As Boolean = False) As String
If FDFErrors Is Nothing Then
Return ""
End If
Dim FDFErrorx As FDFError
Dim retString As String
retString = CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & "FDF Errors:"
If FDFErrors.Length <= 0 Then Return ""
For Each FDFErrorx In FDFErrors
retString = retString & CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & vbTab & "Error: " & FDFErrorx.FDFError_Code & " - " & FDFErrorx.FDFError & CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & vbTab & "#: " & FDFErrorx.FDFError_Number & CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & vbTab & "Module: " & FDFErrorx.FDFError_Module & CStr(IIf(HTMLFormat, "<br>", vbNewLine)) & vbTab & "Message: " & FDFErrorx.FDFError_Msg & CStr(IIf(HTMLFormat, "<br>", vbNewLine))
Next
Return retString
End Function
#Region " IDisposable Support "
Private disposedValue As Boolean = False ' To detect redundant calls
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
_FDFErrors.Clear()
_FDFErrors = Nothing
End If
End If
Me.disposedValue = True
End Sub
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
Public Sub New()
_FDFErrors = New System.Collections.Generic.List(Of FDFError)
End Sub
End Class
End Namespace