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

            if (handler != null)
            {
                handler(this, eventArgs);
            }
        }
Beispiel #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)
                    {
                        LogAggregateException(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);
        }
Beispiel #3
0
        public void DoSearchFinished(CompletedEventArgs e)
        {
            UnSubscribeToSearcherEvents();


            if (!_searcher.IsUIVisible && !checkBox1.Checked)
            {
                _searcher.ShowUI();
            }

            if (checkBox1.Checked)
            {
                _searcher.HideUI();
            }

            btnCloseCancel.Text    = "Close";
            btnCloseCancel.Enabled = true;
            btnCloseCancel.Click  -= btnCancel_Click;
            btnCloseCancel.Click  += btnHide_Click;
            checkBox1.Click       += checkBox1_CheckedChanged;
            // 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));
        }
        public void DoSearchFinished(CompletedEventArgs e)
        {
            UnSubscribeToSearcherEvents();

            if (!_searcher.IsUIVisible && !checkBox1.Checked)
            {
                _searcher.ShowUI();
            }

            if (checkBox1.Checked)
            {
                _searcher.HideUI();
            }

            btnCloseCancel.Text = "Close";
            btnCloseCancel.Enabled = true;
            btnCloseCancel.Click -= btnCancel_Click;
            btnCloseCancel.Click += btnHide_Click;
            checkBox1.Click += checkBox1_CheckedChanged;
               // 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));
        }
Beispiel #5
0
 private void RaiseCompleted(CompletedEventArgs eventArgs)
 {
     var handler = Completed;
     if (handler != null)
     {
         handler(this, eventArgs);
     }
 }
Beispiel #6
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)
                    {
                        LogAggregateException(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);
        }