Exemplo n.º 1
0
        /// <summary>
        /// Given a list of words, re-create the ones that we need to insert.
        /// </summary>
        /// <param name="words"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        private async Task <IList <long> > InsertWordsAsync(
            interfaces.IO.IWords words,
            CancellationToken token)
        {
            // if we have nothing to do... we are done.
            if (!words.Any())
            {
                return(new List <long>());
            }

            // the ids of the words we just added
            var ids = new List <long>(words.Count);

            try
            {
                foreach (var word in words)
                {
                    // get out if needed.
                    token.ThrowIfCancellationRequested();

                    // if the word is not valid, there isn't much we can do.
                    if (!IsValidWord(word))
                    {
                        continue;
                    }

                    // the word we want to insert.
                    var wordId = await InsertWordAsync(word, token).ConfigureAwait(false);

                    if (-1 == wordId)
                    {
                        // we log errors in the insert function
                        continue;
                    }

                    // we added this id.
                    ids.Add(wordId);
                }

                // all done, return whatever we did.
                return(ids);
            }
            catch (OperationCanceledException)
            {
                _logger.Warning("Received cancellation request - Insert multiple words");
                throw;
            }
            catch (Exception ex)
            {
                _logger.Exception(ex);
                throw;
            }
        }
        private async Task <IConnectionFactory> BeginWrite(bool createTransaction, int timeoutMs, CancellationToken token)
        {
            // set the value
            try

            {
                if (null == _transactionSpinner)
                {
                    throw new InvalidOperationException("You cannot start using the database as it has not started yet.");
                }
                var factory = await _transactionSpinner.BeginWrite(() => new SqliteReadWriteConnectionFactory(createTransaction, _config), timeoutMs, token).ConfigureAwait(false);

                PrepareTransaction(factory);
                return(factory);
            }
            catch (TimeoutException)
            {
                throw;
            }
            catch (OperationCanceledException e)
            {
                _logger.Warning("Received cancellation request - Getting count value.");
                // is it my token?
                if (e.CancellationToken != token)
                {
                    _logger.Exception(e);
                }
                throw;
            }
            catch (Exception e)
            {
                _logger.Exception(e);
                throw;
            }
        }
Exemplo n.º 3
0
    /// <summary>
    /// The call back function to check if we are parsing that directory or not.
    /// </summary>
    /// <param name="directory"></param>
    /// <returns></returns>
    private bool ParseDirectory(DirectoryInfo directory)
    {
      if (!helper.File.CanReadDirectory(directory))
      {
        _logger.Warning($"Cannot Parse Directory: {directory.FullName}");
        return false;
      }

      if (!helper.File.IsSubDirectory(IgnorePaths, directory))
      {
        // we will be parsing it and the sub-directories.
        return true;
      }

      // we are ignoreing this.
      _logger.Verbose($"Ignoring: {directory.FullName} and sub-directories.");

      // we are not parsing this
      return false;
    }
Exemplo n.º 4
0
        /// <inheritdoc />
        public Task WorkAsync(CancellationToken token)
        {
            lock (_taskLock)
            {
                // are we still running the start?
                if (!_runningTask?.IsCompleted ?? true)
                {
                    return(Task.CompletedTask);
                }
            }

            try
            {
                lock (_taskLock)
                {
                    // we can re-parse everthing
                    _runningTask = ParseAllDirectoriesAsync(token);
                }
                return(_runningTask);
            }
            catch (OperationCanceledException)
            {
                _logger.Warning("Files/Folder parser processor: Received cancellation request - Work");
                throw;
            }
            catch (Exception e)
            {
                _logger.Exception("There was an exception re-parsing the directories.", e);
                throw;
            }
        }