Пример #1
0
        protected override IEnumerable <Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            var contractName = definition.ContractName;

            if (contractName == typeof(IIOFactory).FullName)
            {
                yield return(new Export(contractName, () => FIOFactory));
            }
            else
            {
                var typeToExport = ExportProviderUtils.GetImportDefinitionType(definition);

                foreach (var attribute in ExportProviderUtils.GetImportDefinitionAttributes(definition))
                {
                    var ioAttribute = attribute as IOAttribute;
                    if (ioAttribute == null)
                    {
                        continue;
                    }

                    var context = IOBuildContext.Create(typeToExport, ioAttribute);
                    if (FIOFactory.CanCreateIOContainer(context))
                    {
                        yield return(new Export(contractName, () => FIOFactory.CreateIO(context)));

                        yield break;
                    }
                }
            }
        }
Пример #2
0
        public virtual bool CanCreate(IOBuildContext context)
        {
            foreach (var registry in FRegistries)
            {
                if (registry.CanCreate(context))
                {
                    return(true);
                }
            }
            var ioType     = context.IOType;
            var openIOType = ioType.IsGenericType ? ioType.GetGenericTypeDefinition() : ioType;

            switch (context.Direction)
            {
            case PinDirection.Input:
                return(FInputDelegates.ContainsKey(ioType) || FInputDelegates.ContainsKey(openIOType));

            case PinDirection.Output:
                return(FOutputDelegates.ContainsKey(ioType) || FOutputDelegates.ContainsKey(openIOType));

            case PinDirection.Configuration:
                return(FConfigDelegates.ContainsKey(ioType) || FConfigDelegates.ContainsKey(openIOType));

            default:
                return(false);
            }
        }
Пример #3
0
        public override bool CanCreate(IOBuildContext context)
        {
            var ioType    = context.IOType;
            var dataType  = context.DataType;
            var attribute = context.IOAttribute;

            if (dataType != null)
            {
                var baseType = dataType.BaseType;
                if (baseType != null && baseType == typeof(Enum))
                {
                    var openIOType = ioType.GetGenericTypeDefinition();
                    if (attribute is InputAttribute)
                    {
                        return(FInputDelegates.ContainsKey(openIOType));
                    }
                    if (attribute is OutputAttribute)
                    {
                        return(FOutputDelegates.ContainsKey(openIOType));
                    }
                    if (attribute is ConfigAttribute)
                    {
                        return(FConfigDelegates.ContainsKey(openIOType));
                    }
                }
            }
            return(false);
        }
Пример #4
0
 public IIOContainer CreateIOContainer(IIOFactory factory, IOBuildContext context)
 {
     if (FCanCreate(context))
     {
         return(FCreate(factory, context));
     }
     return(FRegistry.CreateIOContainer(factory, context));
 }
Пример #5
0
 public bool CanCreate(IOBuildContext context)
 {
     if (FCanCreate(context))
     {
         return(true);
     }
     return(FRegistry.CanCreate(context));
 }
Пример #6
0
        private static IIOContainer CreateConfig(IIOFactory factory, IOBuildContext <ConfigAttribute> context)
        {
            var container  = factory.CreateIOContainer(context.ReplaceIOType(typeof(IEnumConfig)));
            var streamType = typeof(EnumConfigStream <>).MakeGenericType(context.DataType);
            var stream     = Activator.CreateInstance(streamType, container.RawIOObject) as IIOStream;

            return(IOContainer.Create(context, stream, container, null, s => s.Flush(), s => s.Sync()));
        }
Пример #7
0
        public IIOContainer CreateIOContainer(IOBuildContext context)
        {
            var io = FIORegistry.CreateIOContainer(this, context);

            if (io == null)
            {
                throw new NotSupportedException(string.Format("Can't create container for build context '{1}'.", context));
            }
            return(io);
        }
Пример #8
0
 public IOContainerBase(IOBuildContext context, IIOFactory factory, IIOContainer baseContainer, object rawIOObject)
 {
     Factory       = factory;
     BaseContainer = baseContainer;
     RawIOObject   = rawIOObject;
     if (context.SubscribeToIOEvents)
     {
         Factory.Disposing += HandleFactoryDisposing;
     }
 }
Пример #9
0
        private IIOContainer GetColorContainer(IIOFactory factory, IOBuildContext <InputAttribute> context, out int *pLength, out double **ppDoubleData, out Func <bool> validateFunc)
        {
            IIOContainer container;

            container = factory.CreateIOContainer(context.ReplaceIOType(typeof(IColorIn)));
            var colorIn = container.RawIOObject as IColorIn;

            colorIn.GetColorPointer(out pLength, out ppDoubleData);
            validateFunc = GetValidateFunc(colorIn, context.IOAttribute.AutoValidate);

            return(container);
        }
Пример #10
0
        private IIOContainer GetMatrixContainer(IIOFactory factory, IOBuildContext <InputAttribute> context, out int *pLength, out float **ppMatrixData, out Func <bool> validateFunc)
        {
            IIOContainer container;

            container = factory.CreateIOContainer(context.ReplaceIOType(typeof(ITransformIn)));
            var matrixIn = container.RawIOObject as ITransformIn;

            matrixIn.GetMatrixPointer(out pLength, out ppMatrixData);
            validateFunc = GetValidateFunc(matrixIn, context.IOAttribute.AutoValidate);

            return(container);
        }
Пример #11
0
        public virtual IIOContainer CreateIOContainer(IIOFactory factory, IOBuildContext context)
        {
            foreach (var registry in FRegistries)
            {
                if (registry.CanCreate(context))
                {
                    return(registry.CreateIOContainer(factory, context));
                }
            }

            var ioType     = context.IOType;
            var dataType   = context.DataType;
            var openIOType = ioType.IsGenericType ? ioType.GetGenericTypeDefinition() : ioType;

            switch (context.Direction)
            {
            case PinDirection.Input:
                if (FInputDelegates.ContainsKey(ioType))
                {
                    return(FInputDelegates[ioType](factory, context as IOBuildContext <InputAttribute>));
                }
                else if (FInputDelegates.ContainsKey(openIOType))
                {
                    return(FInputDelegates[openIOType](factory, context as IOBuildContext <InputAttribute>));
                }
                break;

            case PinDirection.Output:
                if (FOutputDelegates.ContainsKey(ioType))
                {
                    return(FOutputDelegates[ioType](factory, context as IOBuildContext <OutputAttribute>));
                }
                else if (FOutputDelegates.ContainsKey(openIOType))
                {
                    return(FOutputDelegates[openIOType](factory, context as IOBuildContext <OutputAttribute>));
                }
                break;

            case PinDirection.Configuration:
                if (FConfigDelegates.ContainsKey(ioType))
                {
                    return(FConfigDelegates[ioType](factory, context as IOBuildContext <ConfigAttribute>));
                }
                else if (FConfigDelegates.ContainsKey(openIOType))
                {
                    return(FConfigDelegates[openIOType](factory, context as IOBuildContext <ConfigAttribute>));
                }
                break;
            }

            throw new NotSupportedException(string.Format("Can't create {0} of type '{1}'.", context, ioType));
        }
Пример #12
0
        public static IIOContainer Create <T>(
            IOBuildContext context,
            IIOFactory factory,
            T ioObject,
            Action <T> syncAction  = null,
            Action <T> flushAction = null
            )
        {
            // We need to construct with runtime type here, as compiletime type might be too simple (cast exceptions later).
            var ioHandlerType = typeof(GenericIOContainer <>).MakeGenericType(ioObject.GetType());

            return((IIOContainer)Activator.CreateInstance(ioHandlerType, context, factory, ioObject, syncAction, flushAction));
        }
Пример #13
0
        public static IIOContainer Create <TIOObject>(
            IOBuildContext context,
            TIOObject iOObject,
            IIOContainer baseIOContainer,
            Action <TIOObject> preEvalAction  = null,
            Action <TIOObject> postEvalAction = null,
            Action <TIOObject> configAction   = null
            )
        {
            // We need to construct with runtime type here, as compiletime type might be too simple (cast exceptions later).
            var ioHandlerType = typeof(IOContainer <>).MakeGenericType(iOObject.GetType());

            return((IIOContainer)Activator.CreateInstance(ioHandlerType, context, iOObject, baseIOContainer, preEvalAction, postEvalAction, configAction));
        }
Пример #14
0
        public bool CanCreateIOContainer(IOBuildContext context)
        {
            if (!FIORegistry.CanCreate(context))
            {
                var type = context.IOType;
                if (type.IsGenericType)
                {
                    var openGenericType = type.GetGenericTypeDefinition();
                    return(FIORegistry.CanCreate(context.ReplaceIOType(openGenericType)));
                }

                return(false);
            }
            return(true);
        }
Пример #15
0
        private static IIOContainer CreateOutput(IIOFactory factory, IOBuildContext <OutputAttribute> context)
        {
            var container  = factory.CreateIOContainer(context.ReplaceIOType(typeof(IEnumOut)));
            var streamType = typeof(EnumOutStream <>).MakeGenericType(context.DataType);
            var stream     = Activator.CreateInstance(streamType, container.RawIOObject) as IOutStream;

            if (context.IOAttribute.AutoFlush)
            {
                return(IOContainer.Create(context, stream, container, null, s => s.Flush()));
            }
            else
            {
                return(IOContainer.Create(context, stream, container));
            }
        }
Пример #16
0
        private static IIOContainer CreateInput(IIOFactory factory, IOBuildContext <InputAttribute> context)
        {
            var container  = factory.CreateIOContainer(context.ReplaceIOType(typeof(IEnumIn)));
            var streamType = typeof(EnumInStream <>).MakeGenericType(context.DataType);
            var stream     = Activator.CreateInstance(streamType, container.RawIOObject) as IInStream;

            // Using ManagedIOStream -> needs to be synced on managed side.
            if (context.IOAttribute.AutoValidate)
            {
                return(IOContainer.Create(context, stream, container, s => s.Sync()));
            }
            else
            {
                return(IOContainer.Create(context, stream, container));
            }
        }
Пример #17
0
        public override bool CanCreate(IOBuildContext context)
        {
            // In case of multidimensional streams we're only interested in:
            // * IInStream<IEnumerable<T>>, IInStream<Spread<T>>
            // * IOutStream<Spread<T>>
            var ioType = context.IOType;

            if (ioType.IsGenericType)
            {
                var genericArgument = ioType.GetGenericArguments()[0];
                if (genericArgument.IsGenericType)
                {
                    var attribute  = context.IOAttribute;
                    var openIOType = ioType.GetGenericTypeDefinition();
                    if (openIOType == typeof(IInStream <>) && attribute.IsBinSizeEnabled)
                    {
                        var genericTypeDefinition = genericArgument.GetGenericTypeDefinition();
                        return(genericTypeDefinition == typeof(IEnumerable <>) ||
                               genericTypeDefinition == typeof(global::VL.Lib.Collections.Spread <>) ||
                               genericArgument == typeof(IResourceProvider <Stream>));
                    }
                    if (openIOType == typeof(IOutStream <>) && attribute.IsBinSizeEnabled)
                    {
                        var genericTypeDefinition = genericArgument.GetGenericTypeDefinition();
                        return(genericTypeDefinition == typeof(global::VL.Lib.Collections.Spread <>) ||
                               genericArgument == typeof(IResourceProvider <Stream>));
                    }
                    return(false);
                }
                else
                {
                    // We do not want IInStream<> and IOutStream<> to match.
                    switch (context.Direction)
                    {
                    case PinDirection.Input:
                        return(FInputDelegates.ContainsKey(ioType));

                    case PinDirection.Output:
                        return(FOutputDelegates.ContainsKey(ioType));

                    default:
                        return(false);
                    }
                }
            }
            return(false);
        }
Пример #18
0
        private IIOContainer GetValueContainer(IIOFactory factory, IOBuildContext <InputAttribute> context, out int *pLength, out double **ppDoubleData, out Func <bool> validateFunc)
        {
            IIOContainer container;

            if (context.IOAttribute.CheckIfChanged)
            {
                container = factory.CreateIOContainer(context.ReplaceIOType(typeof(IValueIn)));
                var valueIn = container.RawIOObject as IValueIn;
                valueIn.GetValuePointer(out pLength, out ppDoubleData);
                validateFunc = GetValidateFunc(valueIn, context.IOAttribute.AutoValidate);
            }
            else
            {
                container = factory.CreateIOContainer(context.ReplaceIOType(typeof(IValueFastIn)));
                var valueFastIn = container.RawIOObject as IValueFastIn;
                valueFastIn.GetValuePointer(out pLength, out ppDoubleData);
                validateFunc = GetValidateFunc(valueFastIn, context.IOAttribute.AutoValidate);
            }
            return(container);
        }
Пример #19
0
        public static IIOContainer Create <T>(
            IOBuildContext context,
            IIOFactory factory,
            T ioObject,
            Action <T> syncAction  = null,
            Action <T> flushAction = null
            )
        {
            // We need to construct with runtime type here, as compiletime type might be too simple (cast exceptions later).
            var ioHandlerType = typeof(GenericIOContainer <>).MakeGenericType(ioObject.GetType());
            var containers    = ioObject as IIOMultiPin;

            if (containers == null)
            {
                return((IIOContainer)Activator.CreateInstance(ioHandlerType, context, factory, null, ioObject, null, syncAction, flushAction));
            }
            else
            {
                return((IIOContainer)Activator.CreateInstance(ioHandlerType, context, factory, containers.BaseContainer, ioObject, containers.AssociatedContainers, syncAction, flushAction));
            }
        }
Пример #20
0
 public PluginIOContainer(IOBuildContext context, IIOFactory factory, IPluginIO pluginIO)
     : base(context, factory, pluginIO)
 {
     FPluginHost = factory.PluginHost;
     IOObject    = pluginIO;
 }
Пример #21
0
        protected override IEnumerable <Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            Export export;

            if (!FExports.TryGetValue(definition, out export))
            {
                var contractName = definition.ContractName;
                if (contractName == typeof(IIOFactory).FullName)
                {
                    export = new Export(contractName, () => FIOFactory);
                }
                else
                {
                    var typeToExport = ExportProviderUtils.GetImportDefinitionType(definition);

                    foreach (var attribute in ExportProviderUtils.GetImportDefinitionAttributes(definition))
                    {
                        var ioAttribute = attribute as IOAttribute;
                        if (ioAttribute == null)
                        {
                            continue;
                        }

                        if (!ReflectionModelServices.IsImportingParameter(definition))
                        {
                            var member = ReflectionModelServices.GetImportingMember(definition);
                            if (member.MemberType == MemberTypes.Property)
                            {
                                foreach (var accessor in member.GetAccessors())
                                {
                                    if (FAccessorToExportMap.TryGetValue(accessor, out export))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        if (export == null)
                        {
                            var context = IOBuildContext.Create(typeToExport, ioAttribute);
                            if (FIOFactory.CanCreateIOContainer(context))
                            {
                                export = new Export(contractName, () => FIOFactory.CreateIO(context));
                                // Now register the export for all the base members
                                if (!ReflectionModelServices.IsImportingParameter(definition))
                                {
                                    var member = ReflectionModelServices.GetImportingMember(definition);
                                    if (member.MemberType == MemberTypes.Property)
                                    {
                                        foreach (var accessor in member.GetAccessors().OfType <MethodInfo>())
                                        {
                                            RegisterExport(accessor, export);
                                        }
                                    }
                                }
                            }
                        }
                        if (export != null)
                        {
                            break;
                        }
                    }
                }
                FExports.Add(definition, export);
            }
            if (export != null)
            {
                yield return(export);
            }
        }
Пример #22
0
 public IOContainerBase(IOBuildContext context, IIOFactory factory, object rawIOObject)
     : this(context, factory, null, rawIOObject, null)
 {
 }
Пример #23
0
 public IOContainerBase(IOBuildContext context, IIOContainer baseContainer, object rawIOObject)
     : this(context, baseContainer.Factory, baseContainer, rawIOObject, null)
 {
 }