Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom node small icon load in library #11063

Merged
merged 2 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/LibraryViewExtension/Handlers/IconUrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,22 @@ public IconUrl(string iconName, string resourcePath, bool customNode = false)
if (customNode)
{
string customizationPath = null;
if (Path != null && Path != String.Empty)
if (!string.IsNullOrEmpty(Path))
{
customizationPath = System.IO.Path.GetDirectoryName(Path);
customizationPath = Directory.GetParent(customizationPath).FullName;
customizationPath = System.IO.Path.GetDirectoryName(Path);
customizationPath = Directory.GetParent(customizationPath).FullName;
}

Path = DefaultPath;
Name = DefaultIcon;

if (customizationPath != null &&
File.Exists(System.IO.Path.Combine(customizationPath, "bin", "Package.customization.dll")))
{
Path = System.IO.Path.Combine(customizationPath, "bin", "Package.dll");
}
else
{
Path = DefaultPath;
Name = DefaultIcon;
}
}

Url = string.Format(@"http://localhost{0}/{1}{2}{3}", ServiceEndpoint, Name, query, Path);
Expand Down
12 changes: 6 additions & 6 deletions test/Libraries/PackageManagerTests/PackageLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public void LoadPackagesReturnsAllValidPackagesInValidDirectory()
PathManager = CurrentDynamoModel.PathManager
});

// There are 16 packages in "Dynamo\test\pkgs"
Assert.AreEqual(16, loader.LocalPackages.Count());
// There are 17 packages in "Dynamo\test\pkgs"
Assert.AreEqual(17, loader.LocalPackages.Count());

// Verify that interdependent packages are resolved successfully
// TODO: Review these assertions. Lambdas are not using x, so they are basically just checking that test files exist.
Expand Down Expand Up @@ -181,8 +181,8 @@ public void LoadingPackageDoesNotAffectLoadedSearchEntries()
PathManager = CurrentDynamoModel.PathManager
});

// There are 16 packages in "Dynamo\test\pkgs"
Assert.AreEqual(16, loader.LocalPackages.Count());
// There are 17 packages in "Dynamo\test\pkgs"
Assert.AreEqual(17, loader.LocalPackages.Count());

// Simulate loading new package from PM
string packageDirectory = Path.Combine(TestDirectory, @"core\packageDependencyTests\ZTTestPackage");
Expand Down Expand Up @@ -274,8 +274,8 @@ public void LoadingConflictingCustomNodePackageDoesNotGetLoaded()
PathManager = CurrentDynamoModel.PathManager
});

// There are 16 packages in "Dynamo\test\pkgs"
Assert.AreEqual(16, loader.LocalPackages.Count());
// There are 17 packages in "Dynamo\test\pkgs"
Assert.AreEqual(17, loader.LocalPackages.Count());

var entries = CurrentDynamoModel.SearchModel.SearchEntries.OfType<CustomNodeSearchElement>();

Expand Down
15 changes: 14 additions & 1 deletion test/ViewExtensionLibraryTests/LibraryResourceProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TestNodeSearchElement(string category, string name, ElementTypes type, st
}
}

public class LibraryResourceProviderTests
public class LibraryResourceProviderTests : UnitTestBase
{
private const string EventX = "X";

Expand Down Expand Up @@ -220,6 +220,19 @@ public void IconUrlRoundTrip()
Assert.AreEqual(IconUrl.DefaultIcon, customNode.Name);
}

[Test]
[Category("UnitTests")]
public void CustomNodeIconUrlIsCorrectWhenCustomizationDllExists()
{
var name = "c4a6b7cc-f860-4afc-bc74-72d8888002f2";
var packagePath = Path.Combine(TestDirectory, "pkgs", "IconizedCustomNode");
var customNodePath = Path.Combine(packagePath, "dyf", "MyOR.dyf");
var url = new IconUrl(name, customNodePath, true);

var binaryPath = Path.Combine(packagePath, "bin", "Package.dll");
Assert.AreEqual($"http://localhost/icons/{name}.Small?path={binaryPath}", url.Url);
}

[Test]
[Category("UnitTests")]
public void NodeSearchElementLoadedType()
Expand Down
Binary file not shown.
214 changes: 214 additions & 0 deletions test/pkgs/IconizedCustomNode/dyf/MyOR.dyf
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
{
"Uuid": "c4a6b7cc-f860-4afc-bc74-72d8888002f2",
"IsCustomNode": true,
"Category": "MyNodes",
"Description": "Returns true if any of the arguments is true. Otherwise, it returns false.",
"Name": "MyOR",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"NodeType": "CodeBlockNode",
"Code": "c=a||b;",
"Id": "d0e60fad9c6c4542a39abeeb4f33b2df",
"Inputs": [
{
"Id": "d13eebef699246909ebe1f354d37bc77",
"Name": "a",
"Description": "a",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
},
{
"Id": "11a97880d68d4cc99fde91b804a6450b",
"Name": "b",
"Description": "b",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "64b5b920fdbd4f489743de8264abad71",
"Name": "",
"Description": "c",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CustomNodes.Symbol, DynamoCore",
"NodeType": "InputNode",
"Parameter": {
"Name": "a",
"TypeName": "var",
"TypeRank": -1,
"DefaultValue": null,
"Description": ""
},
"Id": "36758a7df65b43fb90308d8c677ff93f",
"Inputs": [],
"Outputs": [
{
"Id": "c6803d70b8554a399b531f614229fcc7",
"Name": "",
"Description": "Symbol",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "A function parameter, use with custom nodes.\r\n\r\nYou can specify the type and default value for parameter. E.g.,\r\n\r\ninput : var[]..[]\r\nvalue : bool = false"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CustomNodes.Symbol, DynamoCore",
"NodeType": "InputNode",
"Parameter": {
"Name": "b",
"TypeName": "var",
"TypeRank": -1,
"DefaultValue": null,
"Description": ""
},
"Id": "40cfa8b275da4ba3b239f0e3a8400e22",
"Inputs": [],
"Outputs": [
{
"Id": "8fb01cf38d5f4eea8eddf3c64d065287",
"Name": "",
"Description": "Symbol",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "A function parameter, use with custom nodes.\r\n\r\nYou can specify the type and default value for parameter. E.g.,\r\n\r\ninput : var[]..[]\r\nvalue : bool = false"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CustomNodes.Output, DynamoCore",
"NodeType": "OutputNode",
"ElementResolver": null,
"Symbol": "",
"Id": "380b2ca3d42646d686a9bee3f05d24cc",
"Inputs": [
{
"Id": "3f35f0badd2746658a49042e3ceaff46",
"Name": "",
"Description": "",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [],
"Replication": "Disabled",
"Description": "A function output, use with custom nodes"
}
],
"Connectors": [
{
"Start": "64b5b920fdbd4f489743de8264abad71",
"End": "3f35f0badd2746658a49042e3ceaff46",
"Id": "1c00f334cf48408c9ad3ce4f38e9377e"
},
{
"Start": "c6803d70b8554a399b531f614229fcc7",
"End": "d13eebef699246909ebe1f354d37bc77",
"Id": "93bc3fb97f0544e4a54d4e106b342ced"
},
{
"Start": "8fb01cf38d5f4eea8eddf3c64d065287",
"End": "11a97880d68d4cc99fde91b804a6450b",
"Id": "6e8f8f678b79459f97825dae43cd9a33"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [],
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": false,
"IsVisibleInDynamoLibrary": true,
"Version": "2.9.0.2384",
"RunType": "Manual",
"RunPeriod": "1000"
},
"Camera": {
"Name": "Background Preview",
"EyeX": -17.0,
"EyeY": 24.0,
"EyeZ": 50.0,
"LookX": 12.0,
"LookY": -13.0,
"LookZ": -58.0,
"UpX": 0.0,
"UpY": 1.0,
"UpZ": 0.0
},
"NodeViews": [
{
"ShowGeometry": true,
"Name": "Code Block",
"Id": "d0e60fad9c6c4542a39abeeb4f33b2df",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 250.0,
"Y": 0.0
},
{
"ShowGeometry": true,
"Name": "Input",
"Id": "36758a7df65b43fb90308d8c677ff93f",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 0.0,
"Y": 0.0
},
{
"ShowGeometry": true,
"Name": "Input",
"Id": "40cfa8b275da4ba3b239f0e3a8400e22",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 0.0,
"Y": 150.0
},
{
"ShowGeometry": true,
"Name": "Output",
"Id": "380b2ca3d42646d686a9bee3f05d24cc",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"X": 454.20000000000005,
"Y": 0.0
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}
1 change: 1 addition & 0 deletions test/pkgs/IconizedCustomNode/pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"license":"","file_hash":null,"name":"IconizedCustomNode","version":"0.0.3","description":"A description longer","group":"","keywords":null,"dependencies":[],"host_dependencies":[],"contents":"MyOR - Returns true if any of the arguments is true. Otherwise, it returns false.","engine_version":"2.6.1.9496","engine":"dynamo","engine_metadata":"","site_url":"","repository_url":"","contains_binaries":true,"node_libraries":[]}