Beispiel #1
0
        public CachedTypeCatalog(ComposablePartCatalogCache cache)
        {
            Requires.NotNull(cache, "cache");
            ComposablePartCatalog cacheCatalog = cache.GetCacheCatalog(AttributedComposablePartCatalogSite.CreateForReading());

            List <Type> notUpToDateTypes = new List <Type>();
            List <ComposablePartDefinition> upToDateParts = new List <ComposablePartDefinition>();

            foreach (ComposablePartDefinition partDefinition in cacheCatalog.Parts)
            {
                if (!partDefinition.IsPartDefinitionCacheUpToDate())
                {
                    notUpToDateTypes.Add(ReflectionModelServices.GetPartType(partDefinition).Value);
                }
                else
                {
                    upToDateParts.Add(partDefinition);
                }
            }

            if (notUpToDateTypes.Count == 0)
            {
                // everything is up to date, we can use the cached catalog
                this._cacheCatalog = cacheCatalog;
            }
            else
            {
                // some parts are not up-to-date, we will not query the catalog, but rather a combination of the type catalog and up-to-date parts
                this._upToDateParts = upToDateParts;
                this._typeCatalog   = new TypeCatalog(notUpToDateTypes);
            }
        }
Beispiel #2
0
        private string GetTypesDisplay()
        {
            int count = this.PartsInternal.Count();

            if (count == 0)
            {
                return(Strings.CachedTypeCatalog_Empty);
            }

            const int     displayCount = 2;
            StringBuilder builder      = new StringBuilder();

            foreach (ComposablePartDefinition definition in this.PartsInternal.Take(displayCount))
            {
                if (builder.Length > 0)
                {
                    builder.Append(", ");
                }

                builder.Append(ReflectionModelServices.GetPartType(definition).Value.FullName);
            }

            if (count > displayCount)
            {   // Add an elipse to indicate that there
                // are more types than actually listed

                builder.Append(", ...");
            }

            return(builder.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// By default, we are configured to use MEF
        /// </summary>
        protected override void Configure()
        {
            // Add all assemblies to AssemblySource (using a temporary DirectoryCatalog).
            var directoryCatalog = new DirectoryCatalog(@"./");

            AssemblySource.Instance.AddRange(
                directoryCatalog.Parts
                .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                .Where(assembly => !AssemblySource.Instance.Contains(assembly)));

            // Prioritise the executable assembly. This allows the client project to override exports, including IShell.
            // The client project can override SelectAssemblies to choose which assemblies are prioritised.
            _priorityAssemblies = SelectAssemblies().ToList();
            var priorityCatalog  = new AggregateCatalog(_priorityAssemblies.Select(x => new AssemblyCatalog(x)));
            var priorityProvider = new CatalogExportProvider(priorityCatalog);

            // Now get all other assemblies (excluding the priority assemblies).
            var mainCatalog = new AggregateCatalog(
                AssemblySource.Instance
                .Where(assembly => !_priorityAssemblies.Contains(assembly))
                .Select(x => new AssemblyCatalog(x)));
            var mainProvider = new CatalogExportProvider(mainCatalog);

            Container = new CompositionContainer(priorityProvider, mainProvider);
            priorityProvider.SourceProvider = Container;
            mainProvider.SourceProvider     = Container;

            var batch = new CompositionBatch();

            BindServices(batch);
            batch.AddExportedValue(mainCatalog);

            Container.Compose(batch);
        }
Beispiel #4
0
        public SerializableImportDefinition(ImportDefinition importDefinition)
        {
            IsExportFactory = ReflectionModelServices.IsExportFactoryImportDefinition(importDefinition);
            if (IsExportFactory)
            {
                // Handle export factories.
                importDefinition = ReflectionModelServices.GetExportFactoryProductImportDefinition(importDefinition);
            }

            ContractName    = importDefinition.ContractName;
            Cardinality     = importDefinition.Cardinality;
            IsRecomposable  = importDefinition.IsRecomposable;
            IsPrerequisite  = importDefinition.IsPrerequisite;
            Metadata        = new SerializableDictionary <string, object>(importDefinition.Metadata);
            ImportingMember = ReflectionModelServices.IsImportingParameter(importDefinition) ?
                              new SerializableLazyMemberInfo(ReflectionModelServices.GetImportingParameter(importDefinition).Value) :
                              new SerializableLazyMemberInfo(ReflectionModelServices.GetImportingMember(importDefinition));

            var contractBasedImportDefinition = importDefinition as ContractBasedImportDefinition;

            if (contractBasedImportDefinition != null)
            {
                RequiredTypeIdentity   = contractBasedImportDefinition.RequiredTypeIdentity;
                RequiredCreationPolicy = contractBasedImportDefinition.RequiredCreationPolicy;
                RequiredMetadata       = new SerializableDictionary <string, string>(contractBasedImportDefinition.RequiredMetadata.Select(kvp => new KeyValuePair <string, string>(kvp.Key, kvp.Value.AssemblyQualifiedName)));
            }
        }
Beispiel #5
0
        public void Execute(CoroutineExecutionContext context)
        {
            DeploymentCatalog catalog;

            if (Catalogs.TryGetValue(uri, out catalog))
            {
                Completed(this, new ResultCompletionEventArgs());
            }
            else
            {
                catalog = new DeploymentCatalog(new Uri("/ClientBin/" + uri, UriKind.RelativeOrAbsolute));
                catalog.DownloadCompleted += (s, e) => {
                    if (e.Error == null)
                    {
                        Catalogs[uri] = catalog;
                        Catalog.Catalogs.Add(catalog);
                        catalog.Parts
                        .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                        .Where(assembly => !AssemblySource.Instance.Contains(assembly))
                        .Apply(x => AssemblySource.Instance.Add(x));
                    }
                    else
                    {
                        Loader.Hide().Execute(context);
                    }

                    Completed(this, new ResultCompletionEventArgs {
                        Error        = e.Error,
                        WasCancelled = false
                    });
                };

                catalog.DownloadAsync();
            }
        }
        static IEnumerable <ImportDefinition> GetImportDefinitions(Type implementationType)
        {
            var constructors = implementationType.GetConstructors()[0];
            var imports      = new List <ImportDefinition>();

            foreach (var param in constructors.GetParameters())
            {
                var parameter   = param;
                var cardinality = GetCardinality(parameter);
                var importType  = cardinality == ImportCardinality.ZeroOrMore
                                                        ? GetCollectionContractType(parameter.ParameterType)
                                                        : param.ParameterType;

                imports.Add(
                    ReflectionModelServices.CreateImportDefinition(
                        new Lazy <ParameterInfo>(() => parameter),
                        AttributedModelServices.GetContractName(importType),
                        AttributedModelServices.GetTypeIdentity(importType),
                        Enumerable.Empty <KeyValuePair <string, Type> >(),
                        cardinality,
                        CreationPolicy.Any,
                        null)
                    );
            }

            return(imports);
        }
        private static SerializableImportDefinition CreatePropertyImport(
            ContractBasedImportDefinition import,
            Func <Type, TypeIdentity> identityGenerator)
        {
            var memberInfo = ReflectionModelServices.GetImportingMember(import);

            if (memberInfo.MemberType != MemberTypes.Property)
            {
                throw new ArgumentOutOfRangeException("import");
            }

            // this is really ugly because we assume that the underlying methods for a property are named as:
            // get_PROPERTYNAME and set_PROPERTYNAME. In this case we assume that imports always
            // have a set method.
            var getMember = memberInfo.GetAccessors().First(m => m.Name.Contains("set_"));
            var name      = getMember.Name.Substring("set_".Length);
            var property  = getMember.DeclaringType.GetProperty(name);

            var requiredType = ExtractRequiredType(property.GetCustomAttributes(), property.PropertyType);

            if (requiredType == null)
            {
                return(null);
            }

            return(PropertyBasedImportDefinition.CreateDefinition(
                       import.ContractName,
                       TypeIdentity.CreateDefinition(requiredType),
                       import.Cardinality,
                       import.IsRecomposable,
                       import.RequiredCreationPolicy,
                       property,
                       identityGenerator));
        }
Beispiel #8
0
        public void PartCreatorConstraint_ShouldMatchPartCreatorExportDefinition()
        {
            var partCreatorImportDef = ReflectionModelServices.CreateImportDefinition(
                new LazyMemberInfo(MemberTypes.Field, () => new MemberInfo[] { typeof(ConstraintServicesTests) }),
                "Foo",
                "Foo",
                new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("MDKey", typeof(string)) },
                ImportCardinality.ZeroOrMore,
                false,
                CreationPolicy.Any,
                true, // IsPartCreator
                null);

            var metadata = new Dictionary <string, object>();

            metadata["MDKey"] = "MDValue";
            metadata[CompositionConstants.ExportTypeIdentityMetadataName] = "Foo";

            var productExportDefinition = new ExportDefinition("Foo", metadata);

            metadata = new Dictionary <string, object>(metadata);
            metadata[CompositionConstants.ExportTypeIdentityMetadataName] = CompositionConstants.PartCreatorTypeIdentity;
            metadata[CompositionConstants.ProductDefinitionMetadataName]  = productExportDefinition;

            var exportDefinition = new ExportDefinition(CompositionConstants.PartCreatorContractName, metadata);

            var predicate = partCreatorImportDef.Constraint.Compile();

            Assert.IsTrue(partCreatorImportDef.IsConstraintSatisfiedBy(exportDefinition));
            Assert.IsTrue(predicate(exportDefinition));
        }
Beispiel #9
0
        public static IEnumerable <Type> GetDistinctExportsTypes(this CompositionContainer container, params Type[] types)
        {
            IQueryable <ComposablePartDefinition> parts =
                container.Catalog.Parts.Concat(container.Providers.OfType <CatalogExportProvider>().SelectMany(provider => provider.Catalog.Parts)).GroupBy(part => part.ExportDefinitions.FirstOrDefault()).Select(group => group.First());

            return(parts.Select(part => ReflectionModelServices.GetPartType(part).Value).Where(type => types.All(expectedType => expectedType.IsAssignableFrom(type))));
        }
Beispiel #10
0
 private ImportDefinition CreateWrapped(ContractBasedImportDefinition import, Type type)
 {
     if (ReflectionModelServices.IsImportingParameter(import))
     {
         return(ReflectionModelServices.CreateImportDefinition(
                    this.CreateWrapped(ReflectionModelServices.GetImportingParameter(import), type),
                    import.ContractName,
                    import.RequiredTypeIdentity,
                    import.RequiredMetadata,
                    import.Cardinality,
                    import.RequiredCreationPolicy,
                    null));
     }
     else
     {
         return(ReflectionModelServices.CreateImportDefinition(
                    this.CreateWrapped(ReflectionModelServices.GetImportingMember(import), type),
                    import.ContractName,
                    import.RequiredTypeIdentity,
                    import.RequiredMetadata,
                    import.Cardinality,
                    import.IsRecomposable,
                    import.RequiredCreationPolicy,
                    null));
     }
 }
Beispiel #11
0
            /// <summary>
            /// Extracts the ImportDefinition for the T in an ExportFactory{T} import, if applicable.
            /// </summary>
            /// <param name="definition">The ImportDefinition which may be an ExportFactory.</param>
            /// <returns>The import definition that describes the created part, or <c>null</c> if the import definition isn't an ExportFactory.</returns>
            private static MefV1.Primitives.ImportDefinition GetExportFactoryProductImportDefinitionIfApplicable(MefV1.Primitives.ImportDefinition definition)
            {
                // The optimal path that we can code for at the moment is using the internal interface.
                if (IPartCreatorImportDefinition_MightFail != null && ProductImportDefinition_MightFail != null)
                {
                    if (IPartCreatorImportDefinition_MightFail.IsInstanceOfType(definition))
                    {
                        return((MefV1.Primitives.ImportDefinition)ProductImportDefinition_MightFail.GetValue(definition));
                    }
                }
                else
                {
                    // The internal interface, or its member, is gone. Fallback to using the public API that throws.
                    try
                    {
                        if (ReflectionModelServices.IsExportFactoryImportDefinition(definition))
                        {
                            return(ReflectionModelServices.GetExportFactoryProductImportDefinition(definition));
                        }
                    }
                    catch (ArgumentException)
                    {
                        // MEFv1 throws rather than simply returning false when the ImportDefinition is of the incorrect type.
                    }
                }

                return(null);
            }
        public static IDictionary <string, object> WriteImportDefinition(ComposablePartDefinition owner, ContractBasedImportDefinition importDefinition)
        {
            Assumes.NotNull(owner);
            Assumes.NotNull(importDefinition);

            Lazy <Type> partType = ReflectionModelServices.GetPartType(owner);

            IDictionary <string, object> cache = new Dictionary <string, object>();

            cache.WriteContractName(importDefinition.ContractName);
            cache.WriteValue(AttributedCacheServices.CacheKeys.RequiredTypeIdentity, importDefinition.RequiredTypeIdentity, null);
            cache.WriteRequiredMetadata(importDefinition.RequiredMetadata);
            cache.WriteValue(AttributedCacheServices.CacheKeys.RequiredCreationPolicy, importDefinition.RequiredCreationPolicy, CreationPolicy.Any);
            cache.WriteValue(AttributedCacheServices.CacheKeys.Cardinality, importDefinition.Cardinality, ImportCardinality.ExactlyOne);
            if (ReflectionModelServices.IsImportingParameter(importDefinition))
            {
                cache.WriteValue(AttributedCacheServices.CacheKeys.ImportType, AttributedCacheServices.ImportTypes.Parameter);
                cache.WriteLazyParameter(
                    ReflectionModelServices.GetImportingParameter(importDefinition),
                    partType);
            }
            else
            {
                // don't write anything for import type - member assumed
                LazyMemberInfo importingMemberInfo = ReflectionModelServices.GetImportingMember(importDefinition);
                cache.WriteValue(AttributedCacheServices.CacheKeys.IsRecomposable, importDefinition.IsRecomposable, false);
                cache.WriteValue(AttributedCacheServices.CacheKeys.MemberType, importingMemberInfo.MemberType, MemberTypes.Property);
                cache.WriteLazyAccessors(
                    importingMemberInfo.GetAccessors(),
                    partType);
            }

            return(cache);
        }
Beispiel #13
0
        /// <summary>
        /// By default, we are configured to use MEF
        /// </summary>
        protected override void Configure()
        {
            if (Execute.InDesignMode)
            {
                return;
            }

            // only output errors if in release
#if !DEBUG
            Dispatcher.CurrentDispatcher.UnhandledException += ExceptionHelper.UnhandledUiException;
            AppDomain.CurrentDomain.UnhandledException      += ExceptionHelper.UnhandledException;
#endif
            var ignoredAssembies = new[]
            {
                "Assimp32.dll",
                "AssimpNet.dll"
            };

            // Add all assemblies to AssemblySource, excluding assimp.dll because i dont like it specifically
            var rootDir   = new DirectoryInfo(@"./");
            var rootFiles = rootDir.GetFiles("*.dll").Where(info => !ignoredAssembies.Contains(info.Name)).ToList();
            foreach (var fileInfo in rootFiles)
            {
                try
                {
                    var assemblyCatalog = new AssemblyCatalog(Assembly.LoadFrom(fileInfo.Name));
                    var parts           = assemblyCatalog.Parts
                                          .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly).Where(assembly => !AssemblySource.Instance.Contains(assembly));
                    AssemblySource.Instance.AddRange(parts);
                }
                catch (BadImageFormatException ex)
                {
                }
            }


            // Prioritise the executable assembly. This allows the client project to override exports, including IShell.
            // The client project can override SelectAssemblies to choose which assemblies are prioritised.
            var priorityAssemblies = SelectAssemblies().ToList();
            var priorityCatalog    = new AggregateCatalog(priorityAssemblies.Select(x => new AssemblyCatalog(x)));
            var priorityProvider   = new CatalogExportProvider(priorityCatalog);

            // Now get all other assemblies (excluding the priority assemblies).
            var mainCatalog = new AggregateCatalog(
                AssemblySource.Instance
                .Where(assembly => !priorityAssemblies.Contains(assembly))
                .Select(x => new AssemblyCatalog(x)));

            var mainProvider = new CatalogExportProvider(mainCatalog);
            _container = new CompositionContainer(priorityProvider, mainProvider);
            priorityProvider.SourceProvider = _container;
            mainProvider.SourceProvider     = _container;

            var batch = new CompositionBatch();

            BindServices(batch);
            batch.AddExportedValue(mainCatalog);

            _container.Compose(batch);
        }
        /// <summary>
        /// Creates a new instance of a part that the <see cref="T:System.ComponentModel.Composition.Primitives.ComposablePartDefinition"/> describes.
        /// </summary>
        /// <returns>The created part.</returns>
        public override ComposablePart CreatePart()
        {
            ComposablePart part     = null;
            ComposablePart tempPart = null;

            try
            {
                tempPart = ReflectionModelServices.IsDisposalRequired(this._sourcePart)
                               ? new DisposableIsolatingComposablePart(this._sourcePart, this._isolationMetadata)
                               : new IsolatingComposablePart(this._sourcePart, this._isolationMetadata);

                part     = tempPart;
                tempPart = null;
            }
            finally
            {
                if (tempPart != null)
                {
                    var disposablePart = (tempPart as IDisposable);
                    if (disposablePart != null)
                    {
                        disposablePart.Dispose();
                    }
                }
            }

            return(part);
        }
 /// <summary>
 /// Initializes the context from a part and the export.
 /// </summary>
 internal DecoratedExport(ComposablePartDefinition part, ExportDefinition export)
 {
     this.ExportDefinition = export;
     this.ExportingMember  = ReflectionModelServices.GetExportingMember(export);
     this.ExportingType    = ReflectionModelServices.GetPartType(part);
     this.NewMetadata      = new Dictionary <string, object>(export.Metadata);
 }
Beispiel #16
0
        /// <inheritdoc />
        /// <summary>
        /// Override to configure the framework and setup your IoC container.
        /// </summary>
        protected override void Configure()
        {
            // Add all assemblies to AssemblySource (using a temporary DirectoryCatalog).
            var directoryCatalog = new DirectoryCatalog(@".");

            AssemblySource.Instance.AddRange(
                directoryCatalog.Parts
                .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                .Where(assembly => !AssemblySource.Instance.Contains(assembly)));

            _priorityAssemblies = SelectAssemblies().ToList();
            var priorityCatalog  = new AggregateCatalog(_priorityAssemblies.Select(x => new AssemblyCatalog(x)));
            var priorityProvider = new CatalogExportProvider(priorityCatalog);

            var mainCatalog = new AggregateCatalog(
                AssemblySource.Instance
                .Where(assembly => !_priorityAssemblies.Contains(assembly))
                .Select(x => new AssemblyCatalog(x)));
            var mainProvider = new CatalogExportProvider(mainCatalog);

            _container = new CompositionContainer(priorityProvider, mainProvider);
            priorityProvider.SourceProvider = _container;
            mainProvider.SourceProvider     = _container;

            var batch = new CompositionBatch();

            BindServices(batch);

            _container.Compose(batch);
        }
Beispiel #17
0
        private static Type GetParameterType(ImportDefinition definition)
        {
            var importingParameter   = ReflectionModelServices.GetImportingParameter(definition);
            var parameterInfo        = importingParameter.Value;
            var importDefinitionType = parameterInfo.ParameterType;

            return(importDefinitionType);
        }
Beispiel #18
0
 private ExportDefinition CreateWrapped(ExportDefinition export, Type type)
 {
     return(ReflectionModelServices.CreateExportDefinition(
                this.CreateWrapped(ReflectionModelServices.GetExportingMember(export), type),
                export.ContractName,
                export.Metadata.AsLazy(),
                null));
 }
Beispiel #19
0
 internal static ExportDefinition CreateExportDefinition(SerializableExportDefinition serializableExportDefinition)
 {
     return(ReflectionModelServices.CreateExportDefinition(
                CreateLazyMemberInfo(serializableExportDefinition.ExportingMember),
                serializableExportDefinition.ContractName,
                new Lazy <IDictionary <string, object> >(() => serializableExportDefinition.Metadata),
                null)); // TODO: Is it OK to have null for origin?
 }
 /// <summary>
 /// Gets all types within the <see cref="CompositionContainer"/>'s <see cref="CompositionContainer.Catalog"/>.
 /// </summary>
 /// <param name="container">The container.</param>
 /// <returns>Enumeration of <see cref="Type"/>s.</returns>
 /// <remarks></remarks>
 public static IEnumerable <Type> GetExportTypes(this CompositionContainer container)
 {
     return(_ExportedTypes.GetOrAdd(
                container,
                c => c.Catalog.Parts
                .Select(part => ReflectionModelServices.GetPartType(part).Value)
                .ToList()));
 }
Beispiel #21
0
        public void When_querying_using_a_concrete_order_repository_the_order_repository_part_is_created()
        {
            var exports  = new List <Tuple <ComposablePartDefinition, ExportDefinition> >();
            var export   = ConcreteTypeHandler.GetExports(RepositoryImportDefinition, exports).FirstOrDefault();
            var partType = ReflectionModelServices.GetPartType(export.Item1).Value;

            partType.ShouldBeOfType <CustomerRepository>();
        }
Beispiel #22
0
        public override ComposablePart CreatePart()
        {
            var interceptedPart = InterceptedPartDefinition.CreatePart();

            return(ReflectionModelServices.IsDisposalRequired(InterceptedPartDefinition)
                       ? new DisposableInterceptingComposablePart(interceptedPart, this.valueInterceptor)
                       : new InterceptingComposablePart(interceptedPart, this.valueInterceptor));
        }
Beispiel #23
0
 private static Type ComposablePartExportType <T>(ComposablePartDefinition part)
 {
     return(part.ExportDefinitions.Any(
                def => def.Metadata.ContainsKey("ExportTypeIdentity") &&
                def.Metadata["ExportTypeIdentity"].Equals(typeof(T).FullName))
                ? ReflectionModelServices.GetPartType(part).Value
                : null);
 }
Beispiel #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfiguredCatalog" /> class.
 /// </summary>
 /// <param name="catalog">The catalog.</param>
 /// <param name="configurationFilePath">The configuration file path.</param>
 public ConfiguredCatalog(ComposablePartCatalog catalog, string configurationFilePath) : base(catalog, GetPartFilter(configurationFilePath))
 {
     if (_log.IsDebugEnabled)
     {
         var assemblies = catalog.Parts.Select(p => ReflectionModelServices.GetPartType(p).Value.Assembly.GetName().Name).Distinct();
         _log.Debug($"Loaded Assemblies:{Environment.NewLine}{string.Join(Environment.NewLine, assemblies)}");
     }
 }
Beispiel #25
0
        protected override IEnumerable <Assembly> SelectAssemblies()
        {
            if (Execute.InDesignMode)
            {
                return(new List <Assembly>());
            }

            // get the application assembly, and the Metro assembly.
            var assemblies = new List <Assembly>();

            // get assemblies in mods folder
            try
            {
                var modsPath = MCFireDirectories.AppdataMods;
                //create mods folder if it doesnt exist, then walk its subdirectories
                Directory.CreateDirectory(modsPath);
                foreach (var directoryInfo in WalkDirectoryTree(new DirectoryInfo(modsPath)))
                {
                    var catalog = new DirectoryCatalog(directoryInfo.FullName);

                    /*
                     * ░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░
                     * ░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░
                     * ░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░
                     * ░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░
                     * ░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░
                     * █░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█
                     * █░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█
                     * ░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░
                     * ░░█░░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█░░
                     * ░░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█░░░
                     * ░░░░█░░░░▀▀▄░█░░░█░█▀██████░█░░
                     * ░░░░░▀▄░░░░░▀▀▄▄▄█▄█▄█▄█▄▀░░█░░
                     * ░░░░░░░▀▄▄░▒▒▒▒░░░░░░░░░░▒░░░█░
                     * ░░░░░░░░░░▀▀▄▄░▒▒▒▒▒▒▒▒▒▒░░░░█░
                     * ░░░░░░░░░░░░░░▀▄▄▄▄▄░░░░░░░░█░░
                     */

                    // hack out the mods assemblies with this horrible code.
                    assemblies.AddRange(catalog.Parts
                                        .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                                        .Where(assembly => !assemblies.Contains(assembly)));
                }
            }
            catch (SecurityException) { }
            catch (PathTooLongException) { }
            catch (UnauthorizedAccessException) { }
            catch (DirectoryNotFoundException) { }

            // add priority MCFire assemblies.
            assemblies.Add(typeof(Common.Library).Assembly);
            assemblies.Add(typeof(Core.Library).Assembly);
            assemblies.Add(typeof(Graphics.Library).Assembly);
            assemblies.Add(typeof(Client.Library).Assembly);
            assemblies.Add(typeof(Client.Gui.Library).Assembly);
            assemblies.Add(GetType().Assembly);
            return(assemblies);
        }
Beispiel #26
0
        public static T GetExport <T>(this object obj, string propertyName, string contractName)
        {
            LazyMemberInfo info = new LazyMemberInfo(obj.GetType().GetProperty(propertyName));
            var            ed   = ReflectionModelServices.CreateExportDefinition(info, contractName, null, null);
            var            ed1  = ReflectionModelServices.GetExportingMember(ed);
            T someService       = (T)(ed1.GetAccessors().GetValue(0) as System.Reflection.MethodInfo).Invoke(obj, null);

            return((T)someService);
        }
Beispiel #27
0
        protected void PopulateAssemblySourceUsingDirectoryCatalog(string path)
        {
            var directoryCatalog = new DirectoryCatalog(path);

            AssemblySource.Instance.AddRange(
                directoryCatalog.Parts
                .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                .Where(assembly => !AssemblySource.Instance.Contains(assembly)));
        }
Beispiel #28
0
 internal static ComposablePartDefinition CreateComposablePartDefinition(SerializableComposablePartDefinition serializableComposablePartDefinition)
 {
     return(ReflectionModelServices.CreatePartDefinition(
                new Lazy <Type>(() => Type.GetType(serializableComposablePartDefinition.PartTypeAssemblyQualifiedName)),
                serializableComposablePartDefinition.IsDisposalRequired,
                new Lazy <IEnumerable <ImportDefinition> >(() => serializableComposablePartDefinition.ImportDefinitions.Select(CreateImportDefinition)),
                new Lazy <IEnumerable <ExportDefinition> >(() => serializableComposablePartDefinition.ExportDefinitions.Select(CreateExportDefinition)),
                new Lazy <IDictionary <string, object> >(() => serializableComposablePartDefinition.Metadata),
                null)); // TODO: Is it OK to have null for origin?
 }
 /// <summary>
 /// Create a <see cref="ComposablePartDefinition"/> for a specified type using the provided <see cref="IPartConvention"/>.
 /// </summary>
 /// <param name="convention">The <see cref="IPartConvention"/> instance which is used to create the <see cref="ComposablePartDefinition"/>.</param>
 /// <param name="type">The <see cref="Type"/> for which the <see cref="ComposablePartDefinition"/> should be created.</param>
 /// <returns>A <see cref="ComposablePartDefinition"/> instance.</returns>
 private ComposablePartDefinition CreatePartDefinition(IPartConvention convention, Type type)
 {
     return(ReflectionModelServices.CreatePartDefinition(
                new Lazy <Type>(() => type),
                false,
                new Lazy <IEnumerable <ImportDefinition> >(() => CreateImportDefinitions(convention.Imports, type)),
                new Lazy <IEnumerable <ExportDefinition> >(() => CreateExportDefinitions(convention.Exports, type)),
                new Lazy <IDictionary <string, object> >(() => GetPartDefinitionMetadata(convention)),
                null));
 }
Beispiel #30
0
        public void Parts_should_return_definition_with_correct_type()
        {
            var partDefinitions =
                GetPartDefinitionsFromNonEmptyRegistry();

            var partType =
                ReflectionModelServices.GetPartType(partDefinitions.First());

            partType.Value.Equals(typeof(FakePart));
        }