/// <summary> /// Writes spelling words to file. /// </summary> /// <param name="filePath">The file path to write the spelling words to.</param> /// <returns>True if spelling words written to file else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/10/2019</changed> public static bool WriteToFile(string filePath) { var swc = new SpellingWordsCollection(); try { StreamWriter fileWrite; using (fileWrite = new StreamWriter(filePath, false)) { var cnt = swc.ItemsCount(); fileWrite.WriteLine(SpellingPropertiesClass.GetArt2MSpellHeader); Debug.WriteLine(SpellingPropertiesClass.GetArt2MSpellHeader); for (var i = 0; i < cnt; i++) { var word = swc.GetItemAt(i); fileWrite.WriteLine(word); } } return(true); } catch (ArgumentException ex) { MyMessages.ErrorMessage = "Invalid file path. " + filePath; MyMessages.BuildErrorString( MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message); return(false); } catch (IOException ex) { MyMessages.ErrorMessage = "Write 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) { var declaringType = MethodBase.GetCurrentMethod().DeclaringType; if (declaringType != null) { MyMessages.NameOfClass = declaringType.Name; } 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 (FileNotFoundException ex) { MyMessages.ErrorMessage = "Read error has occurred. " + filePath; MyMessages.BuildErrorString(MyMessages.NameOfClass, MyMessages.NameOfMethod, MyMessages.ErrorMessage, ex.Message); return(false); } catch (DirectoryNotFoundException ex) { } catch (IOException ex) { } }