/// <summary>
        ///     Gets the authors directory path.
        /// </summary>
        /// <returns>
        ///     True if directory exists or was created else False.
        /// </returns>
        public bool GetAuthorsDirectoryPath()
        {
            var dirFileOp = new FileClass();
            var validate  = new ValidationClass();

            var dirTop  = BookListPathsProperties.PathTopLevelDirectory;
            var dirName = BookListPathsProperties.NameAuthorsDirectory;

            var cls     = new CombinePathsClass();
            var dirPath = cls.CombineExistingDirectoryPathWithDirectoryName(
                dirTop, dirName);

            if (validate.ValidateDirectoryExists(dirPath))
            {
                BookListPathsProperties.PathAuthorsDirectory = dirPath;
                return(true);
            }

            var clsPaths = new FileClass();

            if (!GetPermissionToCreateDirectory(dirPath))
            {
                return(false);
            }

            BookListPathsProperties.PathAuthorsDirectory = dirPath;
            return(true);
        }
        public static string GetPathToSpecialDirectoryAppDataLocal()
        {
            var dirPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            if (!ValidationClass.ValidateStringValueNotNullNotWhiteSpace(dirPath))
            {
                return(string.Empty);
            }

            return(!ValidationClass.ValidateDirectoryExists(dirPath) ? string.Empty : dirPath);
        }
        /// <summary>
        ///     The GetPathToSpecialDirectoryAppDataLocal.
        /// </summary>
        /// <returns>
        ///     The <see cref="string" /> .
        /// </returns>
        // ReSharper disable once MemberCanBeMade.Global
        public bool GetPathToSpecialDirectoryAppDataLocal()
        {
            var validate = new ValidationClass();
            var dirPath  = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            if (!validate.ValidateStringIsNotNull(dirPath))
            {
                return(false);
            }

            BookListPathsProperties.PathAppDataDirectory = dirPath;

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Gets the book list titles file path.
        /// </summary>
        /// <returns>True if path found else False.</returns>
        public bool GetBookListTitlesFilePath()
        {
            var dirFileOp = new FileClass();
            var validate  = new ValidationClass();

            var dirPath = BookListPathsProperties.PathTitlesDirectory;

            var fileName = BookListPathsProperties.NameTitlesBookListFile;

            var cls      = new CombinePathsClass();
            var filePath = cls.CombineDirectoryPathWithFileName(
                dirPath, fileName);

            var fileExists = validate.ValidateFileExists(filePath, true);

            if (!fileExists)
            {
                var dlgResult = this._msgBox.ShowQuestionMessageBox();

                // Create directory if it does not exist.
                if (dlgResult == DialogResult.Yes)
                {
                    dirFileOp.CreateNewFile(filePath);

                    if (validate.ValidateFileExists(filePath, true))
                    {
                        BookListPathsProperties.PathTitleNamesListFile = filePath;
                        return(true);
                    }
                    else
                    {
                        // return no directory created.
                        BookListPathsProperties.PathTitleNamesListFile = String.Empty;
                        return(false);
                    }
                }
                else
                {
                    // return user does not want to create the directory.
                    BookListPathsProperties.PathTitleNamesListFile = String.Empty;
                    return(false);
                }
            }
            else
            {
                BookListPathsProperties.PathTitleNamesListFile = filePath;
                return(true);
            }
        }
        public static bool AddRawDataReadFromFileToRawDataCollection([NotNull] string filePath)
        {
            if (!ValidationClass.ValidateStringValueNotEmptyNotWhiteSpace(filePath))
            {
                return(false);
            }

            if (!ValidationClass.ValidateFileExits(filePath))
            {
                return(false);
            }

            var data = FileInputClass.ReadTextDataFromFile(filePath);

            return(FillRawDataCollection(data));
        }
        /// <summary>
        ///     Gets the application data directory path.
        /// </summary>
        /// <returns>
        /// </returns>
        public bool GetAppDataDirectoryPath()
        {
            var validate = new ValidationClass();

            var cls = new FileClass();

            // Saves the AppData directory path to BookListPathsProperties.PathAppDataDirectory
            GetPathToSpecialDirectoryAppDataLocal();

            if (validate.ValidateDirectoryExists(BookListPathsProperties.PathAppDataDirectory))
            {
                return(true);
            }

            _msgBox.Msg = "Unable to find the AppData directory unable to continue.";
            _msgBox.ShowErrorMessageBox();
            return(false);
        }
Пример #7
0
        /// <summary>
        ///     add a dash to authors name so first middle and last name can be identified
        ///     by the program.
        /// </summary>
        /// <param name="author">The Author<see cref="string" />.</param>
        /// <returns>The <see cref="string" />.</returns>
        private string AddDashToAuthorName(string author)
        {
            this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            var validate = new ValidationClass();

            if (!validate.ValidateStringIsNotNull(author))
            {
                return(string.Empty);
            }
            if (!validate.ValidateStringHasLength(author))
            {
                return(string.Empty);
            }

            var authorName = string.Empty;

            foreach (var letter in author)
            {
                authorName = string.Concat(authorName, char.IsWhiteSpace(letter) ? "-" : letter.ToString());
            }

            return(authorName);
        }
Пример #8
0
        /// <summary>
        ///     If adding new user then write there name to the Art2MSpell user
        ///     names file.
        /// </summary>
        /// <param name="filePath">The filePath <see cref="string" /> .</param>
        /// <returns>
        ///     True if write successful else false.
        /// </returns>
        public bool WriteAuthorsTitlesToFile(string filePath)
        {
            this._msgBox.NameOfMethod = MethodBase.GetCurrentMethod().Name;

            try
            {
                var coll     = new BookDataCollection();
                var validate = new ValidationClass();

                // Append line to the file.
                using (var writer = new StreamWriter(filePath, false))
                {
                    var count = coll.GetItemsCount();
                    for (var index = 0; index < coll.GetItemsCount(); index++)
                    {
                        writer.WriteLine(coll.GetItemAt(index));
                    }

                    return(true);
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                this._msgBox.Msg = "You do not have access writes for this operation.";

                Debug.WriteLine(ex.ToString());

                this._msgBox.ShowErrorMessageBox();
            }
            catch (ArgumentNullException ex)
            {
                this._msgBox.Msg = $"The path variable contains a null string. {filePath}";

                Debug.WriteLine(ex.ToString());

                this._msgBox.ShowErrorMessageBox();
            }
            catch (ArgumentException ex)
            {
                this._msgBox.Msg = $"The file path value is a null string. {filePath}";

                Debug.WriteLine(ex.ToString());

                this._msgBox.ShowErrorMessageBox();
            }
            catch (DirectoryNotFoundException ex)
            {
                this._msgBox.Msg = "Unable to locate the directory.";

                Debug.WriteLine(ex.ToString());

                this._msgBox.ShowErrorMessageBox();
            }
            catch (PathTooLongException ex)
            {
                this._msgBox.Msg = "the file path is to long.";

                Debug.WriteLine(ex.ToString());

                this._msgBox.ShowErrorMessageBox();
            }
            catch (SecurityException ex)
            {
                this._msgBox.Msg = "The operation has caused a security violation.";

                Debug.WriteLine(ex.ToString());
            }
            catch (IOException ex)
            {
                this._msgBox.Msg = $"File path has invalid characters in it. {filePath}";

                Debug.WriteLine(ex.ToString());

                this._msgBox.ShowErrorMessageBox();
            }

            return(false);
        }