示例#1
0
        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>)));
                    }
                });
            });
        }
示例#2
0
        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()));
                });
            });
        }
示例#3
0
        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));
                });
            });
        }
示例#4
0
        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);
                    }
                });
            });
        }
示例#5
0
        public Cast(IGraphRuntime runtime)
            : base(runtime)
        {
            this.inputPin      = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);
            this.targetTypePin = AddInputPin("TargetType", PinDataTypeFactory.CreateEnum <ConvertTypeCode>(ConvertTypeCode.Float64), PropertyMode.Always);
            this.outputPin     = AddOutputPin("Output", PinDataTypeFactory.FromType(typeof(ISequence <>)));
            this.outputPin.ChangeType(CreateTargetPinDataType(ConvertTypeCode.Float64));
            this.inputPin.WhenNodeEvent.Subscribe(evt =>
            {
                PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType =>
                {
                    var genericInputType  = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault();
                    var genericOutputType = outputPin.DataType.UnderlyingType.GenericTypeArguments.FirstOrDefault();
                    BuildGenericDelegate(genericInputType, genericOutputType);
                });
            });

            this.properties[targetTypePin.Id].WhenNodeEvent.OfType <PropertyChangedEvent>().Subscribe(x =>
            {
                var targetTypeCode = (ConvertTypeCode)x.Value.Value;

                IPinDataType targetPinDataType = CreateTargetPinDataType(targetTypeCode);
                var errors = outputPin.ChangeType(targetPinDataType);
                if (errors.Any())
                {
                    throw new AggregateException("One or more connections could not be reestablished after a data type change.", errors);
                }

                var genericInputType  = inputPin.DataType.UnderlyingType.GenericTypeArguments.FirstOrDefault();
                var genericOutputType = outputPin.DataType.UnderlyingType.GenericTypeArguments.FirstOrDefault();
                BuildGenericDelegate(genericInputType, genericOutputType);
            });
        }
示例#6
0
文件: Zip.cs 项目: Xamla/graph_system
        private bool OnDynamicInputAdd(string id)
        {
            dynamicInputPin.Pin(id).WhenNodeEvent.Subscribe(evt =>
            {
                PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType =>
                {
                    var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault() ?? typeof(object);

                    var pinEvent = (PinConnectionChangeEvent)evt;

                    // subgraph input
                    var pin = SubGraph.InputModule.Outputs.Where(x => x.Id == pinEvent.Source.Id).OfType <IDataTypeChangeable>().FirstOrDefault();
                    pin.ChangeType(PinDataTypeFactory.FromType(genericType));
                });
            });

            try
            {
                addingSubGraphPin = true;
                return(SubGraph.InputModule.AddModulePin(id, true, PinDataTypeFactory.CreateAny()) != null);
            }
            finally
            {
                addingSubGraphPin = false;
            }
        }
示例#7
0
        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));
                });
            });
        }
示例#8
0
        public Count(IGraphRuntime runtime)
            : base(runtime)
        {
            this.inputPin  = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);
            this.outputPin = AddOutputPin("Output", PinDataTypeFactory.CreateInt32());

            this.inputPin.WhenNodeEvent.Subscribe(evt =>
            {
                PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true);
            });
        }
示例#9
0
        public ToSequence(IGraphRuntime runtime)
            : base(runtime)
        {
            this.inputPin  = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(IEnumerable <>)), PropertyMode.Never);
            this.outputPin = AddOutputPin("Output", PinDataTypeFactory.FromType(typeof(ISequence <>)));

            this.inputPin.WhenNodeEvent.Subscribe(evt =>
            {
                PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(IEnumerable <>)), false, pinDataType =>
                {
                    var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault() ?? typeof(object);

                    outputPin.ChangeType(PinDataTypeFactory.FromType(typeof(ISequence <>).MakeGenericType(genericType)));
                });
            });
        }
示例#10
0
        public ForEach(IGraphRuntime runtime)
            : base(runtime, false, (IPinDataType)null, SUBGRAPH_SOURCE_PIN_ID)
        {
            this.inputPin = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);

            this.subGraphSource = ((GenericOutputPin)this.subGraphInputModule.Outputs[SUBGRAPH_SOURCE_PIN_ID]);

            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));
                });
            });
        }
示例#11
0
        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)));
                });
            });
        }
示例#12
0
文件: Any.cs 项目: Xamla/graph_system
        public Any(IGraphRuntime runtime)
            : base(runtime, false, PinDataTypeFactory.Create <bool>(), SUBGRAPH_SOURCE_PIN_ID)
        {
            this.input  = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);
            this.output = AddOutputPin("Output", PinDataTypeFactory.CreateBoolean());

            this.subGraphInput = ((GenericOutputPin)this.subGraphInputModule.Outputs[SUBGRAPH_SOURCE_PIN_ID]);

            this.input.WhenNodeEvent.Subscribe(evt =>
            {
                PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType =>
                {
                    var genericType = pinDataType.UnderlyingType.GenericTypeArguments.FirstOrDefault() ?? typeof(object);
                    subGraphInput.ChangeType(PinDataTypeFactory.FromType(genericType));

                    BuildGenericDelegate();
                });
            });
        }
示例#13
0
        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);
        }
示例#14
0
        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.SetType(pinDataType);
                    }

                    if (!pinsToChange.Any())
                    {
                        if (genericType != null)
                        {
                            output.ChangeType(pinDataType);
                        }
                        else
                        {
                            output.ChangeType(PinDataTypeFactory.FromType(typeof(ISequence <object>)));
                        }
                    }
                });
            }) != null);
        }
示例#15
0
文件: Zip.cs 项目: Xamla/graph_system
        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)));
                });
            });
        }
示例#16
0
文件: If.cs 项目: Xamla/graph_system
 private bool OnDynamicInputAdd(string id)
 {
     arguments.Pin(id).WhenNodeEvent.Subscribe(evt => PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.CreateAny(), false));
     return(true);
 }