private void InternalVerifyOpeningOfDocumentsWithoutException(TestAllProjectsInFolderOptions testOptions, Altaxo.Main.Services.ExternalDrivenBackgroundMonitor monitor) { monitor.ReportProgress("Searching Altaxo project files ...", 0); var path = testOptions.FolderPaths; Current.Console.WriteLine("Begin of test. Search path(s): {0}", path); var filelist = GetAltaxoProjectFileNames(path); int numberOfProjectsTested = 0; int numberOfProjectsFailedToLoad = 0; double totalFilesToTest = filelist.Count; monitor.ReportProgress(string.Format("Searching done, {0} Altaxo project files found.", totalFilesToTest)); foreach (var filename in filelist) { if (monitor.CancellationPending) break; try { System.Diagnostics.Debug.WriteLine(string.Format("Begin opening Altaxo project file {0}", filename)); monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Currently opening: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); ++numberOfProjectsTested; Current.Gui.Execute(Current.ProjectService.OpenProject, filename, true); monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Loaded successfully: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); System.Threading.Thread.Sleep(1000); } catch (Exception) { ++numberOfProjectsFailedToLoad; monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Failed to load: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); Current.Console.WriteLine("Error opening file {0}", filename); } // Project is now opened from the original file #if DEBUG && TRACEDOCUMENTNODES { GC.Collect(); System.Threading.Thread.Sleep(500); bool areThereAnyProblems = false; areThereAnyProblems |= Main.SuspendableDocumentNodeBase.ReportNotConnectedDocumentNodes(false); areThereAnyProblems |= Main.SuspendableDocumentNode.ReportChildListProblems(); areThereAnyProblems |= Main.SuspendableDocumentNode.ReportWrongChildParentRelations(); if (areThereAnyProblems) { Current.Console.WriteLine("Above listed problems were detected after opening the file {0}", filename); Current.Console.WriteLine(); } } #endif if (testOptions.TestSavingAndReopening) { // Test saving of the project (now with the current version of Altaxo) string tempFileName = System.IO.Path.GetTempFileName(); try { monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Currently saving: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); Current.Gui.Execute(Current.ProjectService.SaveProject, tempFileName); monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Saved successfully: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); } catch (Exception) { ++numberOfProjectsFailedToLoad; monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Failed to save: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); Current.Console.WriteLine("Error saving file {0}", filename); } // Close the project now try { Current.Gui.Execute(Current.ProjectService.CloseProject, true); System.Threading.Thread.Sleep(1000); } catch (Exception ex) { Current.Console.WriteLine("Error closing file (after saving) {0}; Message: {1}", filename, ex); Current.Console.WriteLine("Operation will be stopped here because of error on closing"); return; } // Re-Open the project try { monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Currently re-opening: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); Current.Gui.Execute(Current.ProjectService.OpenProject, tempFileName, true); monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Re-opened successfully: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); System.Threading.Thread.Sleep(1000); } catch (Exception ex) { ++numberOfProjectsFailedToLoad; monitor.ReportProgress(string.Format( "Successfully loaded: {0}, failed to load: {1}, total: {2}/{3} projects.\r\n" + "Failed to re-open: {4}", numberOfProjectsTested - numberOfProjectsFailedToLoad, numberOfProjectsFailedToLoad, numberOfProjectsTested, totalFilesToTest, filename), numberOfProjectsTested / totalFilesToTest); Current.Console.WriteLine("Error re-opening file {0}, Message: {1}", filename, ex); } #if DEBUG && TRACEDOCUMENTNODES { GC.Collect(); System.Threading.Thread.Sleep(500); bool areThereAnyProblems = false; areThereAnyProblems |= Main.SuspendableDocumentNodeBase.ReportNotConnectedDocumentNodes(false); areThereAnyProblems |= Main.SuspendableDocumentNode.ReportChildListProblems(); areThereAnyProblems |= Main.SuspendableDocumentNode.ReportWrongChildParentRelations(); if (areThereAnyProblems) { Current.Console.WriteLine("Above listed problems were detected after saving and reopening project {0}", filename); Current.Console.WriteLine(); } } #endif // Close the project now try { Current.Gui.Execute(Current.ProjectService.CloseProject, true); System.Threading.Thread.Sleep(1000); } catch (Exception ex) { Current.Console.WriteLine("Error closing file (after re-opening it) {0}; Message: {1}", filename, ex); Current.Console.WriteLine("Operation will be stopped here because of error on closing"); return; } // delete the temporary project try { System.IO.File.Delete(tempFileName); } catch (Exception ex) { Current.Console.WriteLine("Error deleting temporary Altaxo project file {0}, original from file {1}; Message: {2}", tempFileName, filename, ex.Message); } } else { try { Current.Gui.Execute(Current.ProjectService.CloseProject, true); System.Threading.Thread.Sleep(1000); } catch (Exception ex) { Current.Console.WriteLine("Error closing file {0}; Message: {1}", filename, ex); Current.Console.WriteLine("Operation will be stopped here because of error on closing"); return; } } } Current.Console.WriteLine("End of test. {0} projects tested, {1} projects failed to load", numberOfProjectsTested, numberOfProjectsFailedToLoad); }