/// <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; try { var dirPath = DirectoryFileOperations.CheckDirectoryPathExistsCreate(); var filePath = DirectoryFileOperations.CreatePathToUserFile(dirPath); // Append line to the file. using (var writer = new StreamWriter(filePath, true)) { writer.WriteLine(SpellingPropertiesClass.UserName); } return(true); } catch (UnauthorizedAccessException ex) { Console.WriteLine(ex); throw; } }
/// <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> /// 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() { 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); } }