Beispiel #1
0
 private void MergeResults()
 {
     Logger.logInfo("Merging filter results.");
     foreach (Filter filter in _filterReadyList)
     {
         foreach (int lineNum in filter.FilterHitList)
         {
             if (!_filterHitDict.ContainsKey(lineNum))
             {
                 _filterHitDict.Add(lineNum, lineNum);
             }
         }
         foreach (int lineNum in filter.FilterResultLines)
         {
             if (!_filterResultDict.ContainsKey(lineNum))
             {
                 _filterResultDict.Add(lineNum, lineNum);
             }
         }
         foreach (int lineNum in filter.LastFilterLinesList)
         {
             if (!_lastFilterLinesDict.ContainsKey(lineNum))
             {
                 _lastFilterLinesDict.Add(lineNum, lineNum);
             }
         }
     }
     FilterHitList.AddRange(_filterHitDict.Keys);
     FilterResultLines.AddRange(_filterResultDict.Keys);
     LastFilterLinesList.AddRange(_lastFilterLinesDict.Keys);
     Logger.logInfo("Merging done.");
 }
Beispiel #2
0
        public void DoFilter(FilterParams filterParams, int startLine, int maxCount, ProgressCallback progressCallback)
        {
            FilterResultLines.Clear();
            LastFilterLinesList.Clear();
            FilterHitList.Clear();
            _filterHitDict.Clear();
            _filterReadyList.Clear();
            _filterResultDict.Clear();
            _lastFilterLinesDict.Clear();
            _filterReadyList.Clear();
            _filterWorkerList.Clear();
            _shouldStop = false;

            int interval = maxCount / ThreadCount;

            if (interval < 1)
            {
                interval = 1;
            }
            int workStartLine            = startLine;
            List <WaitHandle> handleList = new List <WaitHandle>();

            _progressLineCount = 0;
            _progressCallback  = progressCallback;
            while (workStartLine < startLine + maxCount)
            {
                if (workStartLine + interval > maxCount)
                {
                    interval = maxCount - workStartLine;
                    if (interval == 0)
                    {
                        break;
                    }
                }
                _logger.Info("FilterStarter starts worker for line {0}, lineCount {1}", workStartLine, interval);
                WorkerFx     workerFx = DoWork;
                IAsyncResult ar       = workerFx.BeginInvoke(filterParams, workStartLine, interval, ThreadProgressCallback,
                                                             FilterDoneCallback, workerFx);
                workStartLine += interval;
                handleList.Add(ar.AsyncWaitHandle);
            }

            WaitHandle[] handles = handleList.ToArray();
            // wait for worker threads completion
            if (handles.Length > 0)
            {
                WaitHandle.WaitAll(handles);
            }

            MergeResults();
        }