-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSampleCsvConsumer.lss
More file actions
113 lines (85 loc) · 2.67 KB
/
SampleCsvConsumer.lss
File metadata and controls
113 lines (85 loc) · 2.67 KB
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
%REM
Class CsvConsumer
Created Nov 9, 2017 by Sam Sirry
Description:
%END REM
Private Class CsvConsumer As ICsvConsumer
Private DataFields As Variant
Private db As NotesDatabase
Private doc As NotesDocument
Private docSavedCount As Long
Private docProcessedCount As Long
Private FieldIndex As Long
Private LastProgressVal As Double
Sub New(tgtDatabase As NotesDatabase)
If tgtDatabase Is Nothing Then
Error 5, "The target database must be supplied"
Else
Set db = tgtDatabase
End If
Const DataFieldsNames = "Date:Time:Duration:Server:Project:Document:URL"
DataFields = Split(DataFieldsNames, ":")
docProcessedCount = -1 'this indicates that we're processing the header of the csv file, which we dont want.
End Sub
Public Sub ConsumeField(ByVal s As String, Continue As Boolean)
If docProcessedCount < 0 Then GoTo Quit 'skip the csv file header row
If doc Is Nothing Then
Set doc = db.Createdocument()
doc.Form = "Log"
End If
If s <> "" Then
Call doc.Replaceitemvalue(DataFields(FieldIndex), s)
End If
Quit:
FieldIndex = FieldIndex +1
End Sub
Public Sub SignalEndOfRecord(Continue As Boolean)
On Error GoTo Hell
If Not doc Is Nothing Then
If ProcessNewDoc(doc) Then
Call doc.Save(False, False, False)
docSavedCount = docSavedCount +1
End If
End If
Set doc = Nothing
docProcessedCount = docProcessedCount +1
FieldIndex = 0
Quit:
Exit Sub
Hell:
'Call your favorite error handler here...
Error Err, ErrThrow(Module, Me)
Resume Quit
End Sub
Public Sub SignalEndOfFile()
Print "Processed " docProcessedCount " docs, of which " docSavedCount " docs were imported."
End Sub
Public Sub SignalProgress(FractionDone As Double)
If (FractionDone = 1) Or (FractionDone - LastProgressVal) => 0.1 Then 'process 10% change or more
Print Fix(FractionDone * 100) "% done."
LastProgressVal = FractionDone
End If
End Sub
%REM
Function ProcessNewDoc
Description: Called from SignalEndOfRecord; do whatever you want with the new document before it's stored in the database.
If the return is True the document gets saved, otherwise it is discarded.
%END REM
Function ProcessNewDoc(doc As NotesDocument) As Boolean
On Error GoTo Hell
'Do whatever you want with the new document before it's stored in the database.
'.
'.
'.
ProcessNewDoc = True
Quit:
Exit Function
Hell:
'Call your favorite error handler here...
Error Err, ErrThrow(Module, Me)
Resume Quit
End Function
End Class
Private Function ErrThrow(ModuleName, ClassObject) As String
ErrThrow = "Error no. " & CStr(Err) & " in Class (" & TypeName(ClassObject) & "), Module (" & ModuleName & ")"
End Function