implemented string concatination node
Some checks failed
Build / build (push) Has been cancelled

This commit is contained in:
Ankitkumar Satapara
2026-04-22 15:33:22 +05:30
parent b2fed489e2
commit 9a9202e373
6 changed files with 129 additions and 1 deletions

View File

@@ -32,6 +32,7 @@ namespace Nodify.Calculator.NodeHandlers
// Register all handlers — order matters for CanCreate/CanRestore matching.
// More specific handlers first (e.g. TakeHandler before generic SystemHandler).
_handlers.Add(new KnotHandler());
_handlers.Add(new StringConcatHandler());
_handlers.Add(new FunctionHandler());
_handlers.Add(new AuthHandler());
_handlers.Add(new TakeHandler());
@@ -79,6 +80,7 @@ namespace Nodify.Calculator.NodeHandlers
return vm switch
{
KnotOperationViewModel => _handlers.OfType<KnotHandler>().FirstOrDefault(),
StringConcatOperationViewModel => _handlers.OfType<StringConcatHandler>().FirstOrDefault(),
FunctionOperationViewModel => _handlers.OfType<FunctionHandler>().FirstOrDefault(),
AuthOperationViewModel => _handlers.OfType<AuthHandler>().FirstOrDefault(),
TakeOperationViewModel => _handlers.OfType<TakeHandler>().FirstOrDefault(),

View File

@@ -0,0 +1,62 @@
using Nodify.Calculator.Models;
using System.Drawing;
using System.Linq;
namespace Nodify.Calculator.NodeHandlers
{
public class StringConcatHandler : INodeHandler
{
public string NodeTypeKey => "System";
public bool CanCreate(OperationInfoViewModel info)
=> info.Type == OperationType.System && info.sysOp == SystemOperations.STRING_CONCAT;
public bool CanRestore(NodeData data)
=> data.NodeType == "System" && data.SystemOp == nameof(SystemOperations.STRING_CONCAT);
public OperationViewModel Create(OperationInfoViewModel info)
{
var strColor = ConnectorViewModel.GetColorForType("string");
var op = new StringConcatOperationViewModel();
// Default two string inputs
op.Input.Add(new ConnectorViewModel { Title = "Str 1", Shape = ConnectorShape.Circle, ConnectorColor = strColor, DataType = "string" });
op.Input.Add(new ConnectorViewModel { Title = "Str 2", Shape = ConnectorShape.Circle, ConnectorColor = strColor, DataType = "string" });
// Single string output
op.Output.Add(new ConnectorViewModel
{
Title = "Result",
IsInput = false,
Shape = ConnectorShape.Circle,
ConnectorColor = strColor,
DataType = "string"
});
return op;
}
public OperationViewModel Restore(NodeData data)
{
var strColor = ConnectorViewModel.GetColorForType("string");
var op = new StringConcatOperationViewModel();
// Restore inputs from saved connectors
foreach (var ic in data.InputConnectors)
op.Input.Add(NodeHandlerRegistry.DeserializeConnector(ic, true));
// Restore output
foreach (var oc in data.OutputConnectors)
op.Output.Add(NodeHandlerRegistry.DeserializeConnector(oc, false));
op.Title = data.Title;
return op;
}
public void Save(OperationViewModel vm, NodeData data)
{
data.NodeType = "System";
data.SystemOp = nameof(SystemOperations.STRING_CONCAT);
}
}
}