Skip to content

Commit

Permalink
use existing library function to lookup previous name hints (#11379)
Browse files Browse the repository at this point in the history
* use existing library function to lookup previous name hints

* modify test migration xml to assert case works with no parameters

* add new test
add migration xml to ffitarget
change method name in lib services

* add one more test case for overload

* add missing dll to migration test framework

* Update ClassWithMigratedMembers.cs

Co-authored-by: michael kirschner <[email protected]>
  • Loading branch information
mjkkirschner and mjkkirschner authored Jan 7, 2021
1 parent 9cf6acf commit f78cf1b
Show file tree
Hide file tree
Showing 10 changed files with 539 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public NodeModel CreateNodeFromXml(XmlElement nodeElement, SaveContext context,
string xmlSignature = nodeElement.Attributes["function"].Value;

string hintedSigniture =
libraryServices.FunctionSignatureFromFunctionSignatureHint(xmlSignature);
libraryServices.GetFunctionSignatureFromFunctionSignatureHint(xmlSignature);

if (hintedSigniture != null)
{
Expand Down
11 changes: 2 additions & 9 deletions src/DynamoCore/Graph/Workspaces/SerializationConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,8 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
else if (typeof(DSFunctionBase).IsAssignableFrom(type))
{
var mangledName = obj["FunctionSignature"].Value<string>();
var priorNames = libraryServices.GetPriorNames();
var functionDescriptor = libraryServices.GetFunctionDescriptor(mangledName);
string newName;

// Update the function descriptor if a newer migrated version of the node exists
if (priorNames.TryGetValue(mangledName, out newName))
{
functionDescriptor = libraryServices.GetFunctionDescriptor(newName);
}
var lookupSignature = libraryServices.GetFunctionSignatureFromFunctionSignatureHint(mangledName) ?? mangledName;
var functionDescriptor = libraryServices.GetFunctionDescriptor(lookupSignature);

// Use the functionDescriptor to try and restore the proper node if possible
if (functionDescriptor == null)
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Library/LibraryServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ internal string NameFromFunctionSignature(string functionSignature)
return splitted[splitted.Length - 2] + "." + splitted[splitted.Length - 1];
}

internal string FunctionSignatureFromFunctionSignatureHint(string functionSignature)
internal string GetFunctionSignatureFromFunctionSignatureHint(string functionSignature)
{
// if the hint is explicit, we can simply return the mapped function
if (priorNameHints.ContainsKey(functionSignature))
Expand Down
1 change: 1 addition & 0 deletions test/DynamoCoreTests/MigrationTestFramework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected override void GetLibrariesToPreload(List<string> libraries)
libraries.Add("DSOffice.dll");
libraries.Add("FunctionObject.ds");
libraries.Add("BuiltIn.ds");
libraries.Add("FFITarget.dll");
base.GetLibrariesToPreload(libraries);
}

Expand Down
14 changes: 14 additions & 0 deletions test/DynamoCoreTests/NodeMigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected override void GetLibrariesToPreload(List<string> libraries)
libraries.Add("DSOffice.dll");
libraries.Add("FunctionObject.ds");
libraries.Add("BuiltIn.ds");
libraries.Add("FFITarget.dll");
base.GetLibrariesToPreload(libraries);
}

Expand Down Expand Up @@ -2271,6 +2272,19 @@ public void TestPackageNodeMigrationForJSONGraphs()
// Verify all 4 nodes exist in the workspace and were properly loaded/opened from above
Assert.AreEqual(4, this.CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
}

[Test]
[Category("UnitTests")]
public void TestZTNodeMigrationJSON_WithDifferentMethodNameAndParams()
{
var legacyGraph = Path.Combine(TestDirectory, "core","migration","TestMigrationFFIClass.dyn");
TestMigration(legacyGraph);

Assert.AreEqual(8, this.CurrentDynamoModel.CurrentWorkspace.Nodes.Count());
AssertPreviewValue("408bd6b17f7f43b28a29175bf12fb01f", "hello");
AssertPreviewValue("013bd08a0f574e85b1d9676ba7004990", "migrated");
AssertPreviewValue("df483e75085340b2a8c359a59dc8ea7a", "migrated");
}
#endregion

#region Private Helper Methods
Expand Down
45 changes: 45 additions & 0 deletions test/Engine/FFITarget/ClassWithMigratedMembers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FFITarget
{
public class ClassWithMigratedMembers
{

public static ClassWithMigratedMembers ByNothing()
{
return new ClassWithMigratedMembers();
}

//we test by opening a file that references a node with three params
public string AMemberWithTwoParams(string a, string b)
{
return a + b;
}
public string AMemberWithThreeParams(string a, string b,string c ="abc")
{
return "migrated";
}
public string AnOverloadedMember(string a, string b)
{
return "original";
}
public string AnOverloadedMember(string a, string b, string c = "abc")
{
return "migrated";
}

//we test a file that uses the node AMemberWithAChangedName1
public string AMemberWithAChangedName2(string a)
{
return a;
}
/* public string AMemberWithAChangedName1(string a)
{
return a;
}*/
}
}
15 changes: 15 additions & 0 deletions test/Engine/FFITarget/FFITarget.Migrations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<migrations>
<priorNameHint>
<oldName>FFITarget.ClassWithMigratedMembers.AMemberWithAChangedName1</oldName>
<newName>FFITarget.ClassWithMigratedMembers.AMemberWithAChangedName2</newName>
</priorNameHint>
<priorNameHint>
<oldName>FFITarget.ClassWithMigratedMembers.AMemberWithTwoParams@string,string</oldName>
<newName>FFITarget.ClassWithMigratedMembers.AMemberWithThreeParams@string,string,string</newName>
</priorNameHint>
<priorNameHint>
<oldName>FFITarget.ClassWithMigratedMembers.AnOverloadedMember@string,string</oldName>
<newName>FFITarget.ClassWithMigratedMembers.AnOverloadedMember@string,string,string</newName>
</priorNameHint>
</migrations>
6 changes: 6 additions & 0 deletions test/Engine/FFITarget/FFITarget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
<Compile Include="AbstractDisposeTracert.cs" />
<Compile Include="AtLevelTestClass.cs" />
<Compile Include="ClassFunctionality.cs" />
<Compile Include="ClassWithMigratedMembers.cs" />
<Compile Include="ClassWithRefParams.cs" />
<Compile Include="CodeCompletionClass.cs" />
<Compile Include="CustomLabel.cs" />
Expand Down Expand Up @@ -98,6 +99,11 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="FFITarget.Migrations.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Loading

0 comments on commit f78cf1b

Please sign in to comment.