Click here to Skip to main content
15,894,405 members
Articles / Web Development / HTML

Building a Shared Code Library as a VS.NET Plug-in

Rate me:
Please Sign up or sign in to vote.
4.00/5 (7 votes)
30 Mar 20055 min read 89.2K   594   41  
A plug-in for VS.NET that stores code snippets in a database. From the plug-in you can add code, search the database for code snippets. Also includes examples on how to integrate with the IDE as a plug-in.
Imports System.Security.Principal
Imports System.Configuration
Imports System.Data.SqlClient

Public Class clsWinAuthentication
#Const InetasiaVersion = False

    Dim aclsDB As New RadDev.Data.SQLBased.clsDbTier(GetOptions.ConnectionString)

    Private pUserID As Integer
    Property UserID() As Integer
        Get
            Return pUserID
        End Get
        Set(ByVal Value As Integer)
            pUserID = Value
        End Set
    End Property

    Private pWinUser As String
    Property WinUser() As String
        Get
            Return pWinUser
        End Get
        Set(ByVal Value As String)
            pWinUser = Value
        End Set
    End Property

    Private pWinDomain As String
    Property WinDomain() As String
        Get
Return pWinDomain
        End Get
        Set(ByVal Value As String)

 pWinDomain = Value
        End Set
    End Property

    Private pFirstName As String
    Property FirstName() As String
        Get
            Return pFirstName
        End Get
        Set(ByVal Value As String)
            pFirstName = Value
        End Set
    End Property

    'purpose is to add a user who isnt already in the database to the database!
    Public Function AddNewUser() As Boolean
        '#If InetasiaVersion = True Then
        ' add them to the users

        Dim aclsDBSP As New RadDev.Data.StoredProcedure.clsDBTierStoredProc
        aclsDBSP.ConnectionString = GetOptions.ConnectionString
        aclsDBSP.AddParameter("@WinDomain", WinDomain, ParameterDirection.Input)
        aclsDBSP.AddParameter("@WinUser", WinUser, ParameterDirection.Input)
        aclsDBSP.AddParameter("@Email", WinUser & WinUser.ToString & "@" & WinDomain.ToString & ".com", ParameterDirection.Input)
        aclsDBSP.AddParameter("@FirstName", WinUser, ParameterDirection.Input)
        aclsDBSP.AddParameter("@LastName", "", ParameterDirection.Input)
        aclsDBSP.AddParameter("@NotifyEmail", 1, ParameterDirection.Input)
        aclsDBSP.AddParameter("@NotifyNetSend", 1, ParameterDirection.Input)
        aclsDBSP.AddParameter("@User_id", 1, ParameterDirection.Output)

        Try
            aclsDBSP.HandleExceptions = True
            aclsDBSP.ExecuteNonQuery("proc_Inserttbluser")
            If aclsDBSP.HasError Then
                Trace.Write("error adding user " & aclsDBSP.ErrorMessage)
                AddNewUser = False
            Else
                AddNewUser = True
                MsgBox("Added " & WinUser & " as a new user successfully.")
                AuthenticateUser(False)
            End If
        Catch ex As Exception
            AddNewUser = False
        End Try
        '#Else
        ' throw up the add new user dialog
        ' dim afrmAddNewUser as New frmAddNewUser 
        ' afrmAddNewUser.showdialog        
        '#End If
    End Function

    Public Sub GetUserDetails()
        Dim User As New WindowsPrincipal(WindowsIdentity.GetCurrent())
        Dim tmpUserName() As String = User.Identity.Name.ToString.Split("\")
        pWinUser = tmpUserName(1)
        pWinDomain = tmpUserName(0)
    End Sub

    Public Function AuthenticateUser(ByVal SilentMode As Boolean) As Boolean
        Dim ValidUser As Boolean = False
        Try
            Dim User As New WindowsPrincipal(WindowsIdentity.GetCurrent())
            Dim tmpUserName() As String = User.Identity.Name.ToString.Split("\")
            pWinUser = tmpUserName(1)
            pWinDomain = tmpUserName(0)
            ValidUser = User.Identity.IsAuthenticated

            '#If InetasiaVersion = True Then
            '            If (pWinDomain.ToUpper <> "INETASIA".ToUpper) And (pWinDomain.ToUpper <> "INETASIA.Com".ToUpper) Then
            '                ValidUser = False
            '                MsgBox("This is an INETASIA only version. Continuing to run again on your system will lead to undesirable consequences. Piracy will be punished.")
            '            End If
            '#End If
            If ValidUser Then
                If LoadUserDetails(User) = 0 Then
                    ' If AddNewUser() Then
                    ValidUser = False
                    If Not SilentMode Then
                        Dim aFrmAbout As New frmAbout
                        aFrmAbout.ShowDialog()
                        If aFrmAbout.UserAdded Then
                            ValidUser = AuthenticateUser(SilentMode)
                        End If
                    End If
                    'Else
                    '   ValidUser = False
                    'End If
                End If
            Else
                ' MsgBox("You were not authenticated by Windows. Please contact your network administrator")
                ' write to the message window it didnt work
                ValidUser = False
            End If

        Finally
            AuthenticateUser = ValidUser
        End Try
    End Function


    Private Function LoadUserDetails(ByVal aUser As WindowsPrincipal) As Integer
        Dim aDataReader As SqlClient.SqlDataReader
        Try
            Try
                Dim Sql As String
                Sql = "select * from tbluser where WinDomain + '\' + WinUser = '" & aUser.Identity.Name.ToString & "'"
#If InetasiaVersion = True Then
                Sql += " and WINDOMAIN = 'INETASIA'"
#End If
                aDataReader = aclsDB.GetDataReader(Sql)
                If aDataReader.Read Then
                    pUserID = aDataReader("User_ID").ToString
                    LoadUserDetails = pUserID
                    'pWinDomain = aDataReader("WinDomain").ToString
                    'pWinUser = aDataReader("WinUser").ToString
                    pFirstName = aDataReader("FirstName").ToString
                Else : LoadUserDetails = 0
                End If

            Catch ex As Exception
                Trace.Write("You have most likely a connectivity problem : " + ex.Message)
                LoadUserDetails = 0
            End Try

        Finally
            If Not (aDataReader Is Nothing) Then
                aDataReader.Close()
            End If
        End Try

    End Function




End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Thailand Thailand
Spent my whole life developing, having worked in C++, Delphi, ASP, then finally settling down to working solely in ASP.Net. Also a forex day trader.

Comments and Discussions