private bool AddinCustomSettingMatches(AddinElement newAddin, AddinElement currAddin) { if (newAddin.CustomSettings.CustomSetting.Count != currAddin.CustomSettings.CustomSetting.Count) { return(false); } foreach (var newSetting in newAddin.CustomSettings.CustomSetting) { bool settingMatches = false; foreach (var currSetting in currAddin.CustomSettings.CustomSetting) { if (newSetting.SettingKey.Equals(currSetting.SettingKey, StringComparison.OrdinalIgnoreCase)) { if (!newSetting.SettingValue.Equals(currSetting.SettingValue, StringComparison.OrdinalIgnoreCase)) { return(false); } else { settingMatches = true; break; } } } if (!settingMatches) { return(false); } } return(true); }
public void Save() { Source.Settings.Addins.Addin.Clear(); foreach (IAddin addin in ConfiguredAddins) { AddinElement addinElement = new AddinElement(); addinElement.ReferenceName = addin.ReferenceName.ToString(); addinElement.FriendlyName = addin.FriendlyName; Dictionary <string, FieldValuePairViewModel> fieldVMs; m_addinConfigurations.TryGetValue(addin, out fieldVMs); if (addin.CustomSettingKeys != null) { foreach (string str in addin.CustomSettingKeys) { FieldValuePairViewModel currentVM; fieldVMs.TryGetValue(str, out currentVM); if (currentVM != null) { CustomSetting customSetting = new CustomSetting(); customSetting.SettingKey = str; customSetting.SettingValue = currentVM.FieldValue; addinElement.CustomSettings.CustomSetting.Add(customSetting); } } } Source.Settings.Addins.Addin.Add(addinElement); } }
/// <summary> /// Build addin instance /// </summary> /// <typeparam name="T">Instance type</typeparam> /// <param name="configuration">Instance configuratio</param> /// <returns></returns> public static TAddin MakeInstance(AddinElement configuration) { if (configuration == null) { throw new ArgumentNullException("configuration"); } // Get type Type typeInstance = Type.GetType(configuration.Type, true); // Create properties Dictionary <string, object> properties = null; if (configuration.PropertyValues != null && configuration.PropertyValues.Count > 0) { properties = new Dictionary <string, object>(); foreach (KeyValueConfigurationElement key in configuration.PropertyValues) { properties[key.Key] = key.Value; } } // Construct return(ObjectBuilder.Build <TAddin>(typeInstance, properties)); }
/// <summary> /// This method allows an Addin implementation to easily retrieve any CustomSettings defined for the Addin from the Configuration /// </summary> /// <param name="configurationService">The ConfigurationService which the Addin can obtain from the ToolkitServiceContainer</param> /// <param name="addinReferenceName">The reference name of the Addin making the call</param> /// <param name="customSettingsKeysAndValues">Add Dictionary of name/value pairs; the caller should fill in the keys with /// the expected CustomSetting names and may also set default values in the values of each pair. /// For each of the named CustomSettings that is found in the configuration for the Addin, the value in the Dictionary will be /// replaced with the CustomSetting value.</param> public static void GetAddinCustomSettings( ConfigurationService configurationService, string addinReferenceName, Dictionary <string, string> customSettingsKeysAndValues) { // BEGIN SUPPORT FOR COMPATABILITY WITH OLD CONFIG FILES foreach (CustomSetting setting in configurationService.MigrationSource.CustomSettings.CustomSetting) { if (customSettingsKeysAndValues.ContainsKey(setting.SettingKey)) { customSettingsKeysAndValues[setting.SettingKey] = setting.SettingValue; } } // END SUPPORT FOR COMPATABILITY WITH OLD CONFIG FILES // Settings in the new format will override those in the old location if both are present AddinElement requestedAddinElement = null; foreach (AddinElement addinElement in configurationService.MigrationSource.Settings.Addins.Addin) { if (string.Equals(addinElement.ReferenceName, addinReferenceName, StringComparison.OrdinalIgnoreCase)) { requestedAddinElement = addinElement; break; } } if (requestedAddinElement != null) { foreach (CustomSetting setting in requestedAddinElement.CustomSettings.CustomSetting) { if (customSettingsKeysAndValues.ContainsKey(setting.SettingKey)) { customSettingsKeysAndValues[setting.SettingKey] = setting.SettingValue; } } } }