2
// DatabaseConfiguration.cs
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
using System.Collections;
35
namespace Mono.Addins.Database
37
internal class DatabaseConfiguration
39
Hashtable addinStatus = new Hashtable ();
41
public bool IsEnabled (string addinId, bool defaultValue)
43
if (addinStatus.Contains (addinId))
44
return addinStatus [addinId] != null;
49
public void SetStatus (string addinId, bool enabled, bool defaultValue)
51
if (enabled == defaultValue)
52
addinStatus.Remove (addinId);
54
addinStatus [addinId] = this;
56
addinStatus [addinId] = null;
59
public static DatabaseConfiguration Read (string file)
61
DatabaseConfiguration config = new DatabaseConfiguration ();
63
StreamReader s = new StreamReader (file);
65
XmlTextReader tr = new XmlTextReader (s);
67
if (tr.IsEmptyElement)
70
tr.ReadStartElement ("Configuration");
73
while (tr.NodeType != XmlNodeType.EndElement) {
75
if (tr.NodeType != XmlNodeType.Element || tr.IsEmptyElement) {
78
else if (tr.LocalName == "DisabledAddins") {
79
// For back compatibility
80
tr.ReadStartElement ();
82
while (tr.NodeType != XmlNodeType.EndElement) {
83
if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin")
84
config.addinStatus [tr.ReadElementString ()] = null;
91
else if (tr.LocalName == "AddinStatus") {
92
tr.ReadStartElement ();
94
while (tr.NodeType != XmlNodeType.EndElement) {
95
if (tr.NodeType == XmlNodeType.Element && tr.LocalName == "Addin") {
96
string aid = tr.GetAttribute ("id");
97
string senabled = tr.GetAttribute ("enabled");
98
if (senabled.Length == 0 || senabled == "True")
99
config.addinStatus [aid] = config;
101
config.addinStatus [aid] = null;
106
tr.ReadEndElement ();
114
public void Write (string file)
116
StreamWriter s = new StreamWriter (file);
118
XmlTextWriter tw = new XmlTextWriter (s);
119
tw.Formatting = Formatting.Indented;
120
tw.WriteStartElement ("Configuration");
121
tw.WriteStartElement ("AddinStatus");
122
foreach (DictionaryEntry e in addinStatus) {
123
tw.WriteStartElement ("Addin");
124
tw.WriteAttributeString ("id", (string)e.Key);
125
tw.WriteAttributeString ("enabled", (e.Value != null).ToString ());
126
tw.WriteEndElement ();
128
tw.WriteEndElement ();
129
tw.WriteEndElement ();