Beispiel #1
0
 private void UpdateSearchCompletionPercentage(
     Progress.IProgressEventsSink progress,
     long lastHandledPosition,
     FileRange.Range fullSearchPositionsRange,
     bool skipMessagesCountCheck)
 {
     if (progress == null)
     {
         return;
     }
     if (!skipMessagesCountCheck && (messagesReadSinceCompletionPercentageUpdate % 256) != 0)
     {
         ++messagesReadSinceCompletionPercentageUpdate;
     }
     else
     {
         double value;
         if (fullSearchPositionsRange.Length > 0)
         {
             value = Math.Max(0d, (double)(lastHandledPosition - fullSearchPositionsRange.Begin) / (double)fullSearchPositionsRange.Length);
         }
         else
         {
             value = 0;
         }
         progress.SetValue(value);
         messagesReadSinceCompletionPercentageUpdate = 0;
     }
 }
Beispiel #2
0
        async Task ExecuteInternal(IPreprocessingStepCallback callback, string specificFileToExtract, Func <PreprocessingStepParams, bool> onNext)
        {
            await callback.BecomeLongRunning();

            callback.TempFilesCleanupList.Add(sourceFile.Uri);

            using (var zipFile = new Ionic.Zip.ZipFile(sourceFile.Uri))
            {
                string currentEntryBeingExtracted     = null;
                Progress.IProgressEventsSink progress = null;
                zipFile.ExtractProgress += (s, evt) =>
                {
                    evt.Cancel = callback.Cancellation.IsCancellationRequested;
                    if (currentEntryBeingExtracted != null && evt.TotalBytesToTransfer != 0)
                    {
                        callback.SetStepDescription(string.Format("Unpacking {1}%: {0}",
                                                                  currentEntryBeingExtracted,
                                                                  evt.BytesTransferred * (long)100 / evt.TotalBytesToTransfer));
                        if (progress != null)
                        {
                            progress.SetValue(
                                (double)evt.BytesTransferred / (double)evt.TotalBytesToTransfer);
                        }
                    }
                };
                var entriesToEnum = specificFileToExtract != null?
                                    Enumerable.Repeat(zipFile[specificFileToExtract], 1) : zipFile.Entries;

                foreach (var entry in entriesToEnum.Where(e => e != null))
                {
                    if (entry.IsDirectory)
                    {
                        continue;
                    }

                    string entryFullPath = sourceFile.FullPath + "\\" + entry.FileName;
                    string tmpFileName   = callback.TempFilesManager.GenerateNewName();

                    callback.SetStepDescription("Unpacking " + entryFullPath);
                    using (FileStream tmpFs = new FileStream(tmpFileName, FileMode.CreateNew))
                        using (var entryProgress = progressAggregator.CreateProgressSink())
                        {
                            currentEntryBeingExtracted = entryFullPath;
                            progress = entryProgress;
                            entry.Extract(tmpFs);
                            currentEntryBeingExtracted = null;
                            progress = null;
                        }

                    string preprocessingStep = string.Format("{0} {1}", name, entry.FileName);

                    if (!onNext(new PreprocessingStepParams(tmpFileName, entryFullPath,
                                                            Utils.Concat(sourceFile.PreprocessingSteps, preprocessingStep))))
                    {
                        break;
                    }
                }
            }
        }
Beispiel #3
0
 void ISourceSearchResultInternal.ReleaseProgress()
 {
     if (progressSink != null)
     {
         progressSink.Dispose();
         progressSink = null;
     }
 }
Beispiel #4
0
 public SearchCommand(
     SearchAllOccurencesParams searchParams,
     Func <SearchResultMessage, bool> callback,
     Progress.IProgressEventsSink progress
     )
 {
     this.searchParams = searchParams;
     this.callback     = callback;
     this.progress     = progress;
 }
Beispiel #5
0
 public EnumMessagesHelper(
     ILogSource ls,
     CancellationToken cancellation,
     Progress.IProgressEventsSink progress
     )
 {
     this.ls              = ls;
     this.cancellation    = cancellation;
     this.progress        = progress;
     this.lsRange         = ls.Provider.Stats.PositionsRange;
     this.lastReadPositon = lsRange.Begin;
 }
Beispiel #6
0
        Task ILogProvider.Search(
            SearchAllOccurencesParams searchParams,
            Func <SearchResultMessage, bool> callback,
            CancellationToken cancellation,
            Progress.IProgressEventsSink progress
            )
        {
            CheckDisposed();
            var     ret = new SearchCommand(searchParams, callback, progress, threads.UnderlyingThreadsContainer);
            Command cmd = new Command(Command.CommandType.Search,
                                      LogProviderCommandPriority.AsyncUserAction, tracer, cancellation, ret);

            PostCommand(cmd);
            return(ret.Task);
        }
Beispiel #7
0
        public SourceSearchResult(
            ILogSourceSearchWorkerInternal worker,
            ISearchResultInternal parent,
            CancellationToken cancellation,
            Progress.IProgressAggregator progress,
            Telemetry.ITelemetryCollector telemetryCollector
            )
        {
            this.searchWorker       = worker;
            this.parent             = parent;
            this.telemetryCollector = telemetryCollector;
            this.messages           = new MessagesContainers.ListBasedCollection();

            this.progressSink = progress.CreateProgressSink();
            this.workerTask   = Worker(cancellation, progressSink);
            AwaitWorker();
        }
Beispiel #8
0
        async Task <SearchResultStatus> Worker(CancellationToken cancellation, Progress.IProgressEventsSink progressSink)
        {
            using (IStringSliceReallocator reallocator = new StringSliceReallocator())
                try
                {
                    bool limitReached = false;
                    await searchWorker.GetMessages(
                        parent.OptionsFilter,
                        (msg) =>
                    {
                        if (!parent.AboutToAddNewMessage())
                        {
                            limitReached = true;
                            return(false);
                        }
                        lock (messagesLock)
                        {
                            if (!messages.Add(msg.Message))
                            {
                                return(true);
                            }
                            msg.Message.SetFilteringResult(msg.FilteringResult.Action);
                            msg.Message.ReallocateTextBuffer(reallocator);
                            Interlocked.Increment(ref hitsCount);
                        }
                        parent.OnResultChanged(this);
                        return(true);
                    },
                        cancellation,
                        progressSink
                        );

                    return(limitReached ? SearchResultStatus.HitLimitReached : SearchResultStatus.Finished);
                }
                catch (OperationCanceledException)
                {
                    return(SearchResultStatus.Cancelled);
                }
        }
Beispiel #9
0
 async Task ILogSourceSearchWorkerInternal.GetMessages(IFilter filter, Func <SearchResultMessage, bool> callback,
                                                       CancellationToken cancellation, Progress.IProgressEventsSink progressSink)
 {
     if (startEvent.Task.Status != TaskStatus.WaitingForActivation)
     {
         throw new InvalidOperationException();
     }
     cancellations.Add(cancellation);
     progressSinks.Add(progressSink);
     callbacks[new NullableDictionaryKey <IFilter>(filter)] = callback;
     await worker;
 }
Beispiel #10
0
        private void DoExtract(
            IPreprocessingStepCallback callback,
            string specificFileToExtract,
            Func <PreprocessingStepParams, bool> onNext,
            string password)
        {
            using (var zipFile = new Ionic.Zip.ZipFile(@params.Location))
            {
                if (password != null)
                {
                    zipFile.Password = password;
                }
                string currentEntryBeingExtracted     = null;
                Progress.IProgressEventsSink progress = null;
                zipFile.ExtractProgress += (s, evt) =>
                {
                    evt.Cancel = callback.Cancellation.IsCancellationRequested;
                    if (currentEntryBeingExtracted != null && evt.TotalBytesToTransfer != 0)
                    {
                        callback.SetStepDescription(string.Format("Unpacking {1}%: {0}",
                                                                  currentEntryBeingExtracted,
                                                                  evt.BytesTransferred * (long)100 / evt.TotalBytesToTransfer));
                        if (progress != null)
                        {
                            progress.SetValue(
                                (double)evt.BytesTransferred / (double)evt.TotalBytesToTransfer);
                        }
                    }
                };
                var entriesToEnum = specificFileToExtract != null?
                                    Enumerable.Repeat(zipFile[specificFileToExtract], 1) : zipFile.Entries;

                foreach (var entry in entriesToEnum.Where(e => e != null))
                {
                    if (entry.IsDirectory)
                    {
                        continue;
                    }

                    string entryFullPath = @params.FullPath + "\\" + entry.FileName;
                    string tmpFileName   = callback.TempFilesManager.GenerateNewName();

                    callback.SetStepDescription("Unpacking " + entryFullPath);
                    using (FileStream tmpFs = new FileStream(tmpFileName, FileMode.CreateNew))
                        using (var entryProgress = progressAggregator.CreateProgressSink())
                        {
                            currentEntryBeingExtracted = entryFullPath;
                            progress = entryProgress;
                            entry.Extract(tmpFs);
                            currentEntryBeingExtracted = null;
                            progress = null;
                        }

                    if (!onNext(new PreprocessingStepParams(tmpFileName, entryFullPath,
                                                            @params.PreprocessingHistory.Add(new PreprocessingHistoryItem(name, entry.FileName)))))
                    {
                        break;
                    }
                }
            }
        }