File: ClientSettingsSection.cs

package info (click to toggle)
mono 6.12.0.199%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,296,836 kB
  • sloc: cs: 11,181,803; xml: 2,850,076; ansic: 699,709; cpp: 123,344; perl: 59,361; javascript: 30,841; asm: 21,853; makefile: 20,405; sh: 15,009; python: 4,839; pascal: 925; sql: 859; sed: 16; php: 1
file content (235 lines) | stat: -rw-r--r-- 8,000 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//------------------------------------------------------------------------------
// <copyright file="ClientSettingsSection.cs" company="Microsoft Corporation">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

namespace System.Configuration
{
    using System;
    using System.Xml;
    using System.Configuration;
    using System.Collections.Specialized;
    using System.Collections;
    using System.IO;
    using System.Text;
     
    /// <devdoc>
    ///     ConfigurationSection class for sections that store client settings. 
    /// </devdoc>
    public sealed class ClientSettingsSection : ConfigurationSection
    {
        private static ConfigurationPropertyCollection _properties;
        private static readonly ConfigurationProperty _propSettings = new ConfigurationProperty(null, typeof(SettingElementCollection), null, ConfigurationPropertyOptions.IsDefaultCollection);

        static ClientSettingsSection () {
            _properties = new ConfigurationPropertyCollection();
            _properties.Add(_propSettings);
        }
        
        public ClientSettingsSection () {
        }
         
        protected override ConfigurationPropertyCollection Properties {
            get {
                return _properties;
            }
        }
         
        /// <include file='doc\ClientSettingsSection.uex' path='docs/doc[@for="ClientSettingsSection.Settings]/*' />
        [ConfigurationProperty("", IsDefaultCollection = true)]
        public SettingElementCollection Settings {
            get {
                return (SettingElementCollection) base[_propSettings];
            }
        }
    } 
     
    public sealed class SettingElementCollection : ConfigurationElementCollection {
        public override ConfigurationElementCollectionType CollectionType {
            get {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName {
            get {
                return "setting";
            }
        }

        protected override ConfigurationElement CreateNewElement() {
            return new SettingElement();
        }

        protected override object GetElementKey(ConfigurationElement element) {
            return ((SettingElement)element).Key;
        }

        public SettingElement Get(string elementKey) {
            return (SettingElement) BaseGet(elementKey);
        }

        public void Add(SettingElement element) {
            BaseAdd(element);
        }

        public void Remove(SettingElement element) {
            BaseRemove(GetElementKey(element));
        }

        public void Clear() {
            BaseClear();
        }
    } 

    public sealed class SettingElement : ConfigurationElement {
        private static ConfigurationPropertyCollection _properties;
        private static readonly ConfigurationProperty _propName = new ConfigurationProperty("name", typeof(string),"",ConfigurationPropertyOptions.IsRequired | ConfigurationPropertyOptions.IsKey);
        private static readonly ConfigurationProperty _propSerializeAs = new ConfigurationProperty("serializeAs", typeof(SettingsSerializeAs),SettingsSerializeAs.String,ConfigurationPropertyOptions.IsRequired);
        private static readonly ConfigurationProperty _propValue = new ConfigurationProperty("value", typeof(SettingValueElement),null,ConfigurationPropertyOptions.IsRequired);
        private static XmlDocument doc = new XmlDocument();

        static SettingElement() {
            // Property initialization
            _properties = new ConfigurationPropertyCollection();

            _properties.Add(_propName);
            _properties.Add(_propSerializeAs);
            _properties.Add(_propValue);
            
        }
        
        public SettingElement() {
        }
        
        public SettingElement(String name, SettingsSerializeAs serializeAs) : this() {
            Name = name;
            SerializeAs = serializeAs;
        }

        internal string Key {
            get {
                return Name;
            }
        }
        
        public override bool Equals(object settings) {
            SettingElement u = settings as SettingElement;
            return (u != null && base.Equals(settings) && Object.Equals(u.Value, Value));
        }

        public override int GetHashCode() {
            return base.GetHashCode() ^ Value.GetHashCode(); 
        }
         
         
        protected override ConfigurationPropertyCollection Properties {
            get {
                return _properties;
            }
        }
         
        [ConfigurationProperty("name", IsRequired = true, IsKey = true, DefaultValue = "")]
        public string Name {
            get {
                return (string)base[_propName];
            }
            set {
                base[_propName] = value;
            }
        }
         
        [ConfigurationProperty("serializeAs", IsRequired = true, DefaultValue = SettingsSerializeAs.String)]
        public SettingsSerializeAs SerializeAs {
            get {
                return (SettingsSerializeAs) base[_propSerializeAs];
            }
            set {
                base[_propSerializeAs] = value;
            }
        }

        [ConfigurationProperty("value", IsRequired = true, DefaultValue = null)]
        public SettingValueElement Value {
            get {
                return (SettingValueElement) base[_propValue];
            }
            set {
                base[_propValue] = value;
            }
        }
    } 

    public sealed class SettingValueElement : ConfigurationElement {
        private static volatile ConfigurationPropertyCollection _properties;
        private static XmlDocument doc = new XmlDocument();

        private XmlNode _valueXml;
        private bool isModified = false;
         
        protected override ConfigurationPropertyCollection Properties {
            get {
                if (_properties == null) {
                    _properties = new ConfigurationPropertyCollection();
                }

                return _properties;
            }
        }
         
        public XmlNode ValueXml {
            get {
                return _valueXml;
            }
            set {
                _valueXml = value;
                isModified = true;
            }
        }

        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            ValueXml = doc.ReadNode(reader);
        }

        public override bool Equals(object settingValue) {
            SettingValueElement u = settingValue as SettingValueElement;
            return (u != null && Object.Equals(u.ValueXml, ValueXml)); 
        }

        public override int GetHashCode() {
            return ValueXml.GetHashCode();
        }

        protected override bool IsModified() {
            return isModified;
        }

        protected override void ResetModified() {
            isModified = false;
        }

        protected override bool SerializeToXmlElement(XmlWriter writer, string elementName) {
            if (ValueXml != null) {
                if (writer != null) {
                    ValueXml.WriteTo(writer);
                }
                return true;
            }

            return false;
        }

        protected override void Reset(ConfigurationElement parentElement) {
            base.Reset(parentElement);
            ValueXml = ((SettingValueElement) parentElement).ValueXml;
        }

        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, 
                                                ConfigurationSaveMode saveMode) {
            base.Unmerge(sourceElement, parentElement, saveMode);
            ValueXml = ((SettingValueElement) sourceElement).ValueXml;
        }
    } 
}