public override void Cleanup() { try { preloader = null; DynamoSelection.Instance.ClearSelection(); if (ViewModel == null) return; var shutdownParams = new DynamoViewModel.ShutdownParams( shutdownHost: false, allowCancellation: false); ViewModel.PerformShutdownSequence(shutdownParams); ViewModel.RequestUserSaveWorkflow -= RequestUserSaveWorkflow; ViewModel = null; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } base.Cleanup(); }
public void Exit() { //Ensure that we leave the workspace marked as //not having changes. Model.HomeSpace.HasUnsavedChanges = false; if (View.IsLoaded) View.Close(); if (ViewModel != null) { var shutdownParams = new DynamoViewModel.ShutdownParams( shutdownHost: false, allowCancellation: false); ViewModel.PerformShutdownSequence(shutdownParams); ViewModel = null; } View = null; Model = null; GC.Collect(); try { var directory = new DirectoryInfo(TempFolder); directory.Delete(true); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
/// <summary> /// Call this method to initiate DynamoModel shutdown sequence. /// See the definition of ShutdownParams structure for more details. /// </summary> /// <param name="shutdownParams">A set of parameters that control the /// way in which shutdown sequence is to be performed. See ShutdownParams /// for more details.</param> /// <returns>Returns true if the shutdown sequence is started, or false /// otherwise (i.e. when user chooses not to proceed with shutting down /// Dynamo).</returns> /// public bool PerformShutdownSequence(ShutdownParams shutdownParams) { if (shutdownSequenceInitiated) { // There was a prior call to shutdown. This could happen for example // when user presses 'ALT + F4' to close the DynamoView, the 'Exit' // handler calls this method to close Dynamo, which in turn closes // the DynamoView ('OnRequestClose' below). When DynamoView closes, // its "Window.Closing" event fires and "DynamoView.WindowClosing" // gets called before 'PerformShutdownSequence' is called again. // return true; } if (!AskUserToSaveWorkspacesOrCancel(shutdownParams.AllowCancellation)) return false; // 'shutdownSequenceInitiated' is marked as true here indicating // that the shutdown may not be stopped. shutdownSequenceInitiated = true; // Request the View layer to close its window (see // ShutdownParams.CloseDynamoView member for details). if (shutdownParams.CloseDynamoView) OnRequestClose(this, EventArgs.Empty); model.ShutDown(shutdownParams.ShutdownHost); if (shutdownParams.ShutdownHost) { model.UpdateManager.HostApplicationBeginQuit(); } UsageReportingManager.DestroyInstance(); return true; }
private bool PerformShutdownSequenceOnViewModel() { // Test cases that make use of views (e.g. recorded tests) have // their own tear down logic as part of the test set-up (mainly // because DynamoModel should stay long enough for verification // code to verify data much later than the window closing). // if (DynamoModel.IsTestMode) return false; var sp = new DynamoViewModel.ShutdownParams( shutdownHost: false, allowCancellation: true, closeDynamoView: false); if (dynamoViewModel.PerformShutdownSequence(sp)) { //Shutdown wasn't cancelled SizeChanged -= DynamoView_SizeChanged; LocationChanged -= DynamoView_LocationChanged; return true; } else { //Shutdown was cancelled return false; } }
public void SearchHighlightMarginConverterTest() { var converter = new SearchHighlightMarginConverter(); var textBlock = new TextBlock { Width = 50, Height = 10 }; # region dynamoViewModel and searchModel DynamoViewModel dynamoViewModel = DynamoViewModel.Start(); var searchModel = new NodeSearchModel(); # endregion var searhViewModel = new SearchViewModel(dynamoViewModel); object[] array = { textBlock, searhViewModel }; var thickness = new Thickness(0, 0, textBlock.ActualWidth, textBlock.ActualHeight); object result; //1. Array is null. //2. TextBlock.Text is empty. //3. TextBlock contains highlighted phrase. // 1 case Assert.Throws<NullReferenceException>(() => converter.Convert(null, null, null, null)); // 2 case textBlock.Text = ""; array[0] = textBlock; result = converter.Convert(array, null, null, null); Assert.AreEqual(thickness, result); // 3 case // This case we can't check properly, because TextBlock.ActualWidth and TextBlock.ActualHeight equals 0. textBlock.Text = "abcd"; array[0] = textBlock; searhViewModel.SearchText = "a"; thickness = new Thickness(0, 0, -6.6733333333333338, 0); result = converter.Convert(array, null, null, null); Assert.AreEqual(thickness, result); var shutdownParams = new DynamoViewModel.ShutdownParams(shutdownHost: false, allowCancellation: false); dynamoViewModel.PerformShutdownSequence(shutdownParams); }
private void RestartTestSetup(bool startInTestMode) { // Shutdown Dynamo and restart it View.Close(); View = null; if (ViewModel != null) { var shutdownParams = new DynamoViewModel.ShutdownParams( shutdownHost: false, allowCancellation: false); ViewModel.PerformShutdownSequence(shutdownParams); ViewModel = null; } // Setup Temp PreferenceSetting Location for testing PreferenceSettings.DynamoTestPath = Path.Combine(TempFolder, "UserPreferenceTest.xml"); Model = DynamoModel.Start( new DynamoModel.DefaultStartConfiguration() { StartInTestMode = startInTestMode }); ViewModel = DynamoViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = Model }); //create the view View = new DynamoView(ViewModel); View.Show(); SynchronizationContext.SetSynchronizationContext(new SynchronizationContext()); }
private void WindowClosing(object sender, CancelEventArgs e) { // Test cases that make use of views (e.g. recorded tests) have // their own tear down logic as part of the test set-up (mainly // because DynamoModel should stay long enough for verification // code to verify data much later than the window closing). // if (DynamoModel.IsTestMode) return; var sp = new DynamoViewModel.ShutdownParams( shutdownHost: false, allowCancellation: true, closeDynamoView: false); if (dynamoViewModel.PerformShutdownSequence(sp)) { SizeChanged -= DynamoView_SizeChanged; LocationChanged -= DynamoView_LocationChanged; } }