/// <summary> /// Get spelling words from file. /// </summary> /// <returns></returns> /// <created>art2m,5/13/2019</created> /// <changed>art2m,5/13/2019</changed> private bool GetWordsFromFile() { var srw = new SpellingReadWriteClass(); var swc = new SpellingWordsCollection(); if (!srw.ReadHeader(SpellingPropertiesClass.SpellingListPath)) { return(false); } SpellingPropertiesClass.FirstWordIsArt2MSpellHeader = true; SpellingPropertiesClass.Art2MSpellSpellingList = true; if (!srw.ReadFile(SpellingPropertiesClass.SpellingListPath)) { return(false); } this.allWords = new string[swc.ItemsCount() - 1]; this.allWords = swc.GetAllItems(); this.txtTotalWords.Text = FormattableString.Invariant($"{swc.ItemsCount()}"); return(true); }
/// <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 = "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> /// Save the contents of lstWords list box to list. /// </summary> /// <created>art2m,5/19/2019</created> /// <changed>art2m,5/19/2019</changed> private void FillListFromListBox() { var swc = new SpellingWordsCollection(); foreach (var item in this.lstWords.Items) { swc.AddItem(item.ToString()); } }
/// <summary> /// Add spelling words list from file to the list box. /// </summary> /// <created>art2m,5/12/2019</created> /// <changed>art2m,5/12/2019</changed> private void AddWordsToListBox() { var swc = new SpellingWordsCollection(); for (var index = 0; index < swc.ItemsCount(); index++) { this.lstWords.Items.Add(swc.GetItemAt(index)); } }
/// <summary> /// Fills the ListBox with words list. /// </summary> private void FillListBoxWithWordsList() { var swc = new SpellingWordsCollection(); if (swc.ItemsCount() < 1) { return; } this.AddWordsToListBox(); }
/// <summary> /// Handles the Click event of the QuitButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void OnQuitButtonClick(object sender, EventArgs e) { var swc = new SpellingWordsCollection(); swc.ClearCollection(); this.index = 0; SpellingPropertiesClass.OpenedSpellingList = false; SpellingPropertiesClass.SpellingListPath = string.Empty; this.SetButtonsEnabledState_QuitButtonClicked(); this.ChangeControls_BackgroundColors(); }
/// <summary> /// Handles the Click event of the Repeat Word Button control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private void OnRepeatWordButtonClick(object sender, EventArgs e) { var swc = new SpellingWordsCollection(); this.txtSpellWord.Focus(); var word = swc.GetItemAt(this.index); this.SaySpellingWord(word); this.txtSpellWord.Focus(); this.txtSpellWord.Text = string.Empty; }
/// <summary> /// Check the spelling word user has entered. /// </summary> /// <param name="word">The word to be checked for spelling.</param> /// <returns>True if word is correct else false.</returns> /// <created>art2m,5/12/2019</created> /// <changed>art2m,5/12/2019</changed> private bool CheckWordSpelling(string word) { var spwc = new SpellingWordsCollection(); if (SpellingListClass.CheckWordSpelling(word)) { this.lstWords.Items.Add(word); spwc.FillCollection(this.lstWords.Items.OfType <string>().ToList()); return(true); } this.AddSuggestions(); return(false); }
/// <summary> /// Check to see if the word is all ready contained in the list box. /// </summary> /// <param name="word">The word to be added to the list box.</param> /// <returns>True if no duplicate word found in the list box else false.</returns> /// <created>art2m,5/12/2019</created> /// <changed>art2m,5/12/2019</changed> private bool CheckListBoxForWord(string word) { var spwc = new SpellingWordsCollection(); List <string> list = this.lstWords.Items.OfType <string>().ToList(); if (list.Contains(word)) { return(true); } spwc.FillCollection(list); this.cboWord.Text = string.Empty; this.cboWord.Focus(); return(false); }
/// <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> /// Check the spelling word user has entered. /// </summary> /// <param name="word">The word to be checked for spelling.</param> /// <returns>True if word is correct else false.</returns> /// <created>art2m,5/12/2019</created> /// <changed>art2m,5/12/2019</changed> private bool CheckWordSpelling(string word) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; var spwc = new SpellingWordsCollection(); if (SpellingListClass.CheckWordSpelling(word)) { this.lstWords.Items.Add(word); spwc.FillCollection(this.lstWords.Items.OfType <string>().ToList()); return(true); } this.AddSuggestions(); return(false); }
/// <summary> /// add the word to spelling list box. add word user entered in combo box /// to the list box. /// </summary> /// <param name="word">The word to be added.</param> /// <created>art2m,5/12/2019</created> /// <changed>art2m,5/12/2019</changed> private void AddWordToListBox() { var word = this.cboWord.Text.Trim(); if (string.IsNullOrEmpty(word)) { this.SetButtonsEnabledState_AddToListButtonClicked(); this.ChangeControlsBackgroundColors(); return; } var spwc = new SpellingWordsCollection(); if (this.CheckListBoxForWord(word)) { this.SetAddingWordProperties(); return; } // If true found duplicate word. if (!this.CheckWordSpelling(word)) { return; } this.lstWords.Items.Add(word); SpellingListClass.SpeakString(word); this.SetAddingWordProperties(); this.SetButtonsEnabledState_AddToListButtonClicked(); this.ChangeControlsBackgroundColors(); this.SetTabOrderAddWordToList(); this.SetTabOrderAddNewWordButton(); return(true); }
/// <summary> /// Check to see if the word is all ready contained in the list box. /// </summary> /// <param name="word">The word to be added to the list box.</param> /// <returns>True if no duplicate word found in the list box else false.</returns> /// <created>art2m,5/12/2019</created> /// <changed>art2m,5/12/2019</changed> private bool CheckListBoxForWord(string word) { var spwc = new SpellingWordsCollection(); // List<string> list = this.lstWords.Items.OfType<string>().ToList(); if (this.lstWords.Items.Contains(word)) { return(true); } // Validate word user is adding has correct spelling. if (!this.CheckWordSpelling(word)) { return; } this.cboWord.Text = string.Empty; this.cboWord.Focus(); 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(); 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> /// 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> /// 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. } }