Exemplo n.º 1
0
 public void LoadProgressDialog()
 {
     Mock<CancellationTokenSource> tksMock = new Mock<CancellationTokenSource>();
     ProgressDialog dialog = new ProgressDialog(tksMock.Object);
     dialog.ShowDialog();
 }
        private async void buttonExport_Click(object sender, EventArgs e)
        {
            //Create Export Paramaters
            bool excludePrivates = radCheckBoxExcludePrivate.Checked;
            bool ignoreDynamicProperties = _settings.IgnoreDynamicallyAddedProperties;
            ExportType exportType = GetExportType();
            int maxDepth = (int)numericUpDownMaxDepth.Value;
            ExportParamaters exportParamaters = new ExportParamaters(excludePrivates, ignoreDynamicProperties, maxDepth, exportType);

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            _waitingDialog = new ProgressDialog(cancellationTokenSource);

            List<ExpressionWithSource> expressions = GetAllExpressions();

            if (expressions.Any())
            {
                //Hide and Show Progress Bar    
                this.Hide();
                _waitingDialog.Show(this);

                TypeRetriever retriever = new TypeRetriever(_dte2);
                var exportGenerator = new ExportGenerator(expressions, retriever, exportParamaters);

                try
                {
                    Dictionary<string, string> lookupGeneratedTexts = await exportGenerator.GenerateTextWithKey(cancellationTokenSource.Token);

                    //Setup event for when the form is shown to close the waiting dialog
                    FormDisplayGeneratedText formDisplayGeneratedText = new FormDisplayGeneratedText(lookupGeneratedTexts, exportType);
                    formDisplayGeneratedText.Shown += formDisplayGeneratedText_Shown;
                    formDisplayGeneratedText.ShowDialog(this);
                }
                catch (ThreadAbortException ex)
                {
                    _waitingDialog.Close();
                }
                catch (ObjectDisposedException ex)
                {
                    _waitingDialog.Close();
                }
                catch (Exception ex)
                {
                    _waitingDialog.Close();
                    Raygun.LogException(ex);
                    MessageBox.Show("Error when attempting to export objects. If error reporting has not been disabled," +
                                    " then your error has already been logged.");
                }
                finally
                {
                    this.Show();
                }
            }
        }