I give no guarantees, I give nothing - so don't bug me, I slapped it together last night on my third or fourth Guinness...
Imports System.Web
Imports System.Configuration
' TODO: Add thread safety.
' TODO: Optimize open/closure of data connections per routine call.
Public Class Provider
Inherits System.Web.SiteMapProvider
Public Overrides Function FindSiteMapNode(ByVal rawUrl As String) As SiteMapNode
Try
' TODO: clean up this code by taking out the redundant snippets.
Me.OpenConnection()
Dim command As Oracle.DataAccess.Client.OracleCommand = Me.m_Connection.CreateCommand()
command.CommandText = "select * from BEN.SITEMAPNODES WHERE URL = '" + rawUrl + "'"
Dim adapter As New Oracle.DataAccess.Client.OracleDataAdapter(command)
Dim node As New SiteMapNodeDS()
adapter.Fill(node.SITEMAPNODES)
If node.SITEMAPNODES.Count = 1 Then
' we have a single result, which is what we want.
Dim sn As New SiteMapNode(Me, node.SITEMAPNODES(0).ID.ToString(), node.SITEMAPNODES(0).URL, node.SITEMAPNODES(0).TITLE, node.SITEMAPNODES(0).DESCRIPTION)
Return sn
Else
If node.SITEMAPNODES.Count > 1 Then
Throw New System.ApplicationException("Too many rows returned; this violates the restraint.")
End If ' otherwise error.
End If
Return Nothing
Finally
Me.CloseConnection()
End Try
End Function 'FindSiteMapNode
Public Overrides Function GetChildNodes(ByVal node As SiteMapNode) As SiteMapNodeCollection
Try
Me.OpenConnection()
Dim command As Oracle.DataAccess.Client.OracleCommand = Me.m_Connection.CreateCommand()
command.CommandText = "select * from BEN.SITEMAPNODES where ROOTNODE = " + node.Key
Dim adapter As New Oracle.DataAccess.Client.OracleDataAdapter(command)
Dim nodeDS As New SiteMapNodeDS()
adapter.Fill(nodeDS.SITEMAPNODES)
If nodeDS.SITEMAPNODES.Count > 0 Then
Dim coll As New SiteMapNodeCollection()
Dim row As SiteMapNodeDS.SITEMAPNODESRow
For Each row In nodeDS.SITEMAPNODES.Rows
coll.Add(New SiteMapNode(Me, row.ID.ToString(), row.URL, row.TITLE, row.DESCRIPTION))
Next row
Return coll
Else
Return Nothing
End If
Finally
Me.CloseConnection()
End Try
End Function 'GetChildNodes
Public Overrides Function GetParentNode(ByVal node As SiteMapNode) As SiteMapNode
' TODO: implement security trimming.
Try
Me.OpenConnection()
Dim command As Oracle.DataAccess.Client.OracleCommand = Me.m_Connection.CreateCommand()
command.CommandText = "SELECT * FROM BEN.SITEMAPNODES WHERE ID = (SELECT ROOTNODE from BEN.SITEMAPNODES where ID = " + node.Key + ")"
Dim adapter As New Oracle.DataAccess.Client.OracleDataAdapter(command)
Dim ds As New SiteMapNodeDS()
adapter.Fill(ds.SITEMAPNODES)
If ds.SITEMAPNODES.Count = 1 Then
Return New SiteMapNode(Me, ds.SITEMAPNODES(0).ID.ToString(), ds.SITEMAPNODES(0).URL, ds.SITEMAPNODES(0).TITLE, ds.SITEMAPNODES(0).DESCRIPTION)
Else
If ds.SITEMAPNODES.Count > 1 Then
Throw New System.ApplicationException("Too many parent nodes found, this violates the constraint rules.")
Else
Return Nothing
End If
End If
Finally
Me.CloseConnection()
End Try
End Function 'GetParentNode
Protected Overrides Function GetRootNodeCore() As SiteMapNode
Try
Me.OpenConnection()
Dim command As Oracle.DataAccess.Client.OracleCommand = Me.m_Connection.CreateCommand()
command.CommandText = "SELECT * FROM BEN.SITEMAPNODES WHERE ROOTNODE = -1"
Dim adapter As New Oracle.DataAccess.Client.OracleDataAdapter(command)
Dim node As New SiteMapNodeDS()
adapter.Fill(node.SITEMAPNODES)
If node.SITEMAPNODES.Count = 1 Then
Return New SiteMapNode(Me, node.SITEMAPNODES(0).ID.ToString(), node.SITEMAPNODES(0).URL, node.SITEMAPNODES(0).TITLE, node.SITEMAPNODES(0).DESCRIPTION)
Else
If node.SITEMAPNODES.Count > 1 Then
Throw New System.ApplicationException("More than one root node discovered, this violates the parent restraint.")
Else
Return Nothing
End If
End If
Finally
Me.CloseConnection()
End Try
End Function 'GetRootNodeCore
Private Function OpenConnection() As Oracle.DataAccess.Client.OracleConnection
If Me.m_Connection Is Nothing Or Me.m_Connection.State <> System.Data.ConnectionState.Open Then
Me.m_Connection = New Oracle.DataAccess.Client.OracleConnection()
Try
Me.m_Connection.ConnectionString = "Data Source=DEV1_BEN;User Id=ben;Password=xxx;"
Me.m_Connection.Open()
Catch
End Try
End If
Return Me.m_Connection
End Function 'OpenConnection
Private Sub CloseConnection()
If Not (Me.m_Connection Is Nothing) Then
Me.m_Connection.Close()
Me.m_Connection.Dispose()
Me.m_Connection = Nothing
End If
Return
End Sub 'CloseConnection
Private m_Connection As Oracle.DataAccess.Client.OracleConnection
End Class 'Provider