Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Revision on Byte to Hexadecimal
Message
De
03/02/2014 10:34:22
 
 
À
03/02/2014 10:21:30
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01592982
Message ID:
01593001
Vues:
25
>What is the code of your class loMD5 ?

This is the code:
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 loSHA256 As SHA256 = Nothing

        ' 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)

                        ' Create a reference to the crypto library
                        loSHA256 = SHA256Managed.Create()

                        ' Be sure it is positioned to the beginning of the stream
                        loStream.Position = 0

                        ' Compute the hash of the fileStream
                        oMD5 = loSHA256.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
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform