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

Migrate number nodes with sequence to CBNs. #7582

Merged
merged 8 commits into from
Feb 9, 2017
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
2 changes: 1 addition & 1 deletion src/DynamoCore/Graph/Nodes/NodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2276,7 +2276,7 @@ protected static NodeMigrationData MigrateToDsVarArgFunction(
return migrationData;
}

[NodeMigration(@from: "1.3.0.0")]
[NodeMigration(version: "1.3.0.0")]
public static NodeMigrationData MigrateShortestLacingToAutoLacing(NodeMigrationData data)
{
var migrationData = new NodeMigrationData(data.Document);
Expand Down
28 changes: 8 additions & 20 deletions src/DynamoCore/Migration/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,30 +313,24 @@ public NodeMigrationData MigrateXmlNode(Version currentVersion, XmlNode elNode,
let attribute =
method.GetCustomAttributes(false).OfType<NodeMigrationAttribute>().FirstOrDefault()
where attribute != null
let result = new { method, attribute.From, attribute.To }
orderby result.From
let result = new { method, attribute.Version}
orderby result.Version
select result).ToList();

var nodeToMigrate = elNode as XmlElement;
var migrationData = new NodeMigrationData(elNode.OwnerDocument);
migrationData.AppendNode(elNode as XmlElement);

while (workspaceVersion != null && workspaceVersion < currentVersion)
foreach(var migration in migrations.Where(m=>m.Version >= workspaceVersion))
{
var nextMigration = migrations.FirstOrDefault(x => x.From >= workspaceVersion);

if (nextMigration == null)
break;

object ret = nextMigration.method.Invoke(this, new object[] { migrationData });
object ret = migration.method.Invoke(this, new object[] { migrationData });
migrationData = ret as NodeMigrationData;

if (DynamoModel.EnableMigrationLogging)
{
// record migration data for successful migrations
migrationReport.AddMigrationDataToNodeMap(nodeToMigrate.Name, migrationData.MigratedNodes);
}
workspaceVersion = nextMigration.To;
}

return migrationData;
Expand Down Expand Up @@ -1353,19 +1347,13 @@ public IEnumerable<XmlElement> MigratedNodes
public class NodeMigrationAttribute : Attribute
{
/// <summary>
/// Latest Version this migration applies to.
/// Version specifies the latest workspace version to which this migration will be applied.
/// </summary>
public Version From { get; private set; }
public Version Version { get; private set; }

/// <summary>
/// Version this migrates to.
/// </summary>
public Version To { get; private set; }

public NodeMigrationAttribute(string from, string to = "")
public NodeMigrationAttribute(string version)
{
From = new Version(from);
To = String.IsNullOrEmpty(to) ? null : new Version(to);
Version = new Version(version);
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/Libraries/CoreNodeModels/Input/BaseTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using ProtoCore.DSASM;
using CoreNodeModels.Properties;
using Newtonsoft.Json;
using Dynamo.Migration;

namespace CoreNodeModels.Input
{
Expand Down Expand Up @@ -737,5 +738,25 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
writer.WriteValue(d);
}
}

[NodeMigration(version: "2.0.0.0")]
public static NodeMigrationData Migrate_Range(NodeMigrationData data)
{
var migrationData = new NodeMigrationData(data.Document);
var oldNode = data.MigratedNodes.ElementAt(0);
var valEls = oldNode.GetElementsByTagName("System.Double"); // The Value node
var val = valEls[0].Attributes["value"].Value;

double result = 0.0;
if (double.TryParse(val, out result))
{
return data;
}

var newNode = MigrationManager.CreateCodeBlockNodeFrom(oldNode);
newNode.Attributes["CodeText"].Value = val + ";";
migrationData.AppendNode(newNode);
return migrationData;
}
}
}
2 changes: 1 addition & 1 deletion src/Libraries/CoreNodeModels/Input/DoubleSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ namespace Dynamo.Nodes
{
public class DoubleSlider
{
[NodeMigration(@from: "0.7.5.0")]
[NodeMigration(version: "0.7.5.0")]
public static NodeMigrationData Migrate_0750(NodeMigrationData data)
{
var migrationData = new NodeMigrationData(data.Document);
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/CoreNodeModels/Input/IntegerSlider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace Dynamo.Nodes
{
public class IntegerSlider
{
[NodeMigration(@from: "0.7.5.0")]
[NodeMigration(version: "0.7.5.0")]
public static NodeMigrationData Migrate_0750(NodeMigrationData data)
{
var migrationData = new NodeMigrationData(data.Document);
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/UnitsUI/UnitsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public LengthFromString():base()
RegisterAllPorts();
}

[NodeMigration(from: "0.6.2")]
[NodeMigration(version: "0.6.2")]
public void MigrateLengthFromFeetToMeters(XmlNode node)
{
//length values were previously stored as decimal feet
Expand All @@ -244,7 +244,7 @@ public void MigrateLengthFromFeetToMeters(XmlNode node)
}
}

[NodeMigration(@from: "0.7.5.0")]
[NodeMigration(version: "0.7.5.0")]
public static NodeMigrationData Migrate_0750(NodeMigrationData data)
{
var migrationData = new NodeMigrationData(data.Document);
Expand Down
21 changes: 7 additions & 14 deletions src/Migrations/CoreNodes/dynBaseTypes.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Linq;
using System.Xml;
using Dynamo.Graph;
using Dynamo.Graph.Nodes;
using Dynamo.Models;
using Dynamo.Migration;

namespace Dynamo.Nodes
{
[AlsoKnownAs("DSCore.SortByKey")]
public class SortByKey : MigrationNode
{
[NodeMigration(from: "0.8.3.0", to: "0.9.0.0")]
[NodeMigration(version: "0.8.3.0")]
public static NodeMigrationData Migrate_0830_to_0900(NodeMigrationData data)
{
NodeMigrationData migrationData = new NodeMigrationData(data.Document);
Expand All @@ -30,7 +23,7 @@ public static NodeMigrationData Migrate_0830_to_0900(NodeMigrationData data)
return migrationData;
}

[NodeMigration(from: "0.9.0.0", to: "0.9.1.0")]
[NodeMigration(version: "0.9.0.0")]
public static NodeMigrationData Migrate_0900_to_0910(NodeMigrationData data)
{
return Migrate_0830_to_0900(data);
Expand All @@ -40,7 +33,7 @@ public static NodeMigrationData Migrate_0900_to_0910(NodeMigrationData data)
[AlsoKnownAs("DSCore.GroupByKey")]
public class GroupByKey : MigrationNode
{
[NodeMigration(from: "0.8.3.0", to: "0.9.0.0")]
[NodeMigration(version: "0.8.3.0")]
public static NodeMigrationData Migrate_0830_to_0900(NodeMigrationData data)
{
NodeMigrationData migrationData = new NodeMigrationData(data.Document);
Expand All @@ -55,7 +48,7 @@ public static NodeMigrationData Migrate_0830_to_0900(NodeMigrationData data)
return migrationData;
}

[NodeMigration(from: "0.9.0.0", to: "0.9.1.0")]
[NodeMigration(version: "0.9.0.0")]
public static NodeMigrationData Migrate_0900_to_0910(NodeMigrationData data)
{
return Migrate_0830_to_0900(data);
Expand All @@ -65,7 +58,7 @@ public static NodeMigrationData Migrate_0900_to_0910(NodeMigrationData data)
[AlsoKnownAs("Dynamo.Nodes.dynBuildSeq", "Dynamo.Nodes.BuildSeq", "DSCoreNodesUI.NumberRange")]
public class NumberRange : MigrationNode
{
[NodeMigration(from: "0.8.2.0", to: "0.8.3.0")]
[NodeMigration(version: "0.8.2.0")]
public static NodeMigrationData Migrate_0820_to_0830(NodeMigrationData data)
{
NodeMigrationData migrationData = new NodeMigrationData(data.Document);
Expand All @@ -82,7 +75,7 @@ public static NodeMigrationData Migrate_0820_to_0830(NodeMigrationData data)
[AlsoKnownAs("DSCoreNodesUI.NumberSeq")]
public class NumberSeq : MigrationNode
{
[NodeMigration(from: "0.8.2.0", to: "0.8.3.0")]
[NodeMigration(version: "0.8.2.0")]
public static NodeMigrationData Migrate_0820_to_0830(NodeMigrationData data)
{
NodeMigrationData migrationData = new NodeMigrationData(data.Document);
Expand Down
6 changes: 2 additions & 4 deletions src/Migrations/DynamoPython/dynPython.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Dynamo.Migration;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

namespace DSIronPythonNode
{
public class PythonNode : MigrationNode
{
[NodeMigration(from: "0.8.3.0", to: "0.9.0.0")]
[NodeMigration(version: "0.8.3.0")]
public static NodeMigrationData Migrate_0830_to_0900(NodeMigrationData data)
{
System.Xml.XmlElement xmlNode = data.MigratedNodes.ElementAt(0);
Expand All @@ -21,7 +19,7 @@ public static NodeMigrationData Migrate_0830_to_0900(NodeMigrationData data)

public class PythonStringNode : MigrationNode
{
[NodeMigration(from: "0.8.3.0", to: "0.9.0.0")]
[NodeMigration(version: "0.8.3.0")]
public static NodeMigrationData Migrate_0830_to_0900(NodeMigrationData data)
{
System.Xml.XmlElement xmlNode = data.MigratedNodes.ElementAt(0);
Expand Down
7 changes: 2 additions & 5 deletions src/Migrations/RevitNodes/SunPath.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System;
using System.Linq;
using System.Xml;
using Dynamo.Graph;
using Dynamo.Graph.Nodes;
using Dynamo.Models;
using Dynamo.Migration;

namespace Dynamo.Nodes
{
public class SunPathDirection : MigrationNode
{
[NodeMigration(from: "0.7.0.0", to: "0.7.3.0")]
[NodeMigration(version: "0.7.0.0")]
public static NodeMigrationData Migrate_0700_to_0730(NodeMigrationData data)
{
var migrationData = new NodeMigrationData(data.Document);
Expand Down Expand Up @@ -56,7 +53,7 @@ namespace DSRevitNodesUI
{
public class SunPathDirection : MigrationNode
{
[NodeMigration(from: "0.7.0.0", to: "0.7.3.0")]
[NodeMigration(version: "0.7.0.0")]
public static NodeMigrationData Migrate_0700_to_0730(NodeMigrationData data)
{
return Dynamo.Nodes.SunPathDirection.Migrate_0700_to_0730(data);
Expand Down
6 changes: 3 additions & 3 deletions test/DynamoCoreTests/CallsiteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Dynamo.Graph.Nodes.ZeroTouch;
using Dynamo.Graph.Workspaces;
using NUnit.Framework;

using Dynamo.Graph.Nodes;

namespace Dynamo.Tests
{
Expand Down Expand Up @@ -96,10 +96,10 @@ private void OpenChangeAndCheckOrphans(string testFileName, string numNodeValue,

CurrentDynamoModel.TraceReconciliationProcessor = new TestTraceReconciliationProcessor(expectedOrphanCount);

var numNode = ws.FirstNodeFromWorkspace<DoubleInput>();
var numNode = ws.FirstNodeFromWorkspace<CodeBlockNodeModel>();

// Increase the number values.
numNode.Value = numNodeValue;
numNode.SetCodeContent(numNodeValue + ";", new ProtoCore.Namespace.ElementResolver());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just a temporary change for testing purposes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This test needs to be updated to work after this migration is added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's going to replace the existing test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see now.


BeginRun();
}
Expand Down
4 changes: 2 additions & 2 deletions test/DynamoCoreTests/DynamoDefects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ public void Defect_MAGN_847()
RunModel(openPath);
AssertPreviewCount("2ea813c4-7729-45b5-b23b-d7a3377f0b31", 4);
var doubleInput = CurrentDynamoModel.CurrentWorkspace.NodeFromWorkspace
("7eba96c0-4715-47f0-a874-01f1887ac465") as DoubleInput;
doubleInput.Value = "6..8";
("7eba96c0-4715-47f0-a874-01f1887ac465") as CodeBlockNodeModel;
doubleInput.SetCodeContent("6..8;", new ProtoCore.Namespace.ElementResolver());
BeginRun();
AssertPreviewCount("2ea813c4-7729-45b5-b23b-d7a3377f0b31", 3);
}
Expand Down
10 changes: 5 additions & 5 deletions test/DynamoCoreTests/NodeMigrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,15 +1788,15 @@ public void TestNumberInput()
"27d6c83d-602c-4d44-a9b6-ab229cb2143d");
var number50 = workspace.NodeFromWorkspace<DoubleInput>(
"ffd50d99-b51d-4104-9e19-041219ca5740");
var numberRange = workspace.NodeFromWorkspace<DoubleInput>(
var numberRange = workspace.NodeFromWorkspace<CodeBlockNodeModel>(
"eb6aa95d-8be4-4ca7-95a6-e696904a71fa");
var numberStep = workspace.NodeFromWorkspace<DoubleInput>(
var numberStep = workspace.NodeFromWorkspace<CodeBlockNodeModel>(
"5fde015f-8a95-4b46-ba64-29de06850938");
var numberCount = workspace.NodeFromWorkspace<DoubleInput>(
var numberCount = workspace.NodeFromWorkspace<CodeBlockNodeModel>(
"ace69b4e-5092-42cf-9fba-9aee6729509d");
var numberApprox = workspace.NodeFromWorkspace<DoubleInput>(
var numberApprox = workspace.NodeFromWorkspace<CodeBlockNodeModel>(
"30e9b7fd-fc09-4243-a34a-146ad841868a");
var numberIncr = workspace.NodeFromWorkspace<DoubleInput>(
var numberIncr = workspace.NodeFromWorkspace<CodeBlockNodeModel>(
"bede0d80-6382-4430-9403-a14c3916e041");

Assert.NotNull(number5);
Expand Down
9 changes: 6 additions & 3 deletions test/DynamoCoreTests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,13 @@ private void DoWorkspaceOpenAndCompare(string filePath)

var wcd1 = new WorkspaceComparisonData(ws1, CurrentDynamoModel.EngineController);

var dirPath = Path.Combine(Path.GetTempPath(), "json");
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
var fi = new FileInfo(filePath);
var filePathBase = Path.Combine(Path.GetTempPath() + @"\json\" + Path.GetFileNameWithoutExtension(fi.Name));
var filePathBase = dirPath + @"\" + Path.GetFileNameWithoutExtension(fi.Name);

ConvertCurrentWorkspaceToDesignScriptAndSave(filePathBase);

Expand Down Expand Up @@ -396,8 +401,6 @@ private void ConvertCurrentWorkspaceToDesignScriptAndSave(string filePathBase)
{
try
{


var workspace = CurrentDynamoModel.CurrentWorkspace;

var libCore = CurrentDynamoModel.EngineController.LibraryServices.LibraryManagementCore;
Expand Down