Example #1
0
        private void DetectorProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            // This function fires on the UI thread so it's safe to edit
            // the UI control directly, no funny business with Control.Invoke.
            // Update the progressBar with the integer supplied to us from the
            // ReportProgress() function.  Note, e.UserState is a "tag" property
            // that can be used to send other information from the
            // BackgroundThread to the UI thread.

            BackgroundWorker worker = sender as BackgroundWorker;

            if (worker.CancellationPending)
            {
                return;
            }

            DetectorData detectorData = detectorDatas[sender];

            detectorData.counter++;
            if (detectorData.counter % 10 != 0)
            {
                return;
            }

            ProjecTypeItem item = detectorData.editor.Items[0] as ProjecTypeItem;

            item.Description = e.UserState as string;
            detectorData.editor.UpdateDropDownSize();
        }
Example #2
0
        private void ProjectTypePopulation(ProjectTypeCellEditor editor)
        {
            // retrieve current row
            int row = editor.EditingCellPos.Row;

            // retrieve current folder path
            string folder = tableModel.Rows[row].Cells[1].Text;

            bool hasCache = Detector.Current.HasExtCache(folder);

            if (!hasCache)
            {
                // create waiting item, to signal progress
                ProjecTypeItem wait = new ProjecTypeItem();
                wait.Text        = "Scanning";
                wait.Description = "Wait please ...";
                wait.ImageIndex  = -1;
                wait.Mark        = true;
                wait.ForeColor   = Color.Red;
                editor.Items.Clear();
                editor.Items.Add(wait);
            }

            // cancel previous worker if running
            if (detectorWorker != null)
            {
                DetectorCancel();
            }

            // create a background worker thread that ReportsProgress & SupportsCancellation
            // hook up the appropriate events.
            DetectorData detectorData = new DetectorData(folder, editor);

            detectorWorker = new BackgroundWorker();
            detectorWorker.WorkerReportsProgress      = true;
            detectorWorker.WorkerSupportsCancellation = true;
            detectorWorker.ProgressChanged           += new ProgressChangedEventHandler(DetectorProgressChanged);
            detectorWorker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(DetectorWorkerCompleted);
            detectorWorker.DoWork         += new DoWorkEventHandler(DetectorDoWork);
            Detector.Current.currentWorker = detectorWorker;
            detectorDatas.Add(detectorWorker, detectorData);
            if (!hasCache)
            {
                detectorWorker.RunWorkerAsync();
            }
            else
            {
                // we have cache, so do operation synchronously, to prevent UI blinking
                DetectorDoWork(detectorWorker, new DoWorkEventArgs(null));
                DetectorWorkerCompleted(detectorWorker, new RunWorkerCompletedEventArgs(null, null, false));
            }
        }
Example #3
0
        private void DetectorDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                // The sender is the BackgroundWorker object we need it to
                // report progress and check for cancellation.
                BackgroundWorker worker = sender as BackgroundWorker;

                DetectorData detectorData = detectorDatas[sender];

                // build list of project types using scanners
                List <ProjecTypeItem> recommendedTypes = new List <ProjecTypeItem>();
                List <ProjecTypeItem> otherTypes       = new List <ProjecTypeItem>();

                foreach (Scanner scanner in Detector.Current.scanners)
                {
                    bool isRecommended = scanner.Scan(detectorData.folder);

                    ProjecTypeItem item = new ProjecTypeItem();
                    item.Text        = scanner.GetName();
                    item.Description = scanner.GetDescription();
                    item.ImageIndex  = scanner.GetImageIndex();
                    item.Mark        = true;
                    item.ForeColor   = isRecommended ? Color.Black : Color.Gray;

                    if (isRecommended)
                    {
                        recommendedTypes.Add(item);
                    }
                    else
                    {
                        otherTypes.Add(item);
                    }
                }

                // enable separator lines
                if (recommendedTypes.Count > 0)
                {
                    recommendedTypes[recommendedTypes.Count - 1].Separator = true;
                }
                if (otherTypes.Count > 0)
                {
                    otherTypes[otherTypes.Count - 1].Separator = true;
                }

                // add lists into listbox
                detectorData.items.AddRange(recommendedTypes.ToArray());
                detectorData.items.AddRange(otherTypes.ToArray());

                ProjecTypeItem custom = new ProjecTypeItem();
                custom.Text        = "Custom";
                custom.Description = "Custom settings";
                custom.ImageIndex  = 0;
                custom.Mark        = true;
                custom.ForeColor   = Color.Blue;
                detectorData.items.Add(custom);
            }
            catch (CancelException)
            {
                e.Cancel = true;
            }
        }
Example #4
0
 public int ProjectTypeComparer(ProjecTypeItem a, ProjecTypeItem b)
 {
     return(a.Text.ToString().CompareTo(b.Text.ToString()));
 }