/// ******************************************************************************** /// <summary> /// Check that there are no invalid characters in the file name. /// </summary> /// <param name="fileName">The file name to check.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static bool CheckForInvalidFileNameCharacters([NotNull] string fileName) { if (fileName == null) throw new ArgumentNullException(nameof(fileName)); // Get a list of invalid file characters. var invalidFileChars = Path.GetInvalidFileNameChars(); try { foreach (var item in invalidFileChars) { var index = fileName.IndexOf(item); if (index != -1) { throw new NotSupportedException(); } } return true; } catch (ArgumentNullException ex) { var sb = new StringBuilder(); sb.AppendLine("The file name cannot be a null value."); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return false; } catch (NotSupportedException ex) { var sb = new StringBuilder(); sb.AppendLine("The file name contains invalid characters. Exiting operation:"); sb.AppendLine(fileName); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return false; }
/// ******************************************************************************** /// <summary> /// Check if file exists if not stop execution by thrown exception. /// </summary> /// <param name="filePath">The file path to validate exists.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidateFileExits(string filePath) { try { if (!File.Exists(filePath)) { throw new FileNotFoundException(); } } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate file for this path. Exiting operation: " + filePath; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } }
/// <summary>Validates the directory exists.</summary> /// <param name="dirPath">The directory path.</param> /// <returns>If directory exists then true else false.</returns> /// <exception cref="ArgumentNullException">Directory path is a null value.</exception> /// <exception cref="DirectoryNotFoundException">This path is not valid for a directory.</exception> public static bool ValidateDirectoryExists([NotNull] string dirPath) { if (dirPath == null) { throw new ArgumentNullException(nameof(dirPath)); } try { if (!Directory.Exists(dirPath)) { throw new DirectoryNotFoundException(); } return(true); } catch (ArgumentNullException ex) { var sb = new StringBuilder(); sb.AppendLine("The directory path cannot be a null value."); sb.AppendLine(dirPath); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { var sb = new StringBuilder(); sb.AppendLine("Invalid directory path."); sb.AppendLine(dirPath); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(sb.ToString()); return(false); } }
/// <summary> /// Check for space in value this will means either space in word that does not belong or /// two words instead of one spelling word. /// </summary> /// <param name="value">The spelling word to validate.</param> /// <returns>True if no space is found else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/10/2019</changed> public static bool ValidateStringOneWord([NotNull] string value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { var index = value.IndexOf(' '); if (index > -1) { throw new NotSupportedException(); } return(true); } catch (ArgumentNullException ex) { var sb = new StringBuilder(); sb.AppendLine("The value is not valid. It is empty or null."); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); } catch (NotSupportedException ex) { var sb = new StringBuilder(); sb.AppendLine("Check to see if space in word or if two words are entered."); sb.AppendLine("Spaces and double words are not allowed."); sb.AppendLine(value); sb.AppendLine(ex.ToString()); Debug.WriteLine(sb.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Check that the path is not too long. /// </summary> /// <param name="value">The path to check for length.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidatePathToLong([NotNull] string value) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { Path.GetFullPath(value); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "The path is too long. exiting operation. " + value; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } catch (SecurityException ex) { } }
/// ******************************************************************************** /// <summary> /// Check the string for length if zero then exit operation. /// </summary> /// <param name="value"></param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidateStringHasLength(string value) { try { if (value.Length == 0) { throw new NotSupportedException(); } } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "This value is not valid. It has no length. Exiting operation. " + value; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } }
public static bool ValidateStringValueIsNotNull(string value) { try { if (value == null) { throw new ArgumentNullException(); } return(true); } catch (Exception ex) { MyMessagesClass.ErrorMessage = V1 + ex.ToString(); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Check the path for any invalid characters. /// </summary> /// <param name="value">The string path to check.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static bool CheckForInvalidPathCharacters([NotNull] string value) { if (value == null) throw new ArgumentNullException(nameof(value)); var invalidPathChars = Path.GetInvalidPathChars(); try { // var charValue = value.ToCharArray(); foreach (var item in invalidPathChars) { var index = value.IndexOf(item); if (index != -1) { throw new ArgumentException(); } } return true; } catch (ArgumentNullException ex) { var sb = new StringBuilder(); sb.AppendLine() } catch (ArgumentException ex) { var sb = new StringBuilder(); sb.AppendLine("The path name contains invalid characters. Exiting operation:"); sb.AppendLine(value); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(sb.ToString()); return false; } }
/// ******************************************************************************** /// <summary> /// Check the string for length if zero then exit operation. /// </summary> /// <param name="value"></param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static bool ValidateStringHasLength([NotNull] string value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } try { if (value.Length == 0) { throw new NotSupportedException(); } return(true); } catch (ArgumentNullException ex) { var sb = new StringBuilder(); sb.AppendLine("The value cannot be null."); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (NotSupportedException ex) { var sb = new StringBuilder(); sb.AppendLine("This value cannot be an empty string."); sb.AppendLine(value); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(sb.ToString()); return(false); } }
/// <summary> /// Validates the file exits. /// </summary> /// <param name="filePath">The file path.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">filePath</exception> /// <exception cref="FileNotFoundException">return false</exception> public static bool ValidateFileExits([NotNull] string filePath) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } try { if (!File.Exists(filePath)) { throw new FileNotFoundException(); } return(true); } catch (ArgumentNullException ex) { var sb = new StringBuilder(); sb.AppendLine(Value7); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (FileNotFoundException ex) { var sb = new StringBuilder(); sb.AppendLine(Value5); sb.AppendLine(filePath); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(sb.ToString()); return(false); } }
/// ******************************************************************************** /// <summary> /// If directory does not exist stop operation. /// </summary> /// <param name="dirPath">The path of the directory to check.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidateDirectoryExists(string dirPath) { try { if (!Directory.Exists(dirPath)) { throw new DirectoryNotFoundException(); } } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "A directory in this path does not exist. Exiting operations. " + dirPath; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } }
/// ******************************************************************************** /// <summary> /// Check if file exists if not stop execution by thrown exception. /// </summary> /// <param name="filePath">The file path to validate exists.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static bool ValidateFileExits([NotNull] string filePath) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } try { if (!File.Exists(filePath)) { throw new FileNotFoundException(); } return(true); } catch (ArgumentNullException ex) { var sb = new StringBuilder(); sb.AppendLine("The file path cannot be a null value."); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (FileNotFoundException ex) { var sb = new StringBuilder(); sb.AppendLine("Unable to locate file for this path. Exiting operation: "); sb.AppendLine(filePath); sb.AppendLine(ex.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(sb.ToString()); return(false); } }
/// <summary> /// Check that there are only letters in the spelling word. /// </summary> /// <param name="value">The spelling word to be checked.</param> /// <returns>True if only letters in the spelling word else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/10/2019</changed> public static bool ValidateSpellingWordHasLettersOnly(string value) { Contract.Requires(!string.IsNullOrEmpty(value)); MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; var val = string.Empty; try { foreach (var letter in value) { if (char.IsLetter(letter)) { continue; } MyMessagesClass.ErrorMessage = "Invalid character in string: " + letter; val = letter.ToString(); throw new NotSupportedException(); } return(true); } catch (NotSupportedException ex) { var sb = new StringBuilder(); sb.AppendLine("Invalid character in string:"); sb.AppendLine(val); sb.AppendLine(ex.ToString()); Debug.WriteLine(sb.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Check that the path is not too long. /// </summary> /// <param name="value">The path to check for length.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidatePathToLong([NotNull] string value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { Path.GetFullPath(value); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "The path is too long. exiting operation. " + value; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = "You do not have required permissions. " + ex; MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The path cannot be null. " + ex; MyMessagesClass.ShowErrorMessageBox(); } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "Contains a colon that is not part of the path. " + ex; MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The specified path or filename exceeds Maximum Length " + ex; MyMessagesClass.ShowErrorMessageBox(); } }
/// ******************************************************************************** /// <summary> /// Check the string for length if zero then exit operation. /// </summary> /// <param name="value"></param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidateStringHasLength([NotNull] string value) { if (value == null) throw new ArgumentNullException(nameof(value)); try { if (value.Length == 0) { throw new NotSupportedException(); } } catch (NotSupportedException ex) { var sb = new StringBuilder(); sb.AppendLine("This value is ) MyMessagesClass.ErrorMessage = + value; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } }
/// ******************************************************************************** /// <summary> /// Check to see if string is null empty or length is 0. Throw exception /// to stop execution in these circumstances. /// </summary> /// <param name="value">The spelling word to be checked.</param> /// <returns>true if no problem is found with string else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static bool ValidateStringValueNotEmptyNotWhiteSpace([NotNull] string value) { if (value == null) { throw new ArgumentNullException(nameof(value)); } MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; value = value.Trim(); try { if (string.IsNullOrEmpty(value)) { throw new NotSupportedException(); } return(true); } catch (NotSupportedException ex) { var sb = new StringBuilder(); sb.AppendLine("The value is not valid. It is empty or null."); sb.AppendLine(value); sb.AppendLine(ex.ToString()); Debug.WriteLine(sb.ToString()); MyMessagesClass.ErrorMessage = sb.ToString(); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Check that there are no invalid characters in the file name. /// </summary> /// <param name="fileName">The file name to check.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void CheckForInvalidFileNameCharacters([NotNull] string fileName) { if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } // Get a list of invalid file characters. var invalidFileChars = Path.GetInvalidFileNameChars(); try { foreach (var item in invalidFileChars) { var index = fileName.IndexOf(item); if (index != -1) { throw new ArgumentException(); } } } catch (ArgumentNullException ex) { var sb StringBuilder(); MyMessagesClass.ErrorMessage = "The file name is null " + ex; MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file name contains invalid characters. Exiting operation: " + fileName + " " + ex; MyMessagesClass.ShowErrorMessageBox(); } }
public static List <string> ReadTextDataFromFile(string filePath) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; var data = new List <string>(); try { var isFile = File.Exists(filePath); using (var sr = new StreamReader(filePath)) { string line; while ((line = sr.ReadLine()) != null) { data.Add(line); } } return(data); } catch (OutOfMemoryException ex) { MyMessagesClass.ErrorMessage = "Not enough memory to continue. Try closing other windows."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } }
public static string CombineDirectoryPathFileNameCheckCreateFile([NotNull] string dirPath, string fileName) { try { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; var filePath = Path.Combine(dirPath, fileName); if (!File.Exists(filePath)) { File.Create(filePath).Dispose(); } return(!File.Exists(filePath) ? string.Empty : filePath); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "Encountered Error when combining directory paths or creating directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "The directory path is to long."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "Not supported for this platform."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "Encountered error while creating directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } }
public static string CombineDirectoryPathWithFileName([NotNull] string dirPath, [NotNull] string fileName) { try { var filePath = Path.Combine(dirPath, fileName); return(filePath); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "Encountered Error when combining directory paths or creating directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "The directory path is to long."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "Not supported for this platform."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "Encountered error while creating directory."; MyMessagesClass.ShowErrorMessageBox(); 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/23/2019</changed> /// ******************************************************************************** public static List <string> ReadAuthorsListFile(string filePath) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { string[] spell; using (var fileRead = new StreamReader(filePath)) { spell = fileRead.ReadToEnd().Split(','); } return(new List <string>(spell)); } catch (OutOfMemoryException ex) { MyMessagesClass.ErrorMessage = "Not enough memory to continue. Try closing other windows."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } }
/// ******************************************************************************** /// <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 WriteArthurFileNamesToListFile(string filePath) { try { using (var streamWriter = new StreamWriter(filePath, false)) { for (var index = 0; index < AuthorNamesListCollection.ItemsCount(); index++) { streamWriter.WriteLine(AuthorNamesListCollection.GetItemAt(index)); } } return(true); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = V7; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = V1 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = V2 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = V3; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = V4; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = V5; Debug.WriteLine(ex.ToString()); } catch (IOException ex) { MyMessagesClass.ErrorMessage = V6 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } return(false); }
/// ******************************************************************************** /// <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 List <string> ReadTitlesFromFile(string filePath) { var userName = new List <string>(); try { if (!File.Exists(filePath)) { return(userName); } using (var reader = new StreamReader(filePath)) { string user; while ((user = reader.ReadLine()) != null) { userName.Add(user.Trim()); } } return(userName); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(userName); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(userName); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(userName); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(userName); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(userName); } }
/// ******************************************************************************** /// <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 WriteAuthorsTitlesToFile(string filePath, List <string> data) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { // Append line to the file. using (var writer = new StreamWriter(filePath, false)) { foreach (var item in data) { writer.WriteLine(item); } return(true); } } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = V7; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = V1 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = V2 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = V3; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = V4; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = V5; Debug.WriteLine(ex.ToString()); } catch (IOException ex) { MyMessagesClass.ErrorMessage = V6 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } return(false); }
public static bool CreateEmptyAuthorNameFile(string filePath) { try { File.Create(filePath).Dispose(); return(true); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "Encountered Error when creating new author file."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "The file path is to long."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "Not supported for this platform."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "Encountered error while creating directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); 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/23/2019</changed> /// ******************************************************************************** public static bool WriteArthurFileNamesToListFile(string filePath) { try { using (var streamWriter = new StreamWriter(filePath, false)) { for (var index = 0; index < AuthorNamesListCollection.ItemsCount(); index++) { streamWriter.WriteLine(AuthorNamesListCollection.GetItemAt(index)); } } return(true); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } return(false); }
public static bool CreateEmptyAuthorNameFile(string filePath) { try { File.Create(filePath).Dispose(); return(true); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = V; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = V1; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = V2; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = Str01; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = V3; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = V4; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(false); } }
/// ******************************************************************************** /// <summary> /// Write spelling words list to file. /// </summary> /// <param name="filePath">Path to write file to.</param> /// <param name="words"></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 WriteArthurNamesToFile(string filePath, IEnumerable <string> words) { var wordsCsv = string.Join(",", words.ToArray()); try { File.WriteAllText(filePath, wordsCsv); return(true); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } 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); } }
/// <summary> /// writes book info to the authors file. /// If Not book series then writes book title name. /// if Series writes book title, series name, volume number. /// </summary> /// <param name="filePath"></param> /// <param name="bookInfo"></param> public static void WriteBookTitleSeriesVolumeNamesToAuthorsFile(string filePath, string bookInfo) { try { if (string.IsNullOrEmpty(filePath)) { return; } if (string.IsNullOrEmpty(bookInfo)) { return; } if (!File.Exists(filePath)) { return; } using (var writer = new StreamWriter(filePath, true)) { writer.WriteLine(bookInfo); } } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = V7; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = V1 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = V2 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = V3; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = V4; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = V5; Debug.WriteLine(ex.ToString()); } catch (IOException ex) { MyMessagesClass.ErrorMessage = V6 + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } }
/// ******************************************************************************** /// <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 WriteAuthorsTitlesToFile(string filePath, List <string> data) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { // Append line to the file. using (var writer = new StreamWriter(filePath, false)) { foreach (var value in data) { writer.WriteLine(value); } return(true); } } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); } return(false); }