/// ******************************************************************************** /// <summary> /// Validate word then if valid place into the collection. /// </summary> /// <param name="word"></param> /// <created>art2m,5/21/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** private static void ValidateWordFromSpellingListAddToCollection(string word) { // check for valid spell list by checking words are all letters and not empty. if (!Validation.ValidateSpellingWord(word)) { return; } Swc.AddItem(word); }
/// <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; StreamReader fileRead; using (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 = "Invalid file path. " + filePath; MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message); return(false); } catch (ArgumentException ex) { } catch (IOException ex) { MyMessages.ErrorMessage = "Read error has occurred. " + filePath; MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message); return(false); } }
/// <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; StreamReader fileRead; using (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. } }