@Michael.Navara ,
Thanks again,
Your Feedback 2.Use different identifier that the email was sent brought me to use a combined string of version and revision of the .idw. The Version String for a specific filename must be different from the one in the csv file otherwise exit sub.
It assures that each file is only processed once and is much easier than finding a solid time comparison solution.
Sub Main()
WorkWithTextFileSample()
End Sub
Private emailInfosFile As String = "C:\Temp\emailInfos.csv"
Private encoding As System.Text.Encoding = System.Text.Encoding.UTF8
Private Sub WorkWithTextFileSample()
'Read data from file
Dim emailInfos As Dictionary(Of String, String) = ReadEmailInfosFromTextFile(emailInfosFile)
Logger.Debug(emailInfos.Count)
'get The Filename
Dim fileName As String = ThisDoc.PathAndFileName(False)
Logger.Debug(emailInfos.Count)
'Get Version/Revision String from emailInfos by file name
Dim VersString3 As String = GetVersString(emailInfos, fileName)
Logger.Debug(timeStamp3)
Dim VersString As String = iProperties.Value("Custom", "AIMD_VERSION_INDEX") & iProperties.Value("Custom", "AIMD_REVISION_INDEX")
AppendEmailInfo(emailInfos, fileName, VersString)
Logger.Debug(emailInfos.Count)
If VersString = VersString3 Then
Exit Sub
End If
'Save data to file
SaveEmailInfosToTextFile(emailInfos)
Logger.Debug("Saved")
End Sub
Private Function GetVersString(emailInfos As Dictionary(Of String, String), fileName As String) As String
If emailInfos.ContainsKey(fileName) Then Return emailInfos(fileName)
'fileName not found
Return "???"
End Function
Private Sub RemoveEmailInfo(emailInfos As Dictionary(Of String, String), fileName As String)
If emailInfos.ContainsKey(fileName) Then
emailInfos.Remove(fileName)
End If
End Sub
Private Function ReadEmailInfosFromTextFile(emailInfosFile As String) As Dictionary(Of String, String)
'File is missing
If Not System.IO.File.Exists(emailInfosFile) Then Return New Dictionary(Of String, String)
'Load file content
Dim emailInfos As New Dictionary(Of String, String)
Dim lines As String() = System.IO.File.ReadAllLines(emailInfosFile, encoding)
For Each line As String In lines
Dim strings As String() = Line.Split(";")
emailInfos.Add(strings(0), strings(1))
Next
Return emailInfos
End Function
Private Sub AppendEmailInfo(emailInfos As Dictionary(Of String, String), fileName As String, VersString As String)
If (emailInfos.ContainsKey(fileName)) Then
emailInfos(fileName) = VersString
Else
emailInfos.Add(fileName, VersString)
End If
End Sub
Private Sub SaveEmailInfosToTextFile(emailInfos As Dictionary(Of String, String))
Dim stringBuilder As New System.Text.StringBuilder
For Each emailInfo As KeyValuePair(Of String, String) In emailInfos
stringBuilder.AppendLine(String.Join(";", emailInfo.Key, emailInfo.Value.ToString()))
Next
System.IO.File.WriteAllText(emailInfosFile, stringBuilder.ToString(), encoding)
End Sub