/// <summary> /// Check to see if the word is already in the list box. /// </summary> /// <param name="duplicate">The items from the list box.</param> /// /// /// <param name="addWord">The word to check for.</param> /// <returns>True if word is all ready in the list else false.</returns> /// <created>,5/10/2019</created> /// <changed>,5/10/2019</changed> public static bool CheckDuplicateWord(List <string> duplicate, string addWord) { var declaringType = MethodBase.GetCurrentMethod().DeclaringType; if (declaringType != null) { MyMessages.NameOfClass = declaringType.Name; } MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; if (!LoopThrewWordsList(duplicate, addWord)) { return(false); } MyMessages.InformationMessage = "The word entered is all ready in the list of spelling words. "; MyMessages.ShowInformationMessageBox( MyMessages.InformationMessage, MyMessages.NameOfClass, MyMessages.NameOfMethod); return(true); }
/// <summary> /// Check for space in value this will means either space in word that does not belong or /// two words instead of one spelling word. /// </summary> /// <param name="value">The spelling word to validate.</param> /// <returns>True if no space is found else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/10/2019</changed> public static bool ValidateStringOneWord(string value) { MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; MyMessages.ErrorMessage = "Check to see if space in word or if two words are entered. Spaces and double words are not allowed. correct this then add the word again. "; try { var index = value.IndexOf(' '); if (index > -1) { throw new NotSupportedException(); } return(true); } catch (NotSupportedException e) { var msg = string.Concat(MyMessages.ErrorMessage, e); MyMessages.ShowErrorMessageBox(msg, MyMessages.NameOfClass, MyMessages.NameOfMethod); return(false); } }
/// ******************************************************************************** /// <summary> /// Check if directory path to Art2m spell directory exits. If not then create it /// and verify its existence. used to hold all files related to Art2MSpell. /// </summary> /// <returns>Directory path if successful else returns empty string.</returns> /// <created>art2m,5/18/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static string CheckExistsCreateArt2MSpellPathDirectory() { MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { var dirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var dirName = SpellingPropertiesClass.GetArt2MSpellDirectoryName; dirPath = Path.Combine(dirPath, dirName); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } return(!Directory.Exists(dirPath) ? string.Empty : dirPath); } catch (ArgumentNullException ex) { MyMessages.ErrorMessage = "Encountered Error when combining directory paths or creating directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (UnauthorizedAccessException ex) { MyMessages.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (PathTooLongException ex) { MyMessages.ErrorMessage = "The directory path is to long."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (DirectoryNotFoundException ex) { MyMessages.ErrorMessage = "Unable to locate the directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (NotSupportedException ex) { MyMessages.ErrorMessage = "Not supported for this platform."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (ArgumentException ex) { MyMessages.ErrorMessage = "Encountered error while creating directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } }
/// ******************************************************************************** /// <summary> /// Creates directories if they do not exist in supplied path; /// </summary> /// <param name="dirPath">The path to create directories from.</param> /// <returns>Directory path if they exist or were created else returns empty string.</returns> /// <created>art2m,5/23/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static string CheckDirectoryExistsCreateDirectory(string dirPath) { try { if (Directory.Exists(dirPath)) { return(dirPath); } Directory.CreateDirectory(dirPath); return(dirPath); } catch (ArgumentNullException ex) { MyMessages.ErrorMessage = "Encountered Error when combining directory paths or creating directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (UnauthorizedAccessException ex) { MyMessages.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (PathTooLongException ex) { MyMessages.ErrorMessage = "The directory path is to long."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (DirectoryNotFoundException ex) { MyMessages.ErrorMessage = "Unable to locate the directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (NotSupportedException ex) { MyMessages.ErrorMessage = "Not supported for this platform."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (ArgumentException ex) { MyMessages.ErrorMessage = "Encountered error while creating directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } }
/// ******************************************************************************** /// <summary> /// Create user sub directory in Art2MSpell directory. This will hold all of /// this users spelling lists. /// </summary> /// <param name="dirPath">The path to the users directory.</param> /// <returns>True if user directory created else false.</returns> /// <created>art2m,5/22/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool CreateUserSpellingListDirectory(string dirPath) { var dirName = SpellingPropertiesClass.UserName; try { dirPath = Path.Combine(dirPath, dirName); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } return(Directory.Exists(dirPath)); } catch (ArgumentNullException ex) { MyMessages.ErrorMessage = "Encountered Error when combining directory paths or creating directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (UnauthorizedAccessException ex) { MyMessages.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (PathTooLongException ex) { MyMessages.ErrorMessage = "The directory path is to long."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (DirectoryNotFoundException ex) { MyMessages.ErrorMessage = "Unable to locate the directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (NotSupportedException ex) { MyMessages.ErrorMessage = "Not supported for this platform."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (ArgumentException ex) { MyMessages.ErrorMessage = "Encountered error while creating directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } }
/// ******************************************************************************** /// <summary> /// Need to save new users name to User file list name. So can be used to identify users /// spelling list. check file exists if not create. /// </summary> /// <param name="dirPath"></param> /// <returns>File path if successful else return empty string.</returns> /// <created>art2m,5/18/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static string CreatePathToUserFile(string dirPath) { MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { var fileName = SpellingPropertiesClass.GetArt2MSpellUserListFileName; var filePath = Path.Combine(dirPath, fileName); if (!File.Exists(filePath)) { File.Create(filePath).Dispose(); } return(!File.Exists(filePath) ? string.Empty : filePath); } catch (ArgumentNullException ex) { MyMessages.ErrorMessage = "Encountered Error when combining directory paths or creating directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (UnauthorizedAccessException ex) { MyMessages.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (PathTooLongException ex) { MyMessages.ErrorMessage = "The directory path is to long."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (DirectoryNotFoundException ex) { MyMessages.ErrorMessage = "Unable to locate the directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (NotSupportedException ex) { MyMessages.ErrorMessage = "Not supported for this platform."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (ArgumentException ex) { MyMessages.ErrorMessage = "Encountered error while creating directory."; MyMessages.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } }
/// <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(); using (var fileRead = new StreamReader(filePath)) { string word; while ((word = fileRead.ReadLine()) != null) { ValidateWordFromSpellingListAddToCollection(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); } }
/// <summary> /// If adding new user then write there name to the Art2MSpell user names file. /// </summary> /// <returns>True if write successful else false.</returns> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/17/2019</changed> public static bool WriteUserNameFile() { MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; var dirPath = DirectoryFileOperations.CheckDirectoryPathExistsCreate(); var filePath = DirectoryFileOperations.CreatePathToUserFile(dirPath); try { // Append line to the file. using (var writer = new StreamWriter(filePath, true)) { writer.WriteLine(SpellingPropertiesClass.UserName); } return(true); } catch (UnauthorizedAccessException ex) { MyMessages.ErrorMessage = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); MyMessages.ShowErrorMessageBox(); return(false); } catch (ArgumentNullException ex) { MyMessages.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessages.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessages.ErrorMessage = "The file path value is a null string. " + 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 (PathTooLongException ex) { MyMessages.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessages.ShowErrorMessageBox(); return(false); } catch (SecurityException ex) { MyMessages.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); return(false); } catch (IOException ex) { MyMessages.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessages.ShowErrorMessageBox(); return(false); } }
/// <summary> /// Write spelling words list to file. /// </summary> /// <param name="filePath">Path to write file to.</param> /// <returns>True if file is written else false.</returns> /// <created>art2m,5/20/2019</created> /// <changed>art2m,5/20/2019</changed> public static bool WriteSpellingWordsToFile(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 (UnauthorizedAccessException ex) { MyMessages.ErrorMessage = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); MyMessages.ShowErrorMessageBox(); return(false); } catch (ArgumentNullException ex) { MyMessages.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessages.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessages.ErrorMessage = "The file path value is a null string. " + 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 (PathTooLongException ex) { MyMessages.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessages.ShowErrorMessageBox(); return(false); } catch (SecurityException ex) { MyMessages.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); return(false); } catch (IOException ex) { MyMessages.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessages.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Read user name file into collection. /// so user can log in with there name. This /// is used to keep each users spelling list together so they can choose /// an all ready saved spelling list to practice. /// </summary> /// <returns></returns> /// <created>art2m,5/20/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool ReadUserNameFile(string filePath) { MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { using (var reader = new StreamReader(filePath)) { string user; while ((user = reader.ReadLine()) != null) { Unc.AddItem(user.Trim()); } } return(true); } catch (ArgumentNullException ex) { MyMessages.ErrorMessage = "The file path value is a null string. " + 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); } }
/// <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) { } }
/// <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. } }
/// <summary> /// Read user name file into collection. /// so user can log in with there name. This /// is used to keep each users spelling list together so they can choose /// an all ready saved spelling list to practice. /// </summary> /// <returns></returns> /// <created>art2m,5/20/2019</created> /// <changed>art2m,5/20/2019</changed> public static bool ReadUserNameFile() { // TODO: Add error handling to this method. MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; var dirPath = DirectoryFileOperations.CheckDirectoryPathExistsCreate(); var filePath = DirectoryFileOperations.CreatePathToUserFile(dirPath); try { using (var reader = new StreamReader(filePath)) { string user; while ((user = reader.ReadLine()) != null) { unc.AddItem(user.Trim()); } } return(true); } catch (ArgumentNullException ex) { MyMessages.ErrorMessage = "The file path value is a null string. " + 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); } }