public virtual void RemoveConnection(Connection connection) { if (ConnectionsTo.Remove(connection)) { HilightOutputAnchorOffByName(connection.LeftAnchorName); } if (ConnectionsFrom.Remove(connection)) { // set right input value to null var rightProperty = NodeInstance.GetType().GetProperty(connection.RightPropertyName); if (rightProperty != null) { rightProperty.SetValue(NodeInstance, null); } EnableInputElement(connection.RightAnchorName); HilightInputAnchorOffByName(connection.RightAnchorName); } }
public virtual Guid Execute(Guid transactionId) { if (LastTransactionId == transactionId || (ConnectionsFrom.Count != 0 && ConnectionsFrom.All(c => c.TransactionId == transactionId))) { return(LastTransactionId); } try { var stopWatch = new Stopwatch(); foreach (var connection in ConnectionsFrom) { if (connection.TransactionId == transactionId) { continue; } // generate output from left node (connection.Left as Node).Execute(transactionId); // get left output value var leftNode = connection.Left.NodeInstance; var leftValue = leftNode .GetType() .GetProperty(connection.LeftPropertyName) .GetValue(leftNode); // set right input value var rightProperty = NodeInstance?.GetType().GetProperty(connection.RightPropertyName); if (rightProperty != null) { rightProperty.SetValue(NodeInstance, Common.Tools.Convert.ChangeType(leftValue, rightProperty.PropertyType)); } connection.TransactionId = transactionId; } if (NodeInstance != null && LastTransactionId != transactionId) { try { stopWatch.Reset(); stopWatch.Start(); NodeInstance.Execute(); RaiseImpulseEvent(); stopWatch.Stop(); // log node input & output var nodeName = AttributeHelper.GetValue <NodeInfoAttribute, string>(NodeInstance.GetType(), nameof(NodeInfoAttribute.DisplayName)) ?? NodeInstance.GetType().Name; var nodeInputs = (NodeInstance as ILoggable)?.GetInputs() ?.Select(i => i == null ? null : (i.Length < LOG_MAX_INPUT_LENGTH ? i : (i.Substring(0, LOG_MAX_INPUT_LENGTH) + "...")).Replace(Environment.NewLine, "\\r\\n")); var nodeOutputs = (NodeInstance as ILoggable)?.GetOutputs() ?.Select(i => i == null ? null : (i.Length < LOG_MAX_OUTPUT_LENGTH ? i : (i.Substring(0, LOG_MAX_OUTPUT_LENGTH) + "...")).Replace(Environment.NewLine, "\\r\\n")); Log.WriteLine($"{ CustomNodeName.Text }:{ nodeName }('{ string.Join("', '", nodeInputs ?? new string[] { }) }')=['{ string.Join("', '", nodeOutputs ?? new string[] { }) }'] | { stopWatch.ElapsedMilliseconds }ms"); LastTransactionId = transactionId; } catch (Exception ex) { Log.WriteLine(ex.ToString()); } } foreach (var outputConnection in ConnectionsTo) { outputConnection.Right.Execute(transactionId); } } catch (FriendlyException ex) { Log.WriteLine(ex.Message); } catch (Exception ex) { Log.WriteLine(ex.ToString()); } return(LastTransactionId); }