473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Configuration in .net 2.0 question

I have having trouble to get the following code (related to custom configuration .net 2.0) to work. Can anyone please help?

Custom config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="Config" type="LibRefresh.Config, LibRefresh" />
<section name="WebApplicationLists" type="LibRefresh.CustomConfigSection, LibRefresh" />
</configSections>
<Config>
<WebApplicationLists>
<WebApplication Name="AUM" URL="http://ntsvgss15120b/aum/default.aspx" LastUpdateOn="10/15/2007 11:47:27 AM" RefreshInterval="20" />
<WebApplication Name="BDRecon" URL="http://ntsvgss15120b/bdrecon/default.aspx" LastUpdateOn="10/12/2007 2:24:41 PM" RefreshInterval="20" />
</WebApplicationLists>
</Config>
</configuration>

Custom config class:

Imports System.Configuration

Public Class CustomConfigSection
Inherits System.Configuration.ConfigurationSection

Private m_cfg As Configuration

#Region " Instance methods "

'Public Sub Encript(ByVal encript As Boolean)
' If encript Then
' Me.SectionInformation.ProtectSection("DataProtecti onConfigurationProvider")
' Else
' Me.SectionInformation.UnprotectSection()
' End If
' Me.Save()
'End Sub

Public Sub Save()
Me.SectionInformation.ForceSave = True
m_cfg.Save(ConfigurationSaveMode.Full)
End Sub

#End Region

<ConfigurationProperty("WebApplicationLists")> _
Public Property WebApplicationLists() As WebApplicationCollection
Get
Return TryCast(Me("WebApplicationLists"), WebApplicationCollection)
End Get
Set(ByVal value As WebApplicationCollection)
Me("WebApplicationLists") = value
End Set
End Property

#Region " Shared methods "
Private Const CS_SECTION As String = "WebApplicationLists"
Private Shared m_current As CustomConfigSection

Public Shared ReadOnly Property Current() As CustomConfigSection
Get
If m_current Is Nothing Then
Dim cfg As Configuration

Dim fileMap As New ExeConfigurationFileMap()
fileMap.ExeConfigFilename = "c:\custom.config"
cfg = ConfigurationManager.OpenMappedExeConfiguration(fi leMap, ConfigurationUserLevel.None)

m_current = DirectCast(cfg.Sections(CS_SECTION), _
CustomConfigSection)

m_current.m_cfg = cfg
End If
Return m_current
End Get
End Property

#End Region

End Class

Public Class WebApplication : Inherits ConfigurationElement

Sub New()
End Sub

<ConfigurationProperty("Name", IsRequired:=True)> _
Public Property Name() As String
Get
Return TryCast(Me("Name"), String)
End Get
Set(ByVal value As String)
Me("Name") = value
End Set
End Property

<ConfigurationProperty("URL", IsRequired:=True)> _
Public Property URL() As String
Get
Return TryCast(Me("URL"), String)
End Get
Set(ByVal value As String)
Me("URL") = value
End Set
End Property

<ConfigurationProperty("LastUpdateOn", IsRequired:=True)> _
Public Property LastUpdateOn() As String
Get
Return TryCast(Me("LastUpdateOn"), String)
End Get
Set(ByVal value As String)
Me("LastUpdateOn") = value
End Set
End Property

<ConfigurationProperty("RefreshInterval", IsRequired:=True)> _
Public Property RefreshInterval() As String
Get
Return TryCast(Me("RefreshInterval"), String)
End Get
Set(ByVal value As String)
Me("RefreshInterval") = value
End Set
End Property

End Class

Public Class WebApplicationCollection : Inherits ConfigurationElementCollection

Protected Sub New()
End Sub

Protected Sub New(ByVal comparer As IComparer)
MyBase.New(comparer)
End Sub

Public Overrides ReadOnly Property CollectionType() As ConfigurationElementCollectionType
Get
Return ConfigurationElementCollectionType.BasicMap
End Get
End Property

Protected Overrides ReadOnly Property ElementName() As String
Get
Return "WebApplication"
End Get
End Property

Protected Overloads Overrides Function CreateNewElement() As ConfigurationElement
Return New WebApplication
End Function

Protected Overrides Function GetElementKey(ByVal element As ConfigurationElement) As Object
Return TryCast(element, WebApplication).Name
End Function

Default Public Overloads Property Item(ByVal index As Integer) As WebApplication
Get
Return CType(MyBase.BaseGet(index), WebApplication)
End Get
Set(ByVal value As WebApplication)
If Not (MyBase.BaseGet(index) Is Nothing) Then
MyBase.BaseRemoveAt(index)
End If
MyBase.BaseAdd(index, value)
End Set
End Property

Default Public Overloads ReadOnly Property Item(ByVal name As String) As WebApplication
Get
Return TryCast(MyBase.BaseGet(name), WebApplication)
End Get
End Property

Public Sub Add(ByVal element As WebApplication)
MyBase.BaseAdd(element)
End Sub 'Add

Public Sub Remove(ByVal name As String)
MyBase.BaseRemove(name)
End Sub 'Remove

Public Sub Remove(ByVal element As WebApplication)
MyBase.BaseRemove(GetElementKey(element))
End Sub 'Remove

Public Sub Clear()
MyBase.BaseClear()
End Sub 'Clear

Public Sub RemoveAt(ByVal index As Integer)
MyBase.BaseRemoveAt(index)
End Sub 'RemoveAt

Public Function GetKey(ByVal index As Integer) As String
Return CStr(MyBase.BaseGetKey(index))
End Function 'GetKey
End Class
Oct 16 '07 #1
0 1107

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Robert | last post by:
I have an application with custom configuration sections in it's app.config file. Here's a shortened excerpt: <monitors> <monitor...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
6
by: barry | last post by:
I have VSTO 2005 and am not able to get ASP.NET Configuration under the Website menu to work. It just shows a not found page and comes back to where I executed it from. My question is can I...
9
by: KarlM | last post by:
After reading some articles regarding confuguration data I'm a bit confused. Where is the right place for storing configuration data? - XML-files? - registry? - INI-files? (from a users point...
3
by: AMP | last post by:
Hello, I asked a similar question yesterday with no responces. I want to read and write to a configuration file with user settings.(Windows App) Are there any good books, or sites that explain...
4
by: Michael Lang | last post by:
I was basically wanting to know how to use the System.Configuration namespace to be able to load an arbitrary number of unknown attributes on an element in a custom section in the .config into a...
9
by: shror | last post by:
hi every body, i have a problem which is when i was checking my mail() form it work fine but the problem is that the form configuration is not set correctly, in details: the from var is not...
3
by: Mike | last post by:
Hi I have problem as folow: Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type...
2
by: remya1000 | last post by:
i'm using VB.NET 2003. Last time while i did a program in Vb.Net 2005, i use "Configuration". and i could read and write to that XML configuration file like the example below. CODES:...
3
by: guybenron | last post by:
Hey, I have a sort of petty-neurotic question, I'm kinda pedantic and like to keep my log directories clean, and this thing is bothering me to the point of actually posting a question (couldn't...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.