From 23ecc07caa19dce34bf56c6c3fac3e54cd2cdcff Mon Sep 17 00:00:00 2001 From: MW Date: Mon, 2 Apr 2007 12:56:35 +0000 Subject: Added OpenSim.GenericConfig.Xml project, so we can swap to a more generic configuration method, so that it is easier to load configuration data from a ogs server --- .../Xml/OpenSim.GenericConfig.Xml.csproj | 93 ++++++++++++++++++++++ .../Xml/OpenSim.GenericConfig.Xml.dll.build | 42 ++++++++++ .../Xml/Properties/AssemblyInfo.cs | 35 ++++++++ OpenSim.GenericConfig/Xml/XmlConfig.cs | 92 +++++++++++++++++++++ 4 files changed, 262 insertions(+) create mode 100644 OpenSim.GenericConfig/Xml/OpenSim.GenericConfig.Xml.csproj create mode 100644 OpenSim.GenericConfig/Xml/OpenSim.GenericConfig.Xml.dll.build create mode 100644 OpenSim.GenericConfig/Xml/Properties/AssemblyInfo.cs create mode 100644 OpenSim.GenericConfig/Xml/XmlConfig.cs (limited to 'OpenSim.GenericConfig') diff --git a/OpenSim.GenericConfig/Xml/OpenSim.GenericConfig.Xml.csproj b/OpenSim.GenericConfig/Xml/OpenSim.GenericConfig.Xml.csproj new file mode 100644 index 0000000..98e813e --- /dev/null +++ b/OpenSim.GenericConfig/Xml/OpenSim.GenericConfig.Xml.csproj @@ -0,0 +1,93 @@ + + + Local + 8.0.50727 + 2.0 + {E88EF749-0000-0000-0000-000000000000} + Debug + AnyCPU + + + + OpenSim.GenericConfig.Xml + JScript + Grid + IE50 + false + Library + + OpenSim.GenericConfig.Xml + + + + + + False + 285212672 + False + + + TRACE;DEBUG + + True + 4096 + False + ..\..\bin\ + False + False + False + 4 + + + + False + 285212672 + False + + + TRACE + + False + 4096 + True + ..\..\bin\ + False + False + False + 4 + + + + + System.dll + False + + + System.Xml.dll + False + + + + + OpenSim.Framework + {8ACA2445-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + + + Code + + + Code + + + + + + + + + + diff --git a/OpenSim.GenericConfig/Xml/OpenSim.GenericConfig.Xml.dll.build b/OpenSim.GenericConfig/Xml/OpenSim.GenericConfig.Xml.dll.build new file mode 100644 index 0000000..f34e4ac --- /dev/null +++ b/OpenSim.GenericConfig/Xml/OpenSim.GenericConfig.Xml.dll.build @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenSim.GenericConfig/Xml/Properties/AssemblyInfo.cs b/OpenSim.GenericConfig/Xml/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..de5f48d --- /dev/null +++ b/OpenSim.GenericConfig/Xml/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OpenSim.GenericConfig")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OpenSim.GenericConfig")] +[assembly: AssemblyCopyright("Copyright © 2007")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("285a3047-f165-46c8-8767-b51428738a09")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OpenSim.GenericConfig/Xml/XmlConfig.cs b/OpenSim.GenericConfig/Xml/XmlConfig.cs new file mode 100644 index 0000000..39321cc --- /dev/null +++ b/OpenSim.GenericConfig/Xml/XmlConfig.cs @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml; +using OpenSim.Framework.Interfaces; + +namespace OpenSim.GenericConfig +{ + public class XmlConfig : IGenericConfig + { + private XmlDocument doc; + private XmlNode rootNode; + private XmlNode configNode; + private string fileName; + + public XmlConfig(string filename) + { + fileName = filename; + } + + public void LoadData() + { + doc = new XmlDocument(); + try + { + XmlTextReader reader = new XmlTextReader(fileName); + reader.WhitespaceHandling = WhitespaceHandling.None; + doc.Load(reader); + reader.Close(); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + return; + } + try + { + rootNode = doc.FirstChild; + if (rootNode.Name != "Root") + throw new Exception("Error: Invalid .xml File. Missing "); + + configNode = rootNode.FirstChild; + if (configNode.Name != "Config") + throw new Exception("Error: Invalid .xml File. first child should be "); + + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + } + + public string GetAttribute(string attributeName) + { + string result = ""; + if (configNode.Attributes[attributeName] != null) + { + result = ((XmlAttribute)configNode.Attributes.GetNamedItem(attributeName)).Value; + } + return result; + } + + public bool SetAttribute(string attributeName, string attributeValue) + { + if (configNode.Attributes[attributeName] != null) + { + configNode.Attributes.GetNamedItem(attributeName).Value = attributeValue; + } + else + { + XmlAttribute attri; + attri = doc.CreateAttribute(attributeName); + attri.Value = attributeValue; + configNode.Attributes.Append(attri); + } + return true; + } + + public void Commit() + { + doc.Save(fileName); + } + + public void Close() + { + configNode = null; + rootNode = null; + doc = null; + } + + } +} -- cgit v1.1