/// <summary>
        /// A folder was created
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="pendingUpdate"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task WorkCreatedAsync(IConnectionFactory factory, IPendingFolderUpdate pendingUpdate, CancellationToken token)
        {
            var directory = pendingUpdate.Directory;

            if (null == directory)
            {
                // we are done
                return;
            }

            // get the files in that directory.
            var files = await _directory.ParseDirectoryAsync(directory, token).ConfigureAwait(false);

            if (files == null)
            {
                // there is nothing to add to this directory so we are done.
                _logger.Verbose($"Directory processor: Did not find any files in the new directory: {directory.FullName}.");
                return;
            }

            // and add them to the persiser
            if (await _persister.Folders.Files.AddOrUpdateFilesAsync(files, token).ConfigureAwait(false))
            {
                // log what we just did
                _logger.Verbose($"Directory processor: Found {files.Count} file(s) in the new directory: {directory.FullName}.");
            }
            else
            {
                _logger.Error($"Directory processor: Unable to add {files.Count} file(s) from the new directory: {directory.FullName}.");
            }
        }
        /// <summary>
        /// A folder was changed
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="pendingUpdate"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task WorkChangedAsync(IConnectionFactory factory, IPendingFolderUpdate pendingUpdate, CancellationToken token)
        {
            // look for the directory name, if we found nothing on record
            // then we will have to go and look in the database.
            var directory = pendingUpdate.Directory;

            // if we have no directory then we have nothing...
            if (directory == null)
            {
                // we are done
                return;
            }

            // Get the files currently on record
            // this can be null if we have nothing.
            var filesOnRecord = pendingUpdate.Files;

            // then get the ones in the file.
            var filesOnFile = await _directory.ParseDirectoryAsync(directory, token).ConfigureAwait(false);

            // we want to add all the files that are on disk but not on record.
            var filesToAdd = helper.File.RelativeComplement(filesOnRecord, filesOnFile);

            // we want to remove all the files that are on record but not on file.
            var filesToRemove = helper.File.RelativeComplement(filesOnFile, filesOnRecord);

            // if we have nothing to do... then get out
            if (!filesToRemove.Any() && !filesToAdd.Any())
            {
                _logger.Verbose($"Directory processor: {directory.FullName} was changed but no files were changed.");
                return;
            }

            // We know that the helper functions never return anything null...
            if (filesToRemove.Any())
            {
                await _persister.Folders.Files.DeleteFilesAsync(filesToRemove, token).ConfigureAwait(false);
            }

            // anything to add?
            if (filesToAdd.Any())
            {
                await _persister.Folders.Files.AddOrUpdateFilesAsync(filesToAdd, token).ConfigureAwait(false);
            }

            _logger.Verbose($"Directory processor: {directory.FullName} was changed {filesToRemove.Count} file(s) removed and {filesToAdd.Count} file(s) added.");
        }
        /// <summary>
        /// A folder was deleted
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="pendingUpdate"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task WorkDeletedAsync(IConnectionFactory factory, IPendingFolderUpdate pendingUpdate, CancellationToken token)
        {
            var directory = pendingUpdate.Directory;

            if (null == directory)
            {
                // we are done
                return;
            }

            // using the foler id is the fastest.
            if (!await _persister.Folders.Files.DeleteFilesAsync(pendingUpdate.FolderId, token))
            {
                _logger.Verbose($"Directory processor: Unable to delete directory: {directory.FullName}.");
                return;
            }
            _logger.Verbose($"Directory processor: {directory.FullName} was deleted.");
        }
        /// <summary>
        /// Process a single folder update
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="pendingFolderUpdate"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private Task ProcessFolderUpdateAsync(IConnectionFactory factory, IPendingFolderUpdate pendingFolderUpdate, CancellationToken token)
        {
            switch (pendingFolderUpdate.PendingUpdateType)
            {
            case UpdateType.Created:
                return(WorkCreatedAsync(factory, pendingFolderUpdate, token));

            case UpdateType.Deleted:
                return(WorkDeletedAsync(factory, pendingFolderUpdate, token));

            case UpdateType.Changed:
                // renamed or content/settingss changed
                return(WorkChangedAsync(factory, pendingFolderUpdate, token));

            case UpdateType.None:
                throw new InvalidEnumArgumentException("The 'none' argument cannot be used here.");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }