/// ******************************************************************************** /// <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> /// 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> /// 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> /// 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> /// 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/23/2019</changed> /// ******************************************************************************** public static bool WriteUserNameFile(string filePath) { MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; 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> /// 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> /// 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/23/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) { 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); } }
/// <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(); } catch (PathTooLongException ex) { } catch (SecurityException ex) { } catch (IOException ex) { } }
/// <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); } }