Esempio n. 1
0
        /// <summary>
        ///     Reads the spelling list from the file the user has opened.
        /// </summary>
        /// <param name="filePath">The file path to the spelling list user wishes to open.</param>
        /// <returns>True if the spelling list words are added to collection else false.</returns>
        /// <created>art2m,5/10/2019</created>
        /// <changed>art2m,5/10/2019</changed>
        public static bool ReadSpellingListFile(string filePath)
        {
            MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            var swc = new SpellingWordsCollection();

            try
            {
                swc.ClearCollection();

                var cnt = 0;

                using (var fileRead = new StreamReader(filePath))
                {
                    string word;
                    while ((word = fileRead.ReadLine()) != null)
                    {
                        if (SpellingPropertiesClass.Art2MSpellSpellingList && (cnt == 0))
                        {
                            cnt = 1;
                            continue;
                        }

                        // check for valid spell list by checking words are all letters and not empty.
                        if (!Validation.ValidateSpellingWord(word))
                        {
                            return(false);
                        }

                        swc.AddItem(word);
                    }
                }

                return(true);
            }
            catch (ArgumentNullException ex)
            {
                MyMessages.ErrorMessage = "The file path is string is null. " + filePath;

                Debug.WriteLine(ex.ToString());

                MyMessages.ShowErrorMessageBox();
                return(false);
            }
            catch (ArgumentException ex)
            {
                MyMessages.ErrorMessage = "The file path value is an empty string.";

                Debug.WriteLine(ex.ToString());
                MyMessages.ShowErrorMessageBox();

                return(false);
            }
            catch (FileNotFoundException ex)
            {
                MyMessages.ErrorMessage = "Unable to locate this file. " + filePath;

                Debug.WriteLine(ex.ToString());

                MyMessages.ShowErrorMessageBox();
                return(false);
            }
            catch (DirectoryNotFoundException ex)
            {
                MyMessages.ErrorMessage = "Unable to locate the directory.";

                Debug.WriteLine(ex.ToString())
                ;
                MyMessages.ShowErrorMessageBox();

                return(false);
            }
            catch (IOException ex)
            {
                MyMessages.ErrorMessage = "File path has invalid characters in it.";

                Debug.WriteLine(ex.ToString());

                MyMessages.ShowErrorMessageBox();

                return(false);
            }
        }