/// ******************************************************************************** /// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** private static void AddNewUserToUserNameFile() { MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; var unc = new UsersNameCollection(); if (unc.ContainsItem(SpellingPropertiesClass.UserName)) { MyMessages.InformationMessage = "This user all ready exists."; MyMessages.ShowInformationMessageBox(); } unc.AddItem(SpellingPropertiesClass.UserName); var dirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); var dirName = SpellingPropertiesClass.GetArt2MSpellDirectoryName; dirPath = DirectoryFileOperations.CombineStringsMakeDirectoryPath(dirPath, dirName); if (string.IsNullOrEmpty(dirPath)) { return; } var fileName = SpellingPropertiesClass.GetArt2MSpellUserListFileName; var filePath = DirectoryFileOperations.CombineDirectoryPathFileNameCheckCreateFile(dirPath, fileName); if (string.IsNullOrEmpty(filePath)) { return; } SpellingReadWriteClass.WriteUserNameFile(filePath); }
/// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/17/2019</changed> private static void AddNewUserToUserNameFile() { MyMessages.NameOfMethod = MethodBase.GetCurrentMethod().Name; var unc = new UsersNameCollection(); if (unc.ContainsItem(SpellingPropertiesClass.UserName)) { MyMessages.InformationMessage = "This user all ready exists."; MyMessages.ShowInformationMessageBox(); } unc.AddItem(SpellingPropertiesClass.UserName); SpellingReadWriteClass.WriteUserNameFile(); var dirPath = DirectoryFileOperations.CheckDirectoryPathExistsCreate(); var retVal = DirectoryFileOperations.CreateUserSpellingListDirectory(dirPath); if (retVal) { return; } MyMessages.ErrorMessage = "Unable to create user directory."; MyMessages.ShowErrorMessageBox(); }
/// ******************************************************************************** /// <summary> /// Place all the user names from the collection into the list box. /// User can then select there name and get all of there spelling list. /// </summary> /// <created>art2m,5/20/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** private void FillListBoxWithUserNames() { for (var index = 0; index < UsersNameCollection.ItemsCount(); index++) { this.lstUsers.Items.Add(UsersNameCollection.GetItemAt(index)); } }
/// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/17/2019</changed> private static void AddNewUserToUserNameFile() { // TODO: Make method for editing and deleting users from user file. // TODO: Make method for adding existing spelling lists to current user. var unc = new UsersNameCollection(); if (unc.ContainsItem(SpellingPropertiesClass.UserName)) { MyMessages.InformationMessage = "This user all ready exists."; MyMessages.ShowInformationMessageBox(); } unc.AddItem(SpellingPropertiesClass.UserName); SpellingReadWriteClass.WriteUserNameFile(); var dirPath = DirectoryFileOperations.CheckDirectoryPathExistsCreate(); var retVal = DirectoryFileOperations.CreateUserSpellingListDirectory(dirPath); if (!retVal) { MyMessages.ErrorMessage = "Unable to create user directory."; MyMessages.ShowErrorMessageBox(); } }
/// ******************************************************************************** /// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** private static void AddNewUserToUserNameFile() { NameOfMethod = MethodBase.GetCurrentMethod().Name; if (UsersNameCollection.ContainsItem(SpellingPropertiesClass.UserName)) { InformationMessage = V2; ShowInformationMessageBox(); } UsersNameCollection.AddItem(SpellingPropertiesClass.UserName); var dirPath = SpellingPropertiesClass.AppDataDirectoryPath; var dirName = SpellingPropertiesClass.GetArt2MSpellDirectoryName; dirPath = DirectoryFileOperationsClass.CombineStringsMakeDirectoryPath(dirPath, dirName); if (string.IsNullOrEmpty(dirPath)) { return; } var fileName = SpellingPropertiesClass.GetArt2MSpellUserListFileName; var filePath = DirectoryFileOperationsClass.CombineDirectoryPathFileNameCheckCreateFile( dirPath, fileName); if (string.IsNullOrEmpty(filePath)) { return; } SpellingReadWriteClass.WriteUserNameFile(filePath); }
/// <summary> /// if user enters text save it to user name. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">Instance containing the event data.</param> private void OnButtonOk_Click(object sender, EventArgs e) { var name = this.txtUserName.Text.Trim(); if (string.IsNullOrEmpty(name) || name.Length < 1) { SpellingPropertiesClass.UserName = string.Empty; return; } SpellingPropertiesClass.UserName = name; if (UsersNameCollection.ContainsItem(name)) { MyMessagesClass.InformationMessage = "This user name all ready exists. Go to select user name to use this name."; MyMessagesClass.ShowInformationMessageBox(); return; } SpellingReadWriteClass.WriteUserNameFile(SpellingPropertiesClass.UserNameFilePath); var dirPath = DirectoryFileOperationsClass.CombineStringsMakeDirectoryPath( SpellingPropertiesClass.Art2MSpellDirectoryPath, SpellingPropertiesClass.UserName); DirectoryFileOperationsClass.CheckDirectoryExistsCreateDirectory(dirPath); SpellingPropertiesClass.CurrentUserSpellingListDirectory = dirPath; }
/// ******************************************************************************** /// <summary> /// Remove the user name from the All names listed file. /// </summary> /// <param name="filePath">The path to the file names list file.</param> /// <returns>True if successful else false.</returns> /// <created>art2m,5/23/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** private bool ReadTheUserNameFileIntoCollection(string filePath) { var retVal = SpellingReadWriteClass.ReadUserNameFile(filePath); if (!retVal) { return(false); } retVal = UsersNameCollection.ContainsItem(SpellingPropertiesClass.UserName); if (!retVal) { return(false); } var index = UsersNameCollection.GetItemIndex(SpellingPropertiesClass.UserName); retVal = UsersNameCollection.RemoveItemAt(index); if (!retVal) { return(false); } return(true); }
/// ******************************************************************************** /// <summary> /// Place all the user names from the collection into the list box. /// User can then select there name and get all of there spelling list. /// </summary> /// <created>art2m,5/20/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** private void FillListBoxWithUserNames() { var userNames = new UsersNameCollection(); for (var index = 0; index < userNames.ItemsCount(); index++) { this.lstUsers.Items.Add(userNames.GetItemAt(index)); } }
/// ******************************************************************************** /// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** private static void AddNewUserToUserNameFile() { NameOfMethod = MethodBase.GetCurrentMethod().Name; if (UsersNameCollection.ContainsItem(SpellingPropertiesClass.UserName)) { InformationMessage = V2; ShowInformationMessageBox(); }
/// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/17/2019</changed> private static void AddNewUserToUserNameFile() { // TODO: Make method for editing and deleting users from user file. // TODO: Make method for adding existing spelling lists to current user. SpellingReadWriteClass.WriteUserNameFile(); var Unc = new UsersNameCollection(); if () }
/// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/17/2019</changed> private static void AddNewUserToUserNameFile() { // TODO: Make method for editing and deleting users from user file. // TODO: Make method for adding existing spelling lists to current user. SpellingReadWriteClass.WriteUserNameFile(); var Unc = new UsersNameCollection(); if (!Unc.ContainsItem(SpellingPropertiesClass.UserName)) { Unc.AddItem(SpellingPropertiesClass.UserName); } }
/// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/17/2019</changed> private static void AddNewUserToUserNameFile() { // TODO: Make method for editing and deleting users from user file. // TODO: Make method for adding existing spelling lists to current user. var unc = new UsersNameCollection(); if (unc.ContainsItem(SpellingPropertiesClass.UserName)) { MyMessages.InformationMessage = "This user all ready exists."; MyMessages.ShowInformationMessageBox(); } unc.AddItem(SpellingPropertiesClass.UserName); SpellingReadWriteClass.WriteUserNameFile(); }
/// <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); var userColl = new UsersNameCollection(); using (var reader = new StreamReader(filePath)) { string user; while ((user = reader.ReadLine()) != null) { userColl.AddItem(user.Trim()); } } return(true); }
private static bool OverWriteUserNameFile(string filePath) { try { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; using (var writer = new StreamWriter(filePath, false)) { for (var index = 0; index < UsersNameCollection.ItemsCount(); index++) { writer.WriteLine(UsersNameCollection.GetItemAt(index)); } } return(true); } catch (Exception e) { Console.WriteLine(e); throw; } }
/// <summary> /// if user enters text save it to user name. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">Instance containing the event data.</param> private void OnButtonOk_Click(object sender, EventArgs e) { var name = this.txtUserName.Text.Trim(); if (string.IsNullOrEmpty(name) || name.Length < 1) { SpellingPropertiesClass.UserName = string.Empty; return; } SpellingPropertiesClass.UserName = name; if (UsersNameCollection.ContainsItem(name)) { MyMessagesClass.InformationMessage = "This user name all ready exists. Go to select user name to use this name."; MyMessagesClass.sh } // TODO: May not be writting user name to file! SpellingReadWriteClass.WriteUserNameFile(filePath); }
/// ******************************************************************************** /// <summary> /// Add new users name to theAr2mSpell User List file. /// </summary> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** private static void AddNewUserToUserNameFile() { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; var unc = new UsersNameCollection(); if (unc.ContainsItem(SpellingPropertiesClass.UserName)) { MyMessagesClass.InformationMessage = Resources.Art2MSpellMainForm_AddNewUserToUserNameFile_This_user_all_ready_exists_; MyMessagesClass.ShowInformationMessageBox(); } unc.AddItem(SpellingPropertiesClass.UserName); var dirPath = SpellingPropertiesClass.AppDataDirectoryPath; var dirName = SpellingPropertiesClass.GetArt2MSpellDirectoryName; dirPath = DirectoryFileOperationsClass.CombineStringsMakeDirectoryPath(dirPath, dirName); if (string.IsNullOrEmpty(dirPath)) { return; } var fileName = SpellingPropertiesClass.GetArt2MSpellUserListFileName; var filePath = DirectoryFileOperationsClass.CombineDirectoryPathFileNameCheckCreateFile(dirPath, fileName); if (string.IsNullOrEmpty(filePath)) { return; } SpellingReadWriteClass.WriteUserNameFile(filePath); }
/// ******************************************************************************** /// <summary> /// Reads file that contains all of the paths To users spelling List file. /// </summary> /// <returns>True if file read is successful.</returns> /// <created>art2m,5/23/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool ReadUsersSpellingListPathsFile(string filePath) { try { if (!File.Exists(filePath)) { return(false); } using (var reader = new StreamReader(filePath)) { string user; while ((user = reader.ReadLine()) != null) { UsersNameCollection.AddItem(user.Trim()); } } return(true); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// OverWrite file using the User Collection after a user has been removed from /// the list. /// </summary> /// <param name="filePath"></param> /// <returns></returns> /// <created>art2m,5/28/2019</created> /// <changed>art2m,5/28/2019</changed> /// ******************************************************************************** private static bool OverWriteUserNameFile(string filePath) { try { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; using (var writer = new StreamWriter(filePath, false)) { for (var index = 0; index < UsersNameCollection.ItemsCount(); index++) { writer.WriteLine(UsersNameCollection.GetItemAt(index)); } } return(true); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }