Пример #1
0
        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;
            }
        }
Пример #2
0
 public CreateArray(IGraphRuntime runtime)
     : base(runtime)
 {
     this.dynamicInputPin = new DynamicInputPin(runtime, inputs, "Input", PinDataTypeFactory.CreateAny(), OnDynamicInputAdd)
     {
         ForceAutoId = true
     };
     this.output = AddOutputPin("Output", PinDataTypeFactory.FromType(typeof(Array)));
 }
Пример #3
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)));
                });
            });
        }
Пример #4
0
        public ConverterModule(IGraphRuntime runtime)
            : base(runtime)
        {
            converterByName.Add("None", null);

            foreach (var c in runtime.TypeConverters)
            {
                string sourceTypeName      = GetShortTypeName(c.SourceType);
                string destinationTypeName = GetShortTypeName(c.DestinationType);

                var converterName = string.Concat(sourceTypeName, " -> ", destinationTypeName);
                if (!converterByName.ContainsKey(converterName))
                {
                    converterByName.Add(converterName, c);
                }
            }

            this.inputPin     = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(object)), PropertyMode.Never);
            this.converterPin = AddInputPin("Converter", PinDataTypeFactory.CreateDynamicEnum(converterByName.Keys.ToArray(), "None"), PropertyMode.Always);
            this.outputPin    = AddOutputPin("Output", PinDataTypeFactory.FromType(typeof(object)));

            this.properties[converterPin.Id].WhenNodeEvent.OfType <PropertyChangedEvent>().Subscribe(x =>
            {
                var converterName = (string)x.Value.Value;
                converterByName.TryGetValue(converterName, out typeConverter);

                IPinDataType sourceType, destinationType;
                if (typeConverter == null)
                {
                    sourceType      = PinDataTypeFactory.CreateAny();
                    destinationType = PinDataTypeFactory.CreateAny();
                }
                else
                {
                    sourceType      = typeConverter.SourceType != null ? PinDataTypeFactory.FromType(typeConverter.SourceType) : PinDataTypeFactory.CreateAny();
                    destinationType = typeConverter.DestinationType != null ? PinDataTypeFactory.FromType(typeConverter.DestinationType) : PinDataTypeFactory.CreateAny();
                }

                var errors = inputPin.ChangeType(sourceType).Concat(outputPin.ChangeType(destinationType));
                if (errors.Any())
                {
                    throw new AggregateException("One or more connections could not be reestablished after a data type change.", errors);
                }
            });
        }
Пример #5
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);
        }
Пример #6
0
        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)));
                });
            });
        }