Exemplo n.º 1
0
        /// <summary>
        /// Disconnects the exporting group from the importing group.
        /// </summary>
        /// <param name="importingGroup">The composition ID of the importing group.</param>
        /// <param name="exportingGroup">The composition ID of the exporting group.</param>
        public void Disconnect(GroupCompositionId importingGroup, GroupCompositionId exportingGroup)
        {
            if ((importingGroup == null) || (exportingGroup == null))
            {
                return;
            }

            if (!m_GroupConnections.ContainsVertex(importingGroup) || (!m_GroupConnections.ContainsVertex(exportingGroup)))
            {
                return;
            }

            var importDefinition = m_GroupConnections
                                   .InEdges(importingGroup)
                                   .Where(edge => edge.Source.Equals(exportingGroup))
                                   .Select(edge => edge.Import)
                                   .FirstOrDefault();

            m_GroupConnections.RemoveInEdgeIf(importingGroup, edge => edge.Source.Equals(exportingGroup));

            DisconnectParts(importingGroup, importDefinition, exportingGroup);
        }
Exemplo n.º 2
0
        private void DisconnectParts(GroupCompositionId importingGroup, GroupImportDefinition importDefinition, GroupCompositionId exportingGroup)
        {
            var definitionId             = m_Groups[importingGroup];
            var importingGroupDefinition = m_Definitions[definitionId];
            var importingParts           = importDefinition
                                           .ImportsToMatch
                                           .Select(id => importingGroupDefinition.Parts.PartByImport(id))
                                           .Join(
                m_Parts,
                partDef => new PartCompositionId(importingGroup, partDef.Id),
                pair => pair.Key,
                (partDef, pair) => pair.Key);

            definitionId = m_Groups[exportingGroup];
            var exportingGroupDefinition = m_Definitions[definitionId];
            var exportingParts           = exportingGroupDefinition.GroupExport
                                           .ProvidedExports
                                           .Select(id => exportingGroupDefinition.Parts.PartByExport(id))
                                           .Join(
                m_Parts,
                partDef => new PartCompositionId(exportingGroup, partDef.Id),
                pair => pair.Key,
                (partDef, pair) => pair.Key);

            foreach (var importingPart in importingParts)
            {
                var matchedExports = m_PartConnections
                                     .InEdges(importingPart)
                                     .Where(edge => exportingParts.Contains(edge.Source))
                                     .Select(edge => new Tuple <ImportRegistrationId, PartCompositionId>(edge.ImportRegistration, edge.Source));

                foreach (var pair in matchedExports)
                {
                    DisconnectInstanceFromExport(importingPart, pair.Item1, pair.Item2);
                }

                m_PartConnections.RemoveInEdgeIf(importingPart, edge => exportingParts.Contains(edge.Source));
            }
        }