public void AddReservedString(ReservedNetworkMacroKeys reservedKey, string value) { string keyOriginal = Prefix + Enum.GetName(typeof(ReservedNetworkMacroKeys), reservedKey); int counter = 1; string key = keyOriginal + "_" + counter.ToString() + Suffix; while (true) { if (MacroStringDictionary.ContainsKey(key) && MacroStringDictionary[key].Equals(value, StringComparison.CurrentCultureIgnoreCase)) { // already have this key with this value // nothing more to do return; } if (MacroStringDictionary.ContainsKey(key) == false) { // don't have this key so add it MacroStringDictionary.Add(key, value); // ensure longest strings are replaced first SortDictionary(); return; } // generate the next key and try again key = keyOriginal + "_" + counter.ToString() + Suffix; counter++; } }
public void CopyFrom(MacrosSystem macroSystem) { MacroStringDictionary.Clear(); MacroStringCustomList = new BindingList <Macro>(macroSystem.MacroStringCustomList); MacroStringSystemList.Clear(); MacroStringCustomListBackup.Clear(); BuildDictionary(); }
public void BuildDictionary() { MacroStringDictionary.Clear(); MacroStringSystemList.Clear(); foreach (ReservedVersionMacroKeys versionKey in Enum.GetValues(typeof(ReservedVersionMacroKeys))) { string key = Enum.GetName(typeof(ReservedVersionMacroKeys), versionKey); string value = MorphemeVersionSelector.GetInstance().GetCurrentValue(versionKey); if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) { continue; } if (MacroStringDictionary.ContainsKey(Prefix + key + Suffix)) { OutputLog.Log(LogSeverity.Warning, "skipping duplicate macro key: " + key); continue; } MacroStringDictionary.Add(Prefix + key + Suffix, value); MacroStringSystemList.Add(new Macro(key, value)); } foreach (Environment.SpecialFolder specialFolder in Enum.GetValues(typeof(Environment.SpecialFolder))) { // only add certain SpecialFolders if (specialFolder != Environment.SpecialFolder.ApplicationData && specialFolder != Environment.SpecialFolder.CommonApplicationData && specialFolder != Environment.SpecialFolder.CommonProgramFiles && specialFolder != Environment.SpecialFolder.Desktop && specialFolder != Environment.SpecialFolder.LocalApplicationData && specialFolder != Environment.SpecialFolder.MyComputer && specialFolder != Environment.SpecialFolder.MyDocuments && specialFolder != Environment.SpecialFolder.ProgramFiles && specialFolder != Environment.SpecialFolder.ProgramFilesX86 && specialFolder != Environment.SpecialFolder.Programs && specialFolder != Environment.SpecialFolder.System) { continue; } string key = Enum.GetName(typeof(Environment.SpecialFolder), specialFolder); var duplicates = from pair in MacroStringSystemList.ToList() // (binding list needs to be converted to list) where (pair.Key != null && pair.Key.Equals(key, StringComparison.CurrentCultureIgnoreCase)) select pair; if (duplicates.Count() > 0) { // only supports one value per key (a 1-1 mapping) continue; } string folderPath = Environment.GetFolderPath(specialFolder); if (string.IsNullOrEmpty(folderPath)) { continue; } MacroStringDictionary.Add(Prefix + key + Suffix, folderPath); MacroStringSystemList.Add(new Macro(key, folderPath)); } // lastly add the custom macros and do not allow duplicates of system macros added above foreach (Macro pair in MacroStringCustomList) { if (string.IsNullOrEmpty(pair.Key) || string.IsNullOrEmpty(pair.Value)) { continue; } if (pair.Key.Equals(pair.Value, StringComparison.CurrentCultureIgnoreCase)) { // avoid infinite recursion OutputLog.Log(LogSeverity.Warning, "skipping macro with equal key and value"); continue; } if (MacroStringDictionary.ContainsKey(Prefix + pair.Key + Suffix)) { OutputLog.Log(LogSeverity.Warning, "skipping duplicate macro key: " + pair.Key); continue; } MacroStringDictionary.Add(Prefix + pair.Key + Suffix, pair.Value); } SortDictionary(); }