Another block of C# code to convert

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ty

    Another block of C# code to convert

    Here is another block that I can not get to convert. This is a class
    module.

    public bool IsAuthenticated (string domain, string username, string
    pwd)
    {
    string domainAndUserna me = domain + @"\" + username;
    DirectoryEntry entry = new DirectoryEntry( _path,
    domainAndUserna me, pwd);
    try
    {
    // Bind to the native AdsObject to force authentication.
    Object obj = entry.NativeObj ect;
    DirectorySearch er search = new DirectorySearch er(entry);
    search.Filter = "(SAMAccountNam e=" + username + ")";
    search.Properti esToLoad.Add("c n");
    SearchResult result = search.FindOne( );
    if(null == result)
    {
    return false;
    }
    // Update the new path to the user in the directory
    _path = result.Path;
    _filterAttribut e = (String)result. Properties["cn"][0];
    }
    catch (Exception ex)
    {
    throw new Exception("Erro r authenticating user. " + ex.Message);
    }
    return true;
    }

    }

    Any help would be apperciated.
  • Lloyd Sheen

    #2
    Re: Another block of C# code to convert


    "Ty" <tbarton@lewist ownhospital.org wrote in message
    news:8b7d2a6b-c7ba-435c-94db-e7a150695d81@59 g2000hsb.google groups.com...
    Here is another block that I can not get to convert. This is a class
    module.
    >
    public bool IsAuthenticated (string domain, string username, string
    pwd)
    {
    string domainAndUserna me = domain + @"\" + username;
    DirectoryEntry entry = new DirectoryEntry( _path,
    domainAndUserna me, pwd);
    try
    {
    // Bind to the native AdsObject to force authentication.
    Object obj = entry.NativeObj ect;
    DirectorySearch er search = new DirectorySearch er(entry);
    search.Filter = "(SAMAccountNam e=" + username + ")";
    search.Properti esToLoad.Add("c n");
    SearchResult result = search.FindOne( );
    if(null == result)
    {
    return false;
    }
    // Update the new path to the user in the directory
    _path = result.Path;
    _filterAttribut e = (String)result. Properties["cn"][0];
    }
    catch (Exception ex)
    {
    throw new Exception("Erro r authenticating user. " + ex.Message);
    }
    return true;
    }
    >
    }
    >
    Any help would be apperciated.

    Public Function IsAuthenticated (ByVal domain As String, ByVal username As
    String, ByVal pwd As String) As Boolean
    Dim domainAndUserna me As String = domain + "\" + username
    Dim entry As New DirectoryEntry( _path, domainAndUserna me, pwd)
    Try
    ' Bind to the native AdsObject to force authentication.
    Dim obj As Object = entry.NativeObj ect
    Dim search As New DirectorySearch er(entry)
    search.Filter = "(SAMAccountNam e=" + username + ")"
    search.Properti esToLoad.Add("c n")
    Dim result As SearchResult = search.FindOne( )
    If result Is Nothing Then
    Return False
    End If
    ' Update the new path to the user in the directory
    _path = result.Path
    _filterAttribut e = DirectCast(resu lt.Properties(" cn")(0), String)
    Catch ex As Exception
    Throw New Exception("Erro r authenticating user. " + ex.Message)
    End Try
    Return True
    End Function




    LS

    Comment

    • Cor Ligthert[MVP]

      #3
      Re: Another block of C# code to convert

      Hi Seth,

      Just for fun.

      I saw your code and made this from it, looks for me more as VB 2008

      I hope Anton will show what it does with his converter, I expect that it is
      better than you showed with those plusses.

      \\\
      Option Infer On
      Option Strict On
      Option Explicit On
      Imports System.Director yServices

      Module Module1
      Sub Main()
      End Sub
      Public Function IsAuthenticated (ByVal domain As String, ByVal username
      As String, ByVal pwd As String) As Boolean
      Dim path, filterAttribute As String 'dummies
      Dim domainAndUserna me = domain & "\" & username
      Dim entry As New DirectoryEntry( path, domainAndUserna me, pwd)
      Try
      ' Bind to the native AdsObject to force authentication.
      Dim obj = entry.NativeObj ect
      Dim search As New DirectorySearch er(entry)
      search.Filter = "(SAMAccountNam e=" & username & ")"
      search.Properti esToLoad.Add("c n")
      Dim result = search.FindOne( )
      If result IsNot Nothing Then
      'Update the new path to the user in the directory
      path = result.Path
      filterAttribute = result.Properti es("cn")(0).ToS tring
      Return True
      Else
      Return False
      End If
      Catch ex As Exception
      Throw New Exception("Erro r authenticating user. " & ex.Message)
      End Try
      End Function
      End Module
      ///


      (I did not test the result, only changed the code)

      Cor

      "Lloyd Sheen" <a@b.cschreef in bericht
      news:%23gSHNA2t IHA.1328@TK2MSF TNGP03.phx.gbl. ..
      >
      "Ty" <tbarton@lewist ownhospital.org wrote in message
      news:8b7d2a6b-c7ba-435c-94db-e7a150695d81@59 g2000hsb.google groups.com...
      >Here is another block that I can not get to convert. This is a class
      >module.
      >>
      >public bool IsAuthenticated (string domain, string username, string
      >pwd)
      >{
      > string domainAndUserna me = domain + @"\" + username;
      > DirectoryEntry entry = new DirectoryEntry( _path,
      > domainAndUserna me, pwd);
      > try
      > {
      > // Bind to the native AdsObject to force authentication.
      > Object obj = entry.NativeObj ect;
      > DirectorySearch er search = new DirectorySearch er(entry);
      > search.Filter = "(SAMAccountNam e=" + username + ")";
      > search.Properti esToLoad.Add("c n");
      > SearchResult result = search.FindOne( );
      > if(null == result)
      > {
      > return false;
      > }
      > // Update the new path to the user in the directory
      > _path = result.Path;
      > _filterAttribut e = (String)result. Properties["cn"][0];
      > }
      > catch (Exception ex)
      > {
      > throw new Exception("Erro r authenticating user. " + ex.Message);
      > }
      > return true;
      >}
      >>
      >}
      >>
      >Any help would be apperciated.
      >
      >
      Public Function IsAuthenticated (ByVal domain As String, ByVal username As
      String, ByVal pwd As String) As Boolean
      Dim domainAndUserna me As String = domain + "\" + username
      Dim entry As New DirectoryEntry( _path, domainAndUserna me, pwd)
      Try
      ' Bind to the native AdsObject to force authentication.
      Dim obj As Object = entry.NativeObj ect
      Dim search As New DirectorySearch er(entry)
      search.Filter = "(SAMAccountNam e=" + username + ")"
      search.Properti esToLoad.Add("c n")
      Dim result As SearchResult = search.FindOne( )
      If result Is Nothing Then
      Return False
      End If
      ' Update the new path to the user in the directory
      _path = result.Path
      _filterAttribut e = DirectCast(resu lt.Properties(" cn")(0), String)
      Catch ex As Exception
      Throw New Exception("Erro r authenticating user. " + ex.Message)
      End Try
      Return True
      End Function
      >
      >

      >
      LS

      Comment

      • =?Utf-8?B?RGF2aWQgQW50b24=?=

        #4
        Re: Another block of C# code to convert

        Except for using '&' instead of '+' (which may be ambiguous in some cases),
        our conversion was quite similar. One difference is that 'DirectCast' is not
        the general purpose equivalent for the C# casting operator - CType is a more
        reliable replacement (google on DirectCast to see why).
        --
        Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

        C++ to C#
        C++ to VB
        C++ to Java
        VB to Java
        Java to VB & C#
        Instant C#: VB to C#
        Instant VB: C# to VB
        Instant C++: VB, C#, or Java to C++/CLI


        "Cor Ligthert[MVP]" wrote:
        Hi Seth,
        >
        Just for fun.
        >
        I saw your code and made this from it, looks for me more as VB 2008
        >
        I hope Anton will show what it does with his converter, I expect that it is
        better than you showed with those plusses.
        >
        \\\
        Option Infer On
        Option Strict On
        Option Explicit On
        Imports System.Director yServices
        >
        Module Module1
        Sub Main()
        End Sub
        Public Function IsAuthenticated (ByVal domain As String, ByVal username
        As String, ByVal pwd As String) As Boolean
        Dim path, filterAttribute As String 'dummies
        Dim domainAndUserna me = domain & "\" & username
        Dim entry As New DirectoryEntry( path, domainAndUserna me, pwd)
        Try
        ' Bind to the native AdsObject to force authentication.
        Dim obj = entry.NativeObj ect
        Dim search As New DirectorySearch er(entry)
        search.Filter = "(SAMAccountNam e=" & username & ")"
        search.Properti esToLoad.Add("c n")
        Dim result = search.FindOne( )
        If result IsNot Nothing Then
        'Update the new path to the user in the directory
        path = result.Path
        filterAttribute = result.Properti es("cn")(0).ToS tring
        Return True
        Else
        Return False
        End If
        Catch ex As Exception
        Throw New Exception("Erro r authenticating user. " & ex.Message)
        End Try
        End Function
        End Module
        ///
        >
        >
        (I did not test the result, only changed the code)
        >
        Cor
        >
        "Lloyd Sheen" <a@b.cschreef in bericht
        news:%23gSHNA2t IHA.1328@TK2MSF TNGP03.phx.gbl. ..

        "Ty" <tbarton@lewist ownhospital.org wrote in message
        news:8b7d2a6b-c7ba-435c-94db-e7a150695d81@59 g2000hsb.google groups.com...
        Here is another block that I can not get to convert. This is a class
        module.
        >
        public bool IsAuthenticated (string domain, string username, string
        pwd)
        {
        string domainAndUserna me = domain + @"\" + username;
        DirectoryEntry entry = new DirectoryEntry( _path,
        domainAndUserna me, pwd);
        try
        {
        // Bind to the native AdsObject to force authentication.
        Object obj = entry.NativeObj ect;
        DirectorySearch er search = new DirectorySearch er(entry);
        search.Filter = "(SAMAccountNam e=" + username + ")";
        search.Properti esToLoad.Add("c n");
        SearchResult result = search.FindOne( );
        if(null == result)
        {
        return false;
        }
        // Update the new path to the user in the directory
        _path = result.Path;
        _filterAttribut e = (String)result. Properties["cn"][0];
        }
        catch (Exception ex)
        {
        throw new Exception("Erro r authenticating user. " + ex.Message);
        }
        return true;
        }
        >
        }
        >
        Any help would be apperciated.

        Public Function IsAuthenticated (ByVal domain As String, ByVal username As
        String, ByVal pwd As String) As Boolean
        Dim domainAndUserna me As String = domain + "\" + username
        Dim entry As New DirectoryEntry( _path, domainAndUserna me, pwd)
        Try
        ' Bind to the native AdsObject to force authentication.
        Dim obj As Object = entry.NativeObj ect
        Dim search As New DirectorySearch er(entry)
        search.Filter = "(SAMAccountNam e=" + username + ")"
        search.Properti esToLoad.Add("c n")
        Dim result As SearchResult = search.FindOne( )
        If result Is Nothing Then
        Return False
        End If
        ' Update the new path to the user in the directory
        _path = result.Path
        _filterAttribut e = DirectCast(resu lt.Properties(" cn")(0), String)
        Catch ex As Exception
        Throw New Exception("Erro r authenticating user. " + ex.Message)
        End Try
        Return True
        End Function




        LS
        >

        Comment

        • Cor Ligthert[MVP]

          #5
          Re: Another block of C# code to convert

          David,

          That was the most important for me,
          Except for using '&' instead of '+' (which may be ambiguous in some
          cases),
          our conversion was quite similar.
          I made the code particulary for 2008 you should not expect that from a
          converter

          The guy who did the casting in C# with (string)bla did of course as well not
          so a good documentative job, as a ToString() from object is one of the most
          basic elements of dotnet.

          Cor



          "David Anton" <DavidAnton@dis cussions.micros oft.comschreef in bericht
          news:C25331E6-1637-47EC-820F-EA7813F862A6@mi crosoft.com...
          Except for using '&' instead of '+' (which may be ambiguous in some
          cases),
          our conversion was quite similar. One difference is that 'DirectCast' is
          not
          the general purpose equivalent for the C# casting operator - CType is a
          more
          reliable replacement (google on DirectCast to see why).
          --
          Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

          C++ to C#
          C++ to VB
          C++ to Java
          VB to Java
          Java to VB & C#
          Instant C#: VB to C#
          Instant VB: C# to VB
          Instant C++: VB, C#, or Java to C++/CLI
          >
          >
          "Cor Ligthert[MVP]" wrote:
          >
          >Hi Seth,
          >>
          >Just for fun.
          >>
          >I saw your code and made this from it, looks for me more as VB 2008
          >>
          >I hope Anton will show what it does with his converter, I expect that it
          >is
          >better than you showed with those plusses.
          >>
          >\\\
          >Option Infer On
          >Option Strict On
          >Option Explicit On
          >Imports System.Director yServices
          >>
          >Module Module1
          > Sub Main()
          > End Sub
          > Public Function IsAuthenticated (ByVal domain As String, ByVal
          >username
          >As String, ByVal pwd As String) As Boolean
          > Dim path, filterAttribute As String 'dummies
          > Dim domainAndUserna me = domain & "\" & username
          > Dim entry As New DirectoryEntry( path, domainAndUserna me, pwd)
          > Try
          > ' Bind to the native AdsObject to force authentication.
          > Dim obj = entry.NativeObj ect
          > Dim search As New DirectorySearch er(entry)
          > search.Filter = "(SAMAccountNam e=" & username & ")"
          > search.Properti esToLoad.Add("c n")
          > Dim result = search.FindOne( )
          > If result IsNot Nothing Then
          > 'Update the new path to the user in the directory
          > path = result.Path
          > filterAttribute = result.Properti es("cn")(0).ToS tring
          > Return True
          > Else
          > Return False
          > End If
          > Catch ex As Exception
          > Throw New Exception("Erro r authenticating user. " &
          >ex.Message)
          > End Try
          > End Function
          >End Module
          >///
          >>
          >>
          >(I did not test the result, only changed the code)
          >>
          >Cor
          >>
          >"Lloyd Sheen" <a@b.cschreef in bericht
          >news:%23gSHNA2 tIHA.1328@TK2MS FTNGP03.phx.gbl ...
          >
          "Ty" <tbarton@lewist ownhospital.org wrote in message
          news:8b7d2a6b-c7ba-435c-94db-e7a150695d81@59 g2000hsb.google groups.com...
          >Here is another block that I can not get to convert. This is a class
          >module.
          >>
          >public bool IsAuthenticated (string domain, string username, string
          >pwd)
          >{
          > string domainAndUserna me = domain + @"\" + username;
          > DirectoryEntry entry = new DirectoryEntry( _path,
          > domainAndUserna me, pwd);
          > try
          > {
          > // Bind to the native AdsObject to force authentication.
          > Object obj = entry.NativeObj ect;
          > DirectorySearch er search = new DirectorySearch er(entry);
          > search.Filter = "(SAMAccountNam e=" + username + ")";
          > search.Properti esToLoad.Add("c n");
          > SearchResult result = search.FindOne( );
          > if(null == result)
          > {
          > return false;
          > }
          > // Update the new path to the user in the directory
          > _path = result.Path;
          > _filterAttribut e = (String)result. Properties["cn"][0];
          > }
          > catch (Exception ex)
          > {
          > throw new Exception("Erro r authenticating user. " + ex.Message);
          > }
          > return true;
          >}
          >>
          >}
          >>
          >Any help would be apperciated.
          >
          >
          Public Function IsAuthenticated (ByVal domain As String, ByVal username
          As
          String, ByVal pwd As String) As Boolean
          Dim domainAndUserna me As String = domain + "\" + username
          Dim entry As New DirectoryEntry( _path, domainAndUserna me, pwd)
          Try
          ' Bind to the native AdsObject to force authentication.
          Dim obj As Object = entry.NativeObj ect
          Dim search As New DirectorySearch er(entry)
          search.Filter = "(SAMAccountNam e=" + username + ")"
          search.Properti esToLoad.Add("c n")
          Dim result As SearchResult = search.FindOne( )
          If result Is Nothing Then
          Return False
          End If
          ' Update the new path to the user in the directory
          _path = result.Path
          _filterAttribut e = DirectCast(resu lt.Properties(" cn")(0), String)
          Catch ex As Exception
          Throw New Exception("Erro r authenticating user. " + ex.Message)
          End Try
          Return True
          End Function
          >
          >

          >
          LS
          >>

          Comment

          • Michel Posseth

            #6
            Re: Another block of C# code to convert

            Ty schreef:
            Here is another block that I can not get to convert. This is a class
            module.
            >
            public bool IsAuthenticated (string domain, string username, string
            pwd)
            {
            string domainAndUserna me = domain + @"\" + username;
            DirectoryEntry entry = new DirectoryEntry( _path,
            domainAndUserna me, pwd);
            try
            {
            // Bind to the native AdsObject to force authentication.
            Object obj = entry.NativeObj ect;
            DirectorySearch er search = new DirectorySearch er(entry);
            search.Filter = "(SAMAccountNam e=" + username + ")";
            search.Properti esToLoad.Add("c n");
            SearchResult result = search.FindOne( );
            if(null == result)
            {
            return false;
            }
            // Update the new path to the user in the directory
            _path = result.Path;
            _filterAttribut e = (String)result. Properties["cn"][0];
            }
            catch (Exception ex)
            {
            throw new Exception("Erro r authenticating user. " + ex.Message);
            }
            return true;
            }
            >
            }
            >
            Any help would be apperciated.

            You mean you posted a part of a class module without telling wich
            references were set and without providing the class scoped variabels

            The next time provide this information , maybe this is the reasson why
            nobody bothered until so far cause the code is pretty simple .


            first of all set a refernce to system.Director yServices

            then in the top of the code file you put this import statement

            Imports System.Director yServices


            Private _path As String
            Private _filterAttribut e As String


            Public Function IsAuthenticated (ByVal domain As String, ByVal
            username As String, ByVal pwd As String) As Boolean
            Dim domainAndUserna me As String = domain + "\" + username
            Dim entry As New DirectoryEntry( _path, domainAndUserna me, pwd)
            Try
            ' Bind to the native AdsObject to force authentication.
            Dim obj As Object = entry.NativeObj ect
            Dim search As New DirectorySearch er(entry)
            search.Filter = "(SAMAccountNam e=" + username + ")"
            search.Properti esToLoad.Add("c n")
            Dim result As SearchResult = search.FindOne( )
            If result Is Nothing Then
            Return False
            End If
            ' Update the new path to the user in the directory
            _path = result.Path
            _filterAttribut e =
            DirectCast(resu lt.Properties(" cn")(0),Strin g)
            Catch ex As Exception
            Throw New Exception("Erro r authenticating user. " + ex.Message)
            End Try
            Return True
            End Function

            regards
            Michel Posseth [MCP]



            Comment

            • Michel Posseth

              #7
              Re: Another block of C# code to convert

              Michel Posseth schreef:
              Ty schreef:
              >Here is another block that I can not get to convert. This is a class
              >module.
              >>
              >public bool IsAuthenticated (string domain, string username, string
              >pwd)
              >{
              > string domainAndUserna me = domain + @"\" + username;
              > DirectoryEntry entry = new DirectoryEntry( _path,
              > domainAndUserna me, pwd);
              > try
              > {
              > // Bind to the native AdsObject to force authentication.
              > Object obj = entry.NativeObj ect;
              > DirectorySearch er search = new DirectorySearch er(entry);
              > search.Filter = "(SAMAccountNam e=" + username + ")";
              > search.Properti esToLoad.Add("c n");
              > SearchResult result = search.FindOne( );
              > if(null == result)
              > {
              > return false;
              > }
              > // Update the new path to the user in the directory
              > _path = result.Path;
              > _filterAttribut e = (String)result. Properties["cn"][0];
              > }
              > catch (Exception ex)
              > {
              > throw new Exception("Erro r authenticating user. " + ex.Message);
              > }
              > return true;
              >}
              >>
              >}
              >>
              >Any help would be apperciated.
              >
              >
              You mean you posted a part of a class module without telling wich
              references were set and without providing the class scoped variabels
              >
              The next time provide this information , maybe this is the reasson why
              nobody bothered until so far cause the code is pretty simple .
              >
              >
              first of all set a refernce to system.Director yServices
              >
              then in the top of the code file you put this import statement
              >
              Imports System.Director yServices
              >
              >
              Private _path As String
              Private _filterAttribut e As String
              >
              >
              Public Function IsAuthenticated (ByVal domain As String, ByVal
              username As String, ByVal pwd As String) As Boolean
              Dim domainAndUserna me As String = domain + "\" + username
              Dim entry As New DirectoryEntry( _path, domainAndUserna me, pwd)
              Try
              ' Bind to the native AdsObject to force authentication.
              Dim obj As Object = entry.NativeObj ect
              Dim search As New DirectorySearch er(entry)
              search.Filter = "(SAMAccountNam e=" + username + ")"
              search.Properti esToLoad.Add("c n")
              Dim result As SearchResult = search.FindOne( )
              If result Is Nothing Then
              Return False
              End If
              ' Update the new path to the user in the directory
              _path = result.Path
              _filterAttribut e =
              DirectCast(resu lt.Properties(" cn")(0),Strin g)
              Catch ex As Exception
              Throw New Exception("Erro r authenticating user. " + ex.Message)
              End Try
              Return True
              End Function
              >
              regards
              Michel Posseth [MCP]
              >
              >
              >
              hmmm on this computer i installed Thunderbird ( just for testing :-) )
              but it looks like i am a bit behind reality ( thought no one had
              answered this one yet )



              Comment

              Working...