private static void ShowInternal(string title, string content, bool hasLinks, IconType iconType) { var window = new UserPromptWindow(); window.Title = title; window.GenerateContent(content, hasLinks); var iconMap = new Dictionary <IconType, Icon> { [IconType.Error] = SystemIcons.Error, [IconType.Warning] = SystemIcons.Warning, [IconType.Information] = SystemIcons.Information, }; window.icon.Source = GetIcon(iconMap[iconType]); window.button.Click += (s, e) => { window.Close(); }; window.Owner = App.Current.MainWindow; window.ShowDialog(); }
private void LoadProfile() { try { Microsoft.Win32.OpenFileDialog openFileDialog = new Win32.OpenFileDialog(); openFileDialog.Filter = StringResources.TestProfileFilter; string initialDir = System.IO.Path.Combine(util.AppConfig.AppDataDirectory, StringResources.TestProfileFolder); if (Directory.Exists(initialDir)) { openFileDialog.InitialDirectory = initialDir; } if (openFileDialog.ShowDialog() != true) { return; } string profile = openFileDialog.FileName, newProfile; if (util.TryUpgradeProfileSettings(profile, out newProfile)) { UserPromptWindow.Show(StringResources.Information, String.Format(StringResources.PtmProfileUpgraded, newProfile), UserPromptWindow.IconType.Information); profile = newProfile; } LoadProfile(profile); } catch (Exception e) { UserPromptWindow.Show(StringResources.Error, e.Message, UserPromptWindow.IconType.Error); return; } }
public static void LogExceptionAndPrompt(string title, IEnumerable <Exception> exceptions) { string logPath = Utility.LogException(exceptions.ToList()); string errorMsg = string.Format(StringResources.ExceptionsHappendWithLogsRecorded, logPath); UserPromptWindow.ShowWithLinks(title, errorMsg, UserPromptWindow.IconType.Error); }
private void BeginDetection() { this.ButtonNext.Content = StringResources.StopDetectButton; this.detectionRunning = true; Pages.AutoDetectionPage.ResetSteps(); detectionFinished = false; SetButtonsStatus(false, true); this.ListBox_Step.IsEnabled = false; Pages.AutoDetectionPage.PropertyListBox.IsEnabled = false; try { if (util.SetPrerequisits() != true) { throw new Exception(StringResources.InvalidValue); } } catch (Exception e) { UserPromptWindow.Show(StringResources.Error, e.Message, UserPromptWindow.IconType.Error); SetButtonsStatus(true, true); this.ListBox_Step.IsEnabled = true; Pages.AutoDetectionPage.PropertyListBox.IsEnabled = true; return; } this.Dispatcher.Invoke((Action)(() => { this.ListBox_Step.IsEnabled = true; })); util.StartDetection((o) => { this.Dispatcher.Invoke((Action)(() => { detectionRunning = false; if (o.Status == DetectionStatus.Finished) { this.ButtonNext.Content = StringResources.NextButton; } else { this.ButtonNext.Content = StringResources.DetectButton; UserPromptWindow.Show(StringResources.Error, o.Exception.Message, UserPromptWindow.IconType.Error); } SetButtonsStatus(true, true); Pages.AutoDetectionPage.PropertyListBox.IsEnabled = true; if (o.Status == DetectionStatus.Finished) { detectionFinished = true; } })); }); }
private void RunTestCaseClicked(List <TestCase> testcases) { if (testcases == null || testcases.Count == 0) { UserPromptWindow.Show(StringResources.Warning, StringResources.NoTestCaseSelected, UserPromptWindow.IconType.Warning); return; } util.SaveLastProfile(); Pages.RunPage.TotalResults.Visibility = System.Windows.Visibility.Hidden; Pages.RunPage.TotalResultsLinkText.Text = ""; SetButtonsStatus(false, false); this.ListBox_Step.IsEnabled = false; Pages.RunPage.EnableControls = false; util.RunByCases(testcases); }
protected override void OnStartup(StartupEventArgs e) { bool isNewInstance = false; mutex = new Mutex(true, "{FE998190-5B44-4816-9A65-295E8A1EBBA1}", out isNewInstance); if (!isNewInstance) { UserPromptWindow.Show(StringResources.Error, StringResources.PTMRunning, UserPromptWindow.IconType.Error); mutex = null; App.Current.Shutdown(); return; } base.OnStartup(e); }
private void SaveProfile_Click(object sender, RoutedEventArgs e) { try { Microsoft.Win32.SaveFileDialog savefile = new Win32.SaveFileDialog(); savefile.Filter = StringResources.TestProfileFilter; if (savefile.ShowDialog() == true) { Pages.util.SaveProfileSettings(savefile.FileName); } } catch (Exception exception) { UserPromptWindow.Show(StringResources.Error, exception.Message, UserPromptWindow.IconType.Error); return; } }
private void ExportCheckedPlaylist_Click(object sender, RoutedEventArgs e) { try { Microsoft.Win32.SaveFileDialog savefile = new Win32.SaveFileDialog(); savefile.Filter = StringResources.PlaylistFilter; if (savefile.ShowDialog() == true) { Pages.util.ExportPlaylist(savefile.FileName, true); } } catch (Exception exception) { UserPromptWindow.Show(StringResources.Error, exception.Message, UserPromptWindow.IconType.Error); return; } }
private void GenerateReport_Click(object sender, RoutedEventArgs e) { var caselist = Pages.util.SelectTestCases( Passed.IsChecked == true, Failed.IsChecked == true, Inconclusive.IsChecked == true, false); if (caselist.Count == 0) { UserPromptWindow.Show(StringResources.Error, StringResources.NoTestCaseSelected, UserPromptWindow.IconType.Error); return; } var selectedRadioButton = ReportFormatGroup.Children.OfType <RadioButton>().FirstOrDefault(rb => rb.IsChecked == true); if (selectedRadioButton == null) { UserPromptWindow.Show(StringResources.Error, StringResources.NoReportFormatSelected, UserPromptWindow.IconType.Error); return; } TestReport report = TestReport.GetInstance(selectedRadioButton.Name, caselist); if (report == null) { UserPromptWindow.Show(StringResources.Error, StringResources.UnknownReportFormat, UserPromptWindow.IconType.Error); return; } Microsoft.Win32.SaveFileDialog saveFileDialog = new Win32.SaveFileDialog(); saveFileDialog.Filter = report.FileDialogFilter; saveFileDialog.DefaultExt = report.FileExtension; if (saveFileDialog.ShowDialog() == true) { report.ExportReport(saveFileDialog.FileName); DialogResult = true; } }
private void ImportPlaylist_Click(object sender, RoutedEventArgs e) { try { Microsoft.Win32.OpenFileDialog openfile = new Win32.OpenFileDialog(); openfile.Filter = StringResources.PlaylistFilter; if (openfile.ShowDialog() == true) { int checkedNumber, notFound; Pages.util.ImportPlaylist(openfile.FileName); Pages.util.ApplyPlaylist(out checkedNumber, out notFound); if (notFound > 0) { UserPromptWindow.Show(StringResources.Error, string.Format(StringResources.NotFoundCaseMessage, notFound), UserPromptWindow.IconType.Error); } } } catch (Exception exception) { UserPromptWindow.Show(StringResources.Error, exception.Message, UserPromptWindow.IconType.Error); return; } }
private void RegisterEvents() { Pages.TestSuiteWindow.Launch_Click = (u) => { if (u.IsInstalled) { try { util.LoadTestSuiteConfig(u); util.LoadTestSuiteAssembly(); } catch (Exception e) { UserPromptWindow.Show(StringResources.Error, e.Message, UserPromptWindow.IconType.Error); return; } ListBox_Step.SelectedIndex = welcomeIndex; Pages.WelcomePage.LoadPage(new Uri(util.AppConfig.UserGuide)); DisableFollowingItems(); util.InitializeDetector(); if (util.AppConfig.PredefinedAdapters != null && util.AppConfig.PredefinedAdapters.Count > 0) { enableConfigureAdapter = true; Item_Adapter.Visibility = System.Windows.Visibility.Visible; } else { Item_Adapter.Visibility = System.Windows.Visibility.Collapsed; } Title = string.Format(StringResources.TitleFormat, util.AppConfig.TestSuiteName, util.AppConfig.TestSuiteVersion); } if (u.InstallStatus == InstallStatus.MSIAvailable) { System.Diagnostics.Process p = new System.Diagnostics.Process() { StartInfo = new System.Diagnostics.ProcessStartInfo { FileName = u.Installer } }; p.Start(); } }; Pages.TestSuiteWindow.Run_Click = (u) => { try { util.LoadTestSuiteConfig(u); util.LoadTestSuiteAssembly(); if (util.AppConfig.PredefinedAdapters != null && util.AppConfig.PredefinedAdapters.Count > 0) { enableConfigureAdapter = true; Item_Adapter.Visibility = System.Windows.Visibility.Visible; } else { Item_Adapter.Visibility = System.Windows.Visibility.Collapsed; } isAutoDetected = false; util.InitializeDetector(); // Last profile should always on the correct version, no need to upgrade this profile LoadProfile(util.LastRuleSelectionFilename); } catch (Exception e) { UserPromptWindow.Show(StringResources.Error, e.Message, UserPromptWindow.IconType.Error); return; } }; Pages.ConfigMethodPage.AutoDetectClicked = () => { if (MessageBox.Show(StringResources.AutoDetectWarning, StringResources.AutoDetectWarningTitle, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { isAutoDetected = true; util.LoadPtfconfig(); Pages.AutoDetectionPage.SetPrerequisits(util.GetPrerequisits()); Pages.AutoDetectionPage.SetDetectionSteps(util.GetDetectSteps()); ListBox_Step.SelectedIndex = detectionIndex; DisableFollowingItems(); } }; Pages.ConfigMethodPage.ManualConfigClicked = () => { isAutoDetected = false; util.LoadPtfconfig(); util.InitializeDetector(); ListBox_Step.SelectedIndex = ruleIndex; UpdateCaseFilter(); DisableFollowingItems(); DisableDetectSteps(); }; Pages.ConfigMethodPage.LoadSettingsClicked = LoadProfile; Pages.AutoDetectionPage.ContentChanged += (s, e) => { if (detectionFinished) { isAutoDetected = true; detectionFinished = false; this.ButtonNext.Content = StringResources.DetectButton; Pages.AutoDetectionPage.ResetSteps(); DisableFollowingItems(); } }; Pages.RunPage.RunTestClicked = RunTestCaseClicked; Pages.RunPage.RunAllTestClicked = RunTest; Pages.RunPage.TotalResultsLink.Click += (s, e) => { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "explorer.exe"; if (!string.IsNullOrEmpty(util.GetLogger().IndexHtmlFilePath)) { startInfo.Arguments = util.GetLogger().IndexHtmlFilePath; } else { startInfo.Arguments = System.IO.Path.Combine(util.AppConfig.TestSuiteDirectory, AppConfig.HtmlResultFolderName); } Process.Start(startInfo); }; }
private void GotoRunPage() { util.InitializeTestEngine(); util.TestFinished += (s, e) => { this.Dispatcher.BeginInvoke((Action)(() => { Logger log = util.GetLogger(); Pages.RunPage.TotalResults.Visibility = System.Windows.Visibility.Visible; Pages.RunPage.TotalResultsLinkText.Focusable = true; Pages.RunPage.TotalResultsLinkText.Text = String.Format("{0} / {1} Passed", e.Passed, util.SelectedCaseCount); if (e.Failed != 0) { Pages.RunPage.TotalResultsLinkText.Text += String.Format(", {0} Failed", e.Failed); } if (e.Inconclusive != 0) { Pages.RunPage.TotalResultsLinkText.Text += String.Format(", {0} Inconclusive", e.Inconclusive); } SetButtonsStatus(true, false); this.ListBox_Step.IsEnabled = true; Pages.RunPage.EnableControls = true; Pages.AutoDetectionPage.PropertyListBox.IsEnabled = true; if (e.Exception.Count > 0) { App.LogExceptionAndPrompt(StringResources.Error, e.Exception); } else { var counts = new int[] { e.Passed, e.Failed, e.Inconclusive }; if (counts.All(count => count == 0)) { UserPromptWindow.Show(StringResources.Error, StringResources.NoTestExecuted, UserPromptWindow.IconType.Error); } } })); }; Pages.RunPage.TotalResults.Visibility = System.Windows.Visibility.Hidden; Pages.RunPage.TotalResultsLinkText.Text = ""; Logger logger = util.GetLogger(); logger.GroupByOutcome.UpdateTestCaseStatus = (from, to, testcase) => { this.Dispatcher.Invoke((Action)(() => { from.RemoveTestCase(testcase); to.AddTestCase(testcase); })); }; logger.GroupByOutcome.UpdateTestCaseList = (group, runningcase) => { this.Dispatcher.Invoke((Action)(() => { int index = group.TestCaseList.IndexOf(runningcase); if (index > 0) { group.TestCaseList.Move(index, 0); } })); }; Pages.RunPage.SetLogger(logger); }