>>// loSHA256 = SHA256Managed.Create()
>>
>>using ( MD5 md5Hash = MD5.Create() )
>>
>>Imports System.IO >Imports System.Security.Cryptography > >Public Class MD5 > > Public cMessage As String = "" > Public cFileName As String = "" > Public lLogError As Boolean = True > Public oMD5() As Byte = Nothing > Private cFileDoesNotExist As String = "" > Private nLanguage As Integer = 0 > Private oApp As Framework.App = Nothing > Private oProcess As Framework.LXProcess = Nothing > > ' This is when we access the class in a desktop mode > Sub New(ByVal toApplication As Framework.App) > oApp = toApplication > nLanguage = oApp.nLanguage > Init() > End Sub > > ' This is when we access the class in a Web or Web Service mode > Public Sub New(ByVal toProcess As Framework.LXProcess) > oProcess = toProcess > oApp = oProcess.oApp > nLanguage = oProcess.nLanguage > Init() > End Sub > > Private Function Init() As Boolean > > ' Based on the language > Select Case nLanguage > > ' English > Case 1 > cFileDoesNotExist = "The file ##File## does not exist." > > ' French > Case 2 > cFileDoesNotExist = "Le fichier ##File## n'existe pas." > > ' Spanish > Case 3 > cFileDoesNotExist = "The file ##File## does not exist." > > ' Portuguese > Case 4 > cFileDoesNotExist = "The file ##File## does not exist." > > End Select > > Return True > End Function > > ' Get the MD5 > Public Function GetMD5() As Boolean > Dim lcMessage As String = "" > Dim lnCounter As Integer = 0 > Dim lnDelay As Integer = 250 > Dim lnRetry As Integer = 8 > Dim loMD5CryptoServiceProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider() > > ' Reset the values > cMessage = "" > oMD5 = Nothing > > ' We retry up to 8 times > For lnCounter = 1 To lnRetry > > Try > > ' If the file exists > If oApp.FileExist(cFileName) Then > > ' Open the destination > Using loStream As Stream = New FileStream(cFileName, FileMode.Open) > > ' Compute the hash of the fileStream > oMD5 = loMD5CryptoServiceProvider.ComputeHash(loStream) > > End Using > > Else > lcMessage = oApp.StrTran(cFileDoesNotExist, "##File##", cFileName) > > ' If we log the error > If lLogError Then > > ' Get the proper definition as per the current scope > If oProcess Is Nothing Then > oApp.ErrorSetup(, lcMessage) > Else > oProcess.ErrorSetup(, lcMessage) > End If > > Else > cMessage = lcMessage > Return False > End If > > End If > > Exit For > > Catch loError As Exception > > ' If we have not reached the maximum tries of 8, we retry > If lnCounter < 8 Then > > ' Wait for a timeout before retrying > System.Threading.Thread.Sleep(lnDelay) > > Continue For > End If > > ' If we log the error > If lLogError Then > > ' Get the proper definition as per the current scope > If oProcess Is Nothing Then > oApp.ErrorSetup(loError) > Else > oProcess.ErrorSetup(loError) > End If > > Else > cMessage = loError.Message > Return False > End If > > End Try > > Next > > ' Reset the values > cFileName = "" > > Return True > End Function > >End Class >