Esempio n. 1
0
        void _pipelineDiagram_SelectedComponentChanged(object sender, IPipelineComponent selected)
        {
            gbArguments.Enabled = true;

            if (selected == null)
            {
                _arumentsCollection1.Setup(_activator, null, null, _catalogueRepository);
            }
            else
            {
                _arumentsCollection1.Setup(_activator, selected, selected.GetClassAsSystemType(), _catalogueRepository);
            }
        }
        private object CreateComponent(IPipelineComponent toBuild)
        {
            var type = toBuild.GetClassAsSystemType();

            if (type == null)
            {
                throw new Exception("Could not find Type '" + toBuild.Class + "'");
            }

            object toReturn = _constructor.Construct(type);

            //all the IArguments we need to initialize the class
            var allArguments = toBuild.GetAllArguments().ToArray();

            //get all possible properties that we could set on the underlying class
            foreach (var propertyInfo in toReturn.GetType().GetProperties())
            {
                SetPropertyIfDemanded(toBuild, toReturn, propertyInfo, allArguments);

                //see if any demand nested initialization
                Attribute nestedInit =
                    System.Attribute.GetCustomAttributes(propertyInfo)
                    .FirstOrDefault(a => a is DemandsNestedInitializationAttribute);

                //this one does
                if (nestedInit != null)
                {
                    // initialise the container before nesting-setting all properties
                    var container = Activator.CreateInstance(propertyInfo.PropertyType);

                    foreach (var nestedProp in propertyInfo.PropertyType.GetProperties())
                    {
                        SetPropertyIfDemanded(toBuild, container, nestedProp, allArguments, propertyInfo);
                    }

                    //use reflection to set the container
                    propertyInfo.SetValue(toReturn, container, null);
                }
            }

            return(toReturn);
        }
        private string MustHave(Type mustHaveType, IPipelineComponent component, string descriptionOfThingBeingChecked)
        {
            //it must have destination
            if (mustHaveType != null)
            {
                if (component == null)
                {
                    return("An explicit " + descriptionOfThingBeingChecked + " must be chosen");
                }
                else
                {
                    Type pipelineComponentType = component.GetClassAsSystemType();

                    if (pipelineComponentType == null)
                    {
                        return("PipelineComponent " + component.Class + " could not be created, check MEF assembly loading in the Diagnostics menu");
                    }

                    if (!mustHaveType.IsAssignableFrom(pipelineComponentType))
                    {
                        return("The pipeline requires a " + descriptionOfThingBeingChecked + " of type " + GetFullName(mustHaveType) +
                               " but the currently configured " + descriptionOfThingBeingChecked + GetFullName(pipelineComponentType) +
                               " is not of the same type or a derrived type");
                    }
                }
            }
            else
            //it cannot have destination
            if (component != null)
            {
                return("Context does not allow for an explicit (custom) " + descriptionOfThingBeingChecked);
            }


            return(null);
        }