private void HandleSimulatorCanceled()
        {
            this.simulator          = null;
            this.btnStart.IsEnabled = true;
            this.btnStop.IsEnabled  = false;
            this.btnLoad.IsEnabled  = true;
            if (this.quickActionButtons != null)
            {
                foreach (var bt in this.quickActionButtons)
                {
                    bt.IsEnabled = true;
                }
            }

            if (this.currentQuickAction != null)
            {
                this.currentQuickAction = null;
                RefreshProjectControls();
            }

            if (this.closeWindowAfterStop)
            {
                Close();
            }
        }
        private void btnLoad_Click(object sender, RoutedEventArgs e)
        {
            if (this.openFileDialog.ShowDialog(this) == true)
            {
                // Try to load the given project.
                try
                {
                    using (var fs = new FileStream(this.openFileDialog.FileName, FileMode.Open,
                                                   FileAccess.Read, FileShare.Read))
                    {
                        this.project = XmlProjectDeserializer.Deserialize(fs);
                    }
                }
                catch (Exception ex)
                {
                    var dialog = new TaskDialog()
                    {
                        Title               = AppName,
                        MainInstruction     = "Could not load the selected project.",
                        Content             = ex.Message,
                        ExpandedInformation = GetExceptionDetailsText(ex),
                        MainIcon            = TaskDialog.TaskDialogIcon.SecurityErrorBar,
                        MainUpdateIcon      = TaskDialog.TaskDialogIcon.Stop,
                        CommonButtons       = TaskDialog.TaskDialogButtons.OK
                    };
                    dialog.Flags |= TaskDialog.TaskDialogFlags.SizeToContent |
                                    TaskDialog.TaskDialogFlags.ExpandFooterArea;

                    dialog.Show(this);
                    return;
                }


                if (this.quickActionButtons != null)
                {
                    foreach (var b in this.quickActionButtons)
                    {
                        this.gridProjectControls.Children.Remove(b);
                    }
                    this.quickActionButtons = null;
                }

                RefreshProjectControls();

                // For each quick action, create a button.
                this.quickActionButtons = new Button[this.project.Configuration.QuickActions.Count];
                for (int idx = 0; idx < this.project.Configuration.QuickActions.Count; idx++)
                {
                    int i           = idx;
                    var quickAction = this.project.Configuration.QuickActions[i];

                    var b = this.quickActionButtons[i] = new Button();
                    b.Height = 21;
                    b.HorizontalAlignment = HorizontalAlignment.Left;
                    b.VerticalAlignment   = VerticalAlignment.Top;
                    b.Margin  = new Thickness(0, 2 + 23 * i, 0, 0);
                    b.Content = "  " + quickAction.Name + "  ";
                    this.gridProjectControls.Children.Add(b);
                    Grid.SetRow(b, 1);

                    b.Click += async(_s, _e) =>
                    {
                        this.currentQuickAction = quickAction;
                        RefreshProjectControls();

                        await RunSimulatorAsync();
                    };
                }
            }
        }