Beispiel #1
0
        /// <summary>
        /// Método acionado quando a instancia estiver sido inicializada.
        /// </summary>
        protected void Initialized()
        {
            var exportManager = _exportManager.Value;
            var exports       = exportManager.GetExports(_uiContext);
            var groups        = new Dictionary <string, IList <Colosoft.Reflection.Composition.IExport> >();

            foreach (var export in exports)
            {
                string typeAssembly = export.Type.AssemblyName.FullName;
                if (!groups.ContainsKey(typeAssembly))
                {
                    var list = new List <Colosoft.Reflection.Composition.IExport>();
                    list.Add(export);
                    groups.Add(typeAssembly, list);
                }
                else
                {
                    var list  = groups[typeAssembly];
                    var index = list.BinarySearch(export, Colosoft.Reflection.Composition.ExportComparer.Instance);
                    if (index < 0)
                    {
                        list.Insert(~index, export);
                    }
                    else
                    {
                        var item = list[index];
                        if (string.IsNullOrEmpty(item.ContractName) && string.IsNullOrEmpty(export.ContractName))
                        {
                            list.Insert(index, export);
                        }
                        else
                        {
                            throw new AssemblyRepositoryCatalogException(ResourceMessageFormatter.Create(() => Properties.Resources.AssemblyRepositoryCatalog_DuplicateExport, export.ContractType, export.ContractName).Format());
                        }
                    }
                }
            }
            foreach (var group in groups)
            {
                var catalogRegister = new AssemblyRepositoryCatalogRegister();
                foreach (var export in group.Value)
                {
                    catalogRegister.Add(export.ContractType, export.ContractName, export.Type);
                }
                var conflict = Add(catalogRegister).FirstOrDefault();
                if (conflict != null)
                {
                    throw new AssemblyRepositoryCatalogException(ResourceMessageFormatter.Create(() => Properties.Resources.AssemblyRepositoryCatalog_DuplicateExport, conflict.ContractType, conflict.ContractName).Format());
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adiciona um novo registrador para o catálogo.
        /// </summary>
        /// <param name="register"></param>
        public AssemblyRepositoryCatalogConflict[] Add(AssemblyRepositoryCatalogRegister register)
        {
            var contractsTemp = new List <ContractInfo>();
            var conflicts     = new List <AssemblyRepositoryCatalogConflict>();

            foreach (var i in register.Contracts)
            {
                var index = _contracts.FindIndex(f => ContractInfoEqualityComparer.Instance.Equals(f, i));
                if (index < 0)
                {
                    contractsTemp.Add(i);
                    _contracts.Add(i);
                }
                else
                {
                    conflicts.Add(new AssemblyRepositoryCatalogConflict(i.ContractName, i.ContractType));
                }
            }
            if (_catalogCollection != null && contractsTemp.Count > 0)
            {
                DiscoverTypes(contractsTemp);
            }
            return(conflicts.ToArray());
        }