/// <summary> /// Imports the settings. /// </summary> /// <param name="extensionName"> /// Name of the extension. /// </param> /// <param name="settings"> /// The settings. /// </param> /// <returns> /// If import settings works. /// </returns> public static bool ImportSettings(string extensionName, ExtensionSettings settings) { var ext = extensions.FirstOrDefault(x => x.Key == extensionName && !x.Value.Initialized(settings)); if (ext.Value != null) { ext.Value.InitializeSettings(settings); } SaveToCache(); // return SaveToStorage(); return(true); }
/// <summary> /// Method to cache and serialize settings object /// </summary> /// <param name="extensionSettings">The extension settings.</param> public void SaveSettings(ExtensionSettings extensionSettings) { if (string.IsNullOrEmpty(extensionSettings.Name)) { extensionSettings.Name = this.Name; } foreach (var setItem in this.settings.Where(setItem => setItem.Name == extensionSettings.Name)) { this.settings.Remove(setItem); break; } this.settings.Add(extensionSettings); this.settings.Sort((s1, s2) => string.Compare(s1.Index.ToString(), s2.Index.ToString())); }
/// <summary> /// Determine if settings has been initialized with default /// values (first time new extension loaded into the manager) /// </summary> /// <param name="xs"> /// The ExtensionSettings. /// </param> /// <returns> /// True if initialized /// </returns> public bool Initialized(ExtensionSettings xs) { return(xs != null && this.settings.Where(setItem => setItem.Name == xs.Name).Any(setItem => setItem.Parameters.Count == xs.Parameters.Count)); }
/// <summary> /// Initializes the settings. /// </summary> /// <param name="extensionSettings">The extension settings.</param> public void InitializeSettings(ExtensionSettings extensionSettings) { extensionSettings.Index = this.settings.Count; this.SaveSettings(extensionSettings); }
/// <summary> /// Will save settings (add to extension object, then /// cache and serialize all object hierarhy to XML) /// </summary> /// <param name="settings"> /// Settings object /// </param> public static void SaveSettings(ExtensionSettings settings) { SaveSettings(settings.Name, settings); }
/// <summary> /// Initializes settings by importing default parameters /// </summary> /// <param name="extensionName"> /// Extension Name /// </param> /// <param name="settings"> /// Settings object /// </param> /// <returns> /// The Extension Settings /// </returns> public static ExtensionSettings InitSettings(string extensionName, ExtensionSettings settings) { ImportSettings(extensionName, settings); return(GetSettings(extensionName, settings.Name)); }
/// <summary> /// Do initial import here. /// If already imported, let extension manager take care of settings /// /// </summary> /// <param name="settings"> /// The settings. /// </param> /// <returns> /// The import settings. /// </returns> public static bool ImportSettings(ExtensionSettings settings) { return(ImportSettings(settings.Name, settings)); }