private static void WriteFavorite(XmlTextWriter w, bool includePassword, FavoriteConfigurationElement favorite) { if (favorite == null) { return; } if (w.WriteState == WriteState.Closed || w.WriteState == WriteState.Error) { return; } w.WriteStartElement("favorite"); PropertyInfo[] infos = favorite.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.GetProperty); foreach (PropertyInfo info in infos) { if (info.Name == "UserName" || info.Name == "Password" || info.Name == "DomainName" || info.Name == "EncryptedPassword" || info.Name == "TsgwUsername" || info.Name == "TsgwPassword" || info.Name == "TsgwDomain" || info.Name == "TsgwEncryptedPassword") { if (!includePassword) { continue; } } if (info.Name == "HtmlFormFields") { w.WriteElementString("HtmlFormFieldsString", favorite.GetType().GetProperty("HtmlFormFieldsString", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(favorite, null).ToString()); continue; } // Has already been exported as favorite.Tag // favorite.TagList is only for a human readable // list of strings. // The same applies to "RedirectedDrives" which is handled by // "redirectDrives" if (info.Name == "TagList" || info.Name == "RedirectedDrives") { continue; } object value = info.GetValue(favorite, null); // if a value is null than the tostring wouldn't be callable. -> // therefore set it to string.Empty. if (value == null || string.IsNullOrEmpty(value.ToString())) { value = string.Empty; } w.WriteElementString(info.Name, value.ToString()); } w.WriteEndElement(); }
private static void WriteFavorite(XmlTextWriter w, bool includePassword, FavoriteConfigurationElement favorite) { if (favorite == null) return; if (w.WriteState == WriteState.Closed || w.WriteState == WriteState.Error) return; w.WriteStartElement("favorite"); PropertyInfo[] infos = favorite.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.GetProperty); foreach (PropertyInfo info in infos) { if (info.Name == "UserName" || info.Name == "Password" || info.Name == "DomainName" || info.Name == "EncryptedPassword" || info.Name == "TsgwUsername" || info.Name == "TsgwPassword" || info.Name == "TsgwDomain" || info.Name == "TsgwEncryptedPassword") if (!includePassword) continue; if (info.Name == "HtmlFormFields") { w.WriteElementString("HtmlFormFieldsString", favorite.GetType().GetProperty("HtmlFormFieldsString", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(favorite, null).ToString()); continue; } // Has already been exported as favorite.Tag // favorite.TagList is only for a human readable // list of strings. // The same applies to "RedirectedDrives" which is handled by // "redirectDrives" if (info.Name == "TagList" || info.Name == "RedirectedDrives") { continue; } object value = info.GetValue(favorite, null); // if a value is null than the tostring wouldn't be callable. -> // therefore set it to string.Empty. if (value == null || string.IsNullOrEmpty(value.ToString())) value = string.Empty; w.WriteElementString(info.Name, value.ToString()); } w.WriteEndElement(); }
/// <summary> /// Reconstructs a new Terminals configuration file from a broken one. /// </summary> /// <remarks>Please read all the comments in this methods before chaning something.</remarks> /// <returns>Returns a complete new Terminals configuration in the form of a <see cref="System.Configuration.Configuration">.NET configuration file</see>.</returns> private static System.Configuration.Configuration ImportConfiguration() { // If we are already in the remapping process/progress // i.e. if we are in this method -> we don't want to go // through it a second or third time for just calling // a property in the Settings class // like // public static bool ShowFullInformationToolTips // { // get { return GetSection().ShowFullInformationToolTips; } // // set // { // GetSection().ShowFullInformationToolTips = value; // SaveImmediatelyIfRequested(); // } // } // Which internally calls GetSection() -> and that forces to call // this method if the mapping of the file fails. // -> So quickly jump out of this procedure // // BTW: Every Save() method call will be ignored as long as the // remappingInProgress := true // That's why we save the file that has been constructed in memory // to the disk until we are finished with the whole parsing process. // (-> see 'Save()' at the end of this method) if (remappingInProgress) { return(OpenConfiguration()); } // Stop the file watcher while we create a plain new configuration file if (fileWatcher != null) { fileWatcher.StopObservation(); } remappingInProgress = true; // Create a temporary copy of this file and overwrite the original // one with a plain new configuration file (as can be seen in the next // few lines (i.e. SaveDefaultConfigFile()) // We'll parse the temporary copy of the file that has been created and // update the plain file if (string.IsNullOrEmpty(tempFile)) { tempFile = Path.GetTempFileName(); CopyFile(ConfigurationFileLocation, tempFile); } // Restart the file watcher again SaveDefaultConfigFile(); if (fileWatcher != null) { fileWatcher.StartObservation(); } // get a list of the properties on the Settings object (static props) PropertyInfo[] propList = typeof(Settings).GetProperties(BindingFlags.Public | BindingFlags.Static | BindingFlags.SetProperty); // Load the whole xml file // No problem if this line fails -> the plain new copy is // totally enough XmlDocument doc = LoadDocument(tempFile); // get the settings (options) XmlNode root = doc.SelectSingleNode("/configuration/settings"); bool terminalsPasswordDetected = false; try { // for each setting's attribute foreach (XmlAttribute att in root.Attributes) { // Set the Terminals password used to encrypt and decrypt the passwords if enabled try { if (att.Name.Equals("TerminalsPassword", StringComparison.CurrentCultureIgnoreCase)) { terminalsPasswordDetected = true; if (!string.IsNullOrWhiteSpace(att.Value)) { remappingSection.TerminalsPassword = att.Value; Log.Debug("The Terminals password has been set in the new configuration file."); continue; } Log.Debug("A Terminals password attribute exists in the broken original configuration file but it hasn't been set."); continue; } } catch (Exception ex) { terminalsPasswordDetected = true; Log.Error("Error occured while trying to set the Terminals password in the new configuration file. This error will prevent terminals from decrypting your passwords.", ex); continue; } // scan for the related property if any foreach (PropertyInfo info in propList) { try { if (info.Name.ToLower() == att.Name.ToLower()) { // found a matching property, try to set it string val = att.Value; if (info.PropertyType.Name == "Version") { info.SetValue(null, new Version(val), null); } else { info.SetValue(null, Convert.ChangeType(val, info.PropertyType), null); } break; } } catch (Exception exc) { Log.Error("Error occured while trying parse the configuration file and map " + att.Name + ": " + exc.Message); break; } } } } catch (Exception exc) { Log.Error("Error occured while trying parse the configuration file and remapping the root settings.", exc); } if (!terminalsPasswordDetected) { Log.Debug("No Terminals password has been found in the broken configuration file."); } // pluginOptions // favoritesButtonsList // toolStripSettings // savedConnectionsList // -> WAS ist mit Groups und anderen Objekten in den Favorites im Code? -> Code-Tree überprüfen // usersMRUList // serversMRUList // domainsMRUList // tags -> werden implizit durch die Favorites gesetzt - Überprüfen ob korrekt // Nicht alle Felder bei den Favorites werden gesetzt // Work through every favorite configuration element XmlNodeList favs = doc.SelectNodes("/configuration/settings/favorites/add"); try { foreach (XmlNode fav in favs) { FavoriteConfigurationElement newFav = new FavoriteConfigurationElement(); // Add the plugin configuration for each favorite element if (fav.ChildNodes != null && fav.ChildNodes.Count == 1) { XmlNode pluginRootElement = fav.ChildNodes[0]; if (pluginRootElement.Name.Equals("PLUGINS", StringComparison.InvariantCultureIgnoreCase)) { foreach (XmlNode plugin in pluginRootElement.ChildNodes) { if (plugin.Name.Equals("PLUGIN", StringComparison.InvariantCultureIgnoreCase) && plugin.Attributes != null && plugin.Attributes.Count > 0) { PluginConfiguration pluginConfig = new PluginConfiguration(); if (plugin.Attributes["name"] != null && !string.IsNullOrEmpty(plugin.Attributes["name"].Value)) { pluginConfig.Name = plugin.Attributes["name"].Value; } if (plugin.Attributes["value"] != null && !string.IsNullOrEmpty(plugin.Attributes["value"].Value)) { pluginConfig.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty).First(property => property.Name.Equals("value", StringComparison.InvariantCultureIgnoreCase)).SetValue(pluginConfig, plugin.Attributes["value"].Value, null); } if (plugin.Attributes["defaultValue"] != null && !string.IsNullOrEmpty(plugin.Attributes["defaultValue"].Value)) { pluginConfig.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty).First(property => property.Name.Equals("defaultValue", StringComparison.InvariantCultureIgnoreCase)).SetValue(pluginConfig, plugin.Attributes["defaultValue"].Value, null); } newFav.PluginConfigurations.Add(pluginConfig); } } } } // Add the attributes of each favorite foreach (XmlAttribute att in fav.Attributes) { foreach (PropertyInfo info in newFav.GetType().GetProperties()) { try { if (info.Name.ToLower() == att.Name.ToLower()) { // found a matching property, try to set it string val = att.Value; if (info.PropertyType.IsEnum) { info.SetValue(newFav, Enum.Parse(info.PropertyType, val), null); } else { info.SetValue(newFav, Convert.ChangeType(val, info.PropertyType), null); } break; } } catch (Exception exc) { string favoriteName = "favorite"; if (fav == null || fav.Attributes.Count < 1 || fav.Attributes["name"] == null || string.IsNullOrEmpty(fav.Attributes["name"].Value)) { favoriteName += "s"; } else { favoriteName += " " + fav.Attributes["name"].Value; } favoriteName += ": "; Log.Error("Error occured while trying parse the configuration file and remapping the " + favoriteName + exc.Message); break; } } } AddFavorite(newFav); } } catch (Exception exc) { Log.Error("Error remapping favorites: " + exc.Message); remappingInProgress = false; return(Config); //return _config; //return OpenConfiguration(); } File.Delete(tempFile); remappingInProgress = false; Save(); return(_config); //return OpenConfiguration(); }
private static FavoriteConfigurationElement ReadProperty(XmlTextReader reader, List<FavoriteConfigurationElement> favorites, FavoriteConfigurationElement favorite) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "favorite": favorite = new FavoriteConfigurationElement(); favorites.Add(favorite); break; default: if (favorite == null) break; PropertyInfo property = favorite.GetType().GetProperty(reader.Name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); if (property == null) break; // Check if the property has a setter -> if not break; MethodInfo propertySetter = property.GetSetMethod(true); if (propertySetter == null) break; try { if (property.GetValue(favorite, null) is Boolean) { property.SetValue(favorite, Convert.ToBoolean(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Decimal) { property.SetValue(favorite, Convert.ToDecimal(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Double) { property.SetValue(favorite, Convert.ToDouble(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Byte) { property.SetValue(favorite, Convert.ToByte(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Char) { property.SetValue(favorite, Convert.ToChar(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is DateTime) { property.SetValue(favorite, Convert.ToDateTime(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Int16) { property.SetValue(favorite, Convert.ToInt16(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Int32) { property.SetValue(favorite, Convert.ToInt32(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Int64) { property.SetValue(favorite, Convert.ToInt64(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is SByte) { property.SetValue(favorite, Convert.ToSByte(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Single) { property.SetValue(favorite, Convert.ToSingle(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is UInt16) { property.SetValue(favorite, Convert.ToUInt16(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is UInt32) { property.SetValue(favorite, Convert.ToUInt32(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is UInt64) { property.SetValue(favorite, Convert.ToUInt64(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Enum) { property.SetValue(favorite, Enum.Parse(property.GetValue(favorite, null).GetType(), reader.ReadString()), null); } else property.SetValue(favorite, reader.ReadString(), null); break; } catch { Log.Warn(string.Format("Unable to set property '{0}'.", reader.Name)); break; } } break; } return favorite; }
private System.Configuration.Configuration ImportConfiguration() { // get a temp filename to hold the current settings which are failing string tempFile = Path.GetTempFileName(); fileWatcher.StopObservation(); MoveAndDeleteFile(fileLocations.Configuration, tempFile); SaveDefaultConfigFile(); fileWatcher.StartObservation(); System.Configuration.Configuration c = OpenConfiguration(); // get a list of the properties on the Settings object (static props) PropertyInfo[] propList = typeof(Settings).GetProperties(); // read all the xml from the erroring file XmlDocument doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(tempFile)); // get the settings root XmlNode root = doc.SelectSingleNode("/configuration/settings"); try { // for each setting's attribute foreach (XmlAttribute att in root.Attributes) { // scan for the related property if any try { foreach (PropertyInfo info in propList) { try { if (info.Name.ToLower() == att.Name.ToLower()) { // found a matching property, try to set it string val = att.Value; info.SetValue(null, Convert.ChangeType(val, info.PropertyType), null); break; } } catch (Exception exc) { // ignore the error Logging.Error("Remapping Settings Inner", exc); } } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Settings Outer", exc); } } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Settings Outer Try", exc); } XmlNodeList favs = doc.SelectNodes("/configuration/settings/favorites/add"); try { foreach (XmlNode fav in favs) { try { FavoriteConfigurationElement newFav = new FavoriteConfigurationElement(); foreach (XmlAttribute att in fav.Attributes) { try { foreach (PropertyInfo info in newFav.GetType().GetProperties()) { try { if (info.Name.ToLower() == att.Name.ToLower()) { // found a matching property, try to set it string val = att.Value; if (info.PropertyType.IsEnum) { info.SetValue(newFav, Enum.Parse(info.PropertyType, val), null); } else { info.SetValue(newFav, Convert.ChangeType(val, info.PropertyType), null); } break; } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Favorites 1", exc); } } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Favorites 2", exc); } } AddFavorite(newFav); } catch (Exception exc) // ignore the error { Logging.Error("Remapping Favorites 3", exc); } } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Favorites 4", exc); } return c; }
private System.Configuration.Configuration ImportConfiguration() { // get a temp filename to hold the current settings which are failing string tempFile = Path.GetTempFileName(); fileWatcher.StopObservation(); MoveAndDeleteFile(fileLocations.Configuration, tempFile); SaveDefaultConfigFile(); fileWatcher.StartObservation(); System.Configuration.Configuration c = OpenConfiguration(); // get a list of the properties on the Settings object (static props) PropertyInfo[] propList = typeof(Settings).GetProperties(); // read all the xml from the erroring file XmlDocument doc = new XmlDocument(); doc.LoadXml(File.ReadAllText(tempFile)); // get the settings root XmlNode root = doc.SelectSingleNode("/configuration/settings"); try { // for each setting's attribute foreach (XmlAttribute att in root.Attributes) { // scan for the related property if any try { foreach (PropertyInfo info in propList) { try { if (info.Name.ToLower() == att.Name.ToLower()) { // found a matching property, try to set it string val = att.Value; info.SetValue(null, Convert.ChangeType(val, info.PropertyType), null); break; } } catch (Exception exc) { // ignore the error Logging.Error("Remapping Settings Inner", exc); } } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Settings Outer", exc); } } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Settings Outer Try", exc); } XmlNodeList favs = doc.SelectNodes("/configuration/settings/favorites/add"); try { foreach (XmlNode fav in favs) { try { FavoriteConfigurationElement newFav = new FavoriteConfigurationElement(); foreach (XmlAttribute att in fav.Attributes) { try { foreach (PropertyInfo info in newFav.GetType().GetProperties()) { try { if (info.Name.ToLower() == att.Name.ToLower()) { // found a matching property, try to set it string val = att.Value; if (info.PropertyType.IsEnum) { info.SetValue(newFav, Enum.Parse(info.PropertyType, val), null); } else { info.SetValue(newFav, Convert.ChangeType(val, info.PropertyType), null); } break; } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Favorites 1", exc); } } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Favorites 2", exc); } } AddFavorite(newFav); } catch (Exception exc) // ignore the error { Logging.Error("Remapping Favorites 3", exc); } } } catch (Exception exc) // ignore the error { Logging.Error("Remapping Favorites 4", exc); } return(c); }
private static FavoriteConfigurationElement ReadProperty(XmlTextReader reader, List <FavoriteConfigurationElement> favorites, FavoriteConfigurationElement favorite) { switch (reader.NodeType) { case XmlNodeType.Element: switch (reader.Name) { case "favorite": favorite = new FavoriteConfigurationElement(); favorites.Add(favorite); break; default: if (favorite == null) { break; } PropertyInfo property = favorite.GetType().GetProperty(reader.Name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); if (property == null) { break; } // Check if the property has a setter -> if not break; MethodInfo propertySetter = property.GetSetMethod(true); if (propertySetter == null) { break; } try { if (property.GetValue(favorite, null) is Boolean) { property.SetValue(favorite, Convert.ToBoolean(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Decimal) { property.SetValue(favorite, Convert.ToDecimal(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Double) { property.SetValue(favorite, Convert.ToDouble(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Byte) { property.SetValue(favorite, Convert.ToByte(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Char) { property.SetValue(favorite, Convert.ToChar(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is DateTime) { property.SetValue(favorite, Convert.ToDateTime(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Int16) { property.SetValue(favorite, Convert.ToInt16(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Int32) { property.SetValue(favorite, Convert.ToInt32(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Int64) { property.SetValue(favorite, Convert.ToInt64(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is SByte) { property.SetValue(favorite, Convert.ToSByte(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Single) { property.SetValue(favorite, Convert.ToSingle(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is UInt16) { property.SetValue(favorite, Convert.ToUInt16(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is UInt32) { property.SetValue(favorite, Convert.ToUInt32(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is UInt64) { property.SetValue(favorite, Convert.ToUInt64(reader.ReadString()), null); } else if (property.GetValue(favorite, null) is Enum) { property.SetValue(favorite, Enum.Parse(property.GetValue(favorite, null).GetType(), reader.ReadString()), null); } else { property.SetValue(favorite, reader.ReadString(), null); } break; } catch { Log.Warn(string.Format("Unable to set property '{0}'.", reader.Name)); break; } } break; } return(favorite); }
/// <summary> /// Reconstructs a new Terminals configuration file from a broken one. /// </summary> /// <remarks>Please read all the comments in this methods before chaning something.</remarks> /// <returns>Returns a complete new Terminals configuration in the form of a <see cref="System.Configuration.Configuration">.NET configuration file</see>.</returns> private static System.Configuration.Configuration ImportConfiguration() { // If we are already in the remapping process/progress // i.e. if we are in this method -> we don't want to go // through it a second or third time for just calling // a property in the Settings class // like // public static bool ShowFullInformationToolTips // { // get { return GetSection().ShowFullInformationToolTips; } // // set // { // GetSection().ShowFullInformationToolTips = value; // SaveImmediatelyIfRequested(); // } // } // Which internally calls GetSection() -> and that forces to call // this method if the mapping of the file fails. // -> So quickly jump out of this procedure // // BTW: Every Save() method call will be ignored as long as the // remappingInProgress := true // That's why we save the file that has been constructed in memory // to the disk until we are finished with the whole parsing process. // (-> see 'Save()' at the end of this method) if (remappingInProgress) return OpenConfiguration(); // Stop the file watcher while we create a plain new configuration file if (fileWatcher != null) fileWatcher.StopObservation(); remappingInProgress = true; // Create a temporary copy of this file and overwrite the original // one with a plain new configuration file (as can be seen in the next // few lines (i.e. SaveDefaultConfigFile()) // We'll parse the temporary copy of the file that has been created and // update the plain file if (string.IsNullOrEmpty(tempFile)) { tempFile = Path.GetTempFileName(); CopyFile(ConfigurationFileLocation, tempFile); } // Restart the file watcher again SaveDefaultConfigFile(); if (fileWatcher != null) fileWatcher.StartObservation(); // get a list of the properties on the Settings object (static props) PropertyInfo[] propList = typeof (Settings).GetProperties(BindingFlags.Public | BindingFlags.Static | BindingFlags.SetProperty); // Load the whole xml file // No problem if this line fails -> the plain new copy is // totally enough XmlDocument doc = LoadDocument(tempFile); // get the settings (options) XmlNode root = doc.SelectSingleNode("/configuration/settings"); bool terminalsPasswordDetected = false; try { // for each setting's attribute foreach (XmlAttribute att in root.Attributes) { // Set the Terminals password used to encrypt and decrypt the passwords if enabled try { if (att.Name.Equals("TerminalsPassword", StringComparison.CurrentCultureIgnoreCase)) { terminalsPasswordDetected = true; if (!string.IsNullOrWhiteSpace(att.Value)) { remappingSection.TerminalsPassword = att.Value; Log.Debug("The Terminals password has been set in the new configuration file."); continue; } Log.Debug("A Terminals password attribute exists in the broken original configuration file but it hasn't been set."); continue; } } catch (Exception ex) { terminalsPasswordDetected = true; Log.Error("Error occured while trying to set the Terminals password in the new configuration file. This error will prevent terminals from decrypting your passwords.", ex); continue; } // scan for the related property if any foreach (PropertyInfo info in propList) { try { if (info.Name.ToLower() == att.Name.ToLower()) { // found a matching property, try to set it string val = att.Value; if (info.PropertyType.Name == "Version") info.SetValue(null, new Version(val), null); else info.SetValue(null, Convert.ChangeType(val, info.PropertyType), null); break; } } catch (Exception exc) { Log.Error("Error occured while trying parse the configuration file and map " + att.Name + ": " + exc.Message); break; } } } } catch (Exception exc) { Log.Error("Error occured while trying parse the configuration file and remapping the root settings.", exc); } if (!terminalsPasswordDetected) { Log.Debug("No Terminals password has been found in the broken configuration file."); } // pluginOptions // favoritesButtonsList // toolStripSettings // savedConnectionsList // -> WAS ist mit Groups und anderen Objekten in den Favorites im Code? -> Code-Tree überprüfen // usersMRUList // serversMRUList // domainsMRUList // tags -> werden implizit durch die Favorites gesetzt - Überprüfen ob korrekt // Nicht alle Felder bei den Favorites werden gesetzt // Work through every favorite configuration element XmlNodeList favs = doc.SelectNodes("/configuration/settings/favorites/add"); try { foreach (XmlNode fav in favs) { FavoriteConfigurationElement newFav = new FavoriteConfigurationElement(); // Add the plugin configuration for each favorite element if (fav.ChildNodes != null && fav.ChildNodes.Count == 1) { XmlNode pluginRootElement = fav.ChildNodes[0]; if (pluginRootElement.Name.Equals("PLUGINS", StringComparison.InvariantCultureIgnoreCase)) { foreach (XmlNode plugin in pluginRootElement.ChildNodes) { if (plugin.Name.Equals("PLUGIN", StringComparison.InvariantCultureIgnoreCase) && plugin.Attributes != null && plugin.Attributes.Count > 0) { PluginConfiguration pluginConfig = new PluginConfiguration(); if (plugin.Attributes["name"] != null && !string.IsNullOrEmpty(plugin.Attributes["name"].Value)) pluginConfig.Name = plugin.Attributes["name"].Value; if (plugin.Attributes["value"] != null && !string.IsNullOrEmpty(plugin.Attributes["value"].Value)) { pluginConfig.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty).First(property => property.Name.Equals("value", StringComparison.InvariantCultureIgnoreCase)).SetValue(pluginConfig, plugin.Attributes["value"].Value, null); } if (plugin.Attributes["defaultValue"] != null && !string.IsNullOrEmpty(plugin.Attributes["defaultValue"].Value)) { pluginConfig.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty).First(property => property.Name.Equals("defaultValue", StringComparison.InvariantCultureIgnoreCase)).SetValue(pluginConfig, plugin.Attributes["defaultValue"].Value, null); } newFav.PluginConfigurations.Add(pluginConfig); } } } } // Add the attributes of each favorite foreach (XmlAttribute att in fav.Attributes) { foreach (PropertyInfo info in newFav.GetType().GetProperties()) { try { if (info.Name.ToLower() == att.Name.ToLower()) { // found a matching property, try to set it string val = att.Value; if (info.PropertyType.IsEnum) { info.SetValue(newFav, Enum.Parse(info.PropertyType, val), null); } else { info.SetValue(newFav, Convert.ChangeType(val, info.PropertyType), null); } break; } } catch (Exception exc) { string favoriteName = "favorite"; if (fav == null || fav.Attributes.Count < 1 || fav.Attributes["name"] == null || string.IsNullOrEmpty(fav.Attributes["name"].Value)) favoriteName += "s"; else favoriteName += " " + fav.Attributes["name"].Value; favoriteName += ": "; Log.Error("Error occured while trying parse the configuration file and remapping the " + favoriteName + exc.Message); break; } } } AddFavorite(newFav); } } catch (Exception exc) { Log.Error("Error remapping favorites: " + exc.Message); remappingInProgress = false; return Config; //return _config; //return OpenConfiguration(); } File.Delete(tempFile); remappingInProgress = false; Save(); return _config; //return OpenConfiguration(); }