Beispiel #1
0
        /// <summary>
        /// Makes the search in the file
        /// </summary>
        /// <param name="searchLine">Search text</param>
        /// <returns>Reference to Result object</returns>
        public Result Search(String searchLine)
        {
            Result result = new Result(searchLine);

            CancellationToken token;

            if (result.TryGetToken(out token))
            {
                Task.Factory.StartNew(() =>
                {
                    //First checker has no previous checker with tuner
                    Tuner tuner = null;
                    for (Int32 i = 0; i < this.partsCount; i++)
                    {
                        if (token.IsCancellationRequested)
                        {
                            return;
                        }
                        Checker currentChecker = checkers[i];
                        Tuner prevTuner        = tuner;
                        tuner = currentChecker.Check(prevTuner, result, token);
                    }

                    if (tuner != null)
                    {
                        //Second subline in empty for the last Tuner
                        tuner.SetTuner(String.Empty);
                    }
                }, token);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Checks the part of file and compare lines with search string
        /// </summary>
        /// <param name="prevTuner">Reference to previous Tuner</param>
        /// <param name="result">Reference to Result</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Reference to new Tuner object, must be send to the next Checker</returns>
        internal Tuner Check(Tuner prevTuner, Result result, CancellationToken token)
        {
            Tuner thisTuner = inTune == 0 ? new Tuner(this, result) : null;

            Task.Factory.StartNew(() =>
            {
                var hashtable = hashtableWeakReference.Target as Hashtable;
                // Hashtable can not be collect now

                if (hashtable == null)
                {
                    // Hashtable is not alive
                    lockSlim.EnterWriteLock();

                    if (token.IsCancellationRequested)
                    {
                        lockSlim.ExitWriteLock();
                        return;
                    }

                    // Make one more check
                    if (!TryReadFromHashtable(result, ref thisTuner, out hashtable))
                    {
                        hashtable = this.Parse(result, thisTuner, prevTuner, token);
                        this.hashtableWeakReference.Target = hashtable;
                    }

                    lockSlim.ExitWriteLock();
                }
                else
                {
                    // Hashtable is alive, first and last substrings is set

                    lockSlim.EnterReadLock();

                    ReadFromHashtable(hashtable, result, ref thisTuner);

                    lockSlim.ExitReadLock();
                }

                if (prevTuner != null)
                {
                    // Send subline to previous Tuner
                    prevTuner.SetTuner(this.firstSubline);
                }

                if (thisTuner != null && hashtable != null)
                {
                    // Send reference to hashtable to the Tuner
                    thisTuner.RequestTune(hashtable);
                }
            }, token);

            return(thisTuner);
        }