Animatroller.Simulator.SimulatorForm.AutoWireUsingReflection C# (CSharp) Method

AutoWireUsingReflection() public method

public AutoWireUsingReflection ( IScene scene ) : SimulatorForm
scene IScene
return SimulatorForm
        public SimulatorForm AutoWireUsingReflection(IScene scene, params IRunningDevice[] excludeDevices)
        {
            AutoWireUsingReflection_Simple(scene, excludeDevices);

            var fields = scene.GetType().GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            foreach (var field in fields)
            {
                object fieldValue = field.GetValue(scene);
                if (fieldValue == null)
                    continue;

                // Auto-wire
                if (typeof(IRunningDevice).IsInstanceOfType(fieldValue))
                {
                    if (excludeDevices.Contains((IRunningDevice)fieldValue))
                        // Excluded
                        continue;
                }

                if (field.GetCustomAttributes(typeof(Animatroller.Framework.SimulatorSkipAttribute), false).Any())
                    continue;

                if (typeof(IPort).IsInstanceOfType(fieldValue))
                    continue;

                if (field.FieldType == typeof(Dimmer3))
                    this.Connect(new Animatroller.Simulator.TestLight(this, (Dimmer3)fieldValue));
                else if (field.FieldType == typeof(ColorDimmer3))
                    this.Connect(new Animatroller.Simulator.TestLight(this, (ColorDimmer3)fieldValue));
                else if (field.FieldType == typeof(StrobeColorDimmer3))
                    this.Connect(new Animatroller.Simulator.TestLight(this, (StrobeColorDimmer3)fieldValue));
                else if (field.FieldType == typeof(StrobeDimmer3))
                    this.Connect(new Animatroller.Simulator.TestLight(this, (StrobeDimmer3)fieldValue));
                else if (field.FieldType == typeof(MovingHead))
                    this.Connect(new Animatroller.Simulator.TestLight(this, (MovingHead)fieldValue));
                //else if (field.FieldType == typeof(Pixel1D))
                //    this.Connect(new Animatroller.Simulator.TestPixel1D((Pixel1D)fieldValue));
                //else if (field.FieldType == typeof(Pixel1D))
                //    this.Connect(new Animatroller.Simulator.TestPixel1D((Pixel1D)fieldValue));
                //else if (field.FieldType == typeof(VirtualPixel1D2))
                //    this.Connect(new Animatroller.Simulator.TestPixel1D((VirtualPixel1D2)fieldValue));
                else if (field.FieldType == typeof(VirtualPixel1D3))
                    this.Connect(new Animatroller.Simulator.TestPixel1D(this, (VirtualPixel1D3)fieldValue));
                else if (field.FieldType == typeof(VirtualPixel2D3))
                    this.Connect(new Animatroller.Simulator.TestPixel2D(this, (VirtualPixel2D3)fieldValue));
                //else if (field.FieldType == typeof(VirtualPixel2D))
                //    this.Connect(new Animatroller.Simulator.TestPixel2D((VirtualPixel2D)fieldValue));
                else if (field.FieldType == typeof(AnalogInput3))
                    this.AddAnalogInput((AnalogInput3)fieldValue);
                else if (field.FieldType == typeof(MotorWithFeedback))
                {
                    // Skip
                    //                    this.AddMotor((MotorWithFeedback)fieldValue);
                }
                else if (field.FieldType == typeof(DigitalInput2))
                {
                    var buttonType = (Animatroller.Framework.SimulatorButtonTypeAttribute)
                        field.GetCustomAttributes(typeof(Animatroller.Framework.SimulatorButtonTypeAttribute), false).FirstOrDefault();

                    if (buttonType != null)
                    {
                        switch (buttonType.Type)
                        {
                            case Framework.SimulatorButtonTypes.FlipFlop:
                                AddDigitalInput_FlipFlop((DigitalInput2)fieldValue, buttonType.ShowOutput);
                                break;

                            case Framework.SimulatorButtonTypes.Momentarily:
                                AddDigitalInput_Momentarily((DigitalInput2)fieldValue);
                                break;
                        }
                    }
                    else
                        AddDigitalInput_Momentarily((DigitalInput2)fieldValue);
                }
                else if (field.FieldType == typeof(DigitalOutput2))
                {
                    this.AddDigitalOutput((DigitalOutput2)fieldValue);
                }
                else if (field.FieldType == typeof(AudioPlayer))
                {
                    // Skip
                }
                else if (field.FieldType == typeof(Animatroller.Framework.Expander.OscServer))
                {
                    // Skip
                }
                else if (field.FieldType == typeof(Animatroller.Framework.Controller.Sequence))
                {
                    // Skip
                }
                else if (field.FieldType == typeof(Animatroller.Framework.Import.LorImport))
                {
                    // Skip
                }
                else if (field.FieldType == typeof(Animatroller.Framework.Import.VixenImport))
                {
                    // Skip
                }
                else if (field.FieldType == typeof(Animatroller.Framework.Import.BaseImporter.Timeline))
                {
                    // Skip
                }
                else if (field.FieldType == typeof(OperatingHours2))
                {
                    // Skip
                }
                else if (field.FieldType == typeof(Animatroller.Framework.Controller.Subroutine))
                {
                    // Skip
                }
                else if (field.FieldType == typeof(Animatroller.Framework.LogicalDevice.VideoPlayer))
                {
                    // Skip
                }
                else if (field.FieldType.Name.StartsWith("EnumStateMachine") ||
                    field.FieldType.Name.StartsWith("IntStateMachine") ||
                    field.FieldType.Name.StartsWith("Timeline"))
                {
                    // Skip
                }
                else if (field.FieldType.FullName.StartsWith("Animatroller.Framework.Effect."))
                {
                    // Skip
                }
                else if (field.FieldType.FullName.StartsWith("Animatroller.Framework.Import."))
                {
                    // Skip
                }
                else
                {
                    log.Trace("Unknown field {0}", field.FieldType);
                }
            }

            return this;
        }