<?xml version="1.0" encoding="utf-8" ?>
<!-- Configuration settings -->
<Configuration>
<!-- Database settings -->
<Database Type="SqlServer" ConnectionString="Server=SQLSERVER;Database=DBNAME;User ID=USER;Password=PWD;" />
<!-- Mail settings -->
<Mail SmtpServer="SMTPSERVER" SenderAddress="sender@domain.com" AlertAddress="alert@domain.com">
<MailTo Address="user1@domain.com"></MailTo>
<MailTo Address="user2@domain.com"></MailTo>
<MailTo Address="user3@domain.com"></MailTo>
<MailTo Address="user4@domain.com"></MailTo>
<MailTo Address="user5@domain.com"></MailTo>
</Mail>
<!-- FileSystem settings -->
<FileSystem>
<Folder Type="Logs" Path="C:\Temp\Batch\Logs\" Duration="365"></Folder>
<Folder Type="PdfDocs" Path="C:\Temp\Batch\PdfDocs\" Duration="365"></Folder>
<Folder Type="Charts" Path="C:\Temp\Batch\Charts\" Duration="365"></Folder>
</FileSystem>
</Configuration>
'Static sealed class
Public NotInheritable Class Configuration
'******************************************************************************
'Static public fields (application settings)
Public Shared ConnectionString As String
Public Shared DbType As String
Public Shared SmtpServer As String
Public Shared SenderAddress As String
Public Shared AlertAddress As String
Public Shared MailTo As ArrayList
Public Shared LogsRoot As String
Public Shared PdfDocsRoot As String
Public Shared ChartsRoot As String
Public Shared LogsDuration As Integer
Public Shared PdfDocsDuration As Integer
Public Shared ChartsDuration As Integer
'******************************************************************************
'Private class constructor
Private Sub New()
End Sub
'******************************************************************************
'Get configuration settings from a file XML
Public Shared Sub GetSettings(Optional ByVal FileName As String = "")
Dim cfg As String = FileName
If cfg = "" Then cfg = CFG_PATH
Try
If IO.File.Exists(cfg) Then
Dim al As New ArrayList()
Dim fs As New IO.FileStream(cfg, IO.FileMode.Open, IO.FileAccess.Read)
Dim stream As New IO.StreamReader(fs)
Dim reader As New Xml.XmlTextReader(stream)
While (reader.Read())
If reader.NodeType = Xml.XmlNodeType.Element Then
If reader.HasAttributes = True And reader.Name = "Database" Then
'Database type
reader.MoveToAttribute("Type")
DbType = reader.Value.ToString
'Database connection string
reader.MoveToAttribute("ConnectionString")
ConnectionString = reader.Value.ToString
End If
If reader.HasAttributes = True And reader.Name = "Mail" Then
'SMTP server
reader.MoveToAttribute("SmtpServer")
SmtpServer = reader.Value.ToString
'Sender e-mail address
reader.MoveToAttribute("SenderAddress")
SenderAddress = reader.Value.ToString
'Alert e-mail address
reader.MoveToAttribute("AlertAddress")
AlertAddress = reader.Value.ToString
End If
If reader.HasAttributes = True And reader.Name = "MailTo" Then
'List of destination e-mail addresses
reader.MoveToAttribute("Address")
al.Add(reader.Value.ToString)
End If
If reader.HasAttributes = True And reader.Name = "Folder" Then
If reader.GetAttribute("Type") = "Logs" Then
'Root folder for log files
reader.MoveToAttribute("Path")
LogsRoot = reader.Value.ToString
'Time expiration period for log files
reader.MoveToAttribute("Duration")
LogsDuration = reader.Value.ToString
End If
If reader.GetAttribute("Type") = "PdfDocs" Then
'Root folder for PDF files
reader.MoveToAttribute("Path")
PdfDocsRoot = reader.Value.ToString
'Time expiration period for PDF files
reader.MoveToAttribute("Duration")
PdfDocsDuration = reader.Value.ToString
End If
If reader.GetAttribute("Type") = "Charts" Then
'Root folder for chart files
reader.MoveToAttribute("Path")
ChartsRoot = reader.Value.ToString
'Time expiration period for chart files
reader.MoveToAttribute("Duration")
ChartsDuration = reader.Value.ToString
End If
End If
End If
End While
MailTo = al
reader.Close()
stream.Close()
fs.Close()
End If
Catch ex As Exception
Throw ex
End Try
End Sub
'******************************************************************************
End Class