private void CodeAnalysis(List<Type> allTypes, Action<List<ClassMetaData>> fn)
        {
            try
            {
                btnReport.IsEnabled = false;
                btnAnalyze.IsEnabled = false;
                btnFix.IsEnabled = false;
                int SecondsToComplete = allTypes != null ? 8 : 20; //Program specific value
                MetroProgressBar progress = new MetroProgressBar();
                progress.IsIndeterminate = false;
                progress.Orientation = System.Windows.Controls.Orientation.Horizontal;
                progress.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

                progress.Width = this.WindowWidth - 10;
                progress.Height = 30;
                Duration duration = new Duration(TimeSpan.FromSeconds((SecondsToComplete * 1.35)));
                DoubleAnimation doubleAnimatiion = new DoubleAnimation(200, duration);
                progress.Visibility = System.Windows.Visibility.Visible;
                progress.Foreground = Brushes.Green;
                progress.Background = Brushes.Transparent;
                progress.BorderBrush = Brushes.Gray;
                progress.BorderThickness = new Thickness(1, 1, 1, 1);
                progress.Padding = new Thickness(1, 1, 1, 1);
                progress.Tag = "Processing......";
                progress.Value = 0;
                lblStatus.Text = "Processing...";
                statusPanel.Visibility = System.Windows.Visibility.Visible;
                statusPanel.Children.Add(progress);
                TaskScheduler uiThread = TaskScheduler.FromCurrentSynchronizationContext();
                List<ClassMetaData> classInfo = null;
                Action MainThreadDoWork = new Action(() =>
                {
                    if (!_isFixMode)
                        classInfo = new CodeAnalysisEngine().ProcessAssembly(allTypes);
                    else
                        files = new CodeAnalysisEngine().ApplyFixToCodeAnalysisDocument(_Path, allTypes, productName);

                    System.Threading.Thread.Sleep(2000);
                });

                Action ExecuteProgressBar = new Action(() =>
                {
                    progress.BeginAnimation(MetroProgressBar.ValueProperty, doubleAnimatiion);
                });

                Action FinalThreadDoWOrk = new Action(() =>
                {
                    if (classInfo != null)
                    {
                        fn(classInfo);
                        mainContainer.Visibility = Visibility.Visible;
                        panelContainer.Visibility = Visibility.Hidden;
                    }
                    else
                    {
                        mainContainer.Visibility = Visibility.Hidden;
                        panelContainer.Visibility = Visibility.Visible;
                        PopulateTiles();
                    }
                    Logo.Visibility = Visibility.Hidden;
                    Logo.Height = 0;
                    helpContainer.Children.Clear();
                    helpContainer.Height = 0;

                    statusPanel.Children.Remove(progress);
                    statusPanel.Visibility = System.Windows.Visibility.Hidden;
                    btnReport.IsEnabled = true;
                    btnAnalyze.IsEnabled = true;
                    btnFix.IsEnabled = true;
                });

                Task MainThreadDoWorkTask = Task.Factory.StartNew(() => MainThreadDoWork());

                Task ExecuteProgressBarTask = new Task(ExecuteProgressBar);
                ExecuteProgressBarTask.RunSynchronously();

                MainThreadDoWorkTask.ContinueWith(t => FinalThreadDoWOrk(), uiThread);

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 2
0
        private void StartDOMEngine(CodeDOMEngine engine, bool isPreview)
        {
            if (engine == null)
                return;

            btnPreview.IsEnabled = false;
            btnCreate.IsEnabled = false;
            int SecondsToComplete = 10; //Program specific value
            panelContainer.Children.Clear();
            txtMsg.Visibility = System.Windows.Visibility.Hidden;
            MetroProgressBar progress = new MetroProgressBar();
            progress.IsIndeterminate = false;
            progress.Orientation = System.Windows.Controls.Orientation.Horizontal;
            progress.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            progress.Width = this.WindowWidth - 330;
            progress.Height = 30;
            Duration duration = new Duration(TimeSpan.FromSeconds((SecondsToComplete * 1.35)));
            DoubleAnimation doubleAnimatiion = new DoubleAnimation(200, duration);
            progress.Visibility = System.Windows.Visibility.Visible;
            progress.Foreground = Brushes.Green;
            progress.Background = Brushes.Transparent;
            progress.BorderBrush = Brushes.Gray;
            progress.BorderThickness = new Thickness(1, 1, 1, 1);
            progress.Padding = new Thickness(1, 1, 1, 1);
            progress.Tag = "Processing......";
            progress.Value = 0;
            lblStatus.Text = (isPreview ? "Processing..." : "Creating Files....");
            statusPanel.Children.Add(progress);
            try
            {
                TaskScheduler uiThread = TaskScheduler.FromCurrentSynchronizationContext();

                Action MainThreadDoWork = new Action(() =>
                {
                    CodeFiles = isPreview ? engine.Preview() : engine.CreateFiles();
                    System.Threading.Thread.Sleep(6000);
                });

                Action ExecuteProgressBar = new Action(() =>
                {
                    progress.BeginAnimation(MetroProgressBar.ValueProperty, doubleAnimatiion);
                });

                Action FinalThreadDoWOrk = new Action(() =>
                {
                    btnPreview.IsEnabled = true;
                    btnCreate.IsEnabled = true;
                    statusPanel.Children.Remove(progress);
                    PopulateTiles();
                });

                Task MainThreadDoWorkTask = Task.Factory.StartNew(() => MainThreadDoWork());

                Task ExecuteProgressBarTask = new Task(ExecuteProgressBar);
                ExecuteProgressBarTask.RunSynchronously();

                MainThreadDoWorkTask.ContinueWith(t => FinalThreadDoWOrk(), uiThread);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 3
0
        private void btnAnalyze_Click(object sender, RoutedEventArgs e)
        {

            btnAnalyze.IsEnabled = false;

            int SecondsToComplete = 6; //Program specific value
            MetroProgressBar progress = new MetroProgressBar();
            progress.IsIndeterminate = false;
            progress.Orientation = System.Windows.Controls.Orientation.Horizontal;
            progress.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            progress.Width = this.WindowWidth - 10;
            progress.Height = 30;
            Duration duration = new Duration(TimeSpan.FromSeconds((SecondsToComplete * 1.35)));
            DoubleAnimation doubleAnimatiion = new DoubleAnimation(200, duration);
            progress.Visibility = System.Windows.Visibility.Visible;
            progress.Foreground = Brushes.Green;
            progress.Background = Brushes.Transparent;
            progress.BorderBrush = Brushes.Gray;
            progress.BorderThickness = new Thickness(1, 1, 1, 1);
            progress.Padding = new Thickness(1, 1, 1, 1);
            progress.Tag = "Processing......";
            progress.Value = 0;
            lblStatus.Text = "Processing...";
            statusPanel.Visibility = System.Windows.Visibility.Visible;
            statusPanel.Children.Add(progress);

            try
            {

                TaskScheduler uiThread = TaskScheduler.FromCurrentSynchronizationContext();

                Action MainThreadDoWork = new Action(() =>
                {
                    System.Threading.Thread.Sleep(2000);
                });

                Action ExecuteProgressBar = new Action(() =>
                {
                    progress.BeginAnimation(MetroProgressBar.ValueProperty, doubleAnimatiion);
                });

                Action FinalThreadDoWOrk = new Action(() =>
                {
                    Process();
                    btnAnalyze.IsEnabled = true;
                    Logo.Visibility = Visibility.Hidden;
                    helpContainer.Visibility = Visibility.Hidden;
                    mainContainer.Visibility = Visibility.Visible;
                    statusPanel.Children.Remove(progress);
                    statusPanel.Visibility = System.Windows.Visibility.Hidden;
                });

                Task MainThreadDoWorkTask = Task.Factory.StartNew(() => MainThreadDoWork());

                Task ExecuteProgressBarTask = new Task(ExecuteProgressBar);
                ExecuteProgressBarTask.RunSynchronously();

                MainThreadDoWorkTask.ContinueWith(t => FinalThreadDoWOrk(), uiThread);

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message, "Error",MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }