/// <summary>
        /// Connects the export with the import.
        /// </summary>
        /// <param name="importRegistration">The ID of the import.</param>
        /// <param name="exportRegistration">The ID of the export.</param>
        public void Connect(ImportRegistrationId importRegistration, ExportRegistrationId exportRegistration)
        {
            {
                Lokad.Enforce.Argument(() => importRegistration);
                Lokad.Enforce.Argument(() => exportRegistration);
            }

            var import = m_Objects.SelectMany(t => t.Value).PartImportById(importRegistration);
            var export = m_Objects.SelectMany(t => t.Value).PartExportById(exportRegistration);

            if (!m_ImportEngine.Accepts(import, export))
            {
                throw new CannotMapExportToImportException();
            }

            if (!m_Connections.ContainsKey(importRegistration))
            {
                m_Connections.Add(importRegistration, new List <ExportRegistrationId>());
            }

            var list = m_Connections[importRegistration];

            if ((import.Cardinality == ImportCardinality.ExactlyOne || import.Cardinality == ImportCardinality.ZeroOrOne) && (list.Count > 0))
            {
                list[0] = exportRegistration;
            }
            else
            {
                list.Add(exportRegistration);
            }
        }
示例#2
0
        public bool Accepts(GroupImportDefinition importDefinition, GroupExportDefinition exportDefinition)
        {
            if (importDefinition == null)
            {
                return(true);
            }

            if (!string.Equals(importDefinition.ContractName, exportDefinition.ContractName, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            var importingGroup = m_Repository.Group(importDefinition.ContainingGroup);
            var exportingGroup = m_Repository.Group(exportDefinition.ContainingGroup);

            var isMatch = true;

            if (exportingGroup.Schedule != null)
            {
                isMatch = importDefinition.ScheduleInsertPosition != null;
            }

            if (isMatch)
            {
                var imports = importDefinition.ImportsToMatch.Select(i => importingGroup.Parts.PartImportById(i));
                var exports = exportDefinition.ProvidedExports.Select(e => exportingGroup.Parts.PartExportById(e));
                foreach (var import in imports)
                {
                    var foundMatch = false;
                    foreach (var export in exports)
                    {
                        if (m_PartImportEngine.Accepts(import, export))
                        {
                            foundMatch = true;
                        }
                    }

                    isMatch = isMatch && foundMatch;
                    if (!isMatch)
                    {
                        break;
                    }
                }
            }

            return(isMatch);
        }