Technology Experience

Contenuti gestiti da Igor Damiani
posts - 949, comments - 2741, trackbacks - 15120

My Links

News

  • Questo blog si propone di raccogliere riflessioni, teoriche e pratiche, su tutto quello che riguarda il world-computing che mi sta attorno: programmazione in .NET, software attuale e futuro, notizie provenienti dal web, tecnologia in generale, open-source.

    L'idea è quella di lasciare una sorta di patrimonio personale, una raccolta di idee che un giorno potrebbe farmi sorridere, al pensiero di dov'ero e cosa stavo facendo.

    10/05/2005,
    Milano

Archives

Post Categories

Generale

Codice della classe AppConfigXML

Imports System.IO
Imports System.Xml
Imports System.Xml.XPath

Public Class AppConfigXML

    Private _FileXML As String
    Private _Application As Application

    ReadOnly Property Application() As Application
        Get
            Return _Application
        End Get
    End Property

    Public Sub New()
    End Sub

    Public Sub Load(ByVal QualeFileXML As String)
        If File.Exists(QualeFileXML) = True Then
            Me._FileXML = QualeFileXML
        Else
            Throw New FileNotFoundException("[" & QualeFileXML & "] not found! Cannot read file!")
        End If

        Dim xmlDoc As New XmlDocument
        Dim i As Integer

        xmlDoc.Load(_FileXML)

        Dim elemList As XmlNodeList = xmlDoc.GetElementsByTagName("application")
        If elemList.Count = 1 Then
            _Application = New Application
            _Application.Name = elemList.Item(0).ChildNodes(0).InnerText
            _Application.ReleaseDate = elemList.Item(0).ChildNodes(1).InnerText
            _Application.Url = elemList.Item(0).ChildNodes(2).InnerText
            _Application.UrlUpdate = elemList.Item(0).ChildNodes(3).InnerText
            _Application.Freeware = elemList.Item(0).ChildNodes(4).InnerText
            _Application.Comments = elemList.Item(0).ChildNodes(5).InnerText

            elemList = xmlDoc.GetElementsByTagName("creator")
            If elemList.Count = 1 Then
                _Application.Creator = New Creator
                _Application.Creator.Person = elemList.Item(0).ChildNodes(0).InnerText
                _Application.Creator.Company = elemList.Item(0).ChildNodes(1).InnerText
                _Application.Creator.Mail = elemList.Item(0).ChildNodes(2).InnerText
                _Application.Creator.Url = elemList.Item(0).ChildNodes(3).InnerText
            End If

            elemList = xmlDoc.GetElementsByTagName("appmodules")
            If elemList.Count = 1 Then
                Dim ModTemp As AppModule
                ReDim _Application.AppModules(elemList.Item(0).ChildNodes.Count - 1)

                For i = 0 To elemList.Item(0).ChildNodes.Count - 1
                    ModTemp = New AppModule
                    ModTemp.Name = elemList.Item(0).ChildNodes(i).ChildNodes(0).InnerText
                    ModTemp.ReleaseDate = elemList.Item(0).ChildNodes(i).ChildNodes(1).InnerText
                    ModTemp.Url = elemList.Item(0).ChildNodes(i).ChildNodes(2).InnerText
                    ModTemp.Freeware = elemList.Item(0).ChildNodes(i).ChildNodes(3).InnerText
                    ModTemp.Active = elemList.Item(0).ChildNodes(i).ChildNodes(4).InnerText
                    ModTemp.Comments = elemList.Item(0).ChildNodes(i).ChildNodes(5).InnerText
                    _Application.AppModules(0) = ModTemp
                Next
            End If
        End If

        elemList = Nothing
        xmlDoc = Nothing
    End Sub

    Public Function GetXMLSetting(ByVal QualeSetting As String, Optional ByVal ValoreDefault As String = "") As String
        Dim xmlDoc As New XmlDocument
        xmlDoc.Load(_FileXML)
        Dim elemList As XmlNodeList = xmlDoc.GetElementsByTagName(QualeSetting)
        If elemList.Count = 1 Then
            Return elemList.Item(0).InnerText
        Else
            Return ValoreDefault
        End If

        xmlDoc = Nothing
    End Function

    Public Sub SaveXMLSetting(ByVal QualeSetting As String, ByVal Valore As String)
        Dim xmlDoc As New XmlDocument
        xmlDoc.Load(_FileXML)
        Dim elemList As XmlNodeList = xmlDoc.GetElementsByTagName(QualeSetting)
        If elemList.Count = 1 Then
            elemList.Item(0).InnerText = Valore
        Else
            'devo creare il nodo che non esiste ancora
            elemList = xmlDoc.GetElementsByTagName("appsettings")
            Dim xmlNodo As XmlNode
            xmlNodo = xmlDoc.CreateNode(XmlNodeType.Element, QualeSetting, "")
            xmlNodo.InnerText = Valore
            elemList.Item(0).AppendChild(xmlNodo)
        End If
        xmlDoc.Save(_FileXML)

        elemList = Nothing
        xmlDoc = Nothing
    End Sub

End Class

#Region "Classi di supporto"
Public Class Application
    Public Name As String
    Public ReleaseDate As Date
    Public Url As String
    Public UrlUpdate As String
    Public Freeware As Boolean
    Public Comments As String
    Public Creator As Creator
    Public AppModules() As AppModule
End Class

Public Class Creator
    Public Person As String
    Public Company As String
    Public Mail As String
    Public Url As String
End Class

Public Class AppModule
    Public Name As String
    Public ReleaseDate As Date
    Public Url As String
    Public Freeware As Boolean
    Public Active As Boolean
    Public Comments As String
End Class
#End Region

Print | posted on mercoledì 13 aprile 2005 17:18 |

Feedback

Gravatar

# Classe AppConfigXML per il file XML del form di About

Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET