예제 #1
0
        private void RaiseCompleted(CompletedEventArgs eventArgs)
        {
            var handler = Completed;

            if (handler != null)
            {
                handler(this, eventArgs);
            }
        }
예제 #2
0
        private void OnFinishedTask(Task <SearchResult> task)
        {
            if (task == null)
            {
                return;
            }
            SearchResult      result = null;
            CompletedReasones reason;

            if (task.IsFaulted)
            {
                reason = CompletedReasones.Faulted;
                if (task.Exception != null)
                {
                    foreach (var error in task.Exception.InnerExceptions)
                    {
                        LogMessage("Error:", error);
                    }
                }
                else
                {
                    LogMessage("Unknow error.");
                }
            }
            else if (task.IsCanceled)
            {
                reason = CompletedReasones.Cancelled;
            }
            else
            {
                try
                {
                    result = task.Result;
                    reason = CompletedReasones.NormalCompleted;
                }
                catch (AggregateException aex)
                {
                    reason = CompletedReasones.Faulted;
                    foreach (var error in aex.InnerExceptions)
                    {
                        LogMessage("Error:", error);
                    }
                }
            }

            var completeArgs = new CompletedEventArgs(result, reason, new ProgressHandler(this));

            RaiseCompleted(completeArgs);
            _searcherUI.DoSearchFinished(completeArgs);
        }
예제 #3
0
        public void DoSearchFinished(CompletedEventArgs e)
        {
            UnSubscribeToSearcherEvents();

            if (!_searcher.IsUIVisible)
            {
                _searcher.ShowUI();
            }
            btnCancel.Enabled = false;
            btnHide.Text      = "Close";
            Text = "Search Finished";

            string message;

            switch (e.Reason)
            {
            case CompletedReasones.Cancelled:
                message = "Search has been canceled successfully.";
                break;

            case CompletedReasones.Faulted:
                message = "Search has been faulted due to an unhandled exception.";
                break;

            case CompletedReasones.NormalCompleted:
                message = e.Result == null || e.Result.IsEmpty()
                                  ? "No results were found. Please change the search criteria."
                                  : "Search finished successfully.";
                break;

            default:
                message = "Search was finished for unknown reason.";
                break;
            }

            searcher_OnMessage(_searcher, new LogMessageEventArgs(message));
        }