Ejemplo n.º 1
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                var conf = new Confirm(Constants.CONFIRM_RECRAWL, "Are you sure?");
                var dr   = DialogResult.OK;

                if (RepositoryUtils.GetOptionValue(Constants.CONFIRM_RECRAWL) == "1" && _repo.GetSourceCount() > 0)
                {
                    dr = conf.ShowDialog();
                }

                if (dr == DialogResult.OK)
                {
                    RemoveAllButMainTab();
                    txtSourceFile.Text = String.Empty;
                    txtGrep.Text       = String.Empty;
                    txtDLL.Text        = String.Empty;

                    if (_timerGrep != null)
                    {
                        _timerGrep_Tick(null, null);
                    }

                    ManageControls(true);
                    lblCount.Text       = "0";
                    lblResultCount.Text = "0";
                    lblHitAt.Text       = String.Empty;

                    var progressHandler = new Progress <ProgressResult>(value =>
                    {
                        var percent = (int)(((double)progressRefresh.Value / (double)progressRefresh.Maximum) * 100);
                        progressRefresh.ProgressBar.Refresh();
                        progressRefresh.ProgressBar.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(progressRefresh.Width / 2 - 10, progressRefresh.Height / 2 - 7));
                        progressRefresh.Value  = value.ProgressValue;
                        tsCurrentSolution.Text = value.WorkingOn;
                    });
                    var progress = progressHandler as IProgress <ProgressResult>;

                    var sw = Stopwatch.StartNew();
                    var t  = Task.Run(() => { _repo.CrawlSource(progress); });

                    t.ContinueWith(r =>
                    {
                        lblCount.Text = _repo.GetSourceCount().ToString();
                        ManageControls(false);
                        progressRefresh.Value = 0;

                        sw.Stop();
                        _timerGrep = new Timer {
                            Interval = MILLISECOND_SEARCH_DELAY
                        };
                        _timerGrep.Tick += _timerGrep_Tick;
                    }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext());

                    t.ContinueWith(r =>
                    {
                        sw.Stop();
                        ManageControls(false);
                    }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext());
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length > 0 && args[0].Equals("-crawldefault"))
            {
                var progressWindow = new RecrawlProgressCommandLine();
                progressWindow.SetProgress(0, "");

                var progressHandler = new Progress <ProgressResult>(value =>
                {
                    var percent   = (int)(((double)progressWindow.GetCurrentProgressValue() / (double)progressWindow.GetMaxProgressValue()) * 100);
                    var workingOn = String.Empty;

                    if (value.WorkingOn != null && value.WorkingOn.Contains(".sln"))
                    {
                        workingOn = Path.GetFileName(value.WorkingOn);
                    }
                    else
                    {
                        workingOn = value.WorkingOn;
                    }

                    progressWindow.SetProgress(value.ProgressValue, workingOn);

                    if (value.CloseForm.HasValue && value.CloseForm.Value)
                    {
                        progressWindow.KillSelf();
                    }
                });

                var progress = progressHandler as IProgress <ProgressResult>;
                var t        = Task.Run(() =>
                {
                    var defaultRootId = RepositoryUtils.GetDefaultRootId()[0];
                    if (defaultRootId != null)
                    {
                        progress.Report(new ProgressResult {
                            ProgressValue = 0, WorkingOn = "Caching..."
                        });

                        var repo = new RepositoryFile(defaultRootId, progress);

                        progress.Report(new ProgressResult {
                            ProgressValue = 0, WorkingOn = $"Refreshing default repository: {repo.Root.RootPath}..."
                        });
                        repo.CrawlSource(progress);

                        progress.Report(new ProgressResult {
                            ProgressValue = 0, CloseForm = true
                        });
                    }
                    else
                    {
                        //Console.WriteLine("No default source repository exists.");
                    }
                });

                progressWindow.ShowDialog();
            }
            else
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Main());
            }
        }