public static void AddAuthorNamesFromAuthorsList(List <string> authorsList) { // add file name author to authors list file. foreach (var author in authorsList) { if (!AuthorNamesCollection.ContainsItem(author)) { AuthorNamesCollection.AddItem(author); } } }
/// <summary> /// Make the list of author names match the FileNames. /// </summary> private void GetAuthorFileNamesAddToAuthorsNamesList() { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; var coll1 = new AuthorNamesCollection(); var coll2 = new AuthorsFileNamesCollection(); coll1.ClearCollection(); for (var index = 0; index < coll2.GetItemsCount(); index++) { coll1.AddItem(coll2.GetItemAt(index)); } }
/// <summary> /// The GetAuthorFileNamesFromAuthorsList. /// </summary> public void GetAuthorFileNamesFromAuthorsList() { var coll = new AuthorNamesCollection(); var input = new InputClass(); var authorNames = input.ReadAuthorNamesFromFile(BookListPathsProperties.PathAuthorsNamesListFile); coll.ClearCollection(); foreach (var name in authorNames) { coll.AddItem(name); } }
/// <summary> /// Read all authors names from authors list. Used to find the Authors /// file. /// </summary> /// <param name="filePath">The file path to the Authors List.</param> public void ReadAuthorsNamesFromFile(string filePath) { this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name; var coll = new AuthorNamesCollection(); coll.ClearCollection(); try { if (!this._validate.ValidateStringIsNotNull(filePath)) { return; } if (!this._validate.ValidateStringHasLength(filePath)) { return; } if (!this._validate.ValidateFileExists(filePath, true)) { return; } using (var sr = new StreamReader(filePath)) { string line; while ((line = sr.ReadLine()) != null) { coll.AddItem(line); } } } catch (OutOfMemoryException ex) { this._msgBox.Msg = "Not enough memory to continue. Try closing other windows."; Debug.WriteLine(ex.ToString()); this._msgBox.ShowErrorMessageBox(); } }