Beispiel #1
0
        /// <summary>
        /// Extracts speak abbreviations from the abbreviations
        /// file and adds them to the phrases file. Removes 'favorite'
        /// phrases from the abbreviations file.
        /// </summary>
        /// <param name="abbreviationsFile">input abbreviations file</param>
        /// <param name="phrasesFile">output phrases file</param>
        private static void extractPhrases(String abbreviationsFile, String phrasesFile)
        {
            var abbreviations = new Abbreviations();

            bool retVal = abbreviations.Load(abbreviationsFile);

            if (!abbreviations.AbbreviationList.Any() || !retVal)
            {
                return;
            }

            var phrases = File.Exists(phrasesFile) ? Phrases.Load(phrasesFile) : new Phrases();

            foreach (var abbreviation in abbreviations.AbbreviationList)
            {
                if (abbreviation.Mode == Abbreviation.AbbreviationMode.Speak && !String.IsNullOrEmpty(abbreviation.Expansion))
                {
                    var phrase = new Phrase {
                        Text = abbreviation.Expansion
                    };

                    if (abbreviation.Mnemonic.StartsWith("**"))
                    {
                        phrase.Favorite = true;
                    }

                    phrases.Add(phrase);
                }
            }

            phrases.Save(phrasesFile);

            var count = 0;

            while (true)
            {
                bool found = false;

                foreach (var abbreviation in abbreviations.AbbreviationList)
                {
                    if (abbreviation.Mnemonic.StartsWith("**"))
                    {
                        abbreviations.Remove(abbreviation.Mnemonic);
                        found = true;
                        count++;
                        break;
                    }
                }

                if (!found)
                {
                    if (count > 0)
                    {
                        abbreviations.Save(abbreviationsFile);
                    }

                    break;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates the singleton instance of the Abbreviations manager
        /// </summary>
        /// <returns>true on success</returns>
        private static bool createAbbreviationsManager()
        {
            bool retVal = true;

            if (isEnabled(StartupFlags.Abbreviations))
            {
                AppAbbreviations = new Abbreviations();
                retVal           = AppAbbreviations.Load();

                if (!retVal)
                {
                    setCompletionStatus("Abbreviations load error.  Abbreviations will be disabled", false);
                }
            }

            return(retVal);
        }