Beispiel #1
0
        protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name,
            ConfigurationSaveMode saveMode)
        {
            if ((CurrentConfiguration != null) &&
                (CurrentConfiguration.TargetFramework != null) &&
                !ShouldSerializeSectionInTargetVersion(CurrentConfiguration.TargetFramework))
                return string.Empty;

            ValidateElement(this, null, true);

            ConfigurationElement tempElement = CreateElement(GetType());
            tempElement.Unmerge(this, parentElement, saveMode);

            StringWriter strWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter writer = new XmlTextWriter(strWriter)
            {
                Formatting = Formatting.Indented,
                Indentation = 4,
                IndentChar = ' '
            };

            tempElement.DataToWriteInternal = saveMode != ConfigurationSaveMode.Minimal;

            if ((CurrentConfiguration != null) && (CurrentConfiguration.TargetFramework != null))
                _configRecord.SectionsStack.Push(this);

            tempElement.SerializeToXmlElement(writer, name);

            if ((CurrentConfiguration != null) && (CurrentConfiguration.TargetFramework != null))
                _configRecord.SectionsStack.Pop();

            writer.Flush();
            return strWriter.ToString();
        }
 protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     RootProfilePropertySettingsCollection settingss = parentElement as RootProfilePropertySettingsCollection;
     RootProfilePropertySettingsCollection settingss2 = sourceElement as RootProfilePropertySettingsCollection;
     base.Unmerge(sourceElement, parentElement, saveMode);
     this.GroupSettings.InternalUnMerge(settingss2.GroupSettings, (settingss != null) ? settingss.GroupSettings : null, saveMode);
 }
Beispiel #3
0
 protected override string SerializeSection(
     ConfigurationElement parentElement,
     string name, ConfigurationSaveMode saveMode)
 {
     string s = base.SerializeSection(parentElement, name, saveMode);
     // You can add custom processing code here.
     return s;
 }
 protected override string SerializeSection(
     ConfigurationElement parentElement,
     string name, ConfigurationSaveMode saveMode)
 {
     string s =
         base.SerializeSection(parentElement,name, saveMode);
     return s;
 }
 protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     base.Unmerge(sourceElement, parentElement, saveMode);
     SwitchElement element = sourceElement as SwitchElement;
     if ((element != null) && (element._attributes != null))
     {
         this._attributes = element._attributes;
     }
 }
 protected override string SerializeSection(ConfigurationElement parentElement, 
     string name, 
     ConfigurationSaveMode saveMode)
 {
     StringWriter stringWriter = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
     XmlTextWriter textWriter = new XmlTextWriter(stringWriter);
     serializer.Serialize(textWriter, Settings);
     return stringWriter.ToString();
 }
 protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
 {
     StringWriter sWriter = new StringWriter(CultureInfo.InvariantCulture);
     XmlTextWriter xWriter = new XmlTextWriter(sWriter);
     xWriter.Formatting = Formatting.Indented;
     xWriter.Indentation = 4;
     xWriter.IndentChar = ' ';
     SerializeToXmlElement(xWriter, name);
     xWriter.Flush();
     return sWriter.ToString();
 }
Beispiel #8
0
        protected internal override void Unmerge(ConfigurationElement sourceElement,
            ConfigurationElement parentElement,
            ConfigurationSaveMode saveMode)
        {
            ProviderSettings parentProviders = parentElement as ProviderSettings;
            parentProviders?.UpdatePropertyCollection(); // before reseting make sure the bag is filled in

            ProviderSettings sourceProviders = sourceElement as ProviderSettings;
            sourceProviders?.UpdatePropertyCollection(); // before reseting make sure the bag is filled in

            base.Unmerge(sourceElement, parentElement, saveMode);
            UpdatePropertyCollection();
        }
        protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode) {
            ValidateElement(this, null, true);

            ConfigurationElement TempElement = CreateElement(this.GetType());
            TempElement.Unmerge(this, parentElement, saveMode);

            StringWriter strWriter = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter writer = new XmlTextWriter(strWriter);
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 4;
            writer.IndentChar = ' ';
            TempElement.DataToWriteInternal = (saveMode != ConfigurationSaveMode.Minimal);
            TempElement.SerializeToXmlElement(writer, name);
            writer.Flush();
            return strWriter.ToString();
        }
        /// <summary>
        /// Creates an XML string containing an unmerged view of the <see cref="ConfigurationSection" /> 
        /// object as a single section to write to a file.
        /// </summary>
        /// <param name="parentElement">The <see cref="ConfigurationElement" /> 
        /// instance to use as the parent when performing the un-merge.</param>
        /// <param name="name">The name of the section to create.</param>
        /// <param name="saveMode">The <see cref="ConfigurationSaveMode" /> instance 
        /// to use when writing to a string.</param>
        /// <returns>
        /// An XML string containing an unmerged view of the <see cref="ConfigurationSection" /> object.
        /// </returns>
        protected override string SerializeSection(ConfigurationElement parentElement, string name, 
            ConfigurationSaveMode saveMode)
        {
            IgniteArgumentCheck.NotNull(parentElement, "parentElement");
            IgniteArgumentCheck.NotNullOrEmpty(name, "name");

            if (IgniteConfiguration == null)
                return string.Format("<{0} />", name);

            var sb = new StringBuilder();

            using (var xmlWriter = XmlWriter.Create(sb))
            {
                IgniteConfigurationXmlSerializer.Serialize(IgniteConfiguration, xmlWriter, name);

                return sb.ToString();
            }
        }
 internal ConfigurationLockCollection UnMergeLockList(
     ConfigurationLockCollection sourceLockList,
     ConfigurationLockCollection parentLockList,
     ConfigurationSaveMode saveMode) {
     if (sourceLockList.ExceptionList == false) {
         switch (saveMode) {
             case ConfigurationSaveMode.Modified: {
                     ConfigurationLockCollection tempLockList = new ConfigurationLockCollection(this, sourceLockList.LockType);
                     foreach (string lockedAttributeName in sourceLockList)
                         if (!parentLockList.Contains(lockedAttributeName) ||
                             sourceLockList.IsValueModified(lockedAttributeName)) {
                             tempLockList.Add(lockedAttributeName, ConfigurationValueFlags.Default);
                         }
                     return tempLockList;
                 }
             case ConfigurationSaveMode.Minimal: {
                     ConfigurationLockCollection tempLockList = new ConfigurationLockCollection(this, sourceLockList.LockType);
                     foreach (string lockedAttributeName in sourceLockList)
                         if (!parentLockList.Contains(lockedAttributeName)) {
                             tempLockList.Add(lockedAttributeName, ConfigurationValueFlags.Default);
                         }
                     return tempLockList;
                 }
         }
     }
     else {
         // exception list write out the entire collection unless the entire collection
         // came from the parent.
         if (saveMode == ConfigurationSaveMode.Modified || saveMode == ConfigurationSaveMode.Minimal) {
             bool sameAsParent = false;
             if (sourceLockList.Count == parentLockList.Count) {
                 sameAsParent = true;
                 foreach (string lockedAttributeName in sourceLockList) {
                     if (!parentLockList.Contains(lockedAttributeName) ||
                         (sourceLockList.IsValueModified(lockedAttributeName) &&
                          saveMode == ConfigurationSaveMode.Modified)) {
                         sameAsParent = false;
                     }
                 }
             }
             if (sameAsParent == true) {
                 return null;
             }
         }
     }
     return sourceLockList;
 }
Beispiel #12
0
        /// <summary>
        /// Creates an XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object as a single section to write to a file.
        /// </summary>
        /// <returns>
        /// An XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object.
        /// </returns>
        /// <param name="parentElement">The <see cref="T:System.Configuration.ConfigurationElement"/> instance to use as the parent when performing the un-merge.</param>
        /// <param name="name">The name of the section to create.</param>
        /// <param name="saveMode">The <see cref="T:System.Configuration.ConfigurationSaveMode"/> instance to use when writing to a string.</param>
        protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
        {
            ExtensionElementMap.Clear();
            currentSection = this;
            TypeResolver.SetAliases(this);
            this.InitializeSectionExtensions();

            var sb = new StringBuilder();

            using (var writer = MakeXmlWriter(sb))
            {
                writer.WriteStartElement(name, XmlNamespace);
                writer.WriteAttributeString("xmlns", XmlNamespace);
                this.TypeAliases.SerializeElementContents(writer, "alias");
                this.Namespaces.SerializeElementContents(writer, "namespace");
                this.Assemblies.SerializeElementContents(writer, "assembly");
                this.SectionExtensions.SerializeElementContents(writer, "sectionExtension");
                this.Containers.SerializeElementContents(writer, "container");
                writer.WriteEndElement();
            }

            return(sb.ToString());
        }
Beispiel #13
0
        protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
        {
            externalDataXml = null;
            ConfigurationElement elem;
            if (parentElement != null) {
                elem = (ConfigurationElement) CreateElement (GetType());
                elem.Unmerge (this, parentElement, saveMode);
            }
            else
                elem = this;

            string ret;
            using (StringWriter sw = new StringWriter ()) {
                using (XmlTextWriter tw = new XmlTextWriter (sw)) {
                    tw.Formatting = Formatting.Indented;
                    elem.SerializeToXmlElement (tw, name);
                    tw.Close ();
                }

                ret = sw.ToString ();
            }

            string config_source = SectionInformation.ConfigSource;

            if (String.IsNullOrEmpty (config_source))
                return ret;

            externalDataXml = ret;
            using (StringWriter sw = new StringWriter ()) {
                bool haveName = !String.IsNullOrEmpty (name);

                using (XmlTextWriter tw = new XmlTextWriter (sw)) {
                    if (haveName)
                        tw.WriteStartElement (name);
                    tw.WriteAttributeString ("configSource", config_source);
                    if (haveName)
                        tw.WriteEndElement ();
                }

                return sw.ToString ();
            }
        }
Beispiel #14
0
 public void Save(ConfigurationSaveMode mode)
 {
     Save(mode, false);
 }
Beispiel #15
0
 void SaveData(XmlTextWriter tw, ConfigurationSaveMode mode, bool forceUpdateAll)
 {
     rootGroup.WriteRootData(tw, this, mode);
 }
Beispiel #16
0
		void Save (Stream stream, ConfigurationSaveMode mode, bool forceUpdateAll)
		{
			XmlTextWriter tw = new XmlTextWriter (new StreamWriter (stream));
			tw.Formatting = Formatting.Indented;
			try {
				tw.WriteStartDocument ();
				if (rootNamespace != null)
					tw.WriteStartElement ("configuration", rootNamespace);
				else
					tw.WriteStartElement ("configuration");
				if (rootGroup.HasConfigContent (this)) {
					rootGroup.WriteConfig (this, tw, mode);
				}
				
				foreach (ConfigurationLocation loc in Locations) {
					if (loc.OpenedConfiguration == null) {
						tw.WriteRaw ("\n");
						tw.WriteRaw (loc.XmlContent);
					}
					else {
						tw.WriteStartElement ("location");
						tw.WriteAttributeString ("path", loc.Path); 
						if (!loc.AllowOverride)
							tw.WriteAttributeString ("allowOverride", "false");
						loc.OpenedConfiguration.SaveData (tw, mode, forceUpdateAll);
						tw.WriteEndElement ();
					}
				}
				
				SaveData (tw, mode, forceUpdateAll);
				tw.WriteEndElement ();
				ResetModified ();
			}
			finally {
				tw.Flush ();
				tw.Close ();
			}
		}
Beispiel #17
0
        static void Main(string[] args)
        {
            string inputStr  = String.Empty;
            string optionStr = String.Empty;
            string parm1     = String.Empty;
            string parm2     = String.Empty;

            // Define a regular expression to allow only
            // alphanumeric inputs that are at most 20 character
            // long. For instance "/iii:".
            Regex rex = new Regex(@"[^\/w]{1,20}");

            parm1 = "none";
            parm2 = "false";

            // Parse the user's input.
            if (args.Length < 1)
            {
                // No option entered.
                Console.Write("Input parameters missing.");
                return;
            }
            else
            {
                // Get the user's options.
                inputStr = args[0].ToLower();


                if (args.Length == 3)
                {
                    // These to be used when serializing
                    // (writing) to the configuration file.
                    parm1 = args[1].ToLower();
                    parm2 = args[2].ToLower();

                    if (!(rex.Match(parm1)).Success &&
                        !(rex.Match(parm2)).Success)
                    {
                        // Wrong option format used.
                        Console.Write("Input format not allowed.");
                        return;
                    }
                }

                if (!(rex.Match(inputStr)).Success)
                {
                    // Wrong option format used.
                    Console.Write("Input format not allowed.");
                    return;
                }
            }

            // <Snippet1>

            // Get the Web application configuration.
            System.Configuration.Configuration configuration =
                WebConfigurationManager.OpenWebConfiguration(
                    "/aspnetTest");

            // Get the <urlMapping> section.
            UrlMappingsSection urlMappingSection =
                (UrlMappingsSection)configuration.GetSection(
                    "system.web/urlMappings");

            // <Snippet2>

            // Get the url mapping collection.
            UrlMappingCollection urlMappings =
                urlMappingSection.UrlMappings;

            // </Snippet2>

            // </Snippet1>

            try
            {
                switch (inputStr)
                {
                case "/add":

                    // <Snippet3>

                    // Create a new UrlMapping object.
                    urlMapping = new UrlMapping(
                        "~/home.aspx", "~/default.aspx?parm1=1");

                    // Add the urlMapping to
                    // the collection.
                    urlMappings.Add(urlMapping);

                    // Update the configuration file.
                    if (!urlMappingSection.IsReadOnly())
                    {
                        configuration.Save();
                    }

                    // </Snippet3>

                    shownUrl  = urlMapping.Url;
                    mappedUrl = urlMapping.MappedUrl;

                    msg = String.Format(
                        "Shown URL: {0}\nMapped URL:  {1}\n",
                        shownUrl, mappedUrl);


                    Console.Write(msg);

                    break;

                case "/clear":

                    // <Snippet4>

                    // Clear the url mapping collection.
                    urlMappings.Clear();

                    // Update the configuration file.

                    // Define the save modality.
                    ConfigurationSaveMode saveMode =
                        ConfigurationSaveMode.Minimal;

                    urlMappings.EmitClear =
                        Convert.ToBoolean(parm2);

                    if (parm1 == "none")
                    {
                        if (!urlMappingSection.IsReadOnly())
                        {
                            configuration.Save();
                        }
                        msg = String.Format(
                            "Default modality, EmitClear:      {0}",
                            urlMappings.EmitClear.ToString());
                    }
                    else
                    {
                        if (parm1 == "full")
                        {
                            saveMode = ConfigurationSaveMode.Full;
                        }
                        else
                        if (parm1 == "modified")
                        {
                            saveMode = ConfigurationSaveMode.Modified;
                        }

                        if (!urlMappingSection.IsReadOnly())
                        {
                            configuration.Save(saveMode);
                        }

                        msg = String.Format(
                            "Save modality:      {0}",
                            saveMode.ToString());
                    }

                    // </Snippet4>

                    Console.Write(msg);

                    break;

                case "/removeobject":

                    // <Snippet5>

                    // Create a UrlMapping object.
                    urlMapping = new UrlMapping(
                        "~/home.aspx", "~/default.aspx?parm1=1");

                    // Remove it from the collection
                    // (if exists).
                    urlMappings.Remove(urlMapping);

                    // Update the configuration file.
                    if (!urlMappingSection.IsReadOnly())
                    {
                        configuration.Save();
                    }

                    // </Snippet5>

                    shownUrl  = urlMapping.Url;
                    mappedUrl = urlMapping.MappedUrl;

                    msg = String.Format(
                        "Shown URL:      {0}\nMapped URL: {1}\n",
                        shownUrl, mappedUrl);

                    Console.Write(msg);

                    break;

                case "/removeurl":

                    // <Snippet6>

                    // Remove the URL with the
                    // specified name from the collection
                    // (if exists).
                    urlMappings.Remove("~/default.aspx");

                    // Update the configuration file.
                    if (!urlMappingSection.IsReadOnly())
                    {
                        configuration.Save();
                    }

                    // </Snippet6>

                    break;

                case "/removeindex":

                    // <Snippet7>

                    // Remove the URL at the
                    // specified index from the collection.
                    urlMappings.RemoveAt(0);

                    // Update the configuration file.
                    if (!urlMappingSection.IsReadOnly())
                    {
                        configuration.Save();
                    }

                    // </Snippet7>

                    break;

                case "/all":

                    // <Snippet8>

                    StringBuilder allUrlMappings = new StringBuilder();

                    foreach (UrlMapping url_Mapping in urlMappings)
                    {
                        // <Snippet9>
                        shownUrl = url_Mapping.Url;
                        // </Snippet9>

                        // <Snippet10>
                        mappedUrl = url_Mapping.MappedUrl;
                        // </Snippet10>

                        msg = String.Format(
                            "Shown URL:  {0}\nMapped URL: {1}\n",
                            shownUrl, mappedUrl);

                        allUrlMappings.AppendLine(msg);
                    }

                    // </Snippet8>

                    Console.Write(allUrlMappings.ToString());
                    break;


                default:
                    // Option is not allowed..
                    Console.Write("Input not allowed.");
                    break;
                }
            }
            catch (ArgumentException e)
            {
                // Never display this. Use it for
                // debugging purposes.
                msg = e.ToString();
            }
        }
 // LAMESPEC: this is missing from MSDN, but is present in the 2.0sp1 version of the
 // class
 protected internal override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     // Why override?
     base.Unmerge(sourceElement, parentElement, saveMode);
 }
Beispiel #19
0
 /// <summary>Invokes the inherited behavior.</summary>
 void IHelperAssistedCustomConfigurationData <CustomSecurityCacheProviderData> .BaseUnmerge(ConfigurationElement sourceElement,
                                                                                            ConfigurationElement parentElement,
                                                                                            ConfigurationSaveMode saveMode)
 {
     base.Unmerge(sourceElement, parentElement, saveMode);
 }
Beispiel #20
0
 public void Save(ConfigurationSaveMode saveMode)
 {
     SaveAsImpl(null, saveMode, false);
 }
Beispiel #21
0
 public void Save(ConfigurationSaveMode saveMode, bool forceSaveAll)
 {
     SaveAsImpl(null, saveMode, forceSaveAll);
 }
 public T Save(ConfigurationSaveMode saveMode = ConfigurationSaveMode.Modified, bool forceSaveAll = false)
 // ReSharper disable once AssignNullToNotNullAttribute
 => SaveAs(CurrentConfiguration?.FilePath, saveMode, forceSaveAll);
Beispiel #23
0
        /// <summary>
        /// Modifies the <see cref="T:System.Configuration.ConfigurationElement" /> object to remove all values that should not be saved.
        /// </summary>
        /// <param name="sourceElement">A <see cref="T:System.Configuration.ConfigurationElement" /> at the current level containing a merged view of the properties.</param>
        /// <param name="parentElement">The parent <see cref="T:System.Configuration.ConfigurationElement" />, or null if this is the top level.</param>
        /// <param name="saveMode">A <see cref="T:System.Configuration.ConfigurationSaveMode" /> that determines which property values to include.</param>
        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);

            if (!(sourceElement is ConfigurationElementBase element))
            {
                return;
            }

            if (element.Options != this.Options)
            {
                this.Options = element.Options;
            }

            if (element.OptionElements != this.OptionElements)
            {
                this.OptionElements = element.OptionElements;
            }
        }
 void ElementUnmerge(ConfigurationElement target, ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     target.GetType().GetMethod("Unmerge", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(target, new object [] { sourceElement, parentElement, saveMode });
 }
        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            if (parentElement != null && sourceElement.GetType() != parentElement.GetType())
            {
                throw new ConfigurationErrorsException("Can't unmerge two elements of different type");
            }

            bool isMinimalOrModified = saveMode == ConfigurationSaveMode.Minimal ||
                                       saveMode == ConfigurationSaveMode.Modified;

            foreach (PropertyInformation prop in sourceElement.ElementInformation.Properties)
            {
                if (prop.ValueOrigin == PropertyValueOrigin.Default)
                {
                    continue;
                }

                PropertyInformation unmergedProp = ElementInformation.Properties [prop.Name];

                object sourceValue = prop.Value;
                if (parentElement == null || !HasValue(parentElement, prop.Name))
                {
                    unmergedProp.Value = sourceValue;
                    continue;
                }

                if (sourceValue == null)
                {
                    continue;
                }

                object parentValue = GetItem(parentElement, prop.Name);
                if (!PropertyIsElement(prop))
                {
                    if (!object.Equals(sourceValue, parentValue) ||
                        (saveMode == ConfigurationSaveMode.Full) ||
                        (saveMode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere))
                    {
                        unmergedProp.Value = sourceValue;
                    }
                    continue;
                }

                var sourceElem = (ConfigurationElement)sourceValue;
                if (isMinimalOrModified && !ElementIsModified(sourceElem))
                {
                    continue;
                }
                if (parentValue == null)
                {
                    unmergedProp.Value = sourceValue;
                    continue;
                }

                var parentElem            = (ConfigurationElement)parentValue;
                ConfigurationElement copy = (ConfigurationElement)unmergedProp.Value;
                ElementUnmerge(copy, sourceElem, parentElem, saveMode);
            }
        }
Beispiel #26
0
 protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement,
                                 ConfigurationSaveMode saveMode)
 {
     base.Unmerge(sourceElement, parentElement, saveMode);
     ValueXml = ((SettingValueElement)sourceElement).ValueXml;
 }
Beispiel #27
0
		public void SaveAs (string filename, ConfigurationSaveMode mode)
		{
			SaveAs (filename, mode, false);
		}
        /// <inheritdoc />
        protected override void Unmerge(System.Configuration.ConfigurationElement sourceElement, System.Configuration.ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);

            IInternalConfigurationElement source = sourceElement as IInternalConfigurationElement;

            if (source == null)
            {
                return;
            }

            lock (_elements)
                _elements = source.ElementsClone;
        }
Beispiel #29
0
		bool HasValues (ConfigurationSaveMode mode)
		{
			foreach (ConfigurationLocation loc in Locations) {
				if (loc.OpenedConfiguration == null)
					continue;
				if (loc.OpenedConfiguration.HasValues (mode))
					return true;
			}

			return rootGroup.HasValues (this, mode);
		}
 protected override void Unmerge(ConfigurationElement sourceElement,
                                         ConfigurationElement parentElement,
                                         ConfigurationSaveMode saveMode) {
     base.Unmerge(sourceElement, parentElement, saveMode); // do this to unmerge locks
     IdentitySection source = sourceElement as IdentitySection;
     if (Impersonate != source.Impersonate) { // this will not be copied by unmerge if it is the same as parent 
         Impersonate = source.Impersonate;    // If it is different than expected make sure it is set or validation
     }                                        // will be missed
     // this section does not inherit in the same manner since partial overrides are not permitted
     if (Impersonate) // was impersonate set in the merge
     {
         if (source.ElementInformation.Properties[_propUserName.Name].IsModified ||
             source.ElementInformation.Properties[_propPassword.Name].IsModified) {
             UserName = source.UserName;
             Password = source.Password;
         }
     }
 }
Beispiel #31
0
 protected internal override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
 }
 public void Save(ConfigurationSaveMode saveMode)
 {
     Save(saveMode, spath);
 }
Beispiel #33
0
 public void SaveAs(string filename, ConfigurationSaveMode mode)
 {
     SaveAs(filename, mode, false);
 }
Beispiel #34
0
		protected override void Unmerge (ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
		{
			if (parentElement != null && sourceElement.GetType() != parentElement.GetType())
				throw new ConfigurationErrorsException ("Can't unmerge two elements of different type");

			bool isMinimalOrModified = saveMode == ConfigurationSaveMode.Minimal ||
				saveMode == ConfigurationSaveMode.Modified;

			foreach (PropertyInformation prop in sourceElement.ElementInformation.Properties)
			{
				if (prop.ValueOrigin == PropertyValueOrigin.Default)
					continue;
				
				PropertyInformation unmergedProp = ElementInformation.Properties [prop.Name];
				
				object sourceValue = prop.Value;
				if (parentElement == null || !HasValue (parentElement, prop.Name)) {
					unmergedProp.Value = sourceValue;
					continue;
				}

				if (sourceValue == null)
					continue;

				object parentValue = GetItem (parentElement, prop.Name);
				if (!PropertyIsElement (prop)) {
					if (!object.Equals (sourceValue, parentValue) || 
					    (saveMode == ConfigurationSaveMode.Full) ||
					    (saveMode == ConfigurationSaveMode.Modified && prop.ValueOrigin == PropertyValueOrigin.SetHere))
						unmergedProp.Value = sourceValue;
					continue;
				}

				var sourceElem = (ConfigurationElement) sourceValue;
				if (isMinimalOrModified && !ElementIsModified (sourceElem))
					continue;
				if (parentValue == null) {
					unmergedProp.Value = sourceValue;
					continue;
				}

				var parentElem = (ConfigurationElement) parentValue;
				ConfigurationElement copy = (ConfigurationElement) unmergedProp.Value;
				ElementUnmerge (copy, sourceElem, parentElem, saveMode);
			}
		}
Beispiel #35
0
        /// <summary>
        /// Serializes the configuration section to an XML string.
        /// Called by .NET Runtime when updating configuration.
        /// </summary>
        /// <param name="parentElement">The parent element of this section.</param>
        /// <param name="name">The name of the section.</param>
        /// <param name="saveMode">The mode to use when saving.</param>
        /// <returns></returns>
        protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
        {
            StringBuilder     str      = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

            ns.Add(string.Empty, ConfigurationConstants.NamespaceUri);
            using (XmlWriter xml = XmlWriter.Create(str, settings))
            {
                XmlSerializer ser = new XmlSerializer(_currentConfig.GetType());
                ser.Serialize(xml, _currentConfig, ns);
            }

            return(str.ToString());
        }
		// LAMESPEC: this is missing from MSDN, but is present in the 2.0sp1 version of the
		// class
		protected internal override void Unmerge (ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
		{
			// Why override?
			base.Unmerge (sourceElement, parentElement, saveMode);
		}
Beispiel #37
0
        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            base.Unmerge(sourceElement, parentElement, saveMode);
            ListenerElement element = sourceElement as ListenerElement;

            if ((element != null) && (element._attributes != null))
            {
                this._attributes = element._attributes;
            }
        }
 internal ConfigurationLockCollection UnMergeLockList(ConfigurationLockCollection sourceLockList, ConfigurationLockCollection parentLockList, ConfigurationSaveMode saveMode)
 {
     if (!sourceLockList.ExceptionList)
     {
         switch (saveMode)
         {
             case ConfigurationSaveMode.Modified:
             {
                 ConfigurationLockCollection locks = new ConfigurationLockCollection(this, sourceLockList.LockType);
                 foreach (string str in sourceLockList)
                 {
                     if (!parentLockList.Contains(str) || sourceLockList.IsValueModified(str))
                     {
                         locks.Add(str, ConfigurationValueFlags.Default);
                     }
                 }
                 return locks;
             }
             case ConfigurationSaveMode.Minimal:
             {
                 ConfigurationLockCollection locks2 = new ConfigurationLockCollection(this, sourceLockList.LockType);
                 foreach (string str2 in sourceLockList)
                 {
                     if (!parentLockList.Contains(str2))
                     {
                         locks2.Add(str2, ConfigurationValueFlags.Default);
                     }
                 }
                 return locks2;
             }
         }
         return sourceLockList;
     }
     if ((saveMode == ConfigurationSaveMode.Modified) || (saveMode == ConfigurationSaveMode.Minimal))
     {
         bool flag = false;
         if (sourceLockList.Count == parentLockList.Count)
         {
             flag = true;
             foreach (string str3 in sourceLockList)
             {
                 if (!parentLockList.Contains(str3) || (sourceLockList.IsValueModified(str3) && (saveMode == ConfigurationSaveMode.Modified)))
                 {
                     flag = false;
                 }
             }
         }
         if (flag)
         {
             return null;
         }
     }
     return sourceLockList;
 }
 protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     base.Unmerge(sourceElement, parentElement, saveMode);
 }
Beispiel #40
0
		public void Save (ConfigurationSaveMode mode)
		{
			Save (mode, false);
		}
        protected internal virtual void Unmerge(ConfigurationElement sourceElement,
                                                ConfigurationElement parentElement,
                                                ConfigurationSaveMode saveMode) {
            if (sourceElement != null) {
                bool hasAnyChildElements = false;


                _lockedAllExceptAttributesList = sourceElement._lockedAllExceptAttributesList;
                _lockedAllExceptElementsList = sourceElement._lockedAllExceptElementsList;
                _fItemLocked = sourceElement._fItemLocked;
                _lockedAttributesList = sourceElement._lockedAttributesList;
                _lockedElementsList = sourceElement._lockedElementsList;
                AssociateContext(sourceElement._configRecord);

                if (parentElement != null) {
                    if (parentElement._lockedAttributesList != null)
                        _lockedAttributesList = UnMergeLockList(sourceElement._lockedAttributesList,
                            parentElement._lockedAttributesList, saveMode);
                    if (parentElement._lockedElementsList != null)
                        _lockedElementsList = UnMergeLockList(sourceElement._lockedElementsList,
                            parentElement._lockedElementsList, saveMode);
                    if (parentElement._lockedAllExceptAttributesList != null)
                        _lockedAllExceptAttributesList = UnMergeLockList(sourceElement._lockedAllExceptAttributesList,
                            parentElement._lockedAllExceptAttributesList, saveMode);
                    if (parentElement._lockedAllExceptElementsList != null)
                        _lockedAllExceptElementsList = UnMergeLockList(sourceElement._lockedAllExceptElementsList,
                            parentElement._lockedAllExceptElementsList, saveMode);
                }

                ConfigurationPropertyCollection props = Properties;
                ConfigurationPropertyCollection collectionKeys = null;

                // check for props not in bag from source
                for (int index = 0; index < sourceElement.Values.Count; index++) {
                    string key = sourceElement.Values.GetKey(index);
                    object value = sourceElement.Values[index];
                    ConfigurationProperty prop = (ConfigurationProperty)sourceElement.Properties[key];
                    if (prop == null || (collectionKeys != null && !collectionKeys.Contains(prop.Name)))
                        continue;
                    if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                        hasAnyChildElements = true;
                    }
                    else {
                        if (value != s_nullPropertyValue) {
                            if (!props.Contains(key)) // this is for optional provider models keys
                            {
                                // _values[key] = value;
                                ConfigurationValueFlags valueFlags = sourceElement.Values.RetrieveFlags(key);
                                _values.SetValue(key, value, valueFlags, null);

                                props.Add(prop);
                            }
                        }
                    }
                }

                foreach (ConfigurationProperty prop in Properties) {
                    if (prop == null || (collectionKeys != null && !collectionKeys.Contains(prop.Name))) {
                        continue;
                    }
                    if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                        hasAnyChildElements = true;
                    }
                    else {
                        object value = sourceElement.Values[prop.Name];

                        // if the property is required or we are writing a full config make sure we have defaults
                        if ((prop.IsRequired == true || saveMode == ConfigurationSaveMode.Full) && (value == null || value == s_nullPropertyValue)) {
                            // If the default value is null, this means there wasnt a reasonable default for the value
                            // and there is nothing more we can do. Otherwise reset the value to the default

                            // Note: 'null' should be used as default for non-empty strings instead
                            // of the current practice to use String.Epmty

                            if (prop.DefaultValue != null) {
                                value = prop.DefaultValue; // need to make sure required properties are persisted
                            }
                        }

                        if (value != null && value != s_nullPropertyValue) {
                            object value2 = null;
                            if (parentElement != null)                      // Is there a parent
                                value2 = parentElement.Values[prop.Name];   // if so get it's value

                            if (value2 == null)                             // no parent use default
                                value2 = prop.DefaultValue;
                            // If changed and not same as parent write or required

                            switch (saveMode) {
                                case ConfigurationSaveMode.Minimal: {
                                        if (!Object.Equals(value, value2) || prop.IsRequired == true)
                                            _values[prop.Name] = value;
                                    }
                                    break;
                                // (value != null && value != s_nullPropertyValue) ||
                                case ConfigurationSaveMode.Modified: {
                                        bool modified = sourceElement.Values.IsModified(prop.Name);
                                        bool inherited = sourceElement.Values.IsInherited(prop.Name);

                                        // update the value if the property is required, modified or it was not inherited
                                        // Also update properties that ARE inherited when we are resetting the object
                                        // as long as the property is not the same as the default value for the property
                                        if ((prop.IsRequired || modified || !inherited) ||
                                            (parentElement == null && inherited && !Object.Equals(value, value2))) {
                                            _values[prop.Name] = value;
                                        }
                                    }
                                    break;
                                case ConfigurationSaveMode.Full: {
                                        if (value != null && value != s_nullPropertyValue)
                                            _values[prop.Name] = value;
                                        else
                                            _values[prop.Name] = value2;

                                    }
                                    break;
                            }
                        }
                    }
                }

                if (hasAnyChildElements) {
                    foreach (ConfigurationProperty prop in Properties) {
                        if (typeof(ConfigurationElement).IsAssignableFrom(prop.Type)) {
                            ConfigurationElement pElem = (ConfigurationElement)((parentElement != null) ? parentElement[prop] : null);
                            ConfigurationElement childElement = (ConfigurationElement)this[prop];
                            if ((ConfigurationElement)sourceElement[prop] != null)
                                childElement.Unmerge((ConfigurationElement)sourceElement[prop],
                                    pElem, saveMode);
                        }

                    }
                }
            }
        }
Beispiel #42
0
 /// <summary>
 /// Reverses the effect of merging configuration information from different levels of the configuration hierarchy.
 /// </summary>
 /// <param name="sourceElement">A <see cref="ConfigurationElement"/> object at the current level containing a merged view of the properties.</param>
 /// <param name="parentElement">The parent <see cref="ConfigurationElement"/> object of the current element, or a <see langword="null"/> reference (Nothing in Visual Basic) if this is the top level.</param>
 /// <param name="saveMode">One of the <see cref="ConfigurationSaveMode"/> values.</param>
 protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     CreateTypesMap((PolymorphicConfigurationElementCollection <T>)sourceElement);
     base.Unmerge(sourceElement, parentElement, saveMode);
     ReleaseTypesMap();
 }
 protected internal virtual new void Unmerge(System.Configuration.ConfigurationElement sourceElement, System.Configuration.ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
 }
Beispiel #44
0
 internal void InternalUnmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     base.Unmerge(sourceElement, parentElement, saveMode);
 }
 public void Save(ConfigurationSaveMode saveMode, string path)
 {
     if (path == spath)
         this.CurrentConfiguration.Save(saveMode);
     else
         this.CurrentConfiguration.SaveAs(path, saveMode);
 }
Beispiel #46
0
        public static void Save(ConfigurationSaveMode saveMode)
        {
            CategoryPropertyItem rootItem = ConfigurationAccessHelper.GetCategoryPropertyByPath(RemoteDesktopConfiguration.Settings.CategoryPropertyItems, CONFIG_ROOT);

            if (rootItem == null)
            {
                rootItem    = new CategoryPropertyItem();
                rootItem.Id = CONFIG_ROOT;
                RemoteDesktopConfiguration.Settings.CategoryPropertyItems.Add(rootItem);
            }

            CategoryPropertyItem piAuthMode = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_AUTHENTICATION_MODE);

            if (piAuthMode == null)
            {
                piAuthMode    = new CategoryPropertyItem();
                piAuthMode.Id = CONFIG_AUTHENTICATION_MODE;
                rootItem.PropertyItems.Add(piAuthMode);
            }
            piAuthMode.EntryValue = AuthenticationMode.ToString();

            CategoryPropertyItem piModuleStore = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_AUTHENTICATION_MODULE_STORE);

            if (piModuleStore == null)
            {
                piModuleStore    = new CategoryPropertyItem();
                piModuleStore.Id = CONFIG_AUTHENTICATION_MODULE_STORE;
                rootItem.PropertyItems.Add(piModuleStore);
            }
            piModuleStore.EntryValue = AuthenticationModuleStore;

            CategoryPropertyItem piPropagation = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_PROPAGATE_ON_NETWORK);

            if (piPropagation == null)
            {
                piPropagation    = new CategoryPropertyItem();
                piPropagation.Id = CONFIG_PROPAGATE_ON_NETWORK;
                rootItem.PropertyItems.Add(piPropagation);
            }
            piPropagation.EntryValue = PropagateServiceOnTheNetwork.ToString();

            CategoryPropertyItem piDesktopShareMode = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_DESKTOP_SHARE_MODE);

            if (piDesktopShareMode == null)
            {
                piDesktopShareMode    = new CategoryPropertyItem();
                piDesktopShareMode.Id = CONFIG_DESKTOP_SHARE_MODE;
                rootItem.PropertyItems.Add(piDesktopShareMode);
            }
            piDesktopShareMode.EntryValue = DesktopShareMode.ToString();

            CategoryPropertyItem piAcceptInputEvents = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_ACCEPT_INPUTS_FROM_CLIENTS);

            if (piAcceptInputEvents == null)
            {
                piAcceptInputEvents    = new CategoryPropertyItem();
                piAcceptInputEvents.Id = CONFIG_ACCEPT_INPUTS_FROM_CLIENTS;
                rootItem.PropertyItems.Add(piAcceptInputEvents);
            }
            piAcceptInputEvents.EntryValue = AcceptKeyboardAndMouseInputFromClients.ToString();

            CategoryPropertyItem piDesktopImageClipWidth = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_DESKTOP_IMAGE_CLIP_WIDTH);

            if (piDesktopImageClipWidth == null)
            {
                piDesktopImageClipWidth    = new CategoryPropertyItem();
                piDesktopImageClipWidth.Id = CONFIG_DESKTOP_IMAGE_CLIP_WIDTH;
                rootItem.PropertyItems.Add(piDesktopImageClipWidth);
            }
            piDesktopImageClipWidth.EntryValue = DesktopImageClipWidth.ToString();

            CategoryPropertyItem piDesktopImageClipHeight = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_DESKTOP_IMAGE_CLIP_HEIGHT);

            if (piDesktopImageClipHeight == null)
            {
                piDesktopImageClipHeight    = new CategoryPropertyItem();
                piDesktopImageClipHeight.Id = CONFIG_DESKTOP_IMAGE_CLIP_HEIGHT;
                rootItem.PropertyItems.Add(piDesktopImageClipHeight);
            }
            piDesktopImageClipHeight.EntryValue = DesktopImageClipHeight.ToString();

            CategoryPropertyItem piClientsPerServiceThreads = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_CLIENTS_PER_SERVICE_THREADS);

            if (piClientsPerServiceThreads == null)
            {
                piClientsPerServiceThreads    = new CategoryPropertyItem();
                piClientsPerServiceThreads.Id = CONFIG_CLIENTS_PER_SERVICE_THREADS;
                rootItem.PropertyItems.Add(piClientsPerServiceThreads);
            }
            piClientsPerServiceThreads.EntryValue = ClientsPerServiceThreads.ToString();

            CategoryPropertyItem piMaximumFailedLoginAttempt = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_MAXIMUM_FAILED_LOGIN_ATTEMPT);

            if (piMaximumFailedLoginAttempt == null)
            {
                piMaximumFailedLoginAttempt    = new CategoryPropertyItem();
                piMaximumFailedLoginAttempt.Id = CONFIG_MAXIMUM_FAILED_LOGIN_ATTEMPT;
                rootItem.PropertyItems.Add(piMaximumFailedLoginAttempt);
            }
            piMaximumFailedLoginAttempt.EntryValue = MaximumFailedLoginAttempt.ToString();

            CategoryPropertyItem piBlackListTimeout = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_BLACKLIST_TIMEOUT);

            if (piBlackListTimeout == null)
            {
                piBlackListTimeout    = new CategoryPropertyItem();
                piBlackListTimeout.Id = CONFIG_BLACKLIST_TIMEOUT;
                rootItem.PropertyItems.Add(piBlackListTimeout);
            }
            piBlackListTimeout.EntryValue = BlackListTimeout.ToString();

            CategoryPropertyItem piImageClipQuality = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_IMAGE_CLIP_QUALITY);

            if (piImageClipQuality == null)
            {
                piImageClipQuality    = new CategoryPropertyItem();
                piImageClipQuality.Id = CONFIG_IMAGE_CLIP_QUALITY;
                rootItem.PropertyItems.Add(piImageClipQuality);
            }
            piImageClipQuality.EntryValue = DefaultImageClipQuality.ToString();

            CategoryPropertyItem piMouseMoveSendingInterval = ConfigurationAccessHelper.GetCategoryPropertyByPath(rootItem.PropertyItems, CONFIG_MOUSE_MOVE_SEND_INTERVAL);

            if (piMouseMoveSendingInterval == null)
            {
                piMouseMoveSendingInterval    = new CategoryPropertyItem();
                piMouseMoveSendingInterval.Id = CONFIG_MOUSE_MOVE_SEND_INTERVAL;
                rootItem.PropertyItems.Add(piMouseMoveSendingInterval);
            }
            piMouseMoveSendingInterval.EntryValue = MouseMoveSendInterval.ToString();

            RemoteDesktopConfiguration.Save(saveMode);
        }
Beispiel #47
0
		void ElementUnmerge (ConfigurationElement target, ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
		{
			target.GetType ().GetMethod ("Unmerge", BindingFlags.NonPublic | BindingFlags.Instance).Invoke (target, new object [] {sourceElement, parentElement, saveMode});
		}
 protected internal override string SerializeSection(ConfigurationElement parentSection, string name, ConfigurationSaveMode saveMode)
 {
     return(this._rawXml);
 }
        protected internal virtual void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            if (sourceElement != null)
            {
                bool flag = false;
                this._lockedAllExceptAttributesList = sourceElement._lockedAllExceptAttributesList;
                this._lockedAllExceptElementsList = sourceElement._lockedAllExceptElementsList;
                this._fItemLocked = sourceElement._fItemLocked;
                this._lockedAttributesList = sourceElement._lockedAttributesList;
                this._lockedElementsList = sourceElement._lockedElementsList;
                this.AssociateContext(sourceElement._configRecord);
                if (parentElement != null)
                {
                    if (parentElement._lockedAttributesList != null)
                    {
                        this._lockedAttributesList = this.UnMergeLockList(sourceElement._lockedAttributesList, parentElement._lockedAttributesList, saveMode);
                    }
                    if (parentElement._lockedElementsList != null)
                    {
                        this._lockedElementsList = this.UnMergeLockList(sourceElement._lockedElementsList, parentElement._lockedElementsList, saveMode);
                    }
                    if (parentElement._lockedAllExceptAttributesList != null)
                    {
                        this._lockedAllExceptAttributesList = this.UnMergeLockList(sourceElement._lockedAllExceptAttributesList, parentElement._lockedAllExceptAttributesList, saveMode);
                    }
                    if (parentElement._lockedAllExceptElementsList != null)
                    {
                        this._lockedAllExceptElementsList = this.UnMergeLockList(sourceElement._lockedAllExceptElementsList, parentElement._lockedAllExceptElementsList, saveMode);
                    }
                }
                ConfigurationPropertyCollection properties = this.Properties;
                ConfigurationPropertyCollection propertys2 = null;
                for (int i = 0; i < sourceElement.Values.Count; i++)
                {
                    string key = sourceElement.Values.GetKey(i);
                    object obj2 = sourceElement.Values[i];
                    ConfigurationProperty property = sourceElement.Properties[key];
                    if ((property != null) && ((propertys2 == null) || propertys2.Contains(property.Name)))
                    {
                        if (property.IsConfigurationElementType)
                        {
                            flag = true;
                        }
                        else if ((obj2 != s_nullPropertyValue) && !properties.Contains(key))
                        {
                            ConfigurationValueFlags valueFlags = sourceElement.Values.RetrieveFlags(key);
                            this._values.SetValue(key, obj2, valueFlags, null);
                            properties.Add(property);
                        }
                    }
                }
                foreach (ConfigurationProperty property2 in this.Properties)
                {
                    object defaultValue;
                    if ((property2 != null) && ((propertys2 == null) || propertys2.Contains(property2.Name)))
                    {
                        if (property2.IsConfigurationElementType)
                        {
                            flag = true;
                        }
                        else
                        {
                            object objA = sourceElement.Values[property2.Name];
                            if (((property2.IsRequired || (saveMode == ConfigurationSaveMode.Full)) && ((objA == null) || (objA == s_nullPropertyValue))) && (property2.DefaultValue != null))
                            {
                                objA = property2.DefaultValue;
                            }
                            if ((objA != null) && (objA != s_nullPropertyValue))
                            {
                                defaultValue = null;
                                if (parentElement != null)
                                {
                                    defaultValue = parentElement.Values[property2.Name];
                                }
                                if (defaultValue == null)
                                {
                                    defaultValue = property2.DefaultValue;
                                }
                                switch (saveMode)
                                {
                                    case ConfigurationSaveMode.Modified:
                                    {
                                        bool flag2 = sourceElement.Values.IsModified(property2.Name);
                                        bool flag3 = sourceElement.Values.IsInherited(property2.Name);
                                        if (((property2.IsRequired || flag2) || !flag3) || (((parentElement == null) && flag3) && !object.Equals(objA, defaultValue)))
                                        {
                                            this._values[property2.Name] = objA;
                                        }
                                        break;
                                    }
                                    case ConfigurationSaveMode.Minimal:
                                        if (!object.Equals(objA, defaultValue) || property2.IsRequired)
                                        {
                                            this._values[property2.Name] = objA;
                                        }
                                        break;

                                    case ConfigurationSaveMode.Full:
                                        if ((objA == null) || (objA == s_nullPropertyValue))
                                        {
                                            goto Label_031E;
                                        }
                                        this._values[property2.Name] = objA;
                                        break;
                                }
                            }
                        }
                    }
                    continue;
                Label_031E:
                    this._values[property2.Name] = defaultValue;
                }
                if (flag)
                {
                    foreach (ConfigurationProperty property3 in this.Properties)
                    {
                        if (property3.IsConfigurationElementType)
                        {
                            ConfigurationElement element = (parentElement != null) ? ((ConfigurationElement) parentElement[property3]) : null;
                            ConfigurationElement element2 = (ConfigurationElement) this[property3];
                            if (((ConfigurationElement) sourceElement[property3]) != null)
                            {
                                element2.Unmerge((ConfigurationElement) sourceElement[property3], element, saveMode);
                            }
                        }
                    }
                }
            }
        }
Beispiel #50
0
 protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
 {
     return(base.SerializeSection(parentElement, name, saveMode));
 }
		protected override void Unmerge (ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
		{
			throw new NotImplementedException ();
		}
Beispiel #52
0
 protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
 {
     helper.HandleUnmerge(sourceElement, parentElement, saveMode);
 }
Beispiel #53
0
		public void Save (ConfigurationSaveMode mode, bool forceUpdateAll)
		{
			if (!forceUpdateAll && (mode != ConfigurationSaveMode.Full) && !HasValues (mode)) {
				ResetModified ();
				return;
			}

			ConfigurationSaveEventHandler saveStart = SaveStart;
			ConfigurationSaveEventHandler saveEnd = SaveEnd;
			
			object ctx = null;
			Exception saveEx = null;
			Stream stream = system.Host.OpenStreamForWrite (streamName, null, ref ctx);
			try {
				if (saveStart != null)
					saveStart (this, new ConfigurationSaveEventArgs (streamName, true, null, ctx));
				
				Save (stream, mode, forceUpdateAll);
				system.Host.WriteCompleted (streamName, true, ctx);
			} catch (Exception ex) {
				saveEx = ex;
				system.Host.WriteCompleted (streamName, false, ctx);
				throw;
			} finally {
				stream.Close ();
				if (saveEnd != null)
					saveEnd (this, new ConfigurationSaveEventArgs (streamName, false, saveEx, ctx));
			}
		}
Beispiel #54
0
 void IHelperAssistedCustomConfigurationData <CustomCacheStorageData> .BaseUnmerge(ConfigurationElement sourceElement,
                                                                                   ConfigurationElement parentElement,
                                                                                   ConfigurationSaveMode saveMode)
 {
     base.Unmerge(sourceElement, parentElement, saveMode);
 }
Beispiel #55
0
		public void SaveAs (string filename, ConfigurationSaveMode mode, bool forceUpdateAll)
		{
			if (!forceUpdateAll && (mode != ConfigurationSaveMode.Full) && !HasValues (mode)) {
				ResetModified ();
				return;
			}
			
			string dir = Path.GetDirectoryName (Path.GetFullPath (filename));
			if (!Directory.Exists (dir))
				Directory.CreateDirectory (dir);
			Save (new FileStream (filename, FileMode.OpenOrCreate, FileAccess.Write), mode, forceUpdateAll);
		}
        protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
        {
            if (((base.CurrentConfiguration != null) && (base.CurrentConfiguration.TargetFramework != null)) && !this.ShouldSerializeSectionInTargetVersion(base.CurrentConfiguration.TargetFramework))
            {
                return(string.Empty);
            }
            ConfigurationElement.ValidateElement(this, null, true);
            ConfigurationElement element = ConfigurationElement.CreateElement(base.GetType());

            element.Unmerge(this, parentElement, saveMode);
            StringWriter  w      = new StringWriter(CultureInfo.InvariantCulture);
            XmlTextWriter writer = new XmlTextWriter(w)
            {
                Formatting  = Formatting.Indented,
                Indentation = 4,
                IndentChar  = ' '
            };

            element.DataToWriteInternal = saveMode != ConfigurationSaveMode.Minimal;
            if ((base.CurrentConfiguration != null) && (base.CurrentConfiguration.TargetFramework != null))
            {
                base._configRecord.SectionsStack.Push(this);
            }
            element.SerializeToXmlElement(writer, name);
            if ((base.CurrentConfiguration != null) && (base.CurrentConfiguration.TargetFramework != null))
            {
                base._configRecord.SectionsStack.Pop();
            }
            writer.Flush();
            return(w.ToString());
        }
Beispiel #57
0
		void SaveData (XmlTextWriter tw, ConfigurationSaveMode mode, bool forceUpdateAll)
		{
			rootGroup.WriteRootData (tw, this, mode);
		}
        protected override void Unmerge(ConfigurationElement sourceElement, ConfigurationElement parentElement, ConfigurationSaveMode saveMode)
        {
            if (sourceElement == null)
            {
                return;
            }

            ServiceModelExtensionCollectionElement <TServiceModelExtensionElement> sourceCollectionElement = (ServiceModelExtensionCollectionElement <TServiceModelExtensionElement>)sourceElement;

            this.UpdateProperties(sourceCollectionElement);
            base.Unmerge(sourceElement, parentElement, saveMode);
        }
 protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
 {
     throw new InvalidOperationException("TestException");
 }
Beispiel #60
0
 protected internal override void Unmerge(
     ConfigurationElement source, ConfigurationElement parent,
     ConfigurationSaveMode updateMode)
 {
     base.Unmerge(source, parent, updateMode);
 }