Example #1
0
        /// ********************************************************************************
        /// <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 bool ReadSpellingListFile(string filePath)
        {
            MyMessagesClass.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)
            {
                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);
            }
        }
Example #2
0
        /// ********************************************************************************
        /// <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 WriteSpellingWordsToFile(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);
            }
        }
Example #3
0
        /// ********************************************************************************
        /// <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 WriteUserNameFile(string filePath)
        {
            MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            try
            {
                // Append line to the file.
                using (var writer = new StreamWriter(filePath, true))
                {
                    writer.WriteLine(SpellingPropertiesClass.UserName);
                }

                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);
            }
        }
Example #4
0
        /// ********************************************************************************
        /// <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> ReadSpellingListFile(string filePath)
        {
            MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            List <string> words;

            var spell = Array.Empty <string>();

            try
            {
                using (var fileRead = new StreamReader(filePath))
                {
                    spell = fileRead.ReadToEnd().Split(',');
                }

                words = new List <string>(spell);
                return(words);
            }
            catch (OutOfMemoryException ex)
            {
                MyMessagesClass.ErrorMessage = "Not enough memory to continue. Try closing other windows.";

                Debug.WriteLine(ex.ToString());

                MyMessagesClass.ShowErrorMessageBox();

                return(words = 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(words = 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(words = new List <string>(Array.Empty <string>()));
            }
            catch (FileNotFoundException ex)
            {
                MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath;

                Debug.WriteLine(ex.ToString());

                MyMessagesClass.ShowErrorMessageBox();
                return(words = new List <string>(Array.Empty <string>()));
            }
            catch (DirectoryNotFoundException ex)
            {
                MyMessagesClass.ErrorMessage = "Unable to locate the directory.";

                Debug.WriteLine(ex.ToString());
                MyMessagesClass.ShowErrorMessageBox();

                return(words = 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(words = new List <string>(Array.Empty <string>()));
            }
        }
Example #5
0
        /// ********************************************************************************
        /// <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);
            }
        }
Example #6
0
        /// ********************************************************************************
        /// <summary>
        /// Create user sub directory in Art2MSpell directory. This will hold all of
        /// this users spelling lists.
        /// </summary>
        /// <param name="dirPath">The path to the users directory.</param>
        /// <returns>True if user directory created else false.</returns>
        /// <created>art2m,5/22/2019</created>
        /// <changed>art2m,5/23/2019</changed>
        /// ********************************************************************************
        public static bool CreateUserSpellingListDirectory(string dirPath)
        {
            var dirName = SpellingPropertiesClass.UserName;

            try
            {
                dirPath = Path.Combine(dirPath, dirName);

                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }

                return(Directory.Exists(dirPath));
            }
            catch (ArgumentNullException ex)
            {
                MyMessagesClass.ErrorMessage = "One or both directory path strings are null. Make sure you are in the"
                                               + " list of users";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(false);
            }
            catch (UnauthorizedAccessException ex)
            {
                MyMessagesClass.ErrorMessage = "You do not have necessary security rating to perform this operation.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(false);
            }
            catch (PathTooLongException ex)
            {
                MyMessagesClass.ErrorMessage = "The directory path is to long. Check path to user folder.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(false);
            }
            catch (DirectoryNotFoundException ex)
            {
                MyMessagesClass.ErrorMessage = "Unable to locate the directory.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(false);
            }
            catch (NotSupportedException ex)
            {
                MyMessagesClass.ErrorMessage = "Not supported for this platform.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(false);
            }
            catch (ArgumentException ex)
            {
                MyMessagesClass.ErrorMessage = "Encountered error while creating directory.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(false);
            }
        }
Example #7
0
        /// ********************************************************************************
        /// <summary>
        /// Combine directory name with file name. Check to see if file exists if it does
        /// return file path else create file.
        /// </summary>
        /// <param name="dirPath">Directory path to join with file name.</param>
        /// <param name="fileName">The file name to create.</param>
        /// <returns>File path if exists or is created. else return empty string.</returns>
        /// <created>art2m,5/23/2019</created>
        /// <changed>art2m,5/23/2019</changed>
        /// ********************************************************************************
        public static string CombineDirectoryPathFileNameCheckCreateFile(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();

                System.Diagnostics.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();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(string.Empty);
            }
            catch (PathTooLongException ex)
            {
                MyMessagesClass.ErrorMessage = "The directory path is to long.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(string.Empty);
            }
            catch (DirectoryNotFoundException ex)
            {
                MyMessagesClass.ErrorMessage = "Unable to locate the directory.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(string.Empty);
            }
            catch (NotSupportedException ex)
            {
                MyMessagesClass.ErrorMessage = "Not supported for this platform.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(string.Empty);
            }
            catch (ArgumentException ex)
            {
                MyMessagesClass.ErrorMessage = "Encountered error while creating directory.";

                MyMessagesClass.ShowErrorMessageBox();

                System.Diagnostics.Debug.WriteLine(ex.ToString());

                return(string.Empty);
            }
        }
Example #8
0
        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);
            }
        }
Example #9
0
        /// ********************************************************************************
        /// <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 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)
            {
                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>
        /// 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/23/2019</changed>
        /// ********************************************************************************
        public static bool ReadUserNameFile(string filePath)
        {
            MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            try
            {
                using (var reader = new StreamReader(filePath))
                {
                    string user;
                    while ((user = reader.ReadLine()) != null)
                    {
                        Unc.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);
            }
        }