View | Details | Raw Unified | Return to bug 8533
Collapse All | Expand All

(-)mcs/class/System/System.Configuration/CustomizableFileSettingsProvider.cs (-35 / +37 lines)
Lines 615-661 namespace System.Configuration Link Here
615
			if (userGroup == null) {
615
			if (userGroup == null) {
616
				userGroup = new UserSettingsGroup ();
616
				userGroup = new UserSettingsGroup ();
617
				config.SectionGroups.Add ("userSettings", userGroup);
617
				config.SectionGroups.Add ("userSettings", userGroup);
618
				ApplicationSettingsBase asb = context.CurrentSettings;
618
			}
619
				ClientSettingsSection cs = new ClientSettingsSection ();
619
			ApplicationSettingsBase asb = context.CurrentSettings;
620
				string class_name = NormalizeInvalidXmlChars ((asb != null ? asb.GetType () : typeof (ApplicationSettingsBase)).FullName);
620
			string class_name = NormalizeInvalidXmlChars ((asb != null ? asb.GetType () : typeof (ApplicationSettingsBase)).FullName);
621
				userGroup.Sections.Add (class_name, cs);
621
			ClientSettingsSection userSection = null;
622
			ConfigurationSection cnf = userGroup.Sections.Get (class_name);
623
			userSection = cnf as ClientSettingsSection;
624
			if (userSection == null) {
625
				userSection = new ClientSettingsSection ();
626
				userGroup.Sections.Add (class_name, userSection);
622
			}
627
			}
623
628
624
			bool hasChanges = false;
629
			bool hasChanges = false;
625
630
626
			foreach (ConfigurationSection section in userGroup.Sections) {
631
			if (userSection == null)
627
				ClientSettingsSection userSection = section as ClientSettingsSection;
632
				return;
628
				if (userSection == null)
629
					continue;
630
633
631
				foreach (SettingsPropertyValue value in collection) {
634
			foreach (SettingsPropertyValue value in collection) {
632
					if (checkUserLevel && value.Property.Attributes.Contains (typeof (SettingsManageabilityAttribute)) != isRoaming)
635
				if (checkUserLevel && value.Property.Attributes.Contains (typeof (SettingsManageabilityAttribute)) != isRoaming)
633
						continue;
636
					continue;
634
					// The default impl does not save the ApplicationScopedSetting properties
637
				// The default impl does not save the ApplicationScopedSetting properties
635
					if (value.Property.Attributes.Contains (typeof (ApplicationScopedSettingAttribute)))
638
				if (value.Property.Attributes.Contains (typeof (ApplicationScopedSettingAttribute)))
636
						continue;
639
					continue;
637
640
638
					hasChanges = true;
641
				hasChanges = true;
639
					SettingElement element = userSection.Settings.Get (value.Name);
642
				SettingElement element = userSection.Settings.Get (value.Name);
640
					if (element == null) {
643
				if (element == null) {
641
						element = new SettingElement (value.Name, value.Property.SerializeAs);
644
					element = new SettingElement (value.Name, value.Property.SerializeAs);
642
						userSection.Settings.Add (element);
645
					userSection.Settings.Add (element);
643
					}
646
				}
644
					if (element.Value.ValueXml == null)
647
				if (element.Value.ValueXml == null)
645
						element.Value.ValueXml = new XmlDocument ().CreateElement ("value");
648
					element.Value.ValueXml = new XmlDocument ().CreateElement ("value");
646
					switch (value.Property.SerializeAs) {
649
				switch (value.Property.SerializeAs) {
647
					case SettingsSerializeAs.Xml:
650
				case SettingsSerializeAs.Xml:
648
						element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
651
					element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
649
						break;
652
					break;
650
					case SettingsSerializeAs.String:
653
				case SettingsSerializeAs.String:
651
						element.Value.ValueXml.InnerText = value.SerializedValue as string;
654
					element.Value.ValueXml.InnerText = value.SerializedValue as string;
652
						break;
655
					break;
653
					case SettingsSerializeAs.Binary:
656
				case SettingsSerializeAs.Binary:
654
						element.Value.ValueXml.InnerText = value.SerializedValue != null ? Convert.ToBase64String (value.SerializedValue as byte []) : string.Empty;
657
					element.Value.ValueXml.InnerText = value.SerializedValue != null ? Convert.ToBase64String (value.SerializedValue as byte []) : string.Empty;
655
						break;
658
					break;
656
					default:
659
				default:
657
						throw new NotImplementedException ();
660
					throw new NotImplementedException ();
658
					}
659
				}
661
				}
660
			}
662
			}
661
			if (hasChanges)
663
			if (hasChanges)
(-)mcs/class/System/Test/System.Configuration/ApplicationSettingsBaseTest.cs (+37 lines)
Lines 417-422 namespace MonoTests.System.Configuration { Link Here
417
			holder.Reset ();
417
			holder.Reset ();
418
			Assert.AreEqual ("", holder.TestKey1OnHolder);
418
			Assert.AreEqual ("", holder.TestKey1OnHolder);
419
		}
419
		}
420
421
		class Bug8533ConfHolder1 : ApplicationSettingsBase {
422
			[UserScopedSetting]
423
			public string TestKey1OnHolder1 { get { return (string)this["TestKey1OnHolder1"] ?? ""; } set { this["TestKey1OnHolder1"] = value; } }
424
425
			[UserScopedSetting]
426
			public string TestKey1OnHolder2 { get { return (string)this["TestKey1OnHolder2"] ?? ""; } set { this["TestKey1OnHolder2"] = value; } }
427
			
428
			[UserScopedSetting]
429
			public string TestKey { get { return (string)this["TestKey"] ?? ""; } set { this["TestKey"] = value; } }
430
		}
431
432
		class Bug8533ConfHolder2 : ApplicationSettingsBase {
433
			[UserScopedSetting]
434
			public string TestKey1OnHolder2 { get { return (string)this["TestKey1OnHolder2"] ?? ""; } set { this["TestKey1OnHolder2"] = value; } }
435
436
			[UserScopedSetting]
437
			public string TestKey { get { return (string)this["TestKey"] ?? ""; } set { this["TestKey"] = value; } }
438
		}
439
440
		[Test]
441
		public void TestBug8533ConfHandlerWronglyMixedUp() {
442
			var holder1 = new Bug8533ConfHolder1();
443
			var holder2 = new Bug8533ConfHolder2();
444
			holder1.TestKey1OnHolder1 = "candy";
445
			holder2.TestKey1OnHolder2 = "donut";
446
			holder1.TestKey = "eclair";
447
			holder1.Save();
448
			holder2.Save();
449
			holder1.Reload();
450
			holder2.Reload();
451
			Assert.AreEqual("", holder1.TestKey1OnHolder2);
452
			Assert.AreEqual("candy", holder1.TestKey1OnHolder1);
453
			Assert.AreEqual("donut", holder2.TestKey1OnHolder2);
454
			Assert.AreEqual("eclair", holder1.TestKey);
455
			Assert.AreEqual("", holder2.TestKey);
456
		}
420
	}
457
	}
421
}
458
}
422
459

Return to bug 8533