From 073170e890689f38b08931f9d894f62a2ad842de Mon Sep 17 00:00:00 2001 From: pinzart Date: Tue, 28 Nov 2023 09:57:12 -0500 Subject: [PATCH 01/15] update --- .../DocumentationBrowserView.xaml.cs | 71 +++++++------- .../DocumentationBrowserViewExtension.cs | 2 +- .../LibraryViewController.cs | 42 +++++++-- .../NotificationCenterController.cs | 92 ++++++++++--------- .../NotificationsViewExtension.cs | 1 + test/DynamoCoreWpfTests/CoreUITests.cs | 3 +- test/DynamoCoreWpfTests/DynamoTestUIBase.cs | 5 +- .../PythonNodeCustomizationTests.cs | 2 +- .../DocumentationBrowserViewExtensionTests.cs | 3 +- .../SystemTestServices/SystemTestBase.cs | 3 +- .../HelixWatch3DViewModelTests.cs | 3 +- 11 files changed, 137 insertions(+), 90 deletions(-) diff --git a/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs b/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs index 766261cab34..dea52d50cb8 100644 --- a/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs +++ b/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Reflection; +using System.Threading.Tasks; using System.Web; using System.Windows; using System.Windows.Controls; @@ -21,7 +22,8 @@ public partial class DocumentationBrowserView : UserControl, IDisposable private readonly DocumentationBrowserViewModel viewModel; private const string VIRTUAL_FOLDER_MAPPING = "appassets"; static readonly string HTML_IMAGE_PATH_PREFIX = @"http://"; - private bool hasBeenInitialized; + private Task hasBeenInitialized; + private bool isDisposing; private ScriptingObject comScriptingObject; private string fontStylePath = "Dynamo.Wpf.Views.GuidedTour.HtmlPages.Resources.ArtifaktElement-Regular.woff"; @@ -104,32 +106,30 @@ private void ShouldAllowNavigation(object sender, CoreWebView2NavigationStarting /// public void NavigateToPage(Uri link) { - InitializeAsync(); + Dispatcher.BeginInvoke(InitializeAsync); } protected virtual void Dispose(bool disposing) { // Cleanup this.viewModel.LinkChanged -= NavigateToPage; - this.documentationBrowser.NavigationStarting -= ShouldAllowNavigation; - this.documentationBrowser.DpiChanged -= DocumentationBrowser_DpiChanged; - - if (this.documentationBrowser.CoreWebView2 != null) + if (this.documentationBrowser != null) { - this.documentationBrowser.CoreWebView2.WebMessageReceived -= CoreWebView2OnWebMessageReceived; - } + this.documentationBrowser.NavigationStarting -= ShouldAllowNavigation; + this.documentationBrowser.DpiChanged -= DocumentationBrowser_DpiChanged; - // Note to test writers - // Disposing the document browser will cause future tests - // that uses the Browser component to crash - if (!Models.DynamoModel.IsTestMode) - { + if (this.documentationBrowser.CoreWebView2 != null) + { + this.documentationBrowser.CoreWebView2.WebMessageReceived -= CoreWebView2OnWebMessageReceived; + } this.documentationBrowser.Dispose(); } } async void InitializeAsync() { + if (isDisposing) return; + VirtualFolderPath = string.Empty; try { @@ -159,7 +159,7 @@ async void InitializeAsync() } // Only initialize once - if (!hasBeenInitialized) + if (hasBeenInitialized == null) { if (!string.IsNullOrEmpty(WebBrowserUserDataFolder)) { @@ -170,21 +170,22 @@ async void InitializeAsync() }; } //Initialize the CoreWebView2 component otherwise we can't navigate to a web page - await documentationBrowser.EnsureCoreWebView2Async(); - - - this.documentationBrowser.CoreWebView2.WebMessageReceived += CoreWebView2OnWebMessageReceived; - comScriptingObject = new ScriptingObject(this.viewModel); - //register the interop object into the browser. - this.documentationBrowser.CoreWebView2.AddHostObjectToScript("bridge", comScriptingObject); - - this.documentationBrowser.CoreWebView2.Settings.IsZoomControlEnabled = true; - this.documentationBrowser.CoreWebView2.Settings.AreDevToolsEnabled = true; - - hasBeenInitialized = true; + hasBeenInitialized = documentationBrowser.EnsureCoreWebView2Async().ContinueWith((_) => { + if (isDisposing) return; + + this.documentationBrowser.CoreWebView2.WebMessageReceived += CoreWebView2OnWebMessageReceived; + comScriptingObject = new ScriptingObject(this.viewModel); + //register the interop object into the browser. + this.documentationBrowser.CoreWebView2.AddHostObjectToScript("bridge", comScriptingObject); + + this.documentationBrowser.CoreWebView2.Settings.IsZoomControlEnabled = true; + this.documentationBrowser.CoreWebView2.Settings.AreDevToolsEnabled = true; + }, TaskScheduler.FromCurrentSynchronizationContext()); } + await hasBeenInitialized; + if (isDisposing) return; - if(Directory.Exists(VirtualFolderPath)) + if (Directory.Exists(VirtualFolderPath)) //Due that the Web Browser(WebView2 - Chromium) security CORS is blocking the load of resources like images then we need to create a virtual folder in which the image are located. this.documentationBrowser.CoreWebView2.SetVirtualHostNameToFolderMapping(VIRTUAL_FOLDER_MAPPING, VirtualFolderPath, CoreWebView2HostResourceAccessKind.DenyCors); @@ -192,10 +193,7 @@ async void InitializeAsync() htmlContent = ResourceUtilities.LoadResourceAndReplaceByKey(htmlContent, "#fontStyle", fontStylePath); - Dispatcher.BeginInvoke(new Action(() => - { - this.documentationBrowser.NavigateToString(htmlContent); - })); + this.documentationBrowser.NavigateToString(htmlContent); } private void CoreWebView2OnWebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs e) @@ -207,8 +205,17 @@ private void CoreWebView2OnWebMessageReceived(object sender, CoreWebView2WebMess /// /// Dispose function for DocumentationBrowser /// - public void Dispose() + public async void Dispose() { + isDisposing = true; + if (Models.DynamoModel.IsTestMode && hasBeenInitialized != null) + { + GC.SuppressFinalize(this); + await hasBeenInitialized; + Dispose(true); + return; + } + Dispose(true); GC.SuppressFinalize(this); } diff --git a/src/DocumentationBrowserViewExtension/DocumentationBrowserViewExtension.cs b/src/DocumentationBrowserViewExtension/DocumentationBrowserViewExtension.cs index b56498864e5..46d6fd85931 100644 --- a/src/DocumentationBrowserViewExtension/DocumentationBrowserViewExtension.cs +++ b/src/DocumentationBrowserViewExtension/DocumentationBrowserViewExtension.cs @@ -178,7 +178,7 @@ public override void Loaded(ViewLoadedParams viewLoadedParams) public override void Shutdown() { - Dispose(); + // Do nothing for now } private void OnInsertFile(object sender, InsertDocumentationLinkEventArgs e) diff --git a/src/LibraryViewExtensionWebView2/LibraryViewController.cs b/src/LibraryViewExtensionWebView2/LibraryViewController.cs index 6c4499fd368..86c9198e165 100644 --- a/src/LibraryViewExtensionWebView2/LibraryViewController.cs +++ b/src/LibraryViewExtensionWebView2/LibraryViewController.cs @@ -18,6 +18,7 @@ using Dynamo.Models; using Dynamo.Search; using Dynamo.Search.SearchElements; +using Dynamo.Utilities; using Dynamo.ViewModels; using Dynamo.Wpf.Interfaces; using Dynamo.Wpf.UI.GuidedTour; @@ -73,6 +74,8 @@ public class LibraryViewController : IDisposable private ICommandExecutive commandExecutive; private DynamoViewModel dynamoViewModel; private FloatingLibraryTooltipPopup libraryViewTooltip; + private Task isInitialized; + bool isDisposing; // private ResourceHandlerFactory resourceFactory; private IDisposable observer; internal WebView2 browser; @@ -319,9 +322,6 @@ internal void AddLibraryView() browser.Loaded += Browser_Loaded; browser.SizeChanged += Browser_SizeChanged; - this.browser = view.mainGrid.Children.OfType().FirstOrDefault(); - InitializeAsync(); - LibraryViewController.SetupSearchModelEventsObserver(browser, dynamoViewModel.Model.SearchModel, this, this.customization); } @@ -350,12 +350,19 @@ async void InitializeAsync() }; } - await browser.EnsureCoreWebView2Async(); - this.browser.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived; - twoWayScriptingObject = new ScriptingObject(this); - //register the interop object into the browser. - this.browser.CoreWebView2.AddHostObjectToScript("bridgeTwoWay", twoWayScriptingObject); - browser.CoreWebView2.Settings.IsZoomControlEnabled = true; + isInitialized = browser.EnsureCoreWebView2Async().ContinueWith((_) => + { + if (isDisposing) return; + + this.browser.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived; + twoWayScriptingObject = new ScriptingObject(this); + //register the interop object into the browser. + this.browser.CoreWebView2.AddHostObjectToScript("bridgeTwoWay", twoWayScriptingObject); + browser.CoreWebView2.Settings.IsZoomControlEnabled = true; + }, TaskScheduler.FromCurrentSynchronizationContext()); + await isInitialized; + + if (isDisposing) return; } private void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs args) @@ -422,6 +429,11 @@ private void Browser_Loaded(object sender, RoutedEventArgs e) { string msg = "Browser Loaded"; LogToDynamoConsole(msg); + + if (!isDisposing) + { + InitializeAsync(); + } } // This enum is for matching the modifier keys between C# and javaScript @@ -712,8 +724,18 @@ internal void LogToDynamoConsole(string message) this.dynamoViewModel.Model.Logger.Log(message); } - public void Dispose() + public async void Dispose() { + isDisposing = true; + + if (Models.DynamoModel.IsTestMode && isInitialized != null) + { + GC.SuppressFinalize(this); + await isInitialized; + Dispose(true); + return; + } + Dispose(true); GC.SuppressFinalize(this); } diff --git a/src/Notifications/NotificationCenterController.cs b/src/Notifications/NotificationCenterController.cs index 7a8a1dd687c..6ec426a63b1 100644 --- a/src/Notifications/NotificationCenterController.cs +++ b/src/Notifications/NotificationCenterController.cs @@ -18,6 +18,7 @@ using Microsoft.Web.WebView2.Wpf; using Dynamo.Utilities; using Dynamo.Configuration; +using System.Threading.Tasks; namespace Dynamo.Notifications { @@ -48,7 +49,7 @@ public void UpdateNotificationWindowSize(int height) } } - public class NotificationCenterController + public class NotificationCenterController : IDisposable { private readonly NotificationUI notificationUIPopup; private readonly DynamoView dynamoView; @@ -68,6 +69,8 @@ public class NotificationCenterController private string jsonStringFile; private NotificationsModel notificationsModel; private const int PopupMaxHeigth = 598; + private Task isInitialized; + private bool isDisposing; internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) { @@ -82,7 +85,6 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) dynamoView.SizeChanged += DynamoView_SizeChanged; dynamoView.LocationChanged += DynamoView_LocationChanged; notificationsButton.Click += NotificationsButton_Click; - dynamoView.Closing += View_Closing; notificationUIPopup = new NotificationUI { @@ -97,50 +99,28 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) // If user turns on the feature, they will need to restart Dynamo to see the count // This ensures no network traffic when Notification center feature is turned off if (dynamoViewModel.PreferenceSettings.EnableNotificationCenter && !dynamoViewModel.Model.NoNetworkMode ) - { - InitializeBrowserAsync(); + { + if (webBrowserUserDataFolder != null) + { + //This indicates in which location will be created the WebView2 cache folder + notificationUIPopup.webView.CreationProperties = new CoreWebView2CreationProperties() + { + UserDataFolder = webBrowserUserDataFolder.FullName + }; + } + notificationUIPopup.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted; + notificationUIPopup.webView.Loaded += WebView_Loaded; + notificationUIPopup.webView.NavigationCompleted += WebView_NavigationCompleted; + RequestNotifications(); } } - private void View_Closing(object sender, System.ComponentModel.CancelEventArgs e) + private void WebView_Loaded(object sender, RoutedEventArgs e) { - dynamoView.Closing -= View_Closing; - SuspendCoreWebviewAsync(); - } - - async void SuspendCoreWebviewAsync() - { - if (notificationUIPopup == null) return; + if (isDisposing) return; - notificationUIPopup.IsOpen = false; - notificationUIPopup.webView.Visibility = Visibility.Hidden; - - if (notificationUIPopup.webView.CoreWebView2 != null) - { - notificationUIPopup.webView.CoreWebView2.Stop(); - notificationUIPopup.webView.CoreWebView2InitializationCompleted -= WebView_CoreWebView2InitializationCompleted; - notificationUIPopup.webView.CoreWebView2.NewWindowRequested -= WebView_NewWindowRequested; - - dynamoView.SizeChanged -= DynamoView_SizeChanged; - dynamoView.LocationChanged -= DynamoView_LocationChanged; - notificationsButton.Click -= NotificationsButton_Click; - notificationUIPopup.webView.NavigationCompleted -= WebView_NavigationCompleted; - } - } - - private void InitializeBrowserAsync() - { - if (webBrowserUserDataFolder != null) - { - //This indicates in which location will be created the WebView2 cache folder - notificationUIPopup.webView.CreationProperties = new CoreWebView2CreationProperties() - { - UserDataFolder = webBrowserUserDataFolder.FullName - }; - } - notificationUIPopup.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted; - notificationUIPopup.webView.EnsureCoreWebView2Async(); + isInitialized = notificationUIPopup.webView.EnsureCoreWebView2Async(); } private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) @@ -180,7 +160,6 @@ private void RequestNotifications() } CountUnreadNotifications(); - notificationUIPopup.webView.NavigationCompleted += WebView_NavigationCompleted; } private void CountUnreadNotifications() @@ -315,5 +294,36 @@ public void RefreshNotifications(string url="") { InvokeJS(@"window.RequestNotifications('" + DynamoUtilities.PathHelper.GetServiceBackendAddress(this, "notificationAddress") + "');"); } } + + public async void Dispose() + { + isDisposing = true; + + if (notificationUIPopup == null) return; + + notificationUIPopup.IsOpen = false; + if (notificationUIPopup.webView != null) + { + if (Models.DynamoModel.IsTestMode && isInitialized != null) + { + await isInitialized; + } + notificationUIPopup.webView.Visibility = Visibility.Hidden; + notificationUIPopup.webView.Loaded -= WebView_Loaded; + + if (notificationUIPopup.webView.CoreWebView2 != null) + { + notificationUIPopup.webView.CoreWebView2.Stop(); + notificationUIPopup.webView.CoreWebView2InitializationCompleted -= WebView_CoreWebView2InitializationCompleted; + notificationUIPopup.webView.CoreWebView2.NewWindowRequested -= WebView_NewWindowRequested; + + dynamoView.SizeChanged -= DynamoView_SizeChanged; + dynamoView.LocationChanged -= DynamoView_LocationChanged; + notificationsButton.Click -= NotificationsButton_Click; + notificationUIPopup.webView.NavigationCompleted -= WebView_NavigationCompleted; + } + notificationUIPopup.webView.Dispose(); + } + } } } diff --git a/src/Notifications/NotificationsViewExtension.cs b/src/Notifications/NotificationsViewExtension.cs index 2840e073f23..21a90e90983 100644 --- a/src/Notifications/NotificationsViewExtension.cs +++ b/src/Notifications/NotificationsViewExtension.cs @@ -68,6 +68,7 @@ public void Dispose() BindingOperations.ClearAllBindings(notificationsMenuItem.CountLabel); } notificationsMenuItem = null; + notificationCenterController?.Dispose(); disposed = true; } } diff --git a/test/DynamoCoreWpfTests/CoreUITests.cs b/test/DynamoCoreWpfTests/CoreUITests.cs index b0b4ffff634..7b7ae64d572 100644 --- a/test/DynamoCoreWpfTests/CoreUITests.cs +++ b/test/DynamoCoreWpfTests/CoreUITests.cs @@ -7,6 +7,7 @@ using System.Windows; using System.Windows.Controls.Primitives; using System.Windows.Input; +using System.Windows.Threading; using CoreNodeModels.Input; using Dynamo.Configuration; using Dynamo.Controls; @@ -819,7 +820,7 @@ private void RestartTestSetupWithNewSettings(Dynamo.Models.DynamoModel.IStartCon //create the view View = new DynamoView(ViewModel); - SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); + SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext()); } #endregion diff --git a/test/DynamoCoreWpfTests/DynamoTestUIBase.cs b/test/DynamoCoreWpfTests/DynamoTestUIBase.cs index 2f7cd01bfb6..296be6f4e4e 100644 --- a/test/DynamoCoreWpfTests/DynamoTestUIBase.cs +++ b/test/DynamoCoreWpfTests/DynamoTestUIBase.cs @@ -14,6 +14,7 @@ using Dynamo.Models; using Dynamo.Nodes; using Dynamo.Scheduler; +using Dynamo.Utilities; using Dynamo.ViewModels; using DynamoCoreWpfTests.Utility; using DynamoShapeManager; @@ -78,7 +79,7 @@ public virtual void Start() View = new DynamoView(ViewModel); View.Show(); - SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); + SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext()); } protected static void RaiseLoadedEvent(FrameworkElement element) @@ -109,6 +110,8 @@ protected virtual DynamoModel.IStartConfiguration CreateStartConfiguration(IPath [TearDown] public void Exit() { + DispatcherUtil.DoEvents(); + //Ensure that we leave the workspace marked as //not having changes. ViewModel.HomeSpace.HasUnsavedChanges = false; diff --git a/test/DynamoCoreWpfTests/PythonNodeCustomizationTests.cs b/test/DynamoCoreWpfTests/PythonNodeCustomizationTests.cs index 6a739b33db4..a07a51bc97f 100644 --- a/test/DynamoCoreWpfTests/PythonNodeCustomizationTests.cs +++ b/test/DynamoCoreWpfTests/PythonNodeCustomizationTests.cs @@ -20,7 +20,7 @@ namespace DynamoCoreWpfTests { - [TestFixture, Category("Failure")] + [TestFixture] public class PythonNodeCustomizationTests : DynamoTestUIBase { bool bTextEnteringEventRaised = false; diff --git a/test/DynamoCoreWpfTests/ViewExtensions/DocumentationBrowserViewExtensionTests.cs b/test/DynamoCoreWpfTests/ViewExtensions/DocumentationBrowserViewExtensionTests.cs index 6d3e73e72d8..15cf0272a9f 100644 --- a/test/DynamoCoreWpfTests/ViewExtensions/DocumentationBrowserViewExtensionTests.cs +++ b/test/DynamoCoreWpfTests/ViewExtensions/DocumentationBrowserViewExtensionTests.cs @@ -144,6 +144,7 @@ public void CanCreatePackageNodeDocumentationAndLoadImages() //There are times in which the URL contain characters like backslash (%5C) then they need to be replaced by the normal slash "/" htmlContent = htmlContent.Replace(@"%5C", "/"); + DispatcherUtil.DoEvents(); // Assert Assert.IsTrue(!string.IsNullOrEmpty(browserView.VirtualFolderPath)); Assert.IsTrue(Directory.Exists(browserView.VirtualFolderPath)); @@ -714,7 +715,7 @@ private string RequestNodeDocs(Dynamo.Graph.Nodes.NodeModel node) return GetSidebarDocsBrowserContents(); } - [Test,Category("Failure")] + [Test] public void AddGraphInSpecificLocationToWorkspace() { //TODO see this issue: diff --git a/test/Libraries/SystemTestServices/SystemTestBase.cs b/test/Libraries/SystemTestServices/SystemTestBase.cs index 9d7a3be1dea..5a26f3ee4fe 100644 --- a/test/Libraries/SystemTestServices/SystemTestBase.cs +++ b/test/Libraries/SystemTestServices/SystemTestBase.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.Threading; +using System.Windows.Threading; using Dynamo.Configuration; using Dynamo.Controls; using Dynamo.Core; @@ -207,7 +208,7 @@ protected virtual void StartDynamo(TestSessionConfiguration testConfig) View = new DynamoView(ViewModel); View.Show(); - SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); + SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext()); } /// diff --git a/test/VisualizationTests/HelixWatch3DViewModelTests.cs b/test/VisualizationTests/HelixWatch3DViewModelTests.cs index b140dd269eb..2253c8280a8 100644 --- a/test/VisualizationTests/HelixWatch3DViewModelTests.cs +++ b/test/VisualizationTests/HelixWatch3DViewModelTests.cs @@ -8,6 +8,7 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media.Media3D; +using System.Windows.Threading; using System.Xml; using CoreNodeModels; using CoreNodeModels.Input; @@ -119,7 +120,7 @@ protected override void StartDynamo(TestSessionConfiguration testConfig) View = new DynamoView(ViewModel); View.Show(); - SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); + SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext()); } /// From 151bbe84c12f04318ae1ce7643a611dcd6fd581d Mon Sep 17 00:00:00 2001 From: pinzart Date: Tue, 28 Nov 2023 13:37:43 -0500 Subject: [PATCH 02/15] Update DynamoTestUIBase.cs --- test/DynamoCoreWpfTests/DynamoTestUIBase.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/DynamoCoreWpfTests/DynamoTestUIBase.cs b/test/DynamoCoreWpfTests/DynamoTestUIBase.cs index 296be6f4e4e..0f585b310fe 100644 --- a/test/DynamoCoreWpfTests/DynamoTestUIBase.cs +++ b/test/DynamoCoreWpfTests/DynamoTestUIBase.cs @@ -41,6 +41,7 @@ protected string ExecutingDirectory [SetUp] public virtual void Start() { + System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.MethodName); var assemblyPath = Assembly.GetExecutingAssembly().Location; preloader = new Preloader(Path.GetDirectoryName(assemblyPath)); preloader.Preload(); @@ -141,6 +142,7 @@ public void Exit() { Console.WriteLine(ex.StackTrace); } + System.Console.WriteLine("Exit test: " + TestContext.CurrentContext.Test.MethodName); } protected virtual void GetLibrariesToPreload(List libraries) From a05f9a12e797940c2a8e3cbf4f786aef7171d896 Mon Sep 17 00:00:00 2001 From: pinzart Date: Tue, 28 Nov 2023 14:24:22 -0500 Subject: [PATCH 03/15] update --- test/DynamoCoreTests/UnitTestBase.cs | 2 ++ test/Libraries/SystemTestServices/SystemTestBase.cs | 3 +++ 2 files changed, 5 insertions(+) diff --git a/test/DynamoCoreTests/UnitTestBase.cs b/test/DynamoCoreTests/UnitTestBase.cs index 425ddc00bfc..882d86d4cec 100644 --- a/test/DynamoCoreTests/UnitTestBase.cs +++ b/test/DynamoCoreTests/UnitTestBase.cs @@ -64,6 +64,7 @@ public static string TestDirectory [SetUp] public virtual void Setup() { + System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.MethodName); SetupDirectories(); if (assemblyHelper == null) @@ -97,6 +98,7 @@ public virtual void Cleanup() { AppDomain.CurrentDomain.AssemblyResolve -= assemblyHelper.ResolveAssembly; } + System.Console.WriteLine("Finish test: " + TestContext.CurrentContext.Test.MethodName); } public string GetNewFileNameOnTempPath(string fileExtension = "dyn") diff --git a/test/Libraries/SystemTestServices/SystemTestBase.cs b/test/Libraries/SystemTestServices/SystemTestBase.cs index 5a26f3ee4fe..0ec8b66ffe6 100644 --- a/test/Libraries/SystemTestServices/SystemTestBase.cs +++ b/test/Libraries/SystemTestServices/SystemTestBase.cs @@ -63,6 +63,7 @@ protected string ExecutingDirectory [SetUp] public virtual void Setup() { + System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.MethodName); var testConfig = GetTestSessionConfiguration(); if (assemblyResolver == null) @@ -140,6 +141,8 @@ public virtual void TearDown() { Console.WriteLine(ex.StackTrace); } + + System.Console.WriteLine("Finish test: " + TestContext.CurrentContext.Test.MethodName); } [OneTimeTearDown] From c78c1a7d7fa1947bc13baf246ba5fcd1530f4c8a Mon Sep 17 00:00:00 2001 From: pinzart Date: Tue, 28 Nov 2023 15:22:04 -0500 Subject: [PATCH 04/15] update --- src/DynamoUtilities/CLIWrapper.cs | 5 +++-- src/DynamoUtilities/DynamoFeatureFlagsManager.cs | 2 +- src/DynamoUtilities/Md2Html.cs | 6 ++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/DynamoUtilities/CLIWrapper.cs b/src/DynamoUtilities/CLIWrapper.cs index 5578e233867..b6040df6a1b 100644 --- a/src/DynamoUtilities/CLIWrapper.cs +++ b/src/DynamoUtilities/CLIWrapper.cs @@ -97,7 +97,7 @@ protected static string GetToolPath(string relativePath) /// /// will return empty string if we don't finish reading all data in the timeout provided in milliseconds. /// - protected virtual async Task GetData(int timeoutms) + protected virtual string GetData(int timeoutms) { var readStdOutTask = Task.Run(() => { @@ -145,7 +145,8 @@ protected virtual async Task GetData(int timeoutms) return writer.ToString(); } }); - var completedTask = await Task.WhenAny(readStdOutTask, Task.Delay(TimeSpan.FromMilliseconds(timeoutms))); + + var completedTask = Task.WhenAny(readStdOutTask, Task.Delay(TimeSpan.FromMilliseconds(timeoutms))).Result; //if the completed task was our read std out task, then return the data //else we timed out, so return an empty string. return completedTask == readStdOutTask ? readStdOutTask.Result : string.Empty; diff --git a/src/DynamoUtilities/DynamoFeatureFlagsManager.cs b/src/DynamoUtilities/DynamoFeatureFlagsManager.cs index d60c886c7c9..de0614bedff 100644 --- a/src/DynamoUtilities/DynamoFeatureFlagsManager.cs +++ b/src/DynamoUtilities/DynamoFeatureFlagsManager.cs @@ -64,7 +64,7 @@ internal void CacheAllFlags() { //wait for response - var dataFromCLI = GetData(featureFlagTimeoutMs).Result; + var dataFromCLI = GetData(featureFlagTimeoutMs); //convert from json string to dictionary. try { diff --git a/src/DynamoUtilities/Md2Html.cs b/src/DynamoUtilities/Md2Html.cs index ceb5908b2a7..532a3268fc1 100644 --- a/src/DynamoUtilities/Md2Html.cs +++ b/src/DynamoUtilities/Md2Html.cs @@ -73,9 +73,7 @@ internal string ParseMd2Html(string mdString, string mdPath) return GetCantCommunicateErrorMessage(); } - var output = GetData(processCommunicationTimeoutms); - - return output.Result; + return GetData(processCommunicationTimeoutms); } /// @@ -104,7 +102,7 @@ internal string SanitizeHtml(string content) var output = GetData(processCommunicationTimeoutms); - return output.Result; + return output; } /// From 28e01632fad2b0e6a0cf561ecc7d640018cb2f5f Mon Sep 17 00:00:00 2001 From: pinzart Date: Tue, 28 Nov 2023 15:24:25 -0500 Subject: [PATCH 05/15] update --- test/DynamoCoreTests/UnitTestBase.cs | 4 ++-- test/DynamoCoreWpfTests/DynamoTestUIBase.cs | 4 ++-- test/Libraries/SystemTestServices/SystemTestBase.cs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/DynamoCoreTests/UnitTestBase.cs b/test/DynamoCoreTests/UnitTestBase.cs index 882d86d4cec..1f831976d30 100644 --- a/test/DynamoCoreTests/UnitTestBase.cs +++ b/test/DynamoCoreTests/UnitTestBase.cs @@ -64,7 +64,7 @@ public static string TestDirectory [SetUp] public virtual void Setup() { - System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.MethodName); + System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.Name); SetupDirectories(); if (assemblyHelper == null) @@ -98,7 +98,7 @@ public virtual void Cleanup() { AppDomain.CurrentDomain.AssemblyResolve -= assemblyHelper.ResolveAssembly; } - System.Console.WriteLine("Finish test: " + TestContext.CurrentContext.Test.MethodName); + System.Console.WriteLine("Finish test: " + TestContext.CurrentContext.Test.Name); } public string GetNewFileNameOnTempPath(string fileExtension = "dyn") diff --git a/test/DynamoCoreWpfTests/DynamoTestUIBase.cs b/test/DynamoCoreWpfTests/DynamoTestUIBase.cs index 0f585b310fe..e73348c3a3c 100644 --- a/test/DynamoCoreWpfTests/DynamoTestUIBase.cs +++ b/test/DynamoCoreWpfTests/DynamoTestUIBase.cs @@ -41,7 +41,7 @@ protected string ExecutingDirectory [SetUp] public virtual void Start() { - System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.MethodName); + System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.Name); var assemblyPath = Assembly.GetExecutingAssembly().Location; preloader = new Preloader(Path.GetDirectoryName(assemblyPath)); preloader.Preload(); @@ -142,7 +142,7 @@ public void Exit() { Console.WriteLine(ex.StackTrace); } - System.Console.WriteLine("Exit test: " + TestContext.CurrentContext.Test.MethodName); + System.Console.WriteLine("Exit test: " + TestContext.CurrentContext.Test.Name); } protected virtual void GetLibrariesToPreload(List libraries) diff --git a/test/Libraries/SystemTestServices/SystemTestBase.cs b/test/Libraries/SystemTestServices/SystemTestBase.cs index 0ec8b66ffe6..9def49330ed 100644 --- a/test/Libraries/SystemTestServices/SystemTestBase.cs +++ b/test/Libraries/SystemTestServices/SystemTestBase.cs @@ -63,7 +63,7 @@ protected string ExecutingDirectory [SetUp] public virtual void Setup() { - System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.MethodName); + System.Console.WriteLine("Start test: " + TestContext.CurrentContext.Test.Name); var testConfig = GetTestSessionConfiguration(); if (assemblyResolver == null) @@ -142,7 +142,7 @@ public virtual void TearDown() Console.WriteLine(ex.StackTrace); } - System.Console.WriteLine("Finish test: " + TestContext.CurrentContext.Test.MethodName); + System.Console.WriteLine("Finish test: " + TestContext.CurrentContext.Test.Name); } [OneTimeTearDown] From eb60fc1daeb3d2ea4c2c4c8750a05539f8680413 Mon Sep 17 00:00:00 2001 From: pinzart Date: Tue, 28 Nov 2023 15:26:13 -0500 Subject: [PATCH 06/15] Update CLIWrapperTests.cs --- test/Libraries/DynamoUtilitiesTests/CLIWrapperTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Libraries/DynamoUtilitiesTests/CLIWrapperTests.cs b/test/Libraries/DynamoUtilitiesTests/CLIWrapperTests.cs index 0657e0b5a70..38c2a96fe6c 100644 --- a/test/Libraries/DynamoUtilitiesTests/CLIWrapperTests.cs +++ b/test/Libraries/DynamoUtilitiesTests/CLIWrapperTests.cs @@ -39,7 +39,7 @@ internal string GetData() { System.Threading.Thread.Sleep(100); process.Kill(); }); - return GetData(2000).Result; + return GetData(2000); } } From fe9a11e852484e4d4b2684e52554fc814a1a0f19 Mon Sep 17 00:00:00 2001 From: pinzart Date: Tue, 28 Nov 2023 23:47:42 -0500 Subject: [PATCH 07/15] update --- .../NotificationCenterController.cs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Notifications/NotificationCenterController.cs b/src/Notifications/NotificationCenterController.cs index 6ec426a63b1..af3e38cebd1 100644 --- a/src/Notifications/NotificationCenterController.cs +++ b/src/Notifications/NotificationCenterController.cs @@ -295,19 +295,13 @@ public void RefreshNotifications(string url="") { } } - public async void Dispose() + private void Dispose(bool disposing) { - isDisposing = true; - if (notificationUIPopup == null) return; notificationUIPopup.IsOpen = false; if (notificationUIPopup.webView != null) { - if (Models.DynamoModel.IsTestMode && isInitialized != null) - { - await isInitialized; - } notificationUIPopup.webView.Visibility = Visibility.Hidden; notificationUIPopup.webView.Loaded -= WebView_Loaded; @@ -325,5 +319,21 @@ public async void Dispose() notificationUIPopup.webView.Dispose(); } } + + public async void Dispose() + { + isDisposing = true; + + if (Models.DynamoModel.IsTestMode && isInitialized != null) + { + GC.SuppressFinalize(this); + await isInitialized; + Dispose(true); + return; + } + + Dispose(true); + GC.SuppressFinalize(this); + } } } From 03e8ade5b8dc68b7ec9442fdd0c332353324e8db Mon Sep 17 00:00:00 2001 From: pinzart Date: Wed, 29 Nov 2023 10:27:43 -0500 Subject: [PATCH 08/15] Update DynamoTestUIBase.cs --- test/DynamoCoreWpfTests/DynamoTestUIBase.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/DynamoCoreWpfTests/DynamoTestUIBase.cs b/test/DynamoCoreWpfTests/DynamoTestUIBase.cs index e73348c3a3c..438355727e0 100644 --- a/test/DynamoCoreWpfTests/DynamoTestUIBase.cs +++ b/test/DynamoCoreWpfTests/DynamoTestUIBase.cs @@ -111,8 +111,6 @@ protected virtual DynamoModel.IStartConfiguration CreateStartConfiguration(IPath [TearDown] public void Exit() { - DispatcherUtil.DoEvents(); - //Ensure that we leave the workspace marked as //not having changes. ViewModel.HomeSpace.HasUnsavedChanges = false; From c82d1fe4532db732bea96c67d23e2fec80a4610a Mon Sep 17 00:00:00 2001 From: pinzart Date: Wed, 29 Nov 2023 10:47:46 -0500 Subject: [PATCH 09/15] Update PackageManagerUITests.cs --- .../PackageManager/PackageManagerUITests.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs b/test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs index 82cd1f00833..d3f8e9d1de1 100644 --- a/test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs +++ b/test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs @@ -1133,10 +1133,13 @@ public void PackageManagerDownloadsBeforeInstalling() .Returns(MessageBoxResult.OK); MessageBoxService.OverrideMessageBoxDuringTests(dlgMock.Object); - //actually perform the download & install operations - pmVmMock.Object.ExecutePackageDownload(id, pkgVer, ""); + Task.Run(() => { + // This test runs on a single thread (using DispatcherSyncronizationContext) + // We need to run the async ExecutePackageDownload function in a separate thread so that the Thread.Sleep call does not cause a deadlock + //actually perform the download & install operations + pmVmMock.Object.ExecutePackageDownload(id, pkgVer, ""); + }).Wait(); - //wait a bit. Thread.Sleep(500); //assert that all downloads are complete before installs, From 83143b58ef5385ef4fb93163069811da9c83d999 Mon Sep 17 00:00:00 2001 From: pinzart Date: Wed, 29 Nov 2023 13:37:29 -0500 Subject: [PATCH 10/15] update --- .../LibraryViewController.cs | 9 ++---- .../NotificationCenterController.cs | 29 +++++++++---------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/LibraryViewExtensionWebView2/LibraryViewController.cs b/src/LibraryViewExtensionWebView2/LibraryViewController.cs index 86c9198e165..dd16b59f766 100644 --- a/src/LibraryViewExtensionWebView2/LibraryViewController.cs +++ b/src/LibraryViewExtensionWebView2/LibraryViewController.cs @@ -123,6 +123,8 @@ internal LibraryViewController(Window dynamoView, ICommandExecutive commandExecu { WebBrowserUserDataFolder = webBrowserUserDataFolder.FullName; } + + InitializeAsync(); } private void DynamoViewModel_PreferencesWindowChanged(object sender, EventArgs e) @@ -361,8 +363,6 @@ async void InitializeAsync() browser.CoreWebView2.Settings.IsZoomControlEnabled = true; }, TaskScheduler.FromCurrentSynchronizationContext()); await isInitialized; - - if (isDisposing) return; } private void CoreWebView2_WebMessageReceived(object sender, CoreWebView2WebMessageReceivedEventArgs args) @@ -429,11 +429,6 @@ private void Browser_Loaded(object sender, RoutedEventArgs e) { string msg = "Browser Loaded"; LogToDynamoConsole(msg); - - if (!isDisposing) - { - InitializeAsync(); - } } // This enum is for matching the modifier keys between C# and javaScript diff --git a/src/Notifications/NotificationCenterController.cs b/src/Notifications/NotificationCenterController.cs index af3e38cebd1..110bbb6a889 100644 --- a/src/Notifications/NotificationCenterController.cs +++ b/src/Notifications/NotificationCenterController.cs @@ -100,27 +100,26 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) // This ensures no network traffic when Notification center feature is turned off if (dynamoViewModel.PreferenceSettings.EnableNotificationCenter && !dynamoViewModel.Model.NoNetworkMode ) { - if (webBrowserUserDataFolder != null) - { - //This indicates in which location will be created the WebView2 cache folder - notificationUIPopup.webView.CreationProperties = new CoreWebView2CreationProperties() - { - UserDataFolder = webBrowserUserDataFolder.FullName - }; - } - notificationUIPopup.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted; - notificationUIPopup.webView.Loaded += WebView_Loaded; - notificationUIPopup.webView.NavigationCompleted += WebView_NavigationCompleted; - + InitializeBrowserAsync(); RequestNotifications(); } } - private void WebView_Loaded(object sender, RoutedEventArgs e) + private async void InitializeBrowserAsync() { - if (isDisposing) return; + if (webBrowserUserDataFolder != null) + { + //This indicates in which location will be created the WebView2 cache folder + notificationUIPopup.webView.CreationProperties = new CoreWebView2CreationProperties() + { + UserDataFolder = webBrowserUserDataFolder.FullName + }; + } + notificationUIPopup.webView.CoreWebView2InitializationCompleted += WebView_CoreWebView2InitializationCompleted; + notificationUIPopup.webView.NavigationCompleted += WebView_NavigationCompleted; isInitialized = notificationUIPopup.webView.EnsureCoreWebView2Async(); + await isInitialized; } private void WebView_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) @@ -303,8 +302,6 @@ private void Dispose(bool disposing) if (notificationUIPopup.webView != null) { notificationUIPopup.webView.Visibility = Visibility.Hidden; - notificationUIPopup.webView.Loaded -= WebView_Loaded; - if (notificationUIPopup.webView.CoreWebView2 != null) { notificationUIPopup.webView.CoreWebView2.Stop(); From 613c704d57c60e0e8fba156311e16e7d4768571c Mon Sep 17 00:00:00 2001 From: pinzart Date: Wed, 29 Nov 2023 14:33:19 -0500 Subject: [PATCH 11/15] Update LibraryViewController.cs --- src/LibraryViewExtensionWebView2/LibraryViewController.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/LibraryViewExtensionWebView2/LibraryViewController.cs b/src/LibraryViewExtensionWebView2/LibraryViewController.cs index dd16b59f766..2149c811191 100644 --- a/src/LibraryViewExtensionWebView2/LibraryViewController.cs +++ b/src/LibraryViewExtensionWebView2/LibraryViewController.cs @@ -123,8 +123,6 @@ internal LibraryViewController(Window dynamoView, ICommandExecutive commandExecu { WebBrowserUserDataFolder = webBrowserUserDataFolder.FullName; } - - InitializeAsync(); } private void DynamoViewModel_PreferencesWindowChanged(object sender, EventArgs e) @@ -323,6 +321,7 @@ internal void AddLibraryView() browser = view.mainGrid.Children.OfType().FirstOrDefault(); browser.Loaded += Browser_Loaded; browser.SizeChanged += Browser_SizeChanged; + InitializeAsync(); LibraryViewController.SetupSearchModelEventsObserver(browser, dynamoViewModel.Model.SearchModel, this, this.customization); From 85e6d94aa659b10efc6e7073f72d52a6ab890619 Mon Sep 17 00:00:00 2001 From: pinzart Date: Wed, 29 Nov 2023 16:01:49 -0500 Subject: [PATCH 12/15] Update DocumentationBrowserView.xaml.cs --- .../DocumentationBrowserView.xaml.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs b/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs index dea52d50cb8..34f80ecfff4 100644 --- a/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs +++ b/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs @@ -111,6 +111,8 @@ public void NavigateToPage(Uri link) protected virtual void Dispose(bool disposing) { + System.Console.WriteLine("documentationBrowser dispose called"); + // Cleanup this.viewModel.LinkChanged -= NavigateToPage; if (this.documentationBrowser != null) @@ -171,6 +173,8 @@ async void InitializeAsync() } //Initialize the CoreWebView2 component otherwise we can't navigate to a web page hasBeenInitialized = documentationBrowser.EnsureCoreWebView2Async().ContinueWith((_) => { + + System.Console.WriteLine("documentationBrowser.EnsureCoreWebView2Async() done"); if (isDisposing) return; this.documentationBrowser.CoreWebView2.WebMessageReceived += CoreWebView2OnWebMessageReceived; From 08be589e801538b56e77798239b24361b2cb5543 Mon Sep 17 00:00:00 2001 From: pinzart Date: Wed, 29 Nov 2023 16:02:52 -0500 Subject: [PATCH 13/15] Update NotificationCenterController.cs --- src/Notifications/NotificationCenterController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Notifications/NotificationCenterController.cs b/src/Notifications/NotificationCenterController.cs index 110bbb6a889..f875d8538f2 100644 --- a/src/Notifications/NotificationCenterController.cs +++ b/src/Notifications/NotificationCenterController.cs @@ -102,7 +102,7 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) { InitializeBrowserAsync(); RequestNotifications(); - } + } } private async void InitializeBrowserAsync() @@ -296,6 +296,8 @@ public void RefreshNotifications(string url="") { private void Dispose(bool disposing) { + System.Console.WriteLine("NotificationCenterControl dispose called"); + if (notificationUIPopup == null) return; notificationUIPopup.IsOpen = false; From f909d6207c82b3901535e3688144ecf535ee0f8a Mon Sep 17 00:00:00 2001 From: pinzart Date: Thu, 30 Nov 2023 10:31:51 -0500 Subject: [PATCH 14/15] update --- .../DocumentationBrowserView.xaml.cs | 3 --- src/Notifications/NotificationCenterController.cs | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs b/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs index 34f80ecfff4..8b3c0774f5f 100644 --- a/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs +++ b/src/DocumentationBrowserViewExtension/DocumentationBrowserView.xaml.cs @@ -111,8 +111,6 @@ public void NavigateToPage(Uri link) protected virtual void Dispose(bool disposing) { - System.Console.WriteLine("documentationBrowser dispose called"); - // Cleanup this.viewModel.LinkChanged -= NavigateToPage; if (this.documentationBrowser != null) @@ -174,7 +172,6 @@ async void InitializeAsync() //Initialize the CoreWebView2 component otherwise we can't navigate to a web page hasBeenInitialized = documentationBrowser.EnsureCoreWebView2Async().ContinueWith((_) => { - System.Console.WriteLine("documentationBrowser.EnsureCoreWebView2Async() done"); if (isDisposing) return; this.documentationBrowser.CoreWebView2.WebMessageReceived += CoreWebView2OnWebMessageReceived; diff --git a/src/Notifications/NotificationCenterController.cs b/src/Notifications/NotificationCenterController.cs index f875d8538f2..3919f5426ba 100644 --- a/src/Notifications/NotificationCenterController.cs +++ b/src/Notifications/NotificationCenterController.cs @@ -296,8 +296,6 @@ public void RefreshNotifications(string url="") { private void Dispose(bool disposing) { - System.Console.WriteLine("NotificationCenterControl dispose called"); - if (notificationUIPopup == null) return; notificationUIPopup.IsOpen = false; From 009732f6c0c155f70cbb815353c6c096b8008880 Mon Sep 17 00:00:00 2001 From: pinzart Date: Thu, 30 Nov 2023 13:14:47 -0500 Subject: [PATCH 15/15] update --- src/DynamoUtilities/CLIWrapper.cs | 5 +---- .../LibraryViewController.cs | 21 +++++++++++-------- .../NotificationCenterController.cs | 7 +++++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/DynamoUtilities/CLIWrapper.cs b/src/DynamoUtilities/CLIWrapper.cs index b6040df6a1b..e4c851ad076 100644 --- a/src/DynamoUtilities/CLIWrapper.cs +++ b/src/DynamoUtilities/CLIWrapper.cs @@ -146,10 +146,7 @@ protected virtual string GetData(int timeoutms) } }); - var completedTask = Task.WhenAny(readStdOutTask, Task.Delay(TimeSpan.FromMilliseconds(timeoutms))).Result; - //if the completed task was our read std out task, then return the data - //else we timed out, so return an empty string. - return completedTask == readStdOutTask ? readStdOutTask.Result : string.Empty; + return readStdOutTask.Wait(timeoutms) ? readStdOutTask.Result : string.Empty; } protected void RaiseMessageLogged(string message) diff --git a/src/LibraryViewExtensionWebView2/LibraryViewController.cs b/src/LibraryViewExtensionWebView2/LibraryViewController.cs index 2149c811191..155e4d84f02 100644 --- a/src/LibraryViewExtensionWebView2/LibraryViewController.cs +++ b/src/LibraryViewExtensionWebView2/LibraryViewController.cs @@ -351,16 +351,19 @@ async void InitializeAsync() }; } - isInitialized = browser.EnsureCoreWebView2Async().ContinueWith((_) => + if (isInitialized == null) { - if (isDisposing) return; - - this.browser.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived; - twoWayScriptingObject = new ScriptingObject(this); - //register the interop object into the browser. - this.browser.CoreWebView2.AddHostObjectToScript("bridgeTwoWay", twoWayScriptingObject); - browser.CoreWebView2.Settings.IsZoomControlEnabled = true; - }, TaskScheduler.FromCurrentSynchronizationContext()); + isInitialized = browser.EnsureCoreWebView2Async().ContinueWith((_) => + { + if (isDisposing) return; + + this.browser.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived; + twoWayScriptingObject = new ScriptingObject(this); + //register the interop object into the browser. + this.browser.CoreWebView2.AddHostObjectToScript("bridgeTwoWay", twoWayScriptingObject); + browser.CoreWebView2.Settings.IsZoomControlEnabled = true; + }, TaskScheduler.FromCurrentSynchronizationContext()); + } await isInitialized; } diff --git a/src/Notifications/NotificationCenterController.cs b/src/Notifications/NotificationCenterController.cs index 3919f5426ba..a67ed58fd1b 100644 --- a/src/Notifications/NotificationCenterController.cs +++ b/src/Notifications/NotificationCenterController.cs @@ -100,13 +100,15 @@ internal NotificationCenterController(DynamoView view, DynamoLogger dynLogger) // This ensures no network traffic when Notification center feature is turned off if (dynamoViewModel.PreferenceSettings.EnableNotificationCenter && !dynamoViewModel.Model.NoNetworkMode ) { - InitializeBrowserAsync(); + notificationUIPopup.webView.Loaded += InitializeBrowserAsync; RequestNotifications(); } } - private async void InitializeBrowserAsync() + private async void InitializeBrowserAsync(object sender, RoutedEventArgs e) { + if (isDisposing) return; + if (webBrowserUserDataFolder != null) { //This indicates in which location will be created the WebView2 cache folder @@ -302,6 +304,7 @@ private void Dispose(bool disposing) if (notificationUIPopup.webView != null) { notificationUIPopup.webView.Visibility = Visibility.Hidden; + notificationUIPopup.webView.Loaded -= InitializeBrowserAsync; if (notificationUIPopup.webView.CoreWebView2 != null) { notificationUIPopup.webView.CoreWebView2.Stop();