private static List <string> BuildAssemblyList([NotNull] TestRunnerControlViewModel testRunnerControlViewModel) { var selectedAssemblyList = testRunnerControlViewModel.SelectedAssemblies.ToList(); if (!testRunnerControlViewModel.CopyDllsToNewFolder) { return(selectedAssemblyList); } var assemblyList = new List <string>(); string tempPath = Path.GetTempPath(); string tempFolder = Path.Combine(tempPath, "StarkBIM"); if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } foreach (var assembly in selectedAssemblyList) { string sourceDirectory = Path.GetDirectoryName(assembly).ThrowIfNull(); var folderName = $"{DateTime.Now.Ticks}"; var destinationDirectory = Path.Combine(tempFolder, folderName); Directory.CreateDirectory(destinationDirectory); // Now Create all of the directories foreach (string dirPath in Directory.GetDirectories(sourceDirectory, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(sourceDirectory, destinationDirectory)); } // Copy all the files & Replaces any files with the same name foreach (string newPath in Directory.GetFiles(sourceDirectory, "*.*", SearchOption.AllDirectories)) { File.Copy(newPath, newPath.Replace(sourceDirectory, destinationDirectory), true); } string newAssembly = assembly.Replace(sourceDirectory, destinationDirectory); assemblyList.Add(newAssembly); } return(assemblyList); }
/// <inheritdoc /> public Result Execute([NotNull] ExternalCommandData commandData, [CanBeNull] ref string message, [CanBeNull][ItemNotNull] ElementSet elements) { try { CommandData = commandData ?? throw new ArgumentNullException(nameof(commandData)); var testRunnerControlViewModel = new TestRunnerControlViewModel(); var mainWindowHandlePtr = Process.GetCurrentProcess().MainWindowHandle; var testRunnerWindow = new TestRunnerWindow { DataContext = testRunnerControlViewModel, WindowStartupLocation = WindowStartupLocation.CenterOwner }; // ReSharper disable once UnusedVariable var wih = new WindowInteropHelper(testRunnerWindow) { Owner = mainWindowHandlePtr }; if (testRunnerWindow.ShowDialog() != true) { return(Result.Cancelled); } List <string> selectedAssemblyList = testRunnerControlViewModel.SelectedAssemblies.ToList(); if (!selectedAssemblyList.Any()) { TaskDialog.Show("Error", "No assemblies selected"); return(Result.Failed); } var nonExistentAssemblies = selectedAssemblyList.Where(a => !File.Exists(a)).ToList(); if (nonExistentAssemblies.Any()) { TaskDialog.Show("Error", $"One or more assemblies does not exist: {nonExistentAssemblies.JoinList(", ")}"); return(Result.Failed); } var assemblyList = selectedAssemblyList.Select(selectedAssembly => ((string AssemblyFileName, string Config))(selectedAssembly, null)).ToList(); Stopwatch stopWatch = Stopwatch.StartNew(); RvtRunnerLogger logger = new RvtRunnerLogger(stopWatch); var testRunner = new TestRunner(logger); var result = testRunner.Run(assemblyList); stopWatch.Stop(); string allMessages = logger.AllMessages.JoinList(); new TaskDialog("Result") { MainInstruction = $"Failing tests: {result}. Total time elapsed: {stopWatch.Elapsed}", ExpandedContent = allMessages }.Show(); Debug.WriteLine(result); } catch (Exception ex) { TaskDialog.Show("Error", $"{ex.GetType()} - {ex.Message}"); return(Result.Failed); } finally { CommandData = null; } return(Result.Succeeded); }