/// <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); } }
/// <summary> /// Provides the part definition that owns the given export registration. /// </summary> /// <param name="partDefinitions">The collection of parts that should be searched for the given export.</param> /// <param name="exportRegistration">The ID of the export.</param> /// <returns>The requested part.</returns> /// <exception cref="UnknownExportDefinitionException">Thrown when the part does not define an export with the given ID.</exception> public static GroupPartDefinition PartByExport( this IEnumerable<GroupPartDefinition> partDefinitions, ExportRegistrationId exportRegistration) { var part = partDefinitions.FirstOrDefault(o => o.RegisteredExports.Contains(exportRegistration)); if (part == null) { throw new UnknownExportDefinitionException(); } return part; }
/// <summary> /// Provides the export definition from the part definition based on the export ID. /// </summary> /// <param name="partDefinition">The part definition that owns the export.</param> /// <param name="exportRegistration">The ID of the export.</param> /// <returns>The requested export definition.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="partDefinition"/> is <see langword="null" />. /// </exception> /// <exception cref="UnknownExportDefinitionException">Thrown when the part does not define an export with the given ID.</exception> public static SerializableExportDefinition PartExportById(this GroupPartDefinition partDefinition, ExportRegistrationId exportRegistration) { { Lokad.Enforce.Argument(() => partDefinition); } if (!partDefinition.RegisteredExports.Contains(exportRegistration)) { throw new UnknownExportDefinitionException(); } return partDefinition.Export(exportRegistration); }
/// <summary> /// Provides the part definition that owns the given export registration. /// </summary> /// <param name="partDefinitions">The collection of parts that should be searched for the given export.</param> /// <param name="exportRegistration">The ID of the export.</param> /// <returns>The requested part.</returns> /// <exception cref="UnknownExportDefinitionException">Thrown when the part does not define an export with the given ID.</exception> public static GroupPartDefinition PartByExport( this IEnumerable <GroupPartDefinition> partDefinitions, ExportRegistrationId exportRegistration) { var part = partDefinitions.FirstOrDefault(o => o.RegisteredExports.Contains(exportRegistration)); if (part == null) { throw new UnknownExportDefinitionException(); } return(part); }
/// <summary> /// Initializes a new instance of the <see cref="PartImportExportEdge{T}"/> class. /// </summary> /// <param name="importPart">The ID of the part that provides the import.</param> /// <param name="importId">The registration ID of the import.</param> /// <param name="exportPart">The ID of the part that provides the export.</param> /// <param name="exportId">The registration ID of the export.</param> public PartImportExportEdge( T importPart, ImportRegistrationId importId, T exportPart, ExportRegistrationId exportId) : base(exportPart, importPart) { { Debug.Assert(importId != null, "The import ID should not be a null reference."); Debug.Assert(exportId != null, "The export ID should not be a null reference."); } m_Import = importId; m_Export = exportId; }
/// <summary> /// Provides the export definition from the part definition that owns the export. /// </summary> /// <param name="partDefinitions">The collection of parts that should be searched for the export definition.</param> /// <param name="exportRegistration">The ID of the export.</param> /// <returns>The requested export definition.</returns> /// <exception cref="UnknownExportDefinitionException">Thrown when none of the parts defines an export with the given ID.</exception> public static SerializableExportDefinition PartExportById( this IEnumerable <GroupPartDefinition> partDefinitions, ExportRegistrationId exportRegistration) { var export = partDefinitions .Where(o => o.RegisteredExports.Contains(exportRegistration)) .Select(o => o.Export(exportRegistration)) .FirstOrDefault(); if (export == null) { throw new UnknownExportDefinitionException(); } return(export); }
/// <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); } }
/// <summary> /// Returns the export definition that was registered with the given ID. /// </summary> /// <param name="id">The ID of the export.</param> /// <returns>The requested export definition.</returns> public SerializableExportDefinition Export(ExportRegistrationId id) { return(m_Exports[id]); }
/// <summary> /// Returns the export definition that was registered with the given ID. /// </summary> /// <param name="id">The ID of the export.</param> /// <returns>The requested export definition.</returns> public SerializableExportDefinition Export(ExportRegistrationId id) { return m_Exports[id]; }
/// <summary> /// Provides the export definition from the part definition that owns the export. /// </summary> /// <param name="partDefinitions">The collection of parts that should be searched for the export definition.</param> /// <param name="exportRegistration">The ID of the export.</param> /// <returns>The requested export definition.</returns> /// <exception cref="UnknownExportDefinitionException">Thrown when none of the parts defines an export with the given ID.</exception> public static SerializableExportDefinition PartExportById( this IEnumerable<GroupPartDefinition> partDefinitions, ExportRegistrationId exportRegistration) { var export = partDefinitions .Where(o => o.RegisteredExports.Contains(exportRegistration)) .Select(o => o.Export(exportRegistration)) .FirstOrDefault(); if (export == null) { throw new UnknownExportDefinitionException(); } return export; }
/// <summary> /// Provides the export definition from the part definition based on the export ID. /// </summary> /// <param name="partDefinition">The part definition that owns the export.</param> /// <param name="exportRegistration">The ID of the export.</param> /// <returns>The requested export definition.</returns> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="partDefinition"/> is <see langword="null" />. /// </exception> /// <exception cref="UnknownExportDefinitionException">Thrown when the part does not define an export with the given ID.</exception> public static SerializableExportDefinition PartExportById(this GroupPartDefinition partDefinition, ExportRegistrationId exportRegistration) { { Lokad.Enforce.Argument(() => partDefinition); } if (!partDefinition.RegisteredExports.Contains(exportRegistration)) { throw new UnknownExportDefinitionException(); } return(partDefinition.Export(exportRegistration)); }