Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PartCompositionInfo"/> class.
        /// </summary>
        /// <param name="definition">The definition of the part.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="definition"/> is <see langword="null" />.
        /// </exception>
        public PartCompositionInfo(GroupPartDefinition definition)
        {
            {
                Lokad.Enforce.Argument(() => definition);
            }

            m_Definition = definition;
        }
Exemplo n.º 2
0
        /// <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));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Provides the import definition from the part definition based on the import ID.
        /// </summary>
        /// <param name="partDefinition">The part definition that owns the import.</param>
        /// <param name="importRegistration">The ID of the import.</param>
        /// <returns>The requested import definition.</returns>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="partDefinition"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="UnknownImportDefinitionException">Thrown when the part does not define an import with the given ID.</exception>
        public static SerializableImportDefinition PartImportById(this GroupPartDefinition partDefinition, ImportRegistrationId importRegistration)
        {
            {
                Lokad.Enforce.Argument(() => partDefinition);
            }

            if (partDefinition.RegisteredImports.Contains(importRegistration))
            {
                throw new UnknownImportDefinitionException();
            }

            return(partDefinition.Import(importRegistration));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Registers a new instance of the given type.
        /// </summary>
        /// <param name="type">The type to create a new instance from.</param>
        /// <returns>
        /// An object that provides a unique ID for the registered object and provides the IDs for the imports, exports,
        /// conditions and actions on that object.
        /// </returns>
        public IPartRegistration RegisterObject(Type type)
        {
            var plugin = m_Repository.Parts().FirstOrDefault(p => p.Identity.Equals(type));
            if (plugin == null)
            {
                throw new UnknownPluginTypeException();
            }

            if (!m_Objects.ContainsKey(type))
            {
                m_Objects.Add(type, new List<GroupPartDefinition>());
            }

            var collection = m_Objects[type];

            var exports = plugin.Exports.ToDictionary(
                e => new ExportRegistrationId(type, collection.Count, e.ContractName),
                e => e);
            var imports = plugin.Imports.ToDictionary(
                i => new ImportRegistrationId(type, collection.Count, i.ContractName),
                i => i);
            var actions = plugin.Actions.ToDictionary(
                a => new ScheduleActionRegistrationId(type, collection.Count, a.ContractName),
                a => a);
            var conditions = plugin.Conditions.ToDictionary(
                c => new ScheduleConditionRegistrationId(type, collection.Count, c.ContractName),
                c => c);

            var registration = new GroupPartDefinition(
                m_IdentityGenerator(type),
                collection.Count,
                exports,
                imports,
                actions,
                conditions);
            collection.Add(registration);

            return registration;
        }