Пример #1
0
 private static GroupDefinition CreateExportingGroup()
 {
     return(new GroupDefinition("a")
     {
         InternalConnections = Enumerable.Empty <PartImportToPartExportMap>(),
         Parts = new List <GroupPartDefinition>
         {
             new GroupPartDefinition(
                 TypeIdentity.CreateDefinition(typeof(int)),
                 0,
                 new Dictionary <ExportRegistrationId, SerializableExportDefinition>
             {
                 {
                     new ExportRegistrationId(typeof(int), 0, "PartContract1"),
                     TypeBasedExportDefinition.CreateDefinition("PartContract1", typeof(int))
                 }
             },
                 new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                 new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                 new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
             new GroupPartDefinition(
                 TypeIdentity.CreateDefinition(typeof(string)),
                 1,
                 new Dictionary <ExportRegistrationId, SerializableExportDefinition>
             {
                 {
                     new ExportRegistrationId(typeof(string), 1, "PartContract2"),
                     TypeBasedExportDefinition.CreateDefinition("PartContract2", typeof(string))
                 }
             },
                 new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                 new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                 new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
             new GroupPartDefinition(
                 TypeIdentity.CreateDefinition(typeof(Version)),
                 2,
                 new Dictionary <ExportRegistrationId, SerializableExportDefinition>
             {
                 {
                     new ExportRegistrationId(typeof(string), 2, "PartContract2"),
                     TypeBasedExportDefinition.CreateDefinition("PartContract2", typeof(string))
                 }
             },
                 new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                 new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                 new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
         },
         GroupExport = GroupExportDefinition.CreateDefinition(
             "ContractName",
             new GroupRegistrationId("a"),
             new List <ExportRegistrationId>
         {
             new ExportRegistrationId(typeof(int), 0, "PartContract1"),
             new ExportRegistrationId(typeof(string), 1, "PartContract2"),
             new ExportRegistrationId(typeof(string), 2, "PartContract2"),
         }),
     });
 }
Пример #2
0
        public bool ExportPassesSelectionCriteria(GroupExportDefinition exportDefinition, IDictionary <string, object> selectionCriteria)
        {
            if (selectionCriteria == null || selectionCriteria.Count == 0)
            {
                return(true);
            }

            return(false);
        }
Пример #3
0
        private Task OnGroupConnect(
            GroupCompositionId importingGroup,
            GroupImportDefinition importDefinition,
            GroupCompositionId exportingGroup,
            GroupExportDefinition exportDefinition)
        {
            if (!m_GroupImportEngine.Accepts(importDefinition, exportDefinition))
            {
                throw new CannotMapExportToImportException();
            }

            return(m_Graph.Connect(importingGroup, importDefinition, exportingGroup));
        }
Пример #4
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);
        }
Пример #5
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;
        }
Пример #6
0
        /// <summary>
        /// Registers a group with the currently stored data.
        /// </summary>
        /// <param name="name">The name of the newly created group.</param>
        /// <returns>The registration ID of the group.</returns>
        public GroupRegistrationId Register(string name)
        {
            var definition = new GroupDefinition(name);

            definition.Parts = m_Objects.SelectMany(p => p.Value).ToList();
            definition.InternalConnections = m_Connections.Select(
                p => new PartImportToPartExportMap(p.Key, (IEnumerable <ExportRegistrationId>)p.Value));

            if (m_Schedule != null)
            {
                definition.Schedule = ScheduleDefinition.CreateDefinition(
                    definition.Id,
                    m_Schedule,
                    m_Actions.ToDictionary(p => p.Value, p => p.Key),
                    m_Conditions.ToDictionary(p => p.Value, p => p.Key));
            }

            if (m_GroupExport != null)
            {
                definition.GroupExport = GroupExportDefinition.CreateDefinition(
                    m_GroupExport.ContractName,
                    definition.Id,
                    NonLinkedExports());
            }

            if (m_GroupImports.Count > 0)
            {
                definition.GroupImports = m_GroupImports.Select(
                    i => GroupImportDefinition.CreateDefinition(
                        i.Value.ContractName,
                        definition.Id,
                        i.Value.InsertPoint,
                        i.Value.ObjectImports))
                                          .ToList();
            }

            Clear();

            m_Repository.AddGroup(definition, m_FileInfo);
            return(definition.Id);
        }
Пример #7
0
        private Task OnGroupConnect(
            GroupCompositionId importingGroup,
            GroupImportDefinition importDefinition,
            GroupCompositionId exportingGroup,
            GroupExportDefinition exportDefinition)
        {
            if (!m_GroupImportEngine.Accepts(importDefinition, exportDefinition))
            {
                throw new CannotMapExportToImportException();
            }

            return m_Graph.Connect(importingGroup, importDefinition, exportingGroup);
        }
Пример #8
0
        public bool ExportPassesSelectionCriteria(GroupExportDefinition exportDefinition, IDictionary<string, object> selectionCriteria)
        {
            if (selectionCriteria == null || selectionCriteria.Count == 0)
            {
                return true;
            }

            return false;
        }
Пример #9
0
        private static GroupDefinition CreateExportingDefinition()
        {
            var groupName = "Export";

            return(new GroupDefinition(groupName)
            {
                Parts = new List <GroupPartDefinition>
                {
                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(int)),
                        0,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>
                    {
                        {
                            new ExportRegistrationId(typeof(int), 0, "PartContract1"),
                            TypeBasedExportDefinition.CreateDefinition("PartContract1", typeof(int))
                        }
                    },
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(string)),
                        1,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>
                    {
                        {
                            new ExportRegistrationId(typeof(string), 1, "PartContract2"),
                            TypeBasedExportDefinition.CreateDefinition("PartContract2", typeof(string))
                        }
                    },
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(Version)),
                        2,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>
                    {
                        {
                            new ExportRegistrationId(typeof(string), 2, "PartContract2"),
                            TypeBasedExportDefinition.CreateDefinition("PartContract2", typeof(string))
                        }
                    },
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),

                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(DateTime)),
                        2,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>
                    {
                        {
                            new ExportRegistrationId(typeof(string), 3, "PartContract3"),
                            TypeBasedExportDefinition.CreateDefinition("PartContract3", typeof(string))
                        }
                    },
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>(),
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
                    new GroupPartDefinition(
                        TypeIdentity.CreateDefinition(typeof(List <int>)),
                        2,
                        new Dictionary <ExportRegistrationId, SerializableExportDefinition>(),
                        new Dictionary <ImportRegistrationId, SerializableImportDefinition>
                    {
                        {
                            new ImportRegistrationId(typeof(string), 1, "PartContract3"),
                            PropertyBasedImportDefinition.CreateDefinition(
                                "PartContract3",
                                TypeIdentity.CreateDefinition(typeof(string)),
                                ImportCardinality.ExactlyOne,
                                false,
                                CreationPolicy.Any,
                                typeof(ImportOnPropertyWithEnumerable).GetProperty("ImportingProperty"))
                        }
                    },
                        new Dictionary <ScheduleActionRegistrationId, ScheduleActionDefinition>(),
                        new Dictionary <ScheduleConditionRegistrationId, ScheduleConditionDefinition>()),
                },
                InternalConnections = new List <PartImportToPartExportMap>
                {
                    new PartImportToPartExportMap(
                        new ImportRegistrationId(typeof(string), 1, "PartContract3"),
                        new List <ExportRegistrationId>
                    {
                        new ExportRegistrationId(typeof(string), 3, "PartContract3")
                    }),
                },
                GroupExport = GroupExportDefinition.CreateDefinition(
                    "ContractName",
                    new GroupRegistrationId(groupName),
                    new List <ExportRegistrationId>
                {
                    new ExportRegistrationId(typeof(int), 0, "PartContract1"),
                    new ExportRegistrationId(typeof(string), 1, "PartContract2"),
                    new ExportRegistrationId(typeof(string), 2, "PartContract2"),
                }),
            });
        }