示例#1
0
 protected void ButtonSettings_Click(object sender, EventArgs e)
 {
     _breakTimer.Stop ();
     var settingsDialog = new SettingsDialog ();
     settingsDialog.Run ();
     Refresh ();
     _breakTimer.Start ();
 }
	/// returns true if the file was opened, false otherwise
	bool OpenFile (string file)
	{
		_textView = null;
		_codeView = null;
		_filePath = file;

		if (string.IsNullOrEmpty(_filePath))
			return false;

		_textView = TextViewFactory.ViewForFile(_filePath);
		_codeView = new CodeView(MissingEditorAPI.currentInspectorWindow, _textView);

		if (_textView != null)
			_settingsDialog = new SettingsDialog(_textView);
		return true;
	}
示例#3
0
	public static void Main (string[] args)
	{
		try {
			SettingsDialog settings = new SettingsDialog (args);
			settings.Run ();
		} catch (Exception e) {
			Log.Error (e, "Error while running beagle-settings");
			HigMessageDialog dialog = new HigMessageDialog (null,
					DialogFlags.Modal,
					MessageType.Error, 
					ButtonsType.Close, 
					Catalog.GetString ("An error occurred"), 
					e.Message);
			dialog.Run ();
			Environment.Exit (1);
		}
	}
示例#4
0
        private void ShowSettings(string defaultTabName)
        {
            var d = new SettingsDialog(Settings)
            {
                DefaultTab = defaultTabName
            };

            TelemetryService.Instance.TrackEvent("ShowSettings");

            if (d.ShowDialog(this) == DialogResult.OK)
            {
                Stop();

                Settings = d.Settings;

                Opacity = (double)Settings.Opacity / 100;

                Logger.Instance.TextBoxThreshold = LogManager.GetLogger("MCEControl").Logger.Repository.LevelMap[Settings.TextBoxLogThreshold];

                Start();
            }
            d.Dispose();
        }
示例#5
0
        /// <summary>
        /// Здесь проводится загрузка активных COM портов, загрузка настроек приложения
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            LoadSerialPorts();
            settings = new SettingsDialogViewModel();
            settings.Load();
            if (settings.DemoMode)
            {
                OnDemoMode(null, null);
            }
            this.SensorsDataTable.ItemsSource = this.SensorsData;

            dialog         = new MessageDialog();
            exitDialog     = new ExitDialog();
            settingsDialog = new SettingsDialog
            {
                DataContext = settings
            };
            settingsDialog.OnDemoMode  += OnDemoMode;
            settingsDialog.OffDemoMode += OffDemoMode;
            updateResultsTableDialog    = new UpdateResultsTableDialog();
        }
 public static void Postfix(ref MainMenuScreen __instance)
 {
     // We only need to do this once. In fact, not checking this probably results in the game freezing due
     // to an infinite recursion.
     if (!CustomUIManager.AreTemplatesInitalized())
     {
         // Find the current ScreenManager to access the Settigns Screen and Settings Dialog, as the Settings
         // Dialog contains a lot of UI elements and is helpful in creating templates.
         ScreenManager  screenManager  = Traverse.Create(Traverse.Create(__instance).Field("gameStateManager").GetValue <GameStateManager>()).Field("screenManager").GetValue <ScreenManager>();
         SettingsScreen settingsScreen = (SettingsScreen)screenManager.GetScreen(ScreenName.Settings);
         SettingsDialog settingsDialog = Traverse.Create(settingsScreen).Field("settingsDialog").GetValue <SettingsDialog>();
         // We need to actually open the Settings Dialog in order for the UI elements to initalize correctly.
         screenManager.ShowScreen(ScreenName.Settings);
         settingsDialog.Open();
         settingsDialog.Close();
         // Use the Patch Notes Dialog as a template for custom dialogs
         PatchNotesUI patch          = Traverse.Create(__instance).Field("patchNotesDialog").GetValue <PatchNotesUI>();
         ScreenDialog dialogTemplate = Traverse.Create(patch).Field("dialog").GetValue <ScreenDialog>();
         CustomUIManager.InitalizeTemplates(settingsScreen, dialogTemplate, settingsDialog);
         // Pretend that nothing has happend and return to the main menu.
         screenManager.ReturnToMainMenu();
     }
 }
示例#7
0
        public MainViewModel()
        {
            var logger = Logger.New(typeof(MainViewModel));

            using (logger.LogPerf("Init"))
            {
                SettingsCommand = new DelegateCommand(_ =>
                {
                    var dlg = new SettingsDialog {
                        ViewModel = new SettingsViewModel()
                    };
                    dlg.ShowDialog();
                });

                SimulationOptions options = new SimulationOptions(new GridSize(9, 9), new GridIndex(4, 4));

                Tabs.Add(new PrTabViewModel(options));
                Tabs.Add(new StTabViewModel(options));
                Tabs.Add(new CpTabViewModel(options));
                Tabs.Add(new СlTabViewModel());

                SelectedTab = Tabs.First();
            }
        }
示例#8
0
        void ShowSettings(object sender, EventArgs e)
        {
            SettingsDialog sd = new SettingsDialog();

            sd.ShowDialog(this);
        }
示例#9
0
 private void SettingsClosed(object sender, EventArgs e)
 {
     _settings = null;
 }
示例#10
0
 private async void AppBarButton_Settings_Click(object sender, RoutedEventArgs e)
 {
     settingsDialog = new Views.SettingsDialog(ViewModel);
     await settingsDialog.ShowAsync();
 }
示例#11
0
        /// <summary>
        /// Show Settings dialog.
        /// </summary>
        public async void ShowSettings()
        {
            var settingsDialog = new SettingsDialog(settingsViewModel);

            await ShowDialog(settingsDialog);
        }
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="dialog"></param>
 /// <param name="name"></param>
 public SettingsExportSkin(SettingsDialog dialog, string name) : base(dialog, name) => CreateExportButton();
示例#13
0
 void OpenSettingsDialogCommand_Execute()
 {
     // The SettingsDialog has been ported from an older version of
     // NUnit and doesn't use an MVP structure. The dialog deals
     // directly with the model.
     using (var dialog = new SettingsDialog((Form)_view, _model.Settings))
     {
         dialog.ShowDialog();
     }
 }
示例#14
0
        private void WireUpEvents()
        {
            // Model Events
            _model.Events.TestsLoading   += NotifyTestsLoading;
            _model.Events.TestLoaded     += (ea) => InitializeMainMenu();
            _model.Events.TestUnloaded   += (ea) => InitializeMainMenu();
            _model.Events.TestsReloading += NotifyTestsReloading;

            _model.Events.TestReloaded += (ea) =>
            {
                InitializeMainMenu();
                _view.OnTestAssembliesLoaded();
            };

            _model.Events.TestChanged += (ea) =>
            {
                if (_model.Services.UserSettings.Engine.ReloadOnChange)
                {
                    _model.ReloadTests();
                }
            };

            _model.Events.RunStarting += (ea) => InitializeMainMenu();
            _model.Events.RunFinished += (ea) => InitializeMainMenu();

            // View Events
            _view.Load            += MainForm_Load;
            _view.MainViewClosing += MainForm_Closing;
            _view.DragDropFiles   += MainForm_DragDrop;

            _view.NewProjectCommand.Execute        += ProjectSaveNotYetImplemented; // _model.NewProject;
            _view.OpenProjectCommand.Execute       += OnOpenProjectCommand;
            _view.CloseCommand.Execute             += _model.UnloadTests;
            _view.SaveCommand.Execute              += ProjectSaveNotYetImplemented; // _model.SaveProject;
            _view.SaveAsCommand.Execute            += ProjectSaveNotYetImplemented; // _model.SaveProject;
            _view.SaveResultsCommand.Execute       += () => SaveResults();
            _view.ReloadTestsCommand.Execute       += _model.ReloadTests;
            _view.RecentProjectsMenu.Popup         += PopulateRecentProjectsMenu;
            _view.SelectedRuntime.SelectionChanged += SelectedRuntime_SelectionChanged;
            _view.ProcessModel.SelectionChanged    += ProcessModel_SelectionChanged;
            _view.DomainUsage.SelectionChanged     += DomainUsage_SelectionChanged;
            _view.RunAsX86.CheckedChanged          += LoadAsX86_CheckedChanged;
            _view.ExitCommand.Execute              += () => Application.Exit();

            _view.SettingsCommand.Execute += () =>
            {
                using (var dialog = new SettingsDialog((Form)_view, _settings))
                {
                    dialog.ShowDialog();
                }
            };

            _view.ExtensionsCommand.Execute += () =>
            {
                using (var extensionsDialog = new ExtensionDialog(_model.Services.ExtensionService))
                {
                    extensionsDialog.Font = _settings.Gui.Font;
                    extensionsDialog.ShowDialog();
                }
            };

            _view.NUnitHelpCommand.Execute += () =>
            { MessageBox.Show("This will show Help", "Not Yet Implemented"); };
            _view.AboutNUnitCommand.Execute += () =>
            { MessageBox.Show("This will show the About Box", "Not Yet Implemented"); };

            _view.MainViewClosing += () => _model.Dispose();
        }
示例#15
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="dialog"></param>
 /// <param name="name"></param>
 public EditorMetadataItem(SettingsDialog dialog, string name, Action <string> saveValue) : base(dialog, name) => throw new NotImplementedException();
示例#16
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="dialog"></param>
 public SettingsFpsLimiter(SettingsDialog dialog)
     : base(dialog, "Frame Limiter Type", FpsLimiterTypesToStringList(), OnChange, (int)ConfigManager.FpsLimiterType.Value)
     => ConfigManager.FpsLimiterType.ValueChanged += OnBindableValueChanged;
示例#17
0
        private void ShowSettings()
        {
            SettingsDialog dialog = new SettingsDialog();

            dialog.ShowDialog();
        }
示例#18
0
        public override void Execute(object parameter)
        {
            new NewDatabase().ShowAsync()
            .ContinueOnSuccessInTheUIThread(newDatabase =>
            {
                var databaseName = newDatabase.DbName.Text;

                if (Path.GetInvalidPathChars().Any(databaseName.Contains))
                {
                    throw new ArgumentException("Cannot create a database with invalid path characters: " + databaseName);
                }
                if (ApplicationModel.Current.Server.Value.Databases.Count(s => s == databaseName) != 0)
                {
                    throw new ArgumentException("A database with the name " + databaseName + " already exists");
                }

                AssertValidName(databaseName);

                var bundlesModel    = new CreateSettingsModel();
                var bundlesSettings = new List <ChildWindow>();
                if (newDatabase.Encryption.IsChecked == true)
                {
                    bundlesSettings.Add(new EncryptionSettings());
                }
                if (newDatabase.Quotas.IsChecked == true || newDatabase.Versioning.IsChecked == true)
                {
                    bundlesModel = ConfigureSettingsModel(newDatabase);

                    var bundleView = new SettingsDialog()
                    {
                        DataContext = bundlesModel
                    };

                    var bundlesSettingsWindow = new ChildWindow()
                    {
                        Title   = "Setup bundles",
                        Content = bundleView,
                    };

                    bundlesSettingsWindow.KeyDown += (sender, args) =>
                    {
                        if (args.Key == Key.Escape)
                        {
                            bundlesSettingsWindow.DialogResult = false;
                        }
                    };

                    bundlesSettings.Add(bundlesSettingsWindow);
                }

                new Wizard(bundlesSettings).StartAsync()
                .ContinueOnSuccessInTheUIThread(bundlesData =>
                {
                    ApplicationModel.Current.AddNotification(new Notification("Creating database: " + databaseName));
                    var settings        = UpdateSettings(newDatabase, newDatabase, bundlesModel);
                    var securedSettings = UpdateSecuredSettings(bundlesData);

                    var databaseDocument = new DatabaseDocument
                    {
                        Id              = newDatabase.DbName.Text,
                        Settings        = settings,
                        SecuredSettings = securedSettings
                    };

                    string encryptionKey   = null;
                    var encryptionSettings = bundlesData.FirstOrDefault(window => window is EncryptionSettings) as EncryptionSettings;
                    if (encryptionSettings != null)
                    {
                        encryptionKey = encryptionSettings.EncryptionKey.Text;
                    }

                    DatabaseCommands.CreateDatabaseAsync(databaseDocument).ContinueOnSuccess(
                        () => DatabaseCommands.ForDatabase(databaseName).EnsureSilverlightStartUpAsync())
                    .ContinueOnSuccessInTheUIThread(() =>
                    {
                        var model = parameter as DatabasesListModel;
                        if (model != null)
                        {
                            model.ForceTimerTicked();
                        }
                        ApplicationModel.Current.AddNotification(
                            new Notification("Database " + databaseName + " created"));

                        HandleBundleAfterCreation(bundlesModel, databaseName, encryptionKey);

                        ExecuteCommand(new ChangeDatabaseCommand(), databaseName);
                    })
                    .Catch();
                });
            })
            .Catch();
        }
示例#19
0
		private void settingsMenu_Click(object sender, EventArgs e)
		{
			SettingsDialog settingsDialog = new SettingsDialog();

			if (settingsDialog.DisplaySettings(mainMenu) == DialogResult.OK)
			{
				Settings.SaveConfiguration(mainMenu);
				UpdateCodeEditorFonts();
			}
		}
示例#20
0
    void mSettings_Click(object sender, EventArgs e)
    {
        SettingsDialog dialog = new SettingsDialog(_deviceManager, _settings);
        DialogResult result = dialog.ShowDialog();

        if (result == DialogResult.OK) {
            _settings.Save();

            // Apply settings
            _deviceManager.AuthenticationEnabled = _settings.AuthorizedDevices;

            if (_multicastSocket != null && !_settings.Multicast) {
                _multicastTimer.Stop();
                _multicastSocket.Close();

                _multicastTimer = null;
                _multicastSocket = null;
            }

            if (_multicastSocket == null && _settings.Multicast) {
                StartMulticasting();
            }

            if (_history == null && _settings.History) {
                StartHistoryTimer();
            }

            if (_history != null && _settings.History) {
                _history.KeepHistory = _settings.KeepHistory;
            }

            if (_history != null && !_settings.History) {
                _historyTimer.Stop();
                _historyTimer = null;
                _history = null;
            }
        }
    }
示例#21
0
        private void SettingsButton_Click(object sender, RibbonControlEventArgs e)
        {
            Excel2007Addin.Settings settings    = Excel2007Addin.Settings.Default;
            SettingsDialog          settingsdlg = new SettingsDialog();

            settingsdlg.AutoEscapeFilter = settings.AutoEscapeFilter;
            settingsdlg.UseProxy         = settings.UseProxy;
            settingsdlg.ProxyAddress     = settings.ProxyAddress;
            settingsdlg.ProxyPort        = settings.ProxyPort;
            settingsdlg.ProxyUsername    = settings.ProxyUsername;
            settingsdlg.ProxyPassword    = DataProtectionHelper.UnProtect(settings.ProxyPassword);
            settingsdlg.RequestTimeout   = settings.RequestTimeout;
            settingsdlg.CellFormatting   = (CellFormattingEnum)settings.CellFormatting;

            if (settingsdlg.ShowDialog().GetValueOrDefault(false))
            {
                // Update metrics xml?
                if (!string.IsNullOrEmpty(settingsdlg.MetricsFileName))
                {
                    System.Xml.XmlDocument doc = new System.Xml.XmlDataDocument();
                    try
                    {
                        doc.Load(XmlReader.Create(settingsdlg.MetricsFileName,
                                                  new XmlReaderSettings()
                        {
                            Schemas        = Analytics.Data.Validation.XmlValidator.LoadSchema("metrics.xsd"),
                            ValidationType = ValidationType.Schema
                        }));
                        settings.Metrics = doc;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error parsing metrics xml. No metrics updated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                // Update dimensions xml?
                if (!string.IsNullOrEmpty(settingsdlg.DimensionsFileName))
                {
                    System.Xml.XmlDocument doc = new System.Xml.XmlDataDocument();
                    try
                    {
                        doc.Load(XmlReader.Create(settingsdlg.DimensionsFileName,
                                                  new XmlReaderSettings()
                        {
                            Schemas        = Analytics.Data.Validation.XmlValidator.LoadSchema("dimensions.xsd"),
                            ValidationType = ValidationType.Schema
                        }));
                        settings.Dimensions = doc;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error parsing dimension xml. No dimensions updated.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                settings.AutoEscapeFilter = settingsdlg.AutoEscapeFilter;
                settings.UseProxy         = settingsdlg.UseProxy;
                settings.ProxyAddress     = settingsdlg.ProxyAddress;
                settings.ProxyUsername    = settingsdlg.ProxyUsername;
                settings.ProxyPassword    = DataProtectionHelper.Protect(settingsdlg.ProxyPassword);
                settings.ProxyPort        = settingsdlg.ProxyPort;
                settings.RequestTimeout   = settingsdlg.RequestTimeout;
                settings.CellFormatting   = (int)settingsdlg.CellFormatting;
                settings.Save();

                Analytics.Settings.Instance.AutoEscapeFilter = settingsdlg.AutoEscapeFilter;
                Analytics.Settings.Instance.UseProxy         = settings.UseProxy;
                Analytics.Settings.Instance.ProxyAddress     = settings.ProxyAddress;
                Analytics.Settings.Instance.ProxyPassword    = settings.ProxyPassword;
                Analytics.Settings.Instance.ProxyPort        = settings.ProxyPort;
                Analytics.Settings.Instance.ProxyUsername    = settings.ProxyUsername;

                Analytics.Settings.Instance.RequestTimeout = settings.RequestTimeout;
                Analytics.Settings.Instance.MetricsXml     = settings.Metrics;
                Analytics.Settings.Instance.DimensionsXml  = settings.Dimensions;
            }
        }
示例#22
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="dialog"></param>
 /// <param name="name"></param>
 public SettingsResolution(SettingsDialog dialog, string name)
     : base(dialog, name, GetElements(), (val, i) => OnChange(dialog, val, i), GetSelectedIndex())
 {
 }
示例#23
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="dialog"></param>
 /// <param name="name"></param>
 public SettingsDefaultSkin(SettingsDialog dialog, string name)
     : base(dialog, name, GetSelectorElements(), (val, i) => OnChange(dialog, val, i), GetSelectedIndex())
 {
 }
示例#24
0
 private void UpdateSettingsDialog(Style style)
 {
     settingsDialog = new SettingsDialog(style);
 }
示例#25
0
 private async void SettingsButton_Click(object sender, RoutedEventArgs e)
 {
     SettingsDialog dialog = new SettingsDialog();
     await dialog.ShowAsync();
 }
示例#26
0
 private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     SettingsDialog sd = new SettingsDialog();
     sd.ShowDialog();
     sd.Dispose();
 }
示例#27
0
 private async void ShowSettingsDialog()
 {
     var dialog = new SettingsDialog();
     await dialog.ShowAsync();
 }
示例#28
0
 /// <summary>
 /// </summary>
 /// <param name="dialog"></param>
 /// <param name="val"></param>
 /// <param name="index"></param>
 private static void OnChange(SettingsDialog dialog, string val, int index)
 => dialog.NewQueuedDefaultSkin = (DefaultSkins)Enum.Parse(typeof(DefaultSkins), val);
示例#29
0
        private void WireUpEvents()
        {
            #region Model Events

            _model.Events.TestsLoading += (TestFilesLoadingEventArgs e) =>
            {
                UpdateViewCommands(testLoading: true);

                var message = e.TestFilesLoading.Count == 1 ?
                              $"Loading Assembly: {e.TestFilesLoading[0]}" :
                              $"Loading {e.TestFilesLoading.Count} Assemblies...";

                _longOpDisplay = _view.LongOperationDisplay(message);
            };

            _model.Events.TestLoaded += (TestNodeEventArgs e) =>
            {
                if (_longOpDisplay != null)
                {
                    _longOpDisplay.Dispose();
                    _longOpDisplay = null;
                }

                UpdateViewCommands();

                var files = _model.TestFiles;
                if (files.Count == 1)
                {
                    _view.SetTitleBar(files.First());
                }
            };

            _model.Events.TestsUnloading += (TestEventArgse) =>
            {
                UpdateViewCommands();
            };

            _model.Events.TestUnloaded += (TestEventArgs e) =>
            {
                _view.RunSummary.Text = null;

                UpdateViewCommands();
            };

            _model.Events.TestsReloading += (TestEventArgs e) =>
            {
                UpdateViewCommands();

                _longOpDisplay = _view.LongOperationDisplay("Reloading...");
            };

            _model.Events.TestReloaded += (TestNodeEventArgs e) =>
            {
                if (_longOpDisplay != null)
                {
                    _longOpDisplay.Dispose();
                    _longOpDisplay = null;
                }

                //SetTitleBar(TestProject.Name);

                if (_settings.Gui.ClearResultsOnReload)
                {
                    _view.RunSummary.Text = null;
                }

                UpdateViewCommands();
            };

            _model.Events.RunStarting += (RunStartingEventArgs e) =>
            {
                UpdateViewCommands();
            };

            _model.Events.RunFinished += (TestResultEventArgs e) =>
            {
                UpdateViewCommands();

                ResultSummary summary = ResultSummaryCreator.FromResultNode(e.Result);
                _view.RunSummary.Text = string.Format(
                    "Passed: {0}   Failed: {1}   Errors: {2}   Inconclusive: {3}   Invalid: {4}   Ignored: {5}   Skipped: {6}   Time: {7}",
                    summary.PassCount, summary.FailedCount, summary.ErrorCount, summary.InconclusiveCount, summary.InvalidCount, summary.IgnoreCount, summary.SkipCount, summary.Duration);

                if (summary.RunCount == 0)
                {
                }

                //string resultPath = Path.Combine(TestProject.BasePath, "TestResult.xml");
                // TODO: Use Work Directory
                string resultPath = "TestResult.xml";
                _model.SaveResults(resultPath);
                //try
                //{
                //    _model.SaveResults(resultPath);
                //    //log.Debug("Saved result to {0}", resultPath);
                //}
                //catch (Exception ex)
                //{
                //    //log.Warning("Unable to save result to {0}\n{1}", resultPath, ex.ToString());
                //}

                //if (e.Result.Outcome.Status == TestStatus.Failed)
                //    _view.Activate();
            };

            _settings.Changed += (s, e) =>
            {
                if (e.SettingName == "Gui.Options.DisplayFormat")
                {
                    InitializeDisplay();
                }
            };

            _model.Events.UnhandledException += (UnhandledExceptionEventArgs e) =>
            {
                var display = new MessageDisplay("TestCentric - Internal Error");
                display.Error($"{e.Message}\n\n{e.StackTrace}");
            };

            #endregion

            #region View Events

            _view.Load += (s, e) =>
            {
                InitializeDisplay(_settings.Gui.DisplayFormat);

                var settings = _model.PackageOverrides;
                if (_options.ProcessModel != null)
                {
                    _view.ProcessModel.SelectedItem = _options.ProcessModel;
                }
                if (_options.DomainUsage != null)
                {
                    _view.DomainUsage.SelectedItem = _options.DomainUsage;
                }
                if (_options.MaxAgents >= 0)
                {
                    _model.Services.UserSettings.Engine.Agents = _options.MaxAgents;
                }
                _view.RunAsX86.Checked = _options.RunAsX86;
            };

            _view.Shown += (s, e) =>
            {
                Application.DoEvents();

                // Load test specified on command line or
                // the most recent one if options call for it
                if (_options.InputFiles.Count != 0)
                {
                    LoadTests(_options.InputFiles);
                }
                else if (_settings.Gui.LoadLastProject && !_options.NoLoad)
                {
                    foreach (string entry in _recentFiles.Entries)
                    {
                        if (entry != null && File.Exists(entry))
                        {
                            LoadTests(entry);
                            break;
                        }
                    }
                }

                //if ( guiOptions.include != null || guiOptions.exclude != null)
                //{
                //    testTree.ClearSelectedCategories();
                //    bool exclude = guiOptions.include == null;
                //    string[] categories = exclude
                //        ? guiOptions.exclude.Split(',')
                //        : guiOptions.include.Split(',');
                //    if ( categories.Length > 0 )
                //        testTree.SelectCategories( categories, exclude );
                //}

                // Run loaded test automatically if called for
                if (_model.IsPackageLoaded && _options.RunAllTests)
                {
                    RunAllTests();
                }
            };

            _view.Move += (s, e) =>
            {
                if (!_view.Maximized)
                {
                    var location = _view.Location;

                    switch (_view.DisplayFormat.SelectedItem)
                    {
                    case "Full":
                    default:
                        _settings.Gui.MainForm.Location  = location;
                        _settings.Gui.MainForm.Maximized = false;
                        break;

                    case "Mini":
                        _settings.Gui.MiniForm.Location  = location;
                        _settings.Gui.MiniForm.Maximized = false;
                        break;
                    }
                }
            };

            _view.Resize += (s, e) =>
            {
                if (!_view.Maximized)
                {
                    if (_view.DisplayFormat.SelectedItem == "Full")
                    {
                        _settings.Gui.MainForm.Size = _view.Size;
                    }
                    else
                    {
                        _settings.Gui.MiniForm.Size = _view.Size;
                    }
                }
            };

            _view.SplitterPositionChanged += (s, e) =>
            {
                _settings.Gui.MainForm.SplitPosition = _view.SplitterPosition;
            };

            _view.FormClosing += (s, e) =>
            {
                if (_model.IsPackageLoaded)
                {
                    if (_model.IsTestRunning)
                    {
                        DialogResult dialogResult = _view.MessageDisplay.Ask(
                            "A test is running, do you want to stop the test and exit?");

                        if (dialogResult == DialogResult.No)
                        {
                            e.Cancel = true;
                            return;
                        }

                        _model.CancelTestRun(true);
                    }

                    if (CloseProject() == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                    }
                }
            };

            _view.RunButton.Execute  += () => RunSelectedTests();
            _view.StopButton.Execute += () => CancelRun();

            _view.FileMenu.Popup += () =>
            {
                bool isPackageLoaded = _model.IsPackageLoaded;
                bool isTestRunning   = _model.IsTestRunning;

                _view.OpenCommand.Enabled  = !isTestRunning;
                _view.CloseCommand.Enabled = isPackageLoaded && !isTestRunning;

                _view.ReloadTestsCommand.Enabled = isPackageLoaded && !isTestRunning;

                var frameworks  = _model.AvailableRuntimes;
                var runtimeMenu = _view.RuntimeMenu;

                runtimeMenu.Visible = frameworks.Count > 1;

                if (runtimeMenu.Visible && runtimeMenu.Enabled && runtimeMenu.MenuItems.Count == 0)
                {
                    var defaultMenuItem = new MenuItem("Default");
                    defaultMenuItem.Name    = "defaultMenuItem";
                    defaultMenuItem.Tag     = "DEFAULT";
                    defaultMenuItem.Checked = true;

                    runtimeMenu.MenuItems.Add(defaultMenuItem);

                    // TODO: Disable selections that are not supported for the target?
                    foreach (IRuntimeFramework framework in frameworks)
                    {
                        MenuItem item = new MenuItem(framework.DisplayName);
                        item.Tag = framework.Id;
                        runtimeMenu.MenuItems.Add(item);
                    }

                    _view.SelectedRuntime.Refresh();
                }

                _view.RecentFilesMenu.Enabled = !isTestRunning;

                //if (!isTestRunning)
                //{
                //    _recentProjectsMenuHandler.Load();
                //}
            };

            _view.OpenCommand.Execute         += () => OpenProject();
            _view.CloseCommand.Execute        += () => CloseProject();
            _view.AddTestFilesCommand.Execute += () => AddTestFiles();
            _view.ReloadTestsCommand.Execute  += () => ReloadTests();

            _view.SelectedRuntime.SelectionChanged += () =>
            {
                ChangePackageSettingAndReload(EnginePackageSettings.RuntimeFramework, _view.SelectedRuntime.SelectedItem);
            };

            _view.ProcessModel.SelectionChanged += () =>
            {
                ChangePackageSettingAndReload(EnginePackageSettings.ProcessModel, _view.ProcessModel.SelectedItem);
            };

            _view.DomainUsage.SelectionChanged += () =>
            {
                ChangePackageSettingAndReload(EnginePackageSettings.DomainUsage, _view.DomainUsage.SelectedItem);
            };

            _view.RunAsX86.CheckedChanged += () =>
            {
                var key = EnginePackageSettings.RunAsX86;
                if (_view.RunAsX86.Checked)
                {
                    ChangePackageSettingAndReload(key, true);
                }
                else
                {
                    ChangePackageSettingAndReload(key, null);
                }
            };

            _view.RecentFilesMenu.Popup += () =>
            {
                var menuItems = _view.RecentFilesMenu.MenuItems;
                // Test for null, in case we are running tests with a mock
                if (menuItems == null)
                {
                    return;
                }

                menuItems.Clear();
                int num = 0;
                foreach (string entry in _model.Services.RecentFiles.Entries)
                {
                    var menuText = string.Format("{0} {1}", ++num, entry);
                    var menuItem = new MenuItem(menuText);
                    menuItem.Click += (sender, ea) =>
                    {
                        string path = ((MenuItem)sender).Text.Substring(2);
                        _model.LoadTests(new[] { path });
                    };
                    menuItems.Add(menuItem);
                    if (num >= _settings.Gui.RecentProjects.MaxFiles)
                    {
                        break;
                    }
                }
            };

            _view.ExitCommand.Execute += () => _view.Close();

            _view.DisplayFormat.SelectionChanged += () =>
            {
                _settings.Gui.DisplayFormat = _view.DisplayFormat.SelectedItem;
                InitializeDisplay(_view.DisplayFormat.SelectedItem);
            };

            _view.IncreaseFontCommand.Execute += () =>
            {
                applyFont(IncreaseFont(_settings.Gui.Font));
            };

            _view.DecreaseFontCommand.Execute += () =>
            {
                applyFont(DecreaseFont(_settings.Gui.Font));
            };

            _view.ChangeFontCommand.Execute += () =>
            {
                Font currentFont = _settings.Gui.Font;
                Font newFont     = _view.DialogManager.SelectFont(currentFont);
                if (newFont != _settings.Gui.Font)
                {
                    applyFont(newFont);
                }
            };

            _view.DialogManager.ApplyFont += (font) => applyFont(font);

            _view.RestoreFontCommand.Execute += () =>
            {
                applyFont(Form.DefaultFont);
            };

            _view.IncreaseFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = IncreaseFont(_settings.Gui.FixedFont);
            };

            _view.DecreaseFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = DecreaseFont(_settings.Gui.FixedFont);
            };

            _view.RestoreFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = new Font(FontFamily.GenericMonospace, 8.0f);
            };

            _view.StatusBarCommand.CheckedChanged += () =>
            {
                _view.StatusBarView.Visible = _view.StatusBarCommand.Checked;
            };

            _view.RunAllCommand.Execute      += () => RunAllTests();
            _view.RunSelectedCommand.Execute += () => RunSelectedTests();
            _view.RunFailedCommand.Execute   += () => RunFailedTests();
            _view.StopRunCommand.Execute     += () => CancelRun();

            _view.SaveResultsCommand.Execute += () => SaveResults();

            _view.OpenWorkDirectoryCommand.Execute += () => System.Diagnostics.Process.Start(_model.WorkDirectory);

            _view.ExtensionsCommand.Execute += () =>
            {
                using (var extensionsDialog = new ExtensionDialog(_model.Services.ExtensionService))
                {
                    extensionsDialog.Font = _settings.Gui.Font;
                    extensionsDialog.ShowDialog();
                }
            };

            _view.SettingsCommand.Execute += () =>
            {
                SettingsDialog.Display(this, _model);
            };

            _view.TestCentricHelpCommand.Execute += () =>
            {
                _view.MessageDisplay.Error("Not Yet Implemented");
            };

            _view.NUnitHelpCommand.Execute += () =>
            {
                System.Diagnostics.Process.Start("https://github.com/nunit/docs/wiki/NUnit-Documentation");
            };

            _view.AboutCommand.Execute += () =>
            {
                using (AboutBox aboutBox = new AboutBox())
                {
                    aboutBox.ShowDialog();
                }
            };

            _view.ResultTabs.SelectionChanged += () =>
            {
                _settings.Gui.SelectedTab = _view.ResultTabs.SelectedIndex;
            };

            #endregion
        }
示例#30
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="dialog"></param>
 /// <param name="name"></param>
 public SettingsCustomSkin(SettingsDialog dialog, string name)
     : base(dialog, name, GetCustomSkinList(), (val, index) => OnChange(dialog, val, index), GetSelectedIndex())
 {
 }
        private void FunctionSettings()
        {
            var dialog = new SettingsDialog();

            DialogHost.Show(dialog);
        }
示例#32
0
        private void WireUpEvents()
        {
            // Model Events
            _model.Events.TestsLoading += (ea) =>
            {
                var message = ea.TestFilesLoading.Count == 1 ?
                              $"Loading Assembly: {ea.TestFilesLoading[0]}" :
                              $"Loading {ea.TestFilesLoading.Count} Assemblies...";
                _view.LongRunningOperation.Display(message);
            };

            _model.Events.TestLoaded += (ea) =>
            {
                _view.LongRunningOperation.Hide();
                InitializeMainMenu();
            };

            _model.Events.TestUnloaded += (ea) => InitializeMainMenu();

            _model.Events.TestsReloading += (ea) =>
            {
                _view.LongRunningOperation.Display("Reloading Tests...");
            };

            _model.Events.TestReloaded += (ea) =>
            {
                _view.LongRunningOperation.Hide();
                InitializeMainMenu();
            };

            _model.Events.TestLoadFailure += (TestLoadFailureEventArgs e) =>
            {
                _view.LongRunningOperation.Hide();
                _view.MessageDisplay.Error(e.Exception.Message);
            };

            _model.Events.TestChanged += (ea) =>
            {
                if (_model.Settings.Engine.ReloadOnChange)
                {
                    _model.ReloadTests();
                }
            };

            _model.Events.RunStarting += (ea) => InitializeMainMenu();

            _model.Events.RunFinished += (ea) =>
            {
                _view.LongRunningOperation.Hide();

                SaveResults();
                InitializeMainMenu();
                if (_options.Unattended)
                {
                    _view.Close();
                }
            };

            // View Events
            _view.Load            += MainForm_Load;
            _view.MainViewClosing += MainForm_Closing;
            _view.DragDropFiles   += MainForm_DragDrop;

            _view.NewProjectCommand.Execute   += ProjectSaveNotYetImplemented; // _model.NewProject;
            _view.OpenProjectCommand.Execute  += OnOpenProjectCommand;
            _view.CloseCommand.Execute        += _model.UnloadTests;
            _view.AddTestFilesCommand.Execute += () =>
            {
                var filesToAdd = _view.DialogManager.SelectMultipleFiles("Add Test Files", CreateOpenFileFilter());

                if (filesToAdd.Count > 0)
                {
                    var files = new List <string>(_model.TestFiles);
                    files.AddRange(filesToAdd);

                    _model.LoadTests(files);
                }
            };
            _view.SaveCommand.Execute        += ProjectSaveNotYetImplemented; // _model.SaveProject;
            _view.SaveAsCommand.Execute      += ProjectSaveNotYetImplemented; // _model.SaveProject;
            _view.SaveResultsCommand.Execute += () => SaveResults();
            _view.ReloadTestsCommand.Execute += _model.ReloadTests;
            _view.RecentProjectsMenu.Popup   += PopulateRecentProjectsMenu;

            _view.RunAsX86.CheckedChanged += () =>
            {
                var key = EnginePackageSettings.RunAsX86;
                if (_view.RunAsX86.Checked)
                {
                    OverridePackageSetting(key, true);
                }
                else
                {
                    OverridePackageSetting(key, null);
                }
            };

            _view.ExitCommand.Execute += () => Application.Exit();

            _view.IncreaseFontCommand.Execute += () =>
            {
                ApplyFont(IncreaseFont(_settings.Gui.Font));
            };

            _view.DecreaseFontCommand.Execute += () =>
            {
                ApplyFont(DecreaseFont(_settings.Gui.Font));
            };

            _view.ChangeFontCommand.Execute += () =>
            {
                Font currentFont = _settings.Gui.Font;
                Font newFont     = _view.DialogManager.SelectFont(currentFont);
                if (newFont != _settings.Gui.Font)
                {
                    ApplyFont(newFont);
                }
            };

            _view.RestoreFontCommand.Execute += () =>
            {
                ApplyFont(Form.DefaultFont);
            };

            _view.SettingsCommand.Execute += () =>
            {
                using (var dialog = new SettingsDialog((Form)_view, _settings))
                {
                    dialog.ShowDialog();
                }
            };

            _view.ExtensionsCommand.Execute += () =>
            {
                using (var extensionsDialog = new ExtensionDialog(_model.Services.ExtensionService))
                {
                    extensionsDialog.Font = _settings.Gui.Font;
                    extensionsDialog.ShowDialog();
                }
            };

            _view.NUnitHelpCommand.Execute += () =>
            { MessageBox.Show("This will show Help", "Not Yet Implemented"); };
            _view.AboutNUnitCommand.Execute += () =>
            { MessageBox.Show("This will show the About Box", "Not Yet Implemented"); };

            _view.MainViewClosing += () => _model.Dispose();
        }
        private void WireUpEvents()
        {
            #region Model Events

            _model.Events.TestsLoading += (TestFilesLoadingEventArgs e) =>
            {
                UpdateViewCommands(testLoading: true);

                var message = e.TestFilesLoading.Count == 1 ?
                              $"Loading Assembly: {e.TestFilesLoading[0]}" :
                              $"Loading {e.TestFilesLoading.Count} Assemblies...";

                BeginLongRunningOperation(message);
            };

            _model.Events.TestLoaded += (TestNodeEventArgs e) =>
            {
                OnLongRunningOperationComplete();

                UpdateViewCommands();
                _view.StopRunButton.Visible   = true;
                _view.ForceStopButton.Visible = false;

                _lastFilesLoaded = _model.TestFiles.ToArray();
                if (_lastFilesLoaded.Length == 1)
                {
                    _view.SetTitleBar(_lastFilesLoaded.First());
                }
            };

            _model.Events.TestsUnloading += (TestEventArgse) =>
            {
                UpdateViewCommands();
                _view.StopRunButton.Visible   = true;
                _view.ForceStopButton.Visible = false;

                BeginLongRunningOperation("Unloading...");
            };

            _model.Events.TestUnloaded += (TestEventArgs e) =>
            {
                OnLongRunningOperationComplete();

                UpdateViewCommands();
                _view.StopRunButton.Visible   = true;
                _view.ForceStopButton.Visible = false;
            };

            _model.Events.TestsReloading += (TestEventArgs e) =>
            {
                UpdateViewCommands();

                BeginLongRunningOperation("Reloading...");
            };

            _model.Events.TestReloaded += (TestNodeEventArgs e) =>
            {
                OnLongRunningOperationComplete();

                UpdateViewCommands();
                _view.StopRunButton.Visible   = true;
                _view.ForceStopButton.Visible = false;
            };

            _model.Events.TestLoadFailure += (TestLoadFailureEventArgs e) =>
            {
                OnLongRunningOperationComplete();

                // HACK: Engine should recognize .NET Standard and give the
                // appropriate error message. For now, we compensate for its
                // failure by issuing the message ourselves and reloading the
                // previously loaded  test.
                var  msg = e.Exception.Message;
                bool isNetStandardError =
                    e.Exception.Message == "Unrecognized Target Framework Identifier: .NETStandard";

                if (!isNetStandardError)
                {
                    _view.MessageDisplay.Error(e.Exception.Message);
                    return;
                }

                _view.MessageDisplay.Error("Test assemblies must target a specific platform, rather than .NETStandard.");
                if (_lastFilesLoaded == null)
                {
                    _view.Close();
                }
                else
                {
                    _model.UnloadTests();
                    _model.LoadTests(_lastFilesLoaded);
                }
            };

            _model.Events.RunStarting += (RunStartingEventArgs e) =>
            {
                UpdateViewCommands();
                _view.StopRunButton.Visible    = true;
                _view.ForceStopButton.Visible  = false;
                _view.RunSummaryButton.Visible = false;
            };

            _model.Events.RunFinished += (TestResultEventArgs e) => OnRunFinished(e.Result);

            // Separate internal method for testing
            void OnRunFinished(ResultNode result)
            {
                OnLongRunningOperationComplete();

                UpdateViewCommands();

                // Reset these in case run was cancelled
                _view.StopRunMenuCommand.Visible   = true;
                _view.ForceStopMenuCommand.Visible = false;
                _view.StopRunButton.Visible        = true;
                _view.ForceStopButton.Visible      = false;
                _view.RunSummaryButton.Visible     = true;

                //string resultPath = Path.Combine(TestProject.BasePath, "TestResult.xml");
                // TODO: Use Work Directory
                string resultPath = "TestResult.xml";

                _model.SaveResults(resultPath);
                //try
                //{
                //    _model.SaveResults(resultPath);
                //    //log.Debug("Saved result to {0}", resultPath);
                //}
                //catch (Exception ex)
                //{
                //    //log.Warning("Unable to save result to {0}\n{1}", resultPath, ex.ToString());
                //}

                //if (e.Result.Outcome.Status == TestStatus.Failed)
                //    _view.Activate();

                // If we were running unattended, it's time to close
                if (_options.Unattended)
                {
                    _view.Close();
                }
                else
                {
                    DisplayTestRunSummary(result, true);
                }
            };

            _settings.Changed += (s, e) =>
            {
                switch (e.SettingName)
                {
                case "TestCentric.Gui.GuiLayout":
                    // Settings have changed (from settings dialog)
                    // so we want to update the GUI to match.
                    var newLayout = _settings.Gui.GuiLayout;
                    var oldLayout = _view.GuiLayout.SelectedItem;
                    // Make sure it hasn't already been changed
                    if (oldLayout != newLayout)
                    {
                        // Save position of form for old layout
                        SaveFormLocationAndSize(oldLayout);
                        // Update the GUI itself
                        SetGuiLayout(newLayout);
                        _view.GuiLayout.SelectedItem = newLayout;
                    }
                    break;

                case "TestCentric.Gui.MainForm.ShowStatusBar":
                    _view.StatusBarView.Visible = _settings.Gui.MainForm.ShowStatusBar;
                    break;
                }
            };

            _model.Events.UnhandledException += (UnhandledExceptionEventArgs e) =>
            {
                MessageBoxDisplay.Error($"{e.Message}\n\n{e.StackTrace}", "TestCentric - Internal Error");
            };

            #endregion

            #region View Events

            _view.Load += (s, e) =>
            {
                var guiLayout = _settings.Gui.GuiLayout;
                _view.GuiLayout.SelectedItem = guiLayout;
                SetGuiLayout(guiLayout);

                var settings = _model.PackageOverrides;
                if (_options.MaxAgents >= 0)
                {
                    _model.Settings.Engine.Agents = _options.MaxAgents;
                }
                _view.RunAsX86.Checked = _options.RunAsX86;
            };

            _view.Shown += (s, e) =>
            {
                Application.DoEvents();

                // Load test specified on command line or
                // the most recent one if options call for it
                if (_options.InputFiles.Count != 0)
                {
                    LoadTests(_options.InputFiles);
                }
                else if (_settings.Gui.LoadLastProject && !_options.NoLoad)
                {
                    foreach (string entry in _recentFiles.Entries)
                    {
                        if (entry != null && File.Exists(entry))
                        {
                            LoadTests(entry);
                            break;
                        }
                    }
                }

                //if ( guiOptions.include != null || guiOptions.exclude != null)
                //{
                //    testTree.ClearSelectedCategories();
                //    bool exclude = guiOptions.include == null;
                //    string[] categories = exclude
                //        ? guiOptions.exclude.Split(',')
                //        : guiOptions.include.Split(',');
                //    if ( categories.Length > 0 )
                //        testTree.SelectCategories( categories, exclude );
                //}

                // Run loaded test automatically if called for
                if (_model.IsPackageLoaded && _options.RunAllTests)
                {
                    RunAllTests();
                }
                // Currently, --unattended without --run does nothing except exit.
                else if (_options.Unattended)
                {
                    _view.Close();
                }
            };

            _view.SplitterPositionChanged += (s, e) =>
            {
                _settings.Gui.MainForm.SplitPosition = _view.SplitterPosition;
            };

            _view.FormClosing += (s, e) =>
            {
                if (_model.IsPackageLoaded)
                {
                    if (_model.IsTestRunning)
                    {
                        if (!_view.MessageDisplay.YesNo("A test is running, do you want to forcibly stop the test and exit?"))
                        {
                            e.Cancel = true;
                            return;
                        }

                        _model.StopTestRun(true);
                    }

                    if (CloseProject() == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                    }
                }

                if (!e.Cancel)
                {
                    SaveFormLocationAndSize(_settings.Gui.GuiLayout);
                }
            };

            _view.FileMenu.Popup += () =>
            {
                bool isPackageLoaded = _model.IsPackageLoaded;
                bool isTestRunning   = _model.IsTestRunning;

                _view.OpenCommand.Enabled  = !isTestRunning;
                _view.CloseCommand.Enabled = isPackageLoaded && !isTestRunning;

                _view.ReloadTestsCommand.Enabled = isPackageLoaded && !isTestRunning;

                _view.SelectAgentMenu.Enabled = _agentSelectionController.AllowAgentSelection();

                _view.RunAsX86.Enabled = isPackageLoaded && !isTestRunning;

                _view.RecentFilesMenu.Enabled = !isTestRunning;

                //if (!isTestRunning)
                //{
                //    _recentProjectsMenuHandler.Load();
                //}
            };

            _view.OpenCommand.Execute         += () => OpenProject();
            _view.CloseCommand.Execute        += () => CloseProject();
            _view.AddTestFilesCommand.Execute += () => AddTestFiles();
            _view.ReloadTestsCommand.Execute  += () => ReloadTests();

            _view.SelectAgentMenu.Popup += () =>
            {
                _agentSelectionController.PopulateMenu();
            };

            _view.RunAsX86.CheckedChanged += () =>
            {
                var key = EnginePackageSettings.RunAsX86;
                if (_view.RunAsX86.Checked)
                {
                    ChangePackageSettingAndReload(key, true);
                }
                else
                {
                    ChangePackageSettingAndReload(key, null);
                }
            };

            _view.RecentFilesMenu.Popup += () =>
            {
                var menuItems = _view.RecentFilesMenu.MenuItems;
                // Test for null, in case we are running tests with a mock
                if (menuItems == null)
                {
                    return;
                }

                menuItems.Clear();
                int num = 0;
                foreach (string entry in _model.RecentFiles.Entries)
                {
                    var menuText = string.Format("{0} {1}", ++num, entry);
                    var menuItem = new ToolStripMenuItem(menuText);
                    menuItem.Click += (sender, ea) =>
                    {
                        // HACK: We are loading new files, cancel any runtime override
                        _model.PackageOverrides.Remove(EnginePackageSettings.RequestedRuntimeFramework);
                        string path = ((ToolStripMenuItem)sender).Text.Substring(2);
                        _model.LoadTests(new[] { path });
                    };
                    menuItems.Add(menuItem);
                    if (num >= _settings.Gui.RecentProjects.MaxFiles)
                    {
                        break;
                    }
                }
            };

            _view.ExitCommand.Execute += () => _view.Close();

            _view.GuiLayout.SelectionChanged += () =>
            {
                // Selection menu item has changed, so we want
                // to update both the display and the settings
                var oldLayout = _settings.Gui.GuiLayout;
                var newLayout = _view.GuiLayout.SelectedItem;
                if (oldLayout != newLayout)
                {
                    SaveFormLocationAndSize(oldLayout);
                    SetGuiLayout(newLayout);
                }
                _settings.Gui.GuiLayout = _view.GuiLayout.SelectedItem;
            };

            _view.IncreaseFontCommand.Execute += () =>
            {
                applyFont(IncreaseFont(_settings.Gui.Font));
            };

            _view.DecreaseFontCommand.Execute += () =>
            {
                applyFont(DecreaseFont(_settings.Gui.Font));
            };

            _view.ChangeFontCommand.Execute += () =>
            {
                Font currentFont = _settings.Gui.Font;
                Font newFont     = _view.DialogManager.SelectFont(currentFont);
                if (newFont != _settings.Gui.Font)
                {
                    applyFont(newFont);
                }
            };

            _view.DialogManager.ApplyFont += (font) => applyFont(font);

            _view.RestoreFontCommand.Execute += () =>
            {
                applyFont(Form.DefaultFont);
            };

            _view.IncreaseFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = IncreaseFont(_settings.Gui.FixedFont);
            };

            _view.DecreaseFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = DecreaseFont(_settings.Gui.FixedFont);
            };

            _view.RestoreFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = new Font(FontFamily.GenericMonospace, 8.0f);
            };

            _view.RunAllMenuCommand.Execute      += () => RunAllTests();
            _view.RunSelectedMenuCommand.Execute += () => RunSelectedTests();
            _view.RunFailedMenuCommand.Execute   += () => RunFailedTests();

            _view.RunAllToolbarCommand.Execute      += () => RunAllTests();
            _view.RunSelectedToolbarCommand.Execute += () => RunSelectedTests();
            _view.RunButton.Execute += () =>
            {
                // Necessary test because we don't disable the button click
                if (_model.HasTests && !_model.IsTestRunning)
                {
                    RunAllTests();
                }
                // TODO: This should actually run the last Run action selected in the dropdown
            };

            _view.DebugAllToolbarCommand.Execute      += () => _model.DebugAllTests();
            _view.DebugSelectedToolbarCommand.Execute += () => _model.DebugSelectedTests();
            _view.DebugButton.Execute += () =>
            {
                // Necessary test because we don't disable the button click
                if (_model.HasTests && !_model.IsTestRunning)
                {
                    _model.DebugAllTests();
                }
                // TODO: This should actually run the last Run action selected in the dropdown
            };

            _view.DisplayFormat.SelectionChanged += () =>
            {
                SetTreeDisplayFormat(_view.DisplayFormat.SelectedItem);
            };

            _view.GroupBy.SelectionChanged += () =>
            {
                switch (_view.DisplayFormat.SelectedItem)
                {
                case "TEST_LIST":
                    _settings.Gui.TestTree.TestList.GroupBy = _view.GroupBy.SelectedItem;
                    break;

                case "FIXTURE_LIST":
                    _settings.Gui.TestTree.FixtureList.GroupBy = _view.GroupBy.SelectedItem;
                    break;
                }
            };

            _view.StopRunMenuCommand.Execute += ExecuteNormalStop;
            _view.StopRunButton.Execute      += ExecuteNormalStop;

            _view.ForceStopMenuCommand.Execute += ExecuteForcedStop;
            _view.ForceStopButton.Execute      += ExecuteForcedStop;

            _view.TestParametersMenuCommand.Execute    += DisplayTestParametersDialog;
            _view.TestParametersToolbarCommand.Execute += DisplayTestParametersDialog;

            _view.RunSummaryButton.Execute += () =>
            {
                var result = _model.GetResultForTest(_model.Tests.Id);
                DisplayTestRunSummary(result, false);
            };

            //_view.RunSummaryButton.CheckedChanged += () =>
            //{
            //    if (_view.RunSummaryButton.Checked)
            //    {
            //        var resultId = _model.GetResultForTest(_model.Tests.Id);
            //        var summary = ResultSummaryCreator.FromResultNode(resultId);
            //        string report = ResultSummaryReporter.WriteSummaryReport(summary);
            //        _view.DisplayTestRunSummary(report);
            //    }
            //    else
            //        _view.HideTestRunSummary();
            //};

            _view.ToolsMenu.Popup += () =>
            {
                _view.SaveResultsAsMenu.MenuItems.Clear();

                foreach (string format in _resultFormats)
                {
                    var formatItem = new ToolStripMenuItem(format);
                    formatItem.Click += (s, e) => SaveResults(format);
                    _view.SaveResultsAsMenu.MenuItems.Add(formatItem);
                }
            };

            _view.SaveResultsCommand.Execute += () => SaveResults();

            _view.OpenWorkDirectoryCommand.Execute += () => System.Diagnostics.Process.Start(_model.WorkDirectory);

            _view.ExtensionsCommand.Execute += () =>
            {
                using (var extensionsDialog = new ExtensionDialog(_model.Services.ExtensionService))
                {
                    extensionsDialog.Font = _settings.Gui.Font;
                    extensionsDialog.ShowDialog();
                }
            };

            _view.SettingsCommand.Execute += () =>
            {
                SettingsDialog.Display(this, _model);
            };

            _view.TestCentricHelpCommand.Execute += () =>
            {
                System.Diagnostics.Process.Start("https://test-centric.org/testcentric-gui");
            };

            _view.NUnitHelpCommand.Execute += () =>
            {
                System.Diagnostics.Process.Start("https://docs.nunit.org/articles/nunit/intro.html");
            };

            _view.AboutCommand.Execute += () =>
            {
                using (AboutBox aboutBox = new AboutBox())
                {
                    aboutBox.ShowDialog();
                }
            };

            _view.ResultTabs.SelectionChanged += () =>
            {
                _settings.Gui.SelectedTab = _view.ResultTabs.SelectedIndex;
            };

            #endregion
        }
示例#34
0
        private void WireUpEvents()
        {
            #region Model Events

            _model.Events.TestsLoading += (TestFilesLoadingEventArgs e) =>
            {
                UpdateViewCommands(testLoading: true);

                _longOpDisplay = _view.LongOperationDisplay("Loading...");
            };

            _model.Events.TestLoaded += (TestNodeEventArgs e) =>
            {
                if (_longOpDisplay != null)
                {
                    _longOpDisplay.Dispose();
                    _longOpDisplay = null;
                }

                foreach (var assembly in _model.TestAssemblies)
                {
                    if (assembly.RunState == RunState.NotRunnable)
                    {
                        _view.MessageDisplay.Error(assembly.GetProperty("_SKIPREASON"));
                    }
                }

                UpdateViewCommands();
            };

            _model.Events.TestsUnloading += (TestEventArgse) =>
            {
                UpdateViewCommands();
            };

            _model.Events.TestUnloaded += (TestEventArgs e) =>
            {
                _view.RunSummary.Text = null;

                UpdateViewCommands();
            };

            _model.Events.TestsReloading += (TestEventArgs e) =>
            {
                UpdateViewCommands();

                _longOpDisplay = _view.LongOperationDisplay("Reloading...");
            };

            _model.Events.TestReloaded += (TestNodeEventArgs e) =>
            {
                if (_longOpDisplay != null)
                {
                    _longOpDisplay.Dispose();
                    _longOpDisplay = null;
                }

                //SetTitleBar(TestProject.Name);

                if (_settings.Gui.ClearResultsOnReload)
                {
                    _view.RunSummary.Text = null;
                }

                UpdateViewCommands();
            };

            _model.Events.RunStarting += (RunStartingEventArgs e) =>
            {
                UpdateViewCommands();
            };

            _model.Events.RunFinished += (TestResultEventArgs e) =>
            {
                UpdateViewCommands();

                ResultSummary summary = ResultSummaryCreator.FromResultNode(e.Result);
                _view.RunSummary.Text = string.Format(
                    "Passed: {0}   Failed: {1}   Errors: {2}   Inconclusive: {3}   Invalid: {4}   Ignored: {5}   Skipped: {6}   Time: {7}",
                    summary.PassCount, summary.FailedCount, summary.ErrorCount, summary.InconclusiveCount, summary.InvalidCount, summary.IgnoreCount, summary.SkipCount, summary.Duration);

                //string resultPath = Path.Combine(TestProject.BasePath, "TestResult.xml");
                // TODO: Use Work Directory
                string resultPath = "TestResult.xml";
                _model.SaveResults(resultPath);
                //try
                //{
                //    _model.SaveResults(resultPath);
                //    //log.Debug("Saved result to {0}", resultPath);
                //}
                //catch (Exception ex)
                //{
                //    //log.Warning("Unable to save result to {0}\n{1}", resultPath, ex.ToString());
                //}

                if (e.Result.Outcome.Status == TestStatus.Failed)
                {
                    _view.Activate();
                }
            };

            _settings.Changed += (s, e) =>
            {
                if (e.SettingName == "Gui.Options.DisplayFormat")
                {
                    InitializeDisplay();
                }
            };

            #endregion

            #region View Events

            _view.Load += (s, e) =>
            {
                InitializeDisplay(_settings.Gui.DisplayFormat);

                // Temporary call, so long as IViewControl is used
                InitializeControls((Control)_view);
            };

            _view.Shown += (s, e) =>
            {
                Application.DoEvents();

                // Load test specified on command line or
                // the most recent one if options call for it
                if (_options.InputFiles.Count != 0)
                {
                    LoadTests(_options.InputFiles);
                }
                else if (_settings.Gui.LoadLastProject && !_options.NoLoad)
                {
                    foreach (string entry in _recentFiles.Entries)
                    {
                        if (entry != null && File.Exists(entry))
                        {
                            LoadTests(entry);
                            break;
                        }
                    }
                }

                //if ( guiOptions.include != null || guiOptions.exclude != null)
                //{
                //    testTree.ClearSelectedCategories();
                //    bool exclude = guiOptions.include == null;
                //    string[] categories = exclude
                //        ? guiOptions.exclude.Split(',')
                //        : guiOptions.include.Split(',');
                //    if ( categories.Length > 0 )
                //        testTree.SelectCategories( categories, exclude );
                //}

                // Run loaded test automatically if called for
                if (_model.IsPackageLoaded && _options.RunAllTests)
                {
                    // TODO: Temporary fix to avoid problem when /run is used
                    // with ReloadOnRun turned on. Refactor TestModel so
                    // we can just do a run without reload.
                    bool reload = _settings.Gui.ReloadOnRun;

                    try
                    {
                        _settings.Gui.ReloadOnRun = false;
                        RunAllTests();
                    }
                    finally
                    {
                        _settings.Gui.ReloadOnRun = reload;
                    }
                }
            };

            _view.Move += (s, e) =>
            {
                if (!_view.Maximized)
                {
                    var location = _view.Location;

                    switch (_view.DisplayFormat.SelectedItem)
                    {
                    case "Full":
                    default:
                        _settings.Gui.MainForm.Left      = location.X;
                        _settings.Gui.MainForm.Top       = location.Y;
                        _settings.Gui.MainForm.Maximized = false;
                        break;

                    case "Mini":
                        _settings.Gui.MiniForm.Left      = location.X;
                        _settings.Gui.MiniForm.Top       = location.Y;
                        _settings.Gui.MiniForm.Maximized = false;
                        break;
                    }
                }
            };

            _view.Resize += (s, e) =>
            {
                if (!_view.Maximized)
                {
                    var size = _view.Size;

                    if (_view.DisplayFormat.SelectedItem == "Full")
                    {
                        _settings.Gui.MainForm.Width  = size.Width;
                        _settings.Gui.MainForm.Height = size.Height;
                    }
                    else
                    {
                        _settings.Gui.MiniForm.Width  = size.Width;
                        _settings.Gui.MiniForm.Height = size.Height;
                    }
                }
            };

            _view.SplitterPosition.Changed += () =>
            {
                _settings.Gui.MainForm.SplitPosition = _view.SplitterPosition.Value;
            };

            _view.FormClosing += (s, e) =>
            {
                if (_model.IsPackageLoaded)
                {
                    if (_model.IsTestRunning)
                    {
                        DialogResult dialogResult = _view.MessageDisplay.Ask(
                            "A test is running, do you want to stop the test and exit?");

                        if (dialogResult == DialogResult.No)
                        {
                            e.Cancel = true;
                            return;
                        }

                        _model.CancelTestRun();
                    }

                    if (CloseProject() == DialogResult.Cancel)
                    {
                        e.Cancel = true;
                    }
                }
            };

            _view.RunButton.Execute  += () => RunSelectedTests();
            _view.StopButton.Execute += () => CancelRun();

            _view.FileMenu.Popup += () =>
            {
                bool isPackageLoaded = _model.IsPackageLoaded;
                bool isTestRunning   = _model.IsTestRunning;

                _view.OpenCommand.Enabled  = !isTestRunning;
                _view.CloseCommand.Enabled = isPackageLoaded && !isTestRunning;

                _view.ReloadTestsCommand.Enabled = isPackageLoaded && !isTestRunning;

                var frameworks  = _model.AvailableRuntimes;
                var runtimeMenu = _view.RuntimeMenu;

                runtimeMenu.Visible = frameworks.Count > 1;

                if (runtimeMenu.Visible && runtimeMenu.Enabled && runtimeMenu.MenuItems.Count == 0)
                {
                    var defaultMenuItem = new MenuItem("Default");
                    defaultMenuItem.Name    = "defaultMenuItem";
                    defaultMenuItem.Tag     = "DEFAULT";
                    defaultMenuItem.Checked = true;

                    runtimeMenu.MenuItems.Add(defaultMenuItem);

                    // TODO: Disable selections that are not supported for the target?
                    foreach (IRuntimeFramework framework in frameworks)
                    {
                        MenuItem item = new MenuItem(framework.DisplayName);
                        item.Tag = framework.Id;
                        runtimeMenu.MenuItems.Add(item);
                    }

                    _view.SelectedRuntime.Refresh();
                }

                _view.RecentFilesMenu.Enabled = !isTestRunning;

                //if (!isTestRunning)
                //{
                //    _recentProjectsMenuHandler.Load();
                //}
            };

            _view.OpenCommand.Execute        += () => OpenProject();
            _view.CloseCommand.Execute       += () => CloseProject();
            _view.AddTestFileCommand.Execute += () => AddTestFile();
            _view.ReloadTestsCommand.Execute += () => ReloadTests();

            _view.SelectedRuntime.SelectionChanged += () =>
            {
                ChangePackageSetting(EnginePackageSettings.RuntimeFramework, _view.SelectedRuntime.SelectedItem);
            };

            _view.RecentFilesMenu.Popup += () =>
            {
                var menuItems = _view.RecentFilesMenu.MenuItems;
                // Test for null, in case we are running tests with a mock
                if (menuItems == null)
                {
                    return;
                }

                menuItems.Clear();
                int num = 0;
                foreach (string entry in _model.Services.RecentFiles.Entries)
                {
                    var menuText = string.Format("{0} {1}", ++num, entry);
                    var menuItem = new MenuItem(menuText);
                    menuItem.Click += (sender, ea) =>
                    {
                        string path = ((MenuItem)sender).Text.Substring(2);
                        _model.LoadTests(new[] { path });
                    };
                    menuItems.Add(menuItem);
                }
            };

            _view.ExitCommand.Execute += () => _view.Close();

            _view.DisplayFormat.SelectionChanged += () =>
            {
                _settings.Gui.DisplayFormat = _view.DisplayFormat.SelectedItem;
                InitializeDisplay(_view.DisplayFormat.SelectedItem);
            };

            _view.TreeMenu.Popup += () =>
            {
                TreeNode selectedNode = _view.TreeView.SelectedNode;

                _view.CheckboxesCommand.Checked = _settings.Gui.TestTree.ShowCheckBoxes;

                if (selectedNode != null && selectedNode.Nodes.Count > 0)
                {
                    bool isExpanded = selectedNode.IsExpanded;
                    _view.CollapseCommand.Enabled = isExpanded;
                    _view.ExpandCommand.Enabled   = !isExpanded;
                }
                else
                {
                    _view.CollapseCommand.Enabled = _view.ExpandCommand.Enabled = false;
                }
            };

            _view.CheckboxesCommand.CheckedChanged += () =>
            {
                _settings.Gui.TestTree.ShowCheckBoxes = _view.TreeView.CheckBoxes = _view.CheckboxesCommand.Checked;
            };

            _view.ExpandCommand.Execute += () =>
            {
                _view.TreeView.SelectedNode.Expand();
            };

            _view.CollapseCommand.Execute += () =>
            {
                _view.TreeView.SelectedNode.Collapse();
            };

            _view.ExpandAllCommand.Execute += () =>
            {
                _view.TreeView.ExpandAll();
            };

            _view.CollapseAllCommand.Execute += () =>
            {
                _view.TreeView.CollapseAll();
            };

            _view.HideTestsCommand.Execute += () =>
            {
                _view.TreeView.HideTests();
            };

            _view.PropertiesCommand.Execute += () =>
            {
                if (_view.TreeView.SelectedNode != null)
                {
                    _view.TreeView.ShowPropertiesDialog((TestSuiteTreeNode)_view.TreeView.SelectedNode);
                }
            };

            _view.IncreaseFontCommand.Execute += () =>
            {
                applyFont(IncreaseFont(_settings.Gui.Font));
            };

            _view.DecreaseFontCommand.Execute += () =>
            {
                applyFont(DecreaseFont(_settings.Gui.Font));
            };

            _view.ChangeFontCommand.Execute += () =>
            {
                FontDialog fontDialog = new FontDialog();
                fontDialog.FontMustExist    = true;
                fontDialog.Font             = _settings.Gui.Font;
                fontDialog.MinSize          = 6;
                fontDialog.MaxSize          = 12;
                fontDialog.AllowVectorFonts = false;
                fontDialog.ScriptsOnly      = true;
                fontDialog.ShowEffects      = false;
                fontDialog.ShowApply        = true;
                fontDialog.Apply           += (s, e) =>
                {
                    applyFont(((FontDialog)s).Font);
                };
                if (fontDialog.ShowDialog() == DialogResult.OK)
                {
                    applyFont(fontDialog.Font);
                }
            };

            _view.RestoreFontCommand.Execute += () =>
            {
                applyFont(Form.DefaultFont);
            };

            _view.IncreaseFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = IncreaseFont(_settings.Gui.FixedFont);
            };

            _view.DecreaseFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = DecreaseFont(_settings.Gui.FixedFont);
            };

            _view.RestoreFixedFontCommand.Execute += () =>
            {
                _settings.Gui.FixedFont = new Font(FontFamily.GenericMonospace, 8.0f);
            };

            _view.StatusBarCommand.CheckedChanged += () =>
            {
                _view.StatusBarView.Visible = _view.StatusBarCommand.Checked;
            };

            _view.RunAllCommand.Execute      += () => RunAllTests();
            _view.RunSelectedCommand.Execute += () => RunSelectedTests();
            _view.RunFailedCommand.Execute   += () => RunFailedTests();
            _view.StopRunCommand.Execute     += () => CancelRun();

            _view.ToolsMenu.Popup += () =>
            {
                _view.ProjectEditorCommand.Enabled = File.Exists(_model.ProjectEditorPath);
            };

            _view.ProjectEditorCommand.Execute += () =>
            {
                string editorPath = _settings.Gui.ProjectEditorPath;
                if (editorPath != null && File.Exists(editorPath))
                {
                    System.Diagnostics.Process.Start(editorPath);
                }
            };

            _view.SaveResultsCommand.Execute += () => SaveResults();

            _view.ExtensionsCommand.Execute += () =>
            {
                using (var extensionsDialog = new ExtensionDialog(_model.Services.ExtensionService))
                {
                    extensionsDialog.Font = _settings.Gui.Font;
                    extensionsDialog.ShowDialog();
                }
            };

            _view.SettingsCommand.Execute += () =>
            {
                SettingsDialog.Display(this, _model);
            };

            _view.TestCentricHelpCommand.Execute += () =>
            {
                _view.MessageDisplay.Error("Not Yet Implemented");
            };

            _view.NUnitHelpCommand.Execute += () =>
            {
                System.Diagnostics.Process.Start("https://github.com/nunit/docs/wiki/NUnit-Documentation");
            };

            _view.AboutCommand.Execute += () =>
            {
                using (AboutBox aboutBox = new AboutBox())
                {
                    aboutBox.ShowDialog();
                }
            };

            _view.ResultTabs.SelectionChanged += () =>
            {
                _settings.Gui.SelectedTab = _view.ResultTabs.SelectedIndex;
            };

            #endregion
        }
示例#35
0
        private void ShowSettingsDialog(object sender, EventArgs e)
        {
            var dialog = new SettingsDialog(_package);

            dialog.ShowModal();
        }
示例#36
0
        public async Task ShowSettingsDialog()
        {
            var dialog = new SettingsDialog();

            await ShowDialog(dialog);
        }
示例#37
0
 /// <inheritdoc />
 /// <summary>
 /// </summary>
 /// <param name="dialog"></param>
 /// <param name="name"></param>
 public SettingsCalibrateOffset(SettingsDialog dialog, string name) : base(dialog, name) => CreateExportButton();