Esempio n. 1
0
        public void CopyFrom(MacrosSystem macroSystem)
        {
            MacroStringDictionary.Clear();
            MacroStringCustomList = new BindingList <Macro>(macroSystem.MacroStringCustomList);
            MacroStringSystemList.Clear();
            MacroStringCustomListBackup.Clear();

            BuildDictionary();
        }
Esempio n. 2
0
        public bool IsCustomMacroValid(string macro)
        {
            {
                var duplicates = from pair in MacroStringCustomList.ToList() // (binding list needs to be converted to list)
                                 where (pair.Key != null && pair.Key.Equals(macro, StringComparison.CurrentCultureIgnoreCase))
                                 select pair;

                if (duplicates.Count() > 1)
                {
                    /// already have this macro
                    OutputLog.Log(LogSeverity.Warning, "duplicate macro will be ignored: " + macro);
                    return(false);
                }
            }

            {
                var duplicates = from pair in MacroStringSystemList.ToList() // (binding list needs to be converted to list)
                                 where (pair.Key != null && pair.Key.Equals(macro, StringComparison.CurrentCultureIgnoreCase))
                                 select pair;

                if (duplicates.Count() > 0)
                {
                    /// cannot use a system macro
                    OutputLog.Log(LogSeverity.Warning, "system macro will be ignored: " + macro);
                    return(false);
                }
            }


            foreach (ReservedNetworkMacroKeys key in Enum.GetValues(typeof(ReservedNetworkMacroKeys)))
            {
                string keyStr = Enum.GetName(typeof(ReservedNetworkMacroKeys), key);

                if (keyStr.Equals(macro, StringComparison.CurrentCultureIgnoreCase))
                {
                    // cannot use a context reserved macro
                    OutputLog.Log(LogSeverity.Warning, "context macro will be ignored: " + macro);
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 3
0
        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();
        }