Exemple #1
0
        public bool ExecuteWithBackgroundDialogAndSuspendNotifications(Altaxo.Data.DataTable myTable)
        {
            var reporter = new Altaxo.Main.Services.ExternalDrivenBackgroundMonitor();
            var t        = new System.Threading.Thread(() => ExecuteWithSuspendedNotifications(myTable, reporter));

            t.Start();
            return(Current.Gui.ShowBackgroundCancelDialog(1000, t, reporter));
        }
        public static void ShowDialogToVerifyOpeningOfDocumentsWithoutException()
        {
            if (Current.Project.IsDirty)
            {
                var e = new System.ComponentModel.CancelEventArgs();
                Current.IProjectService.AskForSavingOfProject(e);
                if (e.Cancel)
                {
                    return;
                }
            }

            var testOptions = new TestAllProjectsInFolderOptions();

            if (!Current.Gui.ShowDialog(ref testOptions, "Test Altaxo project files on your disk", false))
            {
                return;
            }

            var monitor = new Altaxo.Main.Services.ExternalDrivenBackgroundMonitor();

            Current.Gui.ShowBackgroundCancelDialog(10, () => InternalVerifyOpeningOfDocumentsWithoutExceptionStart(testOptions, monitor), monitor);
        }
		/// <summary>
		/// Executes the script in the background with showing the background dialog. If no instance of the script object exists, a error message will be stored and the return value is false.
		/// If the script object exists, the data change notifications will be switched of (for all tables).
		/// Then the Execute function of this script object is called. Afterwards, the data changed notifications are switched on again.
		/// </summary>
		/// <param name="myColumn">The property column this script is working on.</param>
		/// <returns>True if executed without exceptions, otherwise false.</returns>
		/// <remarks>If exceptions were thrown during execution, the exception messages are stored
		/// inside the column script and can be recalled by the Errors property.</remarks>
		public bool ExecuteWithBackgroundDialogAndSuspendNotifications(Altaxo.Data.DataColumn myColumn)
		{
			var reporter = new Altaxo.Main.Services.ExternalDrivenBackgroundMonitor();
			System.Threading.Thread t = new System.Threading.Thread(() => ExecuteWithSuspendedNotifications(myColumn, reporter));
			t.Start();
			return Current.Gui.ShowBackgroundCancelDialog(1000, reporter, t);
		}
		public static void ShowDialogToVerifyOpeningOfDocumentsWithoutException()
		{
			if (Current.Project.IsDirty)
			{
				var e = new System.ComponentModel.CancelEventArgs();
				Current.ProjectService.AskForSavingOfProject(e);
				if (e.Cancel)
					return;
			}

			var testOptions = new TestAllProjectsInFolderOptions();
			if (!Current.Gui.ShowDialog(ref testOptions, "Test Altaxo project files on your disk", false))
				return;

			var monitor = new Altaxo.Main.Services.ExternalDrivenBackgroundMonitor();
			Current.Gui.ShowBackgroundCancelDialog(10, monitor, () => InternalVerifyOpeningOfDocumentsWithoutExceptionStart(testOptions, monitor));
		}
        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.Dispatcher.InvokeIfRequired(Current.IProjectService.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.Dispatcher.InvokeIfRequired(Current.IProjectService.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.Dispatcher.InvokeIfRequired(() => Current.IProjectService.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.Dispatcher.InvokeIfRequired(Current.IProjectService.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.Dispatcher.InvokeIfRequired(() => Current.IProjectService.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.Dispatcher.InvokeIfRequired(() => Current.IProjectService.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);
        }
        private static void InternalVerifyOpeningOfDocumentsWithoutExceptionStart(TestAllProjectsInFolderOptions testOptions, Altaxo.Main.Services.ExternalDrivenBackgroundMonitor monitor)
        {
            var reporter         = new Reporter(testOptions, Current.Console);
            var oldOutputService = Current.GetService <Services.ITextOutputService>();

            Current.RemoveService <Services.ITextOutputService>();
            Current.AddService <Services.ITextOutputService>(reporter);
            if (!object.ReferenceEquals(Current.Console, reporter))
            {
                throw new InvalidProgramException("Current console now should be the reporter! Please debug.");
            }

            var test = new TestAllProjectsInFolder(reporter, testOptions);

            Current.IProjectService.ProjectChanged += test.EhProjectChanged;

            try
            {
                test.InternalVerifyOpeningOfDocumentsWithoutException(testOptions, monitor);
            }
            catch (Exception ex)
            {
                reporter.WriteLine("Fatal error: Test has to close due to an unhandled exception. The exception details:");
                reporter.WriteLine(ex.ToString());
            }
            finally
            {
                Current.IProjectService.ProjectChanged += test.EhProjectChanged;

                reporter.WriteLine("----------------------- End of test ------------------------------------------");
                reporter.Close();

                Current.RemoveService <Services.ITextOutputService>();
                Current.AddService <Services.ITextOutputService>(oldOutputService);
            }
        }