Esempio n. 1
0
        /// <summary>
        ///     Validate real spelling list by reading header from file should be Art2MmSpell!!
        /// </summary>
        /// <param name="filePath">The path to the file.</param>
        /// <returns>True if valid spelling list else false.</returns>
        /// <created>art2m,5/12/2019</created>
        /// <changed>art2m,5/12/2019</changed>
        public static bool ReadHeader(string filePath)
        {
            var clsValid = new Validation();

            try
            {
                using (var fileRead = new StreamReader(filePath))
                {
                    var word = fileRead.ReadLine();

                    return(clsValid.ValidateThisIsArt2MSpellSpellingList(word));
                }
            }
            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 = "Read error has occurred. " + filePath;
                MyMessages.BuildErrorString(
                    MyMessages.NameOfClass,
                    MyMessages.NameOfMethod,
                    MyMessages.ErrorMessage,
                    ex.Message);
                return(false);
            }
        }
        /// <summary>
        ///     Validate real spelling list by reading header from file should be Art2MmSpell!!
        /// </summary>
        /// <param name="filePath">The path to the file.</param>
        /// <returns>True if valid spelling list else false.</returns>
        /// <created>art2m,5/12/2019</created>
        /// <changed>art2m,5/12/2019</changed>
        public static bool ReadHeader(string filePath)
        {
            try
            {
                using (var fileRead = new StreamReader(filePath))
                {
                    var word = fileRead.ReadLine();

                    return(Validation.ValidateThisIsArt2MSpellSpellingList(word));
                }
            }
            catch (ArgumentNullException ex)
            {
                MyMessages.ErrorMessage = "The file path value is a null string. " + 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);
            }
        }