Exemplo n.º 1
0
        /// <summary>
        /// Connects the exporting group with the importing group via the given import.
        /// </summary>
        /// <param name="connection">The object that describes how the group import and the group export should be connected.</param>
        public void Connect(GroupConnection connection)
        {
            {
                Lokad.Enforce.Argument(() => connection);
                Lokad.Enforce.With <UnknownGroupCompositionIdException>(
                    m_Groups.ContainsKey(connection.ImportingGroup),
                    Resources.Exceptions_Messages_UnknownGroupCompositionId);
                Lokad.Enforce.With <UnknownGroupCompositionIdException>(
                    m_Groups.ContainsKey(connection.ExportingGroup),
                    Resources.Exceptions_Messages_UnknownGroupCompositionId);
            }

            m_GroupConnections.AddEdge(new GroupCompositionGraphEdge(connection.ImportingGroup, connection.GroupImport, connection.ExportingGroup));

            var importingParts = PartsForGroup(connection.ImportingGroup);
            var exportingParts = PartsForGroup(connection.ExportingGroup);

            ConnectParts(connection.PartConnections, importingParts, exportingParts);
        }
Exemplo n.º 2
0
        private void ConnectParts(
            IEnumerable <PartImportToPartExportMap> connections,
            IEnumerable <Tuple <PartCompositionId, GroupPartDefinition> > importingParts,
            IEnumerable <Tuple <PartCompositionId, GroupPartDefinition> > exportingParts)
        {
            foreach (var map in connections)
            {
                var importingPart = importingParts.FirstOrDefault(p => p.Item2.RegisteredImports.Contains(map.Import));
                Debug.Assert(importingPart != null, "Cannot connect parts that are not registered.");

                foreach (var export in map.Exports)
                {
                    var exportingPart = exportingParts.FirstOrDefault(p => p.Item2.RegisteredExports.Contains(export));
                    m_PartConnections.AddEdge(
                        new PartImportExportEdge <PartCompositionId>(
                            importingPart.Item1,
                            map.Import,
                            exportingPart.Item1,
                            export));
                }
            }

            ConstructInstancesIfComplete(importingParts.Select(p => p.Item1));
        }