Archive

Posts Tagged ‘VB.NET’

SAP RFC Connection Wrapper für VB.NET

8. Januar 2011 2 Kommentare

Es kommt mal vor, dass man aus einer .NET Anwendung Daten aus SAP ziehen möchte und dann schlägt man sich etwa mit der COM Schnittstelle von “SAP.Functions” herum oder… Man nutzt einfach diesen Wrapper…

 

vb.net
1
23
45
67
89
1011
1213
1415
1617
1819
2021
2223
2425
2627
2829
3031
3233
3435
3637
3839
4041
4243
4445
4647
4849
5051
5253
5455
5657
5859
6061
6263
6465
6667
6869
7071
7273
7475
7677
7879
8081
8283
8485
8687
8889
9091
9293
9495
9697
9899
100101
102103
104105
106107
108109
110111
112113
114115
116117
118119
120121
122123
124125
126127
128129
130131
132133
134135
136137
138139
140141
142143
144145
146147
148149
150151
152153
154155
156157
158159
160161
162163
164165
166167
168169
170171
172173
174175
176177
178179
180181
182183
184185
186187
188189
190191
192193
194195
196197
198199
200201
202203
204205
206207
208209
210211
212213
214215
216217
218219
220221
222223
224225
226227
228229
230231
232233
234235
236237
238239
240241
242243
244245
246247
248249
250251
252253
254255
256257
258259
260261
262263
264265
266267
268269
270271
272273
274275
276277
278279
280281
282283
284285
286287
288289
290291
292293
294295
296297
298299
300301
302303
304305
306307
308309
310311
312313
314315
316317
318319
320321
322323
324325
326327
328329
330331
332333
334335
336337
338339
340341
342343
344345
346347
348349
350351
352353
354355
356357
358359
360361
362363
364365
366367
368369
370371
372373
374375
376377
378379
380381
382383
384385
386387
388389
390391
392393
394395
396397
398399
400401
402403
404405
406407
408409
410411
412413
414415
416417
418419
420421
422423
424425
426427
428429
430431
432433
434435
436437
438439
440441
442443
444445
446447
448449
450451
452453
454455
456457
458
' Legacy of void
 Option Explicit On ' Always 🙂
' But dont turn on "Option Strict" ... Option Strict disallows late binding!  imports Systemimports System.Windows.Forms
imports System.Collectionsimports System.Collections.ObjectModel
 namespace SAPconnect
        ' SAP Connector class
    public class Connector                ' SAP Types        public enum SapTypes
            [Char] = 0            [Date] = 1
            BCD = 2            Time = 3
            [Hex] = 4            Num = 6
            Float = 7            [Long] = 8
            [Short] = 9            [Byte] = 10
        end enum        #Region "Properties"        Public Property HostName As String
        Public Property SystemNumber As String        Public Property Client As String
        Public Property User As String        Public Property Language As String
        Public Property Password As String        Public Property MessageServer As String
        Public Property GroupName As String        Public Property ApplicationServer As String
         Private _system As String
        Public Property System As String            Set(ByVal value As String)
                _system = value            End Set
            Get                If status AndAlso sapcon IsNot Nothing Then
                    Return sapcon.system                Else
                    Return ""                End If
            End Get        End Property
         Private _status As Boolean
        Public ReadOnly Property Status As Boolean            Get
                Return _status            End Get
        End Property  #End Region                private sapfunc as Object        Private sapcon As Object
         Public Sub New()
            Try                sapfunc = CreateObject("SAP.Functions")
                sapcon = sapfunc.Connection            Catch e As Exception
                ' Change this                MessageBox.Show(e.Message, "SAP Connector", MessageBoxButtons.OK, _
                    MessageBoxIcon.Exclamation)            End Try
        End Sub          Protected Overrides Sub Finalize()            Disconnect() ' Be sure to disconnect first before trying to kill the class
        End Sub  #Region "Connect and Disconnect methods"          Public Function Connect() As Boolean              Try                If Not Status Then
                     With sapcon
                         .System = _system
                        .HostName = HostName                        .SystemNumber = SystemNumber
                        .Client = Client                        .User = User
                        .Language = Language                        .Password = Password
                         'New Properties
                        .MessageServer = MessageServer                        .GroupName = GroupName
                        .ApplicationServer = ApplicationServer                      End With                      If sapcon.LogOn(0, True) Then                        _status = True
                        Return True                    End If
                 End If
             Catch e As Exception
                ' Change this                MessageBox.Show(e.Message, "SAP Connector", MessageBoxButtons.OK, _
                    MessageBoxIcon.Exclamation)            End Try
             _status = False
            Return False          End Function          Public Sub Disconnect()            If sapcon IsNot Nothing Then
                sapcon.LogOff()                sapcon = Nothing
            End If            _status = False
        End Sub  #End Region  #Region "RFC 'export' 'export' 'call' list wrapper"          ''' <summary>        ''' Holds the function call name
        ''' </summary>        Private _function As String
        Public Property [Function] As String            Get
                Return _function            End Get
            Set(ByVal value As String)                _function = value
                'connect to sap if status = false                If Not status Then connect()
            End Set        End Property
         ''' <summary>
        ''' calls the function - returns false if unsuccessful        ''' all function call parameters will be cleared after every call
        ''' </summary>        Public Function [Call]() As Boolean
             If sapfunc Is Nothing Then Return False
            'try to connect            If Not status Then
                If Not connect Then Return False            End If
             Try
                If [Function].Length > 0 Then                      ' clear old function calls                    sapfunc.removeall()
                     With sapfunc.Add([Function])
                        ' add all "exports" to the function call                        For i As Integer = 0 To count() - 1
                            If item(i).type = 0 Then                                .exports(item(i).key) = item(i).value
                                'else                                '    .tables(item(i).key)
                            End If                        Next
                        Return .call                    End With
                End If            Catch
            End Try              Return False          End Function          ''' <summary>        ''' Alias of Call
        ''' </summary>          Public Function Send() As Boolean
            Return [Call]()        End Function
         'hold the function call parameters
#Region "AddFunctionParameter"          Private mcol As sapCollection = New sapCollection()          ''' <summary>        ''' "exports" for retrieving data
        ''' </summary>          Public Sub AddFunctionParameter(ByVal param As String, ByVal value As String)
            mcol.add(New sapexports(param, value, 0))        End Sub
         ''' <summary>
        ''' Alias of AddFunctionParameter        ''' </summary>  
        Public Sub add(ByVal param As String, ByVal value As String)            AddFunctionParameter(param, value)
        End Sub          ''' <summary>        ''' Alias of AddFunctionParameter
        ''' </summary>          Public Sub exports(ByVal param As String, ByVal value As String)
            AddFunctionParameter(param, value)        End Sub
         ''' <summary>
        ''' Alias of AddFunctionParameter        ''' </summary>  
        Public Sub param(ByVal param As String, ByVal value As String)            AddFunctionParameter(param, value)
        End Sub          ''' <summary>        ''' "exports" for retrieving tables
        ''' </summary>          Public Sub tables(ByVal param As String)
            mcol.add(New sapexports(param, "x", 1))        End Sub
 #End Region
           ''' <summary>        ''' Returns the function and the return value from SAP
        ''' </summary>          Default Public ReadOnly Property Item(ByVal index As Integer) As sapexports
            Get                Return mcol(index)
            End Get        End Property
        ''' <summary>        ''' Returns the function and the return value from SAP
        ''' </summary>          Default Public ReadOnly Property Item(ByVal Key As String) As sapexports
            Get                Return mcol(key)
            End Get        End Property
         Public Sub Clear()
            mcol.clear()        End Sub
         Public Function Count() As Integer
            Return mcol.Count        End Function
         Public Function Contains(ByVal param As String) As Boolean
            Return mcol.contains(param)        End Function
         ''' <summary>
        ''' returns the data type        ''' </summary>  
        Public Function GetDataType(ByVal param As String) As Integer            Return CInt(sapfunc.item([Function]).imports(param).sapType)
        End Function          ''' <summary>        ''' returns the output data
        ''' </summary>          Public Function [Get](ByVal param As String) As Object
            Try                  If status AndAlso sapfunc IsNot Nothing Then                    Select Case CInt(sapfunc.item([Function]).imports(param).sapType)
                        'Case sapTypes.[Char], sapTypes.[Date], sapTypes.BCD, sapTypes.Time, sapTypes.[Hex]                        '    Return sapfunc.item([Function]).imports(param).value
                         Case sapTypes.Num, sapTypes.Float, sapTypes.[Long], sapTypes.[Short]
                            Return sapfunc.item([Function]).imports(param).value(param)                              'Case sapTypes.[Byte]                            '    Return sapfunc.item([Function]).imports(param).value
                         Case Else
                            Return sapfunc.item([Function]).imports(param).value                      End Select                End If
             Catch
                ' Change this                MessageBox.Show(e.Message, "SAP Connector", MessageBoxButtons.OK, _
                    MessageBoxIcon.Exclamation)            End Try
            Return Nothing          End Function          ''' <summary>        ''' Same as Get, but this only returns double values
        ''' </summary>          Public Function GetDouble(ByVal param As String) As Double
            Return sapfunc.item([Function]).imports(param).value(param)        End Function
 #Region "aliases of get"
        ''' <summary>        ''' Alias of Get
        ''' </summary>          Public Function [imports](ByVal param As String) As Object
            Return [Get](param)        End Function
        ''' <summary>        ''' Alias of Get
        ''' </summary>          Public Function data(ByVal param As String) As Object
            Return [Get](param)        End Function
        ''' <summary>        ''' Alias of Get
        ''' </summary>          Public Function grab(ByVal param As String) As Object
            Return [Get](param)        End Function
#End Region  #Region "Table stuff"          ''' <summary>        ''' Retrieves a Table
        ''' </summary>          Public Function GetTable(ByVal param As String, ByVal row As Integer, _
               ByVal fieldname As String) As String            Dim tbl As Object = sapfunc.item([Function]).tables(param)
            Try                If tbl.rowcount > 0 Then
                    Return tbl(row, fieldname)                End If
            Catch            End Try
            Return ""        End Function
         ''' <summary>
        ''' Retrieves a Table        ''' </summary>  
        Public Function GetTable(ByVal param As String, ByVal row As Integer, _               ByVal field As Integer) As String
            Dim tbl As Object = sapfunc.item([Function]).tables(param)            Try
                If tbl.rowcount > 0 Then                    Return tbl(row, field)
                End If            Catch
            End Try            Return ""
        End Function          ''' <summary>        ''' Retrieves a Table
        ''' </summary>          Public Function GetTable(ByVal param As String, ByVal fieldname As String) As String()
            Dim tbl As Object = sapfunc.item([Function]).tables(param)            Dim tblarray() As String : ReDim tblarray(tbl.rowcount - 1)
            Try                If tbl.rowcount > 0 Then
                     For i As Integer = 0 To tbl.rowcount - 1
                        tblarray(i) = tbl(i + 1, fieldname)                    Next
                 End If
            Catch            End Try
            Return tblarray        End Function
         ''' <summary>
        ''' Retrieves a Table        ''' </summary>  
        Public Function GetTable(ByVal param As String, ByVal field As Integer) As String()            Dim tbl As Object = sapfunc.item([Function]).tables(param)
            Dim tblarray() As String : ReDim tblarray(tbl.rowcount - 1)            Try
                If tbl.rowcount > 0 Then                      For i As Integer = 0 To tbl.rowcount - 1                        tblarray(i) = tbl(i + 1, field)
                    Next                  End If            Catch
            End Try            Return tblarray
        End Function          ''' <summary>        ''' Close the data
        ''' </summary>          Public Sub TableClose(ByVal param As String)
            sapfunc.item([Function]).tables(param).freetable()        End Sub
         ''' <summary>
        ''' Appends a new row        ''' </summary>  
        Public Sub TableAppendRow(ByVal param As String)            sapfunc.item([Function]).tables(param).AppendRow()
        End Sub          Public Sub TableFilter(ByVal param As String, ByVal row As Integer, _                ByVal fieldname As String, ByVal value As String)
            sapfunc.item([Function]).tables(param)(row, fieldname) = value        End Sub
 #End Region
 #End Region
 #Region "Collections"
         Public Class sapCollection : Inherits KeyedCollection(Of String, sapexports)
            Public Sub New()                MyBase.new()
            End Sub              Protected Overrides Function GetKeyForItem(ByVal item As sapexports) As String                Return item.Key
            End Function        End Class
         Public Class sapexports
             Public Sub New(ByVal key As String, ByVal value As String, ByVal type As Integer)
                Me.key = key                Me.value = value
                Me.type = type            End Sub
             Public Key As String
            Public Value As String            Public Type As Integer ' 0 = exports, 1 = tables
         End Class
 #End Region
     End Class
 end namespace
 
GeSHi 1.0.8.8
Kategorien:.NET, VB Schlagwörter: ,

Informationen aus dem Active Directory ziehen mit VB.NET und ADO


Und hier ist die VB.NET Version als Konsolenprogramm.
Das Programm kann man mit folgendem Befehl kompilieren.

vbc ldap.vb /out:LDAP.exe /reference:"C:\windows\assembly\GAC\ADODB\7.0.3300.0__b03f5f7f11d50a3a\adodb.dll"

vbc findet man unter
C:\Windows\Microsoft.NET\Framework[64]\[.NET Version]

imports System
imports system.text
imports system.runtime.interopservices
imports System.DirectoryServices

Public Class LDAP

    Private Const MAX_STRING_LENGTH As Integer = 100
    Private Const TITLE_LENGTH As Integer = 30

    ' 1 = name, id, department
    ' 2 = all
    ' 4 = max
    ' 8 = acc

    Private Shared ReturnType As Integer = 1

    Public Shared Sub Main()

        Dim queryParam As String = ""
        Dim args() As String = split(command(), " ")

        For i As Integer = 0 To args.Getupperbound(0)
            Select Case args(i)
                Case "-help" : ShowHelp() : End
                Case "-all" : ReturnType += 2
                Case "-max" : ReturnType += 4
                Case "-acc" : ReturnType += 8
                Case "-user" : If args.getupperbound(0) >= i + 1 Then AddQueryParam(queryparam, "name=" & args(i + 1))
                Case "-lname" : If args.getupperbound(0) >= i + 1 Then AddQueryParam(queryparam, "sn=" & args(i + 1))
                Case "-fname" : If args.getupperbound(0) >= i + 1 Then AddQueryParam(queryparam, "givenName=" & args(i + 1))
                Case "-dept" : If args.getupperbound(0) >= i + 1 Then AddQueryParam(queryparam, "ou=" & args(i + 1))
            End Select
        Next
        If queryParam.Trim().Length > 0 Then
            ShowADInfo(queryParam)
        Else
            If args.GetUpperBound(0) >= 0 Then
                AddQueryParam(queryParam, "sn=" & args(0))
                ShowADInfo(queryParam)
            End If
        End If
        console.writeline("")
    End Sub

    Private Shared Sub AddQueryParam(ByRef queryParam As String, ByVal argument As String)

        If queryParam.Trim().Length = 0 Then
            queryParam = "(" & argument & ")"
        Else
            queryParam &= " (" & argument & ")"
        End If

    End Sub

    Private Shared Sub ShowADInfo(ByVal queryParam As String)

        Dim oCon As adodb.connection = New adodb.connection()
        Dim rs As adodb.recordset = New adodb.recordset()
        Dim oRoot As Object = Nothing
        Dim oDomain As Object = Nothing
        Dim sConCommand As String = ""

        Try

            oRoot = GetObject("LDAP://rootDSE")
            oDomain = GetObject("LDAP://" & oRoot.get("defaultNamingContext"))
            sConCommand = "<" & oDomain.adspath & ">;" & _
              "(&(objectCategory=person) " & queryParam & ");" & _
              "adsPath;subTree"

            oCon.Provider = "ADsDSOObject"
            oCon.Open("Active Directory")
            rs = oCon.Execute(sConCommand)

            If rs.recordcount = 1 Then
                ConsoleWrite("\nFound Entry: " & rs.recordcount.tostring & "\n")
            Else
                ConsoleWrite("\nFound Entries: " & rs.recordcount.tostring & "\n")
            End If

            rs.movefirst()
            Do While Not (rs.eof)

                ConsoleWrite("=============================================")

                If ((ReturnType And 1) = 1) And Not ((ReturnType And 4) = 4) Then
                    With GetObject(rs.fields("adsPath").value.tostring)
                        ConsoleWrite("Full Name", .fullname)
                        ConsoleWrite("User ID", .name)
                        ConsoleWrite("Department", .department)

                        ConsoleWrite("Account Expiration Date", .AccountExpirationDate)
                        ConsoleWrite("Division", .division)
                        ConsoleWrite("Email Address", .emailaddress)
                        ConsoleWrite("Phone Number", .telephonenumber)
                        ConsoleWrite("Mobile Number", .TelephoneMobile)
                    End With
                End If

                If (ReturnType And 4) = 4 Then

                    With GetObject(rs.fields("adsPath").value.tostring)

                        ConsoleWrite("Title", .Title)
                        ConsoleWrite("Name Prefix", .NamePrefix)
                        ConsoleWrite("Name Suffix", .NameSuffix)
                        ConsoleWrite("First Name", .firstname)
                        ConsoleWrite("Last Name", .lastname)
                        ConsoleWrite("Other Name", .othername)
                        ConsoleWrite("User ID", .name)
                        ConsoleWrite("Department", .department)

                        ConsoleWrite("Division", .division)
                        ConsoleWrite("Email Address", .emailaddress)
                        ConsoleWrite("Phone Number", .telephonenumber)
                        ConsoleWrite("Mobile Number", .TelephoneMobile)
                        ConsoleWrite("Phone Home", .TelephoneHome)
                        ConsoleWrite("Fax Number", .Faxnumber)
                        ConsoleWrite("Pager", .TelephonePager)
                        ConsoleWrite("Employee ID", .EmployeeID)
                        ConsoleWrite("Languages", Join(.languages, ", "))
                        ConsoleWrite("Manager", .manager)

                        ConsoleWrite("Postal Addresses", .PostalAddresses)
                        ConsoleWrite("Postal Codes", .PostalCodes)
                        ConsoleWrite("Office Locations", .OfficeLocations)

                    End With
                End If

                If (ReturnType And 8) = 8 Then
                    With GetObject(rs.fields("adsPath").value.tostring)

                        ConsoleWrite("Account Disabled", .AccountDisabled)
                        ConsoleWrite("Account Expiration Date", .AccountExpirationDate)
                        ConsoleWrite("Bad Login Address", .BadLoginAddress)
                        ConsoleWrite("Bad Login Count", .BadLoginCount)
                        ConsoleWrite("Class", .Class)
                        ConsoleWrite("Description", .Description)
                        ConsoleWrite("Grace Logins Allowed", .GraceLoginsAllowed)
                        ConsoleWrite("Grace Logins Remaining", .GraceLoginsRemaining)
                        ConsoleWrite("GUID", .GUID)
                        ConsoleWrite("Home Directory", .HomeDirectory)

                        ConsoleWrite("Home Page", .HomePage)
                        ConsoleWrite("Is Account Locked", .IsAccountLocked)
                        ConsoleWrite("Last Failed Login", .LastFailedLogin)
                        ConsoleWrite("Last Login", .LastLogin)
                        ConsoleWrite("Last Logoff", .LastLogoff)
                        ConsoleWrite("Login Hours", .LoginHours)
                        ConsoleWrite("Login Script", .LoginScript)
                        ConsoleWrite("Login Workstations", .LoginWorkstations)
                        ConsoleWrite("Max Logins", .MaxLogins)
                        ConsoleWrite("Parent", .Parent)
                        ConsoleWrite("Password Expiration Date", .PasswordExpirationDate)
                        ConsoleWrite("Password Last Changed", .PasswordLastChanged)
                        ConsoleWrite("Password Mininmum Length", .PasswordMinimumLength)
                        ConsoleWrite("Password Required", .PasswordRequired)
                        ConsoleWrite("Profile", .Profile)
                        ConsoleWrite("Required Unique Password", .RequireUniquePassword)
                        ConsoleWrite("Schema", .Schema)
                        ConsoleWrite("SeeAlso", .SeeAlso)

                    End With
                End If

                If (ReturnType And 2) = 2 Then
                    Dim userEntry As DirectoryEntry = New DirectoryEntry(rs.fields("adsPath").value.tostring)
                    For Each Key As String In userEntry.properties.propertynames
                        If LCase(userEntry.Properties(Key).Value.gettype.tostring) = "system.byte[]" Then
                            ConsoleWrite(Key, ToHex(CType(userEntry.properties(Key).value, Byte())))

                        ElseIf LCase(userEntry.properties(Key).value.gettype.tostring) = "system.__comobject" Then
                            ConsoleWrite(Key, _
                            DateTime.FromFileTimeUtc(GetInt64FromLargeInteger(userEntry.properties(Key).value)).ToLocalTime & _
                            " (" & GetInt64FromLargeInteger(userEntry.properties(Key).value) & ")")

                        ElseIf LCase(userEntry.properties(Key).value.gettype.tostring) = "system.object[]" Then
                            Dim i As Integer = 1
                            ConsoleWrite(Fill(Key))
                            For Each x As Object In userEntry.properties(Key).value
                                ConsoleWrite(i, x.ToString)
                                i += 1
                            Next

                        Else
                            ConsoleWrite(Key, userEntry.Properties(Key).Value.ToString())

                        End If
                    Next
                    userEntry.dispose()
                End If

                rs.movenext()
            Loop
            Err.Clear()

        Catch e As Exception
            ConsoleWrite(e.Message)

        Finally

            If rs IsNot Nothing Then
                If rs.state <> 0 Then rs.close()
                rs = Nothing
            End If

            If oCon IsNot Nothing Then
                If oCon.state <> 0 Then oCon.close()
                oCon = Nothing
            End If

            oRoot = Nothing
            oDomain = Nothing

        End Try

    End Sub

    Private Shared Function ToHex(ByVal bByte() As Byte) As String
        Dim str As String = ""
        For i As Integer = 0 To bbyte.getupperbound(0)
            str &= Hex(bByte(i)).PadLeft(2, CChar("0"))
        Next
        Return str
    End Function

    Private Shared Sub ShowHelp()
        ConsoleWrite("PARAMETERS:")
        ConsoleWrite("-help \t Shows Help")
        ConsoleWrite("-user \t Finds the user via UID")
        ConsoleWrite("-lname \t Finds every matching user via last name")
        ConsoleWrite("-fname \t Finds every matching user via first name")
        ConsoleWrite("-dept \t Finds every matching user via department")
        ConsoleWrite("-all \t All information")
        ConsoleWrite("-max \t Minimal information")
        ConsoleWrite("-acc \t Account Information")
        consolewrite("\nUSAGE:")
        consolewrite("ldap -max -lname doe")
        consolewrite("ldap -max -lname doe -fname j*")
        consolewrite("\nDEFAULTS:")
        consolewrite("""ldap doe"" is the same as ""ldap -lname doe""\n")
    End Sub

#Region "Fill"
    Private Overloads Shared Function Fill() As String
        Return Fill("")
    End Function

    Private Overloads Shared Function Fill(ByVal C As Char) As String
        Return Fill("", C)
    End Function

    Private Overloads Shared Function Fill(ByVal sString As String) As String
        If sString.Length > TITLE_LENGTH Then
            Return Left(sString, TITLE_LENGTH)
        Else
            Return sString.PadRight(TITLE_LENGTH, CChar("."))
        End If
    End Function

    Private Overloads Shared Function Fill(ByVal sString As String, ByVal C As Char) As String
        If sString.Length > TITLE_LENGTH Then
            Return Left(sString, TITLE_LENGTH)
        Else
            Return sString.PadRight(TITLE_LENGTH, C)
        End If
    End Function
#End Region

#Region "Console Write"
    Private Overloads Shared Sub ConsoleWrite(ByVal sName As String, ByVal sText As String)
        If sText.Length > MAX_STRING_LENGTH Then
            Dim iCut As Integer = CInt((sText.Length / MAX_STRING_LENGTH) - 1)
            If iCut < 0 Then iCut = 0
            Console.WriteLine(Fill(sName) & Mid(sText, 1, MAX_STRING_LENGTH))
            If iCut > 0 Then
                For i As Integer = 1 To iCut
                    Console.WriteLine(Fill(CChar(" ")) & Mid(sText, i * MAX_STRING_LENGTH + 1, MAX_STRING_LENGTH))
                Next
            End If
        Else
            Console.WriteLine(Fill(sName) & sText)
        End If
    End Sub

    Private Overloads Shared Sub ConsoleWrite(ByVal int As Integer, ByVal sText As String)
        If sText.Length > MAX_STRING_LENGTH Then
            Dim iCut As Integer = CInt((sText.Length / MAX_STRING_LENGTH) - 1)
            If iCut < 0 Then iCut = 0
            Console.WriteLine((CStr(int.ToString) & ". ").PadLeft(TITLE_LENGTH, CChar(" ")) & Mid(sText, 1, MAX_STRING_LENGTH))
            If iCut > 0 Then
                For i As Integer = 1 To iCut
                    Console.WriteLine(Fill(CChar(" ")) & Mid(sText, i * MAX_STRING_LENGTH + 1, MAX_STRING_LENGTH))
                Next
            End If
        Else
            Console.WriteLine((CStr(int.ToString) & ". ").PadLeft(TITLE_LENGTH, CChar(" ")) & sText)
        End If
    End Sub

    Private Overloads Shared Sub ConsoleWrite(ByVal sText As String)
        sText = Replace(sText, "\t", vbTab)
        sText = Replace(sText, "\n", vbNewLine)
        Console.WriteLine(sText)
    End Sub
#End Region

    ' http://www.eggheadcafe.com/software/aspnet/31107648/systembyte-and-systemcomobject-in-ad-ldap-browser.aspx
#Region "Converters"
    Private Shared Function GetInt64FromLargeInteger(ByVal largeInteger As Object) As Int64

        Dim low As Int32
        Dim high As Int32
        Dim valBytes(7) As Byte

        Dim longInt As IADsLargeInteger = CType(largeInteger, IADsLargeInteger)
        low = longInt.LowPart
        high = longInt.HighPart

        BitConverter.GetBytes(low).CopyTo(valBytes, 0)
        BitConverter.GetBytes(high).CopyTo(valBytes, 4)

        Return BitConverter.ToInt64(valBytes, 0)

    End Function

    <ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)> _
    Private Interface IADsLargeInteger
        Property HighPart() As Int32
        Property LowPart() As Int32
    End Interface
#End Region

End Class

Kategorien:.NET Schlagwörter: