Esempio n. 1
0
        public Take(IGraphRuntime runtime)
            : base(runtime)
        {
            this.inputPin  = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);
            this.countPin  = AddInputPin("Count", PinDataTypeFactory.CreateInt32(5), PropertyMode.Default);
            this.outputPin = AddOutputPin("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, object> >(this, EvaluateInternalAttribute.GetMethod(GetType()).MakeGenericMethod(genericType));
                    }
                    else
                    {
                        genericDelegate = null;
                    }

                    outputPin.ChangeType(pinDataType);
                });
            });
        }
Esempio n. 2
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));
                });
            });
        }
Esempio n. 3
0
 public ViewCurrent(IGraphRuntime runtime)
     : base(runtime, ModuleKind.ViewModule)
 {
     this.inputPin = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <string>), string.Empty, WellKnownEditors.Hidden, null, null), PropertyMode.Never);
     this.data     = AddInputPin("data", PinDataTypeFactory.CreateString(), PropertyMode.Always);
     EnableVirtualOutputPin();
 }
Esempio n. 4
0
        private static IPinDataType CreateTargetPinDataType(ConvertTypeCode typeCode)
        {
            switch (typeCode)
            {
            case ConvertTypeCode.Any:
                return(PinDataTypeFactory.CreateAny());;

            case ConvertTypeCode.Boolean:
                return(PinDataTypeFactory.CreateBoolean());

            case ConvertTypeCode.Byte:
                return(PinDataTypeFactory.FromType(typeof(byte)));

            case ConvertTypeCode.Int16:
                return(PinDataTypeFactory.FromType(typeof(short)));

            case ConvertTypeCode.Int32:
                return(PinDataTypeFactory.CreateInt32());

            case ConvertTypeCode.Int64:
                return(PinDataTypeFactory.FromType(typeof(long)));

            case ConvertTypeCode.Float32:
                return(PinDataTypeFactory.FromType(typeof(float)));

            case ConvertTypeCode.Float64:
                return(PinDataTypeFactory.FromType(typeof(double)));

            case ConvertTypeCode.String:
                return(PinDataTypeFactory.CreateString());
            }

            return(PinDataTypeFactory.Create <object>());
        }
Esempio n. 5
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()));
                });
            });
        }
Esempio n. 6
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);
            });
        }
Esempio n. 7
0
        public Aggregate(IGraphRuntime runtime)
            : base(runtime, false, SUBGRAPH_SOURCE_PIN_ID, SUBGRAPH_ACCUMULATE_PIN_ID)
        {
            this.sourceInput = AddInputPin("Source", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);
            this.seedInput   = AddInputPin("Seed", PinDataTypeFactory.CreateAny(), PropertyMode.Allow);
            this.output      = AddOutputPin("Output", PinDataTypeFactory.CreateAny());

            this.subGraphInput      = ((GenericOutputPin)this.subGraphInputModule.Outputs[SUBGRAPH_SOURCE_PIN_ID]);
            this.subGraphAccumulate = (GenericOutputPin)this.subGraphInputModule.Outputs[SUBGRAPH_ACCUMULATE_PIN_ID];
            this.subGraphOutput     = subGraph.OutputModule.DefaultInputPin;

            this.sourceInput.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();
                });
            });

            this.seedInput.WhenNodeEvent.Subscribe(evt =>
            {
                PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.CreateAny(), false, pinDataType =>
                {
                    subGraphAccumulate.ChangeType(pinDataType);
                    output.ChangeType(pinDataType);
                    subGraphOutput.ChangeType(pinDataType);

                    BuildGenericDelegate();
                });
            });
        }
Esempio n. 8
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;
            }
        }
Esempio n. 9
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.ChangeType(pinDataType);
                    }

                    if (!pinsToChange.Any())
                    {
                        outputPin.ChangeType(pinDataType);
                    }
                });
            }) != null);
        }
Esempio n. 10
0
        public SelectMany(IGraphRuntime runtime)
            : base(runtime, false, PinDataTypeFactory.FromType(typeof(ISequence <>)), SUBGRAPH_SOURCE_PIN_ID)
        {
            this.inputPin          = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);
            this.sequentialPin     = AddInputPin("Sequential", PinDataTypeFactory.Create <bool>(true), PropertyMode.Default);
            this.outputPin         = AddOutputPin("Output", PinDataTypeFactory.Create <ISequence <object> >());
            this.maxConcurrencyPin = AddInputPin("MaxConcurrency", PinDataTypeFactory.Create <int>(8), PropertyMode.Default);

            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));

                    BuildGenericDelegate();
                });
            });

            this.subGraphResult.WhenNodeEvent.Subscribe(evt =>
            {
                PinConnectionChangeEventHandler.ConnectionSensitivePinDataType(evt, PinDataTypeFactory.FromType(typeof(ISequence <>)), true, pinDataType =>
                {
                    outputPin.ChangeType(pinDataType);

                    BuildGenericDelegate();
                });
            });
        }
Esempio n. 11
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);
                    }
                });
            });
        }
Esempio n. 12
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)));
 }
Esempio n. 13
0
 public Merge(IGraphRuntime runtime)
     : base(runtime)
 {
     this.dynamicInputPin = new DynamicInputPin(runtime, inputs, "Input", PinDataTypeFactory.FromType(typeof(ISequence <>)), OnDynamicInputAdd)
     {
         Renameable = true
     };
     this.outputPin = AddOutputPin("Output", PinDataTypeFactory.FromType(typeof(ISequence <>)));
 }
Esempio n. 14
0
        public SequenceEqual(IGraphRuntime runtime)
            : base(runtime)
        {
            this.firstInputPin  = AddInputPin("First", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);
            this.secondInputPin = AddInputPin("Second", PinDataTypeFactory.FromType(typeof(ISequence <>)), PropertyMode.Never);
            this.outputPin      = AddOutputPin("Result", PinDataTypeFactory.CreateBoolean());

            this.firstInputPin.WhenNodeEvent.Subscribe(HandleInputPinEvent);
            this.secondInputPin.WhenNodeEvent.Subscribe(HandleInputPinEvent);
        }
Esempio n. 15
0
        public void BuildOutputPins(Type itemType)
        {
            if (itemType == this.itemType)
            {
                return;
            }

            // do not fall back to object when we have build pins for another type before
            // (most likely the drop back to object is due to a disconnect and we do not want to loose all existing connections)
            if (itemType == typeof(object) && itemPropertyPins.Count > 0)
            {
                return;
            }

            var oldConnections = new Dictionary <string, IPin[]>();

            // remove all outputs
            foreach (var itemPropertiesPin in itemPropertyPins)
            {
                oldConnections.Add(itemPropertiesPin.Id, itemPropertiesPin.Connections.Select(x => x.Remote).ToArray());
                itemPropertiesPin.DisconnectAll();
                outputs.Remove(itemPropertiesPin);
            }
            itemPropertyPins.Clear();

            var itemProperties = itemType.GetProperties(BINDING_FLAGS).Where(p => p.GetIndexParameters().Length == 0);

            if (itemProperties.Any())
            {
                // add one output pin for every property
                foreach (var property in itemProperties)
                {
                    if (this.itemPropertyPins.Any(p => p.Id == property.Name))
                    {
                        continue;
                    }

                    var pin = AddOutputPin(property.Name, PinDataTypeFactory.FromType(property.PropertyType));
                    this.itemPropertyPins.Add(pin);

                    // try to reestablish exsting connections
                    RestorePinConnection(pin, oldConnections);
                }
            }
            else
            {
                // add a single pin for items without properties
                this.itemPropertyPins.Add(AddOutputPin(itemType.Name, PinDataTypeFactory.FromType(itemType)));
            }

            // store current type in property
            this.ItemTypeName = itemType.AssemblyQualifiedName;
            this.itemType     = itemType;
        }
Esempio n. 16
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);
            });
        }
Esempio n. 17
0
        public GetValuesFromArray(IGraphRuntime runtime)
            : base(runtime)
        {
            this.AddInputPin(COUNT_PIN_NAME, PinDataTypeFactory.FromType(typeof(int)), PropertyMode.Always);
            this.AddInputPin("array", PinDataTypeFactory.FromType(typeof(Array)), PropertyMode.Never);

            this.AddOutputPin("OutputRemainings", PinDataTypeFactory.FromType(typeof(Array)));
            this.dynamicOutputPin = new DynamicOutputPin(runtime, outputs, "Output", PinDataTypeFactory.Create <object>());

            this.properties[COUNT_PIN_NAME]
            .WhenNodeEvent
            .OfType <PropertyChangedEvent>()
            .Subscribe(x => UpdateOutputs((int)x.Value.Value));
        }
Esempio n. 18
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)));
                });
            });
        }
Esempio n. 19
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));
                });
            });
        }
Esempio n. 20
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)));
                });
            });
        }
Esempio n. 21
0
 public ForceType(IGraphRuntime runtime)
     : base(runtime)
 {
     this.input  = AddInputPin("Input", PinDataTypeFactory.CreateAny(), PropertyMode.Never);
     this.output = AddOutputPin("Output", PinDataTypeFactory.CreateAny());
     this.type   = AddInputPin("Type", PinDataTypeFactory.CreateString("System.Object"), PropertyMode.Always);
     this.properties[this.type.Id].WhenNodeEvent.OfType <PropertyChangedEvent>().Subscribe(x =>
     {
         var genericInputType = Type.GetType((string)x.Value.Value, false, true) ?? typeof(object);
         var dataType         = PinDataTypeFactory.FromType(genericInputType);
         var errors           = input.ChangeType(dataType).Concat(output.ChangeType(dataType));
         if (errors.Any())
         {
             throw new AggregateException("One or more connections could not be reestablished after a data type change.", errors);
         }
     });
 }
Esempio n. 22
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);
                }
            });
        }
Esempio n. 23
0
        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();
                });
            });
        }
Esempio n. 24
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);
        }
Esempio n. 25
0
        public ReadableToV(IGraphRuntime runtime)
            : base(runtime)
        {
            this.targetTypePin = AddInputPin("TargetType", PinDataTypeFactory.CreateEnum <ConvertTypeCode>(ConvertTypeCode.Float64), PropertyMode.Always);
            this.outputPin     = AddOutputPin("Output", PinDataTypeFactory.FromType(typeof(V <>)));
            this.outputPin.ChangeType(CreateTargetPinDataType(ConvertTypeCode.Float64));
            this.data = AddInputPin("Input", PinDataTypeFactory.FromType(typeof(IReadable)), PropertyMode.Allow);

            this.delimiter = AddInputPin("Delimiter", PinDataTypeFactory.FromType(typeof(char), ','), PropertyMode.Default);

            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 del = (char)this.Properties.GetValue("Delimiter");
        }
Esempio n. 26
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)));
                });
            });
        }
Esempio n. 27
0
        protected virtual void UpdateSignature()
        {
            if (this.Graph == null)     // file path resolving only possible when module is attached to graph
            {
                return;
            }

            logger.LogInformation("UpdateSignature");
            lock (gate)
            {
                PySignature signature = null;

                // when there is no script available
                var src = this.GetScript();
                if (string.IsNullOrEmpty(src))
                {
                    // there are no arguments
                    signature   = new PySignature();
                    this.Script = null;
                    SetParserError(null);
                }
                else
                {
                    mainThread.RunSync(() =>
                    {
                        using (PyScope ps = Py.CreateScope())
                        {
                            PyObject script = PythonEngine.Compile(src, filename ?? "", mode);
                            ps.Execute(script);
                            signature   = PySignature.GetSignature(ps, this.FunctionName);
                            this.Script = script;
                        }
                    });

                    this.SetParserError(null);
                }

                try
                {
                    this.signature = signature;

                    // remove all argument pins that no longer exist
                    var unusedPins = argumentPins.Where(pin => !signature.HasArgument(pin.Id)).ToArray();
                    foreach (var unusedPin in unusedPins)
                    {
                        unusedPin.DisconnectAll();
                        argumentPins.Remove(unusedPin);
                        logger.LogInformation($"Removing input pin: {unusedPin.Id}");
                        inputs.Remove(unusedPin);
                    }

                    foreach (var arg in signature.Arguments)
                    {
                        var existingPin = argumentPins.FirstOrDefault(x => x.Id == arg.Name);
                        if (existingPin == null)
                        {
                            var newPin = this.AddInputPin(arg.Name, PinDataTypeFactory.FromType(arg.Type), PropertyMode.Allow);
                            argumentPins.Add(newPin);
                        }
                        else
                        {
                            // check type
                            if (existingPin.DataType.UnderlyingType != arg.Type)
                            {
                                existingPin.ChangeType(PinDataTypeFactory.FromType(arg.Type));
                            }
                        }
                    }

                    // get all pin ids which are not member of this dynamic pin collection
                    var nonDynamicPinIds = this.inputs.Where(x => !argumentPins.Contains(x)).Select(x => x.ObjectId);

                    // reorder module input pins
                    var orderedArgumentPinObjectIds = signature.Arguments.Select(x => argumentPins.First(y => y.Id == x.Name).ObjectId);
                    var newOrder = nonDynamicPinIds.Concat(orderedArgumentPinObjectIds).ToArray();
                    this.inputs.Reorder(newOrder);

                    // analyse return type of script
                    Type[] returnTypes;
                    if (signature.ReturnType == null)
                    {
                        returnTypes = new Type[0];
                    }
                    else if (TypeHelpers.IsTuple(signature.ReturnType))
                    {
                        returnTypes = TypeHelpers.GetTupleTypes(signature.ReturnType);
                    }
                    else
                    {
                        returnTypes = new Type[] { signature.ReturnType };
                    }

                    // remove pins that are not needed anymore
                    while (resultPins.Count > returnTypes.Length)
                    {
                        var last = resultPins[resultPins.Count - 1];
                        logger.LogInformation($"Removing output pin: {last.Id}");
                        last.DisconnectAll();
                        outputs.Remove(last);
                        resultPins.RemoveAt(resultPins.Count - 1);
                    }

                    for (int i = 0; i < returnTypes.Length; i++)
                    {
                        if (i < resultPins.Count)
                        {
                            var existingPin = resultPins[i];
                            if (existingPin.DataType.UnderlyingType != returnTypes[i])
                            {
                                existingPin.ChangeType(PinDataTypeFactory.FromType(returnTypes[i]));
                            }
                        }
                        else
                        {
                            var newPin = this.AddOutputPin($"output{i}", PinDataTypeFactory.FromType(returnTypes[i]));
                            resultPins.Add(newPin);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw;
                }
            }
        }
Esempio n. 28
0
        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;
            }
        }