public SequenceToArray(IGraphRuntime runtime) : base(runtime, ModuleKind.Module, DisplayMode.Collapsed) { this.inputPin = AddInputPin("Sequence", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Allow); this.outputPin = AddOutputPin("Array", PinDataTypeFactory.FromType(typeof(object[]))); this.inputPin.WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType => { var method = EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(pinDataType.UnderlyingType); var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault() ?? pinDataType.UnderlyingType; if (genericType != null) { genericDelegate = new GenericDelegate <Func <object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(genericType)); } else { genericDelegate = null; } outputPin.ChangeType(PinDataTypeFactory.FromType(genericType.MakeArrayType())); }); }); }
public First(IGraphRuntime runtime) : base(runtime) { this.inputPin = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never); this.outputPin = AddOutputPin("Output", PinDataTypeFactory.Create <object>()); this.inputPin.WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType => { var method = EvaluateInternalAttribute.GetMethod(GetType()); var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault(); if (genericType != null) { genericDelegate = new GenericDelegate <Func <object, object, Task <object> > >(this, method.MakeGenericMethod(genericType)); } else { genericDelegate = null; genericType = typeof(object); } outputPin.ChangeType(PinDataTypeFactory.FromType(genericType)); }); }); }
private void BuildGenericDelegate() { var inputType = subGraphInput.DataType.UnderlyingType; var accumulateType = seedInput.DataType.UnderlyingType; var method = EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(inputType, accumulateType); genericDelegate = new GenericDelegate <Func <object, object, object, object, object> >(this, method); }
public Return(IGraphRuntime runtime) : base(runtime) { this.inputPin = AddInputPin("Value", PinDataTypeFactory.CreateAny(), PropertyMode.Allow); this.outputPin = AddOutputPin("Sequence", PinDataTypeFactory.Create <ISequence <object> >()); this.inputPin.WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.CreateAny(), false, pinDataType => { var method = EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(pinDataType.UnderlyingType); genericDelegate = new GenericDelegate <Func <object, object> >(this, method); outputPin.ChangeType(PinDataTypeFactory.FromType(typeof(ISequence <>).MakeGenericType(pinDataType.UnderlyingType))); }); }); }
private bool OnDynamicInputAdd(string id) { return(dynamicInputPin.Pin(id).WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType => { var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault(); if (genericType != null) { genericDelegate = new GenericDelegate <Func <object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(genericType)); } else { genericDelegate = null; } var pinsToChange = dynamicInputPin.Pins.Where(x => x.Id != id && x.DataType.UnderlyingType != pinDataType.UnderlyingType).OfType <IDataTypeChangeable>(); foreach (var pin in pinsToChange) { pin.ChangeType(pinDataType); } if (!pinsToChange.Any()) { outputPin.ChangeType(pinDataType); } }); }) != null); }
private void BuildGenericDelegate(Type genericInputType, Type genericOutputType) { if (genericInputType != null && genericOutputType != null) { genericDelegate = new GenericDelegate <Func <object, object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(genericInputType, genericOutputType)); } else { genericDelegate = null; } }
private void BuildGenericDelegate() { var inputType = subGraphSource.DataType.UnderlyingType; var outputType = subGraphResult.DataType.UnderlyingType; var outputElementType = outputType.GenericTypeArguments.FirstOrDefault() ?? typeof(object); genericDelegate = new GenericDelegate <Func <object, object, object, object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(inputType, outputElementType)); }
private void BuildGenericDelegate() { var inputType = subGraphSource.DataType.UnderlyingType; var outputType = subGraphResult.DataType.UnderlyingType; genericDelegate = new GenericDelegate <Func <object, object, object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(inputType, outputType)); }
public Repeat(IGraphRuntime runtime) : base(runtime) { this.inputPin = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never); this.countPin = AddInputPin("Count", PinDataTypeFactory.Create <int?>(null, WellKnownEditors.IntNumber), PropertyMode.Default); this.outputPin = AddOutputPin("Output", PinDataTypeFactory.FromType(typeof(ISequence <object>))); this.inputPin.WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType => { var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault(); if (genericType != null) { genericDelegate = new GenericDelegate <Func <object, object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(genericType)); outputPin.ChangeType(pinDataType); } else { genericDelegate = null; outputPin.ChangeType(PinDataTypeFactory.FromType(typeof(ISequence <object>))); } }); }); }
public Broadcast(IGraphRuntime runtime) : base(runtime) { this.inputPin = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never); this.dynamicOutputPin = new DynamicOutputPin(runtime, outputs, "Output", PinDataTypeFactory.FromType(typeof(ISequence <>))); this.inputPin.WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType => { var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault(); if (genericType != null) { genericDelegate = new GenericDelegate <Func <object, object[]> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(genericType)); } else { genericDelegate = null; } foreach (var pin in dynamicOutputPin.Pins.OfType <IDataTypeChangeable>()) { pin.ChangeType(pinDataType); } }); }); }
public Zip(IGraphRuntime runtime) : base(runtime, true) { this.dynamicInputPin = new DynamicInputPin( runtime, inputs, "Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), OnDynamicInputAdd, id => SubGraph.InputModule.RemoveModulePin(id) ); this.outputPin = AddOutputPin("Output", PinDataTypeFactory.FromType(typeof(ISequence <object>))); this.subGraphResult = this.SubGraph.OutputModule.DefaultInputPin; this.subGraphResult.WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.CreateAny(), false, pinDataType => { this.genericDelegate = new GenericDelegate <Func <object, object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(pinDataType.UnderlyingType)); this.outputPin.ChangeType(PinDataTypeFactory.FromType(typeof(ISequence <>).MakeGenericType(pinDataType.UnderlyingType))); }); }); }
private bool OnDynamicInputAdd(string id) { return(dynamicInputPin.Pin(id).WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.CreateAny(), false, pinDataType => { var dataType = pinDataType.UnderlyingType; this.outputType = dataType; var count = this.dynamicInputPin.Count; var outputType = Array.CreateInstance(dataType, count).GetType(); this.output.ChangeType(PinDataTypeFactory.FromType(outputType)); if (dataType != null) { genericDelegate = new GenericDelegate <Func <object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(dataType)); } else { genericDelegate = null; } }); }) != null); }
private void HandleInputPinEvent(NodeEvent evt) { if (inHandleInputPinEvent) { return; } try { inHandleInputPinEvent = true; var pin = evt.Source as GenericInputPin; var pinDataTypeA = PinDataTypeFactory.FromType(typeof(ISequence <>)); var pinDataTypeB = PinDataTypeFactory.FromType(typeof(ISequence <>)); // determine common type IPinDataType pinDataType; if (firstInputPin.Connections.Any() && secondInputPin.Connections.Any()) { // check if both data types are compatible var firstType = firstInputPin.Connections[0].DataType; var secondType = secondInputPin.Connections[0].DataType; if (firstType.IsAssignableFrom(secondType)) { pinDataType = PinDataTypeFactory.FromType(firstType); } else if (secondType.IsAssignableFrom(firstType)) { pinDataType = PinDataTypeFactory.FromType(secondType); } else { throw new Exception("Connected sequence pin data types are not compatible."); } } else { if (firstInputPin.Connections.Any()) { pinDataType = PinDataTypeFactory.FromType(firstInputPin.Connections[0].DataType); } else if (secondInputPin.Connections.Any()) { pinDataType = PinDataTypeFactory.FromType(secondInputPin.Connections[0].DataType); } else { pinDataType = PinDataTypeFactory.FromType(typeof(ISequence <>)); } } var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault() ?? typeof(object); if (genericType != null) { genericDelegate = new GenericDelegate <Func <object, object, object, Task <bool> > >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(genericType)); } else { genericDelegate = null; } pin.SetType(pinDataType); if (pin == firstInputPin) { secondInputPin.ChangeType(pinDataType); } else { firstInputPin.ChangeType(pinDataType); } } finally { inHandleInputPinEvent = false; } }
private void BuildGenericDelegate() { var inputType = subGraphInput.DataType.UnderlyingType; genericDelegate = new GenericDelegate <Func <object, object, object, Task <bool> > >(this, EvaluateInternalAttribute.GetMethod(GetType())); }
public Where(IGraphRuntime runtime) : base(runtime, false, PinDataTypeFactory.Create <bool>(), SUBGRAPH_SOURCE_PIN_ID) { this.inputPin = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never); this.outputPin = AddOutputPin("Output", PinDataTypeFactory.Create <ISequence <object> >()); this.subGraphSource = ((GenericOutputPin)this.subGraphInputModule.Outputs[SUBGRAPH_SOURCE_PIN_ID]); this.subGraphResult = this.SubGraph.OutputModule.DefaultInputPin; this.inputPin.WhenNodeEvent.Subscribe(evt => { PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType => { var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault() ?? typeof(object); subGraphSource.ChangeType(PinDataTypeFactory.FromType(genericType)); var outputType = PinDataTypeFactory.FromType(typeof(ISequence <>).MakeGenericType(genericType)); if (outputPin.DataType.UnderlyingType != outputType.UnderlyingType) { outputPin.ChangeType(outputType); } genericDelegate = new GenericDelegate <Func <object, object, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(genericType)); }); }); }