/// <summary>
		/// Construtor padrão.
		/// </summary>
		/// <param name="partDescription"></param>
		/// <param name="assemblyContainer"></param>
		public ProviderParameterImportDefinitionContainer(PartDescription partDescription, IAssemblyContainer assemblyContainer)
		{
			partDescription.Require("partDescription");
			assemblyContainer.Require("assemblyContainer");
			_partDescription = partDescription;
			_assemblyContainer = assemblyContainer;
		}
示例#2
0
 /// <summary>
 /// Recupera uma lista de todas as definições de import da parte.
 /// </summary>
 /// <param name="part"></param>
 /// <param name="providerParameterImportContainer"></param>
 /// <returns></returns>
 private Lazy <IEnumerable <ImportDefinition> > GetImportDefinitions(PartDescription part, ProviderParameterImportDefinitionContainer providerParameterImportContainer)
 {
     return(new Lazy <IEnumerable <ImportDefinition> >(() => {
         var imports = new List <ImportDefinition>();
         foreach (var i in part.Imports)
         {
             ImportDescription import = i;
             imports.Add(new ProviderImportDefinition(new Lazy <System.Reflection.MemberInfo>(() => GetMemberInfo(part.TypeName, import.MemberName), false), import, part.PartCreationPolicy));
         }
         foreach (var i in providerParameterImportContainer.GetImportDefinitions())
         {
             imports.Add(i);
         }
         return imports;
     }));
 }
示例#3
0
        /// <summary>
        /// Recupera a lista de todas as definições de export para a parte.
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        private IList <ProviderExportDefinition> GetExportDefinitions(PartDescription part)
        {
            var exports = new List <ProviderExportDefinition>();

            foreach (var i in part.Exports)
            {
                try
                {
                    ExportDescription export = i;
                    var getter = new ProviderExportDefinitionMemberGetter(this, part, export);
                    exports.Add(new ProviderExportDefinition(getter.GetMember, export, part.PartCreationPolicy));
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return(exports);
        }
示例#4
0
 /// <summary>
 /// Instancia do membro associado.
 /// </summary>
 public System.Reflection.MemberInfo GetMember()
 {
     if (_member == null)
     {
         if (_member == null)
         {
             if (_part != null && _part.ImportingConstructor != null)
             {
                 _member = (System.Reflection.MemberInfo)_part.ImportingConstructor.GetConstructor(_catalog._assemblies);
             }
             else if (_part != null)
             {
                 _member = _catalog.GetMemberInfo(_part.TypeName, _export.MemberName);
             }
             if (_member != null)
             {
                 _catalog = null;
                 _part    = null;
                 _export  = null;
             }
         }
     }
     return(_member);
 }
示例#5
0
        private void DiscoverTypes(IEnumerable <ContractInfo> contracts)
        {
            lock (_lock)
            {
                if (_catalogCollection == null)
                {
                    _catalogCollection = new AggregateCatalog();
                }
                var exports = new List <Tuple <ContractInfo, Colosoft.Reflection.Composition.IExport> >();
                foreach (var i in contracts)
                {
                    if (i.Types.Count == 0)
                    {
                        var tuple = new Tuple <ContractInfo, Reflection.Composition.IExport>(i, ExportManager.GetExport(i.ContractType, i.ContractName, _uiContext));
                        if (tuple.Item2 != null)
                        {
                            exports.Add(tuple);
                        }
                    }
                    else
                    {
                        var contractExports = ExportManager.GetExports(i.ContractType, i.ContractName, _uiContext);
                        int contractCount   = 0;
                        foreach (var j in contractExports)
                        {
                            if (i.Types.Contains(j.Type, Colosoft.Reflection.TypeName.TypeNameEqualityComparer.Instance))
                            {
                                contractCount++;
                                var tuple = new Tuple <ContractInfo, Reflection.Composition.IExport>(i, j);
                                exports.Add(tuple);
                            }
                        }
                    }
                }
                if (exports.Count > 0)
                {
                    var pkgParts         = new List <Colosoft.Reflection.AssemblyPart>();
                    var partDescriptions = new List <PartDescription>();
                    foreach (var i in exports)
                    {
                        var assemblyPart = new Colosoft.Reflection.AssemblyPart(string.Format("{0}.dll", i.Item2.Type.AssemblyName.Name));
                        if (!pkgParts.Exists(f => StringComparer.InvariantCultureIgnoreCase.Equals(f.Source, assemblyPart.Source)))
                        {
                            pkgParts.Add(assemblyPart);
                        }
                        System.ComponentModel.Composition.CreationPolicy creationPolicy = System.ComponentModel.Composition.CreationPolicy.Any;
                        switch (i.Item2.CreationPolicy)
                        {
                        case Reflection.Composition.CreationPolicy.NonShared:
                            creationPolicy = System.ComponentModel.Composition.CreationPolicy.NonShared;
                            break;

                        case Reflection.Composition.CreationPolicy.Shared:
                            creationPolicy = System.ComponentModel.Composition.CreationPolicy.Shared;
                            break;
                        }
                        ImportingConstructorDescription importingConstructor = null;
                        if (i.Item2.ImportingConstructor)
                        {
                            importingConstructor = new ImportingConstructorDescription(i.Item2.Type, null);
                        }
                        var partDescription = new PartDescription(i.Item2.Type, new ExportDescription[] {
                            new ExportDescription {
                                ContractTypeName = i.Item1.ContractType,
                                ContractName     = string.IsNullOrEmpty(i.Item2.ContractName) ? null : i.Item2.ContractName.Trim(),
                                Metadata         = i.Item2.Metadata
                            }
                        }, new ImportDescription[0], i.Item2.UseDispatcher, importingConstructor, creationPolicy);
                        partDescriptions.Add(partDescription);
                    }
                    var catalog          = new DefinitionCatalog(new DiscoverAssembliesContainer(this, _assemblyRepository, pkgParts.ToArray(), exports), partDescriptions);
                    var addedDefinitions = catalog.Parts;
                    using (AtomicComposition composition = new AtomicComposition())
                    {
                        var args = new ComposablePartCatalogChangeEventArgs(addedDefinitions, Enumerable.Empty <ComposablePartDefinition>(), composition);
                        this.OnChanging(args);
                        _catalogCollection.Catalogs.Add(catalog);
                        composition.Complete();
                    }
                    ComposablePartCatalogChangeEventArgs e = new ComposablePartCatalogChangeEventArgs(addedDefinitions, Enumerable.Empty <ComposablePartDefinition>(), null);
                    this.OnChanged(e);
                }
            }
        }
示例#6
0
 /// <summary>
 /// Construtor padrão.
 /// </summary>
 /// <param name="catalog"></param>
 /// <param name="part"></param>
 /// <param name="export"></param>
 public ProviderExportDefinitionMemberGetter(DefinitionCatalog catalog, PartDescription part, ExportDescription export)
 {
     _catalog = catalog;
     _part    = part;
     _export  = export;
 }
示例#7
0
        /// <summary>
        /// Recupera as definição para importar os parametros
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        private IList <ProviderParameterImportDefinition> GetParametersImportDefinitions(PartDescription part)
        {
            var imports = new List <ProviderParameterImportDefinition>();

            if (part.ImportingConstructor != null)
            {
                foreach (var i in part.ImportingConstructor.GetParameterImportDefinitions(_assemblies))
                {
                    imports.Add(new ProviderParameterImportDefinition(i.Item2, i.Item1, System.ComponentModel.Composition.CreationPolicy.Any));
                }
            }
            return(imports);
        }