Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/DynamoDS/Dynamo
Browse files Browse the repository at this point in the history
  • Loading branch information
zeusongit committed Feb 13, 2025
2 parents 72ace7a + b00145d commit b707fad
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 55 deletions.
11 changes: 5 additions & 6 deletions src/DynamoCore/Graph/Nodes/NodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1223,18 +1223,17 @@ protected NodeModel(IEnumerable<PortModel> inPorts, IEnumerable<PortModel> outPo
RaisesModificationEvents = true;
}


internal protected AssemblyName NameOfAssemblyReferencedByNode = null;

/// <summary>
/// The method returns the assembly name from which the node originated.
/// </summary>
/// <returns>Assembly Name</returns>
internal virtual AssemblyName GetNameOfAssemblyReferencedByNode()
{
AssemblyName assemblyName = null;

var assembly = this.GetType().Assembly;
assemblyName = AssemblyName.GetAssemblyName(assembly.Location);

return assemblyName;
NameOfAssemblyReferencedByNode ??= GetType().Assembly.GetName();
return NameOfAssemblyReferencedByNode;
}

/// <summary>
Expand Down
13 changes: 7 additions & 6 deletions src/DynamoCore/Graph/Nodes/ZeroTouch/DSFunctionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ public override IdentifierNode GetAstIdentifierForOutputIndex(int outputIndex)
/// <returns>Assembly Name</returns>
internal override AssemblyName GetNameOfAssemblyReferencedByNode()
{
AssemblyName assemblyName = null;

var descriptor = this.Controller.Definition;
if (descriptor.IsPackageMember)
if (NameOfAssemblyReferencedByNode == null)
{
assemblyName = AssemblyName.GetAssemblyName(descriptor.Assembly);
var descriptor = this.Controller.Definition;
if (descriptor.IsPackageMember)
{
NameOfAssemblyReferencedByNode = AssemblyName.GetAssemblyName(descriptor.Assembly);
}
}

return assemblyName;
return NameOfAssemblyReferencedByNode;
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCore/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ Dynamo.Graph.Nodes.NodeModel.MarkNodeAsModified(bool forceExecute = false) -> vo
Dynamo.Graph.Nodes.NodeModel.Modified -> System.Action<Dynamo.Graph.Nodes.NodeModel>
Dynamo.Graph.Nodes.NodeModel.Name.get -> string
Dynamo.Graph.Nodes.NodeModel.Name.set -> void
Dynamo.Graph.Nodes.NodeModel.NameOfAssemblyReferencedByNode -> System.Reflection.AssemblyName
Dynamo.Graph.Nodes.NodeModel.NeedsForceExecution.get -> bool
Dynamo.Graph.Nodes.NodeModel.NodeExecutionBegin -> System.Action<Dynamo.Graph.Nodes.NodeModel>
Dynamo.Graph.Nodes.NodeModel.NodeExecutionEnd -> System.Action<Dynamo.Graph.Nodes.NodeModel>
Expand Down
23 changes: 21 additions & 2 deletions src/DynamoCoreWpf/Utilities/ActionDebouncer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Cancel()

/// <summary>
/// Delays the "action" for a "timeout" number of milliseconds
/// The input Action will run on same syncronization context as the Debounce method call.
/// The input Action will run on same syncronization context as the Debounce method call (or the thread pool if a sync context does not exist, ex. in non UI tests).
/// </summary>
/// <param name="timeout">Number of milliseconds to wait</param>
/// <param name="action">The action to execute after the timeout runs out.</param>
Expand All @@ -36,6 +36,25 @@ public void Debounce(int timeout, Action action)
Cancel();
cts = new CancellationTokenSource();

// The TaskScheduler.FromCurrentSynchronizationContext() exists only if there is a valid SyncronizationContex.
// Calling this method from a non UI thread could have a null SyncronizationContex.Current,
// so in that case we use the default TaskScheduler which uses the thread pool.
TaskScheduler taskScheduler = null;
if (SynchronizationContext.Current != null)
{// This should always be the case in UI threads.
taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
}
else
{
// This might happen when running tests in non UI threads.
// But if we are in a UI thread, then log this as a potential error.
if (System.Windows.Application.Current?.Dispatcher?.Thread == Thread.CurrentThread)
{// UI thread.
logger?.LogError("The UI thread does not seem to have a SyncronizationContext.");
}
taskScheduler = TaskScheduler.Default;
}

Task.Delay(timeout, cts.Token).ContinueWith((t) =>
{
try
Expand All @@ -50,7 +69,7 @@ public void Debounce(int timeout, Action action)
logger?.Log("Failed to run debounce action with the following error:");
logger?.Log(ex.ToString());
}
}, TaskScheduler.FromCurrentSynchronizationContext());
}, taskScheduler);
}

public void Dispose()
Expand Down
40 changes: 27 additions & 13 deletions src/DynamoCoreWpf/ViewModels/Core/ConnectorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,16 +1222,20 @@ public override void Dispose()
{
NodeEnd.PropertyChanged -= nodeEndViewModel_PropertyChanged;
}
ConnectorPinViewCollection.CollectionChanged -= HandleCollectionChanged;

workspaceViewModel.PropertyChanged -= WorkspaceViewModel_PropertyChanged;

foreach (var pin in ConnectorPinViewCollection.ToList())
if (ConnectorPinViewCollection != null)
{
pin.RequestRedraw -= HandlerRedrawRequest;
pin.RequestSelect -= HandleRequestSelected;
ConnectorPinViewCollection.CollectionChanged -= HandleCollectionChanged;

foreach (var pin in ConnectorPinViewCollection.ToList())
{
pin.RequestRedraw -= HandlerRedrawRequest;
pin.RequestSelect -= HandleRequestSelected;
}
}

workspaceViewModel.PropertyChanged -= WorkspaceViewModel_PropertyChanged;

this.PropertyChanged -= ConnectorViewModelPropertyChanged;
DiscardAllConnectorPinModels();

Expand Down Expand Up @@ -1451,17 +1455,27 @@ internal List<Point> CollectPinLocations()
/// </summary>
public void Redraw()
{
if (this.ConnectorModel?.End != null && ConnectorPinViewCollection?.Count > 0)
try
{
RedrawBezierManyPoints();
if (this.ConnectorModel != null && ConnectorPinViewCollection != null)
{
if (this.ConnectorModel?.End != null && ConnectorPinViewCollection?.Count > 0)
{
RedrawBezierManyPoints();
}
else if (this.ConnectorModel?.End != null)
{
this.Redraw(this.ConnectorModel.End.Center);
}
}

this.SetCollapsedByNodeViewModel();
RaisePropertyChanged(nameof(ZIndex));
}
else if (this.ConnectorModel?.End != null)
catch (Exception ex)
{
this.Redraw(this.ConnectorModel.End.Center);
workspaceViewModel.DynamoViewModel.Model.Logger.Log("Error when redrawing the connector: " + ex.StackTrace);
}

this.SetCollapsedByNodeViewModel();
RaisePropertyChanged(nameof(ZIndex));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,6 @@ private void PopulateMyPackages()
var p = GetSearchElementViewModel(pkg, true);

p.RequestDownload += this.PackageOnExecuted;
p.RequestShowFileDialog += this.OnRequestShowFileDialog;
p.IsOnwer = true;

myPackages.Add(p);
Expand Down Expand Up @@ -1239,6 +1238,8 @@ internal void RefreshInfectedPackages()
internal void AddToSearchResults(PackageManagerSearchElementViewModel element)
{
element.RequestDownload += this.PackageOnExecuted;
element.RequestShowFileDialog += this.OnRequestShowFileDialog;

this.SearchResults.Add(element);
}

Expand Down Expand Up @@ -1479,9 +1480,6 @@ internal IEnumerable<PackageManagerSearchElementViewModel> GetAllPackages()
list.Reverse();
}

foreach (var x in list)
x.RequestShowFileDialog += OnRequestShowFileDialog;

return list;
}

Expand Down
5 changes: 3 additions & 2 deletions src/DynamoPackages/PackageManagerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ private void OnCurrentWorkspaceChanged(IWorkspaceModel ws)

private PackageInfo GetNodePackageFromAssemblyName(AssemblyName assemblyName)
{
if (NodePackageDictionary != null && NodePackageDictionary.ContainsKey(assemblyName.FullName))
if (NodePackageDictionary?.TryGetValue(assemblyName.FullName, out var packages) == true)
{
return NodePackageDictionary[assemblyName.FullName].Last();
return packages.Last();
}

return null;
}

Expand Down
13 changes: 7 additions & 6 deletions src/Libraries/PythonNodeModels/PythonNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ public string EngineName
/// <returns>Assembly Name</returns>
internal override AssemblyName GetNameOfAssemblyReferencedByNode()
{
AssemblyName assemblyName = null;

var pyEng = PythonEngineManager.Instance.AvailableEngines.Where(x => x.Name.Equals(this.EngineName)).FirstOrDefault();
if (pyEng != null)
if (NameOfAssemblyReferencedByNode == null)
{
assemblyName = AssemblyName.GetAssemblyName(pyEng.GetType().Assembly.Location);
var pyEng = PythonEngineManager.Instance.AvailableEngines.Where(x => x.Name.Equals(this.EngineName)).FirstOrDefault();
if (pyEng != null)
{
NameOfAssemblyReferencedByNode = pyEng.GetType().Assembly.GetName();
}
}

return assemblyName;
return NameOfAssemblyReferencedByNode;
}

/// <summary>
Expand Down
16 changes: 8 additions & 8 deletions test/DynamoCoreWpfTests/DynamoTestUIBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void PrettyPrint(object obj)
Console.WriteLine("}");
}

internal void SetupStartupDiagnostics()
internal void StartupDiagnostics()
{
System.Console.WriteLine($"PID {Process.GetCurrentProcess().Id} Start test: {TestContext.CurrentContext.Test.Name}");
TestUtilities.WebView2Tag = TestContext.CurrentContext.Test.Name;
Expand All @@ -69,7 +69,7 @@ internal void SetupStartupDiagnostics()
Dispatcher.CurrentDispatcher.Hooks.OperationPosted += Hooks_OperationPosted;
}

internal void SetupBeforeCleanupDiagnostics()
internal void BeforeCleanupDiagnostics()
{
Dispatcher.CurrentDispatcher.Hooks.OperationPosted -= Hooks_OperationPosted;
if (!SkipDispatcherFlush)
Expand All @@ -78,7 +78,7 @@ internal void SetupBeforeCleanupDiagnostics()
}
}

internal void SetupAfterCleanupDiagnostics()
internal void AfterCleanupDiagnostics()
{
TestUtilities.WebView2Tag = string.Empty;
using (var currentProc = Process.GetCurrentProcess())
Expand All @@ -93,10 +93,10 @@ internal void SetupAfterCleanupDiagnostics()
}
}

internal void SetupCleanupDiagnostics()
internal void CleanupDiagnostics()
{
SetupBeforeCleanupDiagnostics();
SetupAfterCleanupDiagnostics();
BeforeCleanupDiagnostics();
AfterCleanupDiagnostics();
}
}

Expand Down Expand Up @@ -132,7 +132,7 @@ protected string ExecutingDirectory
[SetUp]
public virtual void Start()
{
testDiagnostics.SetupStartupDiagnostics();
testDiagnostics.StartupDiagnostics();
var assemblyPath = Assembly.GetExecutingAssembly().Location;
preloader = new Preloader(Path.GetDirectoryName(assemblyPath));
preloader.Preload();
Expand Down Expand Up @@ -229,7 +229,7 @@ public void Exit()
{
Console.WriteLine(ex.StackTrace);
}
testDiagnostics.SetupAfterCleanupDiagnostics();
testDiagnostics.AfterCleanupDiagnostics();
}

protected virtual void GetLibrariesToPreload(List<string> libraries)
Expand Down
11 changes: 3 additions & 8 deletions test/DynamoCoreWpfTests/RecordedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Threading;
using CoreNodeModels.Input;
Expand All @@ -24,10 +23,6 @@
using ProtoCore;
using PythonNodeModels;
using SystemTestServices;
using System.Windows.Threading;
using DynamoCoreWpfTests.Utility;
using System.Diagnostics;
using System.Threading.Tasks;

namespace DynamoCoreWpfTests
{
Expand All @@ -54,7 +49,7 @@ public class RecordedUnitTestBase : DynamoViewModelUnitTest

public override void Setup()
{
testDiagnostics.SetupStartupDiagnostics();
testDiagnostics.StartupDiagnostics();

base.Setup();
// Fixed seed randomizer for predictability.
Expand All @@ -63,10 +58,10 @@ public override void Setup()

public override void Cleanup()
{
testDiagnostics.SetupBeforeCleanupDiagnostics();
testDiagnostics.BeforeCleanupDiagnostics();
commandCallback = null;
base.Cleanup();
testDiagnostics.SetupAfterCleanupDiagnostics();
testDiagnostics.AfterCleanupDiagnostics();
}

#endregion
Expand Down

0 comments on commit b707fad

Please sign in to comment.