Implemente parse json node having universal connector
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
This commit is contained in:
@@ -42,6 +42,7 @@ namespace Nodify.Calculator.NodeHandlers
|
||||
_handlers.Add(new NewObjectHandler());
|
||||
_handlers.Add(new CopyHandler());
|
||||
_handlers.Add(new SplitHandler());
|
||||
_handlers.Add(new ParseJsonHandler());
|
||||
_handlers.Add(new GetSetVariableHandler());
|
||||
_handlers.Add(new GetSetModelHandler());
|
||||
_handlers.Add(new BeginEndHandler());
|
||||
@@ -81,6 +82,7 @@ namespace Nodify.Calculator.NodeHandlers
|
||||
{
|
||||
KnotOperationViewModel => _handlers.OfType<KnotHandler>().FirstOrDefault(),
|
||||
StringConcatOperationViewModel => _handlers.OfType<StringConcatHandler>().FirstOrDefault(),
|
||||
ParseJsonOperationViewModel => _handlers.OfType<ParseJsonHandler>().FirstOrDefault(),
|
||||
FunctionOperationViewModel => _handlers.OfType<FunctionHandler>().FirstOrDefault(),
|
||||
AuthOperationViewModel => _handlers.OfType<AuthHandler>().FirstOrDefault(),
|
||||
TakeOperationViewModel => _handlers.OfType<TakeHandler>().FirstOrDefault(),
|
||||
|
||||
97
Examples/Nodify.Calculator/NodeHandlers/ParseJsonHandler.cs
Normal file
97
Examples/Nodify.Calculator/NodeHandlers/ParseJsonHandler.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Nodify.Calculator.Models;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Nodify.Calculator.NodeHandlers
|
||||
{
|
||||
public class ParseJsonHandler : INodeHandler
|
||||
{
|
||||
public string NodeTypeKey => "System";
|
||||
|
||||
public bool CanCreate(OperationInfoViewModel info)
|
||||
=> info.Type == OperationType.System && info.sysOp == SystemOperations.PARSEJSON;
|
||||
|
||||
public bool CanRestore(NodeData data)
|
||||
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.PARSEJSON);
|
||||
|
||||
public OperationViewModel Create(OperationInfoViewModel info)
|
||||
{
|
||||
var op = new ParseJsonOperationViewModel();
|
||||
|
||||
// Input: universal connector that accepts any shape (Circle, Square, Grid)
|
||||
op.Input.Add(new ConnectorViewModel
|
||||
{
|
||||
Title = "Input",
|
||||
Shape = ConnectorShape.Circle,
|
||||
ConnectorColor = Color.White,
|
||||
IsCopyConnector = true
|
||||
});
|
||||
|
||||
// Default output (will be updated when user selects target type)
|
||||
op.Output.Add(new ConnectorViewModel
|
||||
{
|
||||
Title = "Result",
|
||||
IsInput = false,
|
||||
Shape = ConnectorShape.Circle,
|
||||
ConnectorColor = Color.LimeGreen,
|
||||
DataType = "object"
|
||||
});
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
public OperationViewModel Restore(NodeData data)
|
||||
{
|
||||
var op = new ParseJsonOperationViewModel();
|
||||
|
||||
// Input: universal connector
|
||||
op.Input.Add(new ConnectorViewModel
|
||||
{
|
||||
Title = "Input",
|
||||
Shape = ConnectorShape.Circle,
|
||||
ConnectorColor = Color.White,
|
||||
IsCopyConnector = true
|
||||
});
|
||||
|
||||
// Restore adapted input connector from saved data
|
||||
if (data.InputConnectors.Count > 0 && data.InputConnectors[0].Shape != "Circle")
|
||||
{
|
||||
var saved = data.InputConnectors[0];
|
||||
var inp = op.Input[0];
|
||||
inp.Shape = NodeHandlerRegistry.ParseShape(saved.Shape);
|
||||
inp.ConnectorColor = Color.FromArgb(saved.ColorArgb);
|
||||
inp.DataType = saved.DataType;
|
||||
}
|
||||
|
||||
// Restore selected target type (this triggers UpdateOutputConnector via property setter)
|
||||
if (!string.IsNullOrEmpty(data.ParseJsonTargetType))
|
||||
{
|
||||
op.RefreshAvailableTypes();
|
||||
op.SelectedTargetType = data.ParseJsonTargetType;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Default output
|
||||
op.Output.Add(new ConnectorViewModel
|
||||
{
|
||||
Title = "Result",
|
||||
IsInput = false,
|
||||
Shape = ConnectorShape.Circle,
|
||||
ConnectorColor = Color.LimeGreen,
|
||||
DataType = "object"
|
||||
});
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
public void Save(OperationViewModel vm, NodeData data)
|
||||
{
|
||||
data.NodeType = "System";
|
||||
data.SystemOp = nameof(SystemOperations.PARSEJSON);
|
||||
if (vm is ParseJsonOperationViewModel parseVm)
|
||||
{
|
||||
data.ParseJsonTargetType = parseVm.SelectedTargetType ?? "object";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user