Example #1
0
 private IEnumerable <EntityTypeAsset> AssembleEntityTypes(
     Type externalSystem,
     EntityTypeSuite entityTypes,
     ConnectorSuite sinks,
     ConnectorSuite cacheFeeds,
     IDictionary <Type, ExternalSystemAsset> externalSystemAssetsByType)
 {
     return
         (entityTypes
          .DestinationSystemEntityTypes[externalSystem]
          .Keys
          .Select(entityType => new EntityTypeAsset(
                      entityType,
                      entityTypes
                      .DestinationSystemEntityTypes[externalSystem][entityType]
                      .Attribute,
                      new SharedIdentifierSourceSystemsProvider(
                          externalSystemAssetsByType,
                          entityTypes
                          .DestinationSystemEntityTypes[externalSystem][entityType]
                          .SharedSourceSystemIdentifiersAttributes),
                      this.GetEntityTypeSink(entityType, externalSystem, sinks),
                      this.GetEntityTypeCacheFeed(entityType, externalSystem, cacheFeeds)))
          .ToArray());
 }
Example #2
0
        private IEnumerable <Feed> GetFeeds(
            IDictionary <Type, ExternalSystemAttribute> externalSystems,
            EntityTypeSuite entityTypes)
        {
            var feeds = new HashSet <Feed>();

            foreach (CombinedAsset <FeedAttribute> feedAsset
                     in this.assetExtractor.GetFeeds())
            {
                bool isNonGeneric          = this.IsNonGeneric(feedAsset.AssetType);
                bool hasOneGenericArgument =
                    this.HasOneGenericArgument(feedAsset.AssetType);
                if (isNonGeneric)
                {
                    this.ProcessNonGenericFeedAsset(
                        feeds, feedAsset, externalSystems, entityTypes);
                }
                else if (hasOneGenericArgument)
                {
                    this.ProcessGenericFeed(
                        feeds, feedAsset, externalSystems, entityTypes);
                }
                else
                {
                    this.ThrowInterfaceImplementedIllegaly(
                        feedAsset.AssetType, typeof(IFeed <>));
                }
            }
            return(feeds);
        }
Example #3
0
        private IDictionary <Type, ExternalSystemAsset> AssembleExternalSystems(
            IDictionary <Type, ExternalSystemAttribute> externalSystems,
            IDictionary <Type, SourceSystemParametersAttribute> sourceSystemParameters,
            EntityTypeSuite entityTypes,
            ConnectorSuite sinks,
            ConnectorSuite cacheFeeds)
        {
            var externalSystemAssetsByType = new Dictionary <Type, ExternalSystemAsset>();

            foreach (Type externalSystem in externalSystems.Keys)
            {
                externalSystemAssetsByType.Add(
                    externalSystem,
                    new ExternalSystemAsset(
                        externalSystem,
                        externalSystems[externalSystem],
                        this.Get(externalSystem, sourceSystemParameters),
                        this.AssembleEntityTypes(
                            externalSystem,
                            entityTypes,
                            sinks,
                            cacheFeeds,
                            externalSystemAssetsByType)));
            }
            return(externalSystemAssetsByType);
        }
Example #4
0
 private void ValidateEntityType(Type entityType, EntityTypeSuite entityTypes)
 {
     if (!entityTypes.AllEntityTypes.Contains(entityType))
     {
         throw new InvalidOperationException(string.Format(
                                                 Resources.TypeDoesNotRepresentEntityType,
                                                 entityType.FullName));
     }
 }
Example #5
0
 private ConnectorSuite GetCacheFeeds(
     IDictionary <Type, ExternalSystemAttribute> externalSystems,
     EntityTypeSuite entityTypes)
 {
     return(this.GetDestinationSystemConnectors(
                this.assetExtractor.GetCacheFeeds(),
                cacheFeedAttribute => cacheFeedAttribute.DestinationSystem,
                typeof(ICacheFeed <>),
                externalSystems,
                entityTypes,
                Resources.MultipleCacheFeedsDefinedForDestinationSystem,
                Resources.MultipleCacheFeedsDefinedForEntityType));
 }
Example #6
0
        private ConnectorSuite GetDestinationSystemConnectors <TAttribute>(
            IEnumerable <SingularAsset <TAttribute> > connectorAssets,
            Func <TAttribute, Type> getDestinationSystem,
            Type genericInterfaceType,
            IDictionary <Type, ExternalSystemAttribute> externalSystems,
            EntityTypeSuite entityTypes,
            string multipleAssetsDefinedForDestinationSystemExceptionMessageFormat,
            string multipleAssetsDefinedForEntityTypeExceptionMessageFormat)
        {
            var destinationSystemConnectors = new Dictionary <Type, Type>();
            var entityTypeConnectors        = new Dictionary <Type, Type>();

            foreach (SingularAsset <TAttribute> connectorAsset in connectorAssets)
            {
                bool isNonGeneric          = this.IsNonGeneric(connectorAsset.AssetType);
                bool hasOneGenericArgument =
                    this.HasOneGenericArgument(connectorAsset.AssetType);
                Type destinationSystem =
                    getDestinationSystem(connectorAsset.AssetAttribute);
                if (hasOneGenericArgument && destinationSystem != null)
                {
                    this.AddDestinationSystemConnector(
                        destinationSystemConnectors,
                        destinationSystem,
                        connectorAsset.AssetType,
                        genericInterfaceType,
                        externalSystems,
                        multipleAssetsDefinedForDestinationSystemExceptionMessageFormat);
                }
                else if (isNonGeneric && destinationSystem == null)
                {
                    this.AddEntityTypeConnectors(
                        entityTypeConnectors,
                        connectorAsset.AssetType,
                        genericInterfaceType,
                        entityTypes,
                        multipleAssetsDefinedForEntityTypeExceptionMessageFormat);
                }
                else
                {
                    this.ThrowInterfaceImplementedIllegaly(
                        connectorAsset.AssetType, genericInterfaceType);
                }
            }
            return(new ConnectorSuite(
                       destinationSystemConnectors, entityTypeConnectors));
        }
Example #7
0
        private AssetSuite AssembleAssets(
            IDictionary <Type, ExternalSystemAttribute> externalSystems,
            IDictionary <Type, SourceSystemParametersAttribute> sourceSystemParameters,
            EntityTypeSuite entityTypes,
            ConnectorSuite sinks,
            ConnectorSuite cacheFeeds,
            IEnumerable <Feed> feeds)
        {
            IDictionary <Type, ExternalSystemAsset> externalSystemAssetsByType =
                this.AssembleExternalSystems(
                    externalSystems,
                    sourceSystemParameters,
                    entityTypes,
                    sinks,
                    cacheFeeds);

            return(new AssetSuite(
                       externalSystemAssetsByType.Values,
                       this.AssembleFeeds(feeds, externalSystemAssetsByType)));
        }
Example #8
0
        private void ProcessGenericFeed(
            HashSet <Feed> feeds,
            CombinedAsset <FeedAttribute> feedAsset,
            IDictionary <Type, ExternalSystemAttribute> externalSystems,
            EntityTypeSuite entityTypes)
        {
            FeedAttribute genericFeedAttribute =
                this.GetGenericFeedAttribute(feedAsset, externalSystems);

            foreach (Type entityType in genericFeedAttribute.EntityTypes)
            {
                this.ValidateEntityType(entityType, entityTypes);
                this.AddFeed(
                    feeds,
                    new Feed(
                        genericFeedAttribute.SourceSystem,
                        entityType,
                        feedAsset.AssetType,
                        new[] { genericFeedAttribute }));
            }
        }
Example #9
0
        /// <summary>
        /// Assembles the suite of assets (i.e., external systems, entity types, feeds,
        /// etc.) found in all currently loaded assemblies.
        /// </summary>
        /// <returns>The suite of assets assembled.</returns>
        public AssetSuite AssembleAssets()
        {
            AssetSuite assetSuite;
            IDictionary <Type, ExternalSystemAttribute>
            externalSystems = this.GetExternalSystems();
            IDictionary <Type, SourceSystemParametersAttribute>
            sourceSystemParameters         = this.assetExtractor.GetSourceSystemParameters();
            EntityTypeSuite    entityTypes = this.GetEntityTypes(externalSystems);
            ConnectorSuite     sinks       = this.GetSinks(externalSystems, entityTypes);
            ConnectorSuite     cacheFeeds  = this.GetCacheFeeds(externalSystems, entityTypes);
            IEnumerable <Feed> feeds       = this.GetFeeds(externalSystems, entityTypes);

            assetSuite = this.AssembleAssets(
                externalSystems,
                sourceSystemParameters,
                entityTypes,
                sinks,
                cacheFeeds,
                feeds);
            this.ValidateAssetSuite(assetSuite);
            return(assetSuite);
        }
Example #10
0
        private void ProcessNonGenericFeedAsset(
            HashSet <Feed> feeds,
            CombinedAsset <FeedAttribute> feedAsset,
            IDictionary <Type, ExternalSystemAttribute> externalSystems,
            EntityTypeSuite entityTypes)
        {
            FeedAttribute defaultAttribute = this.GetDefaultFeedAttribute(feedAsset);
            IDictionary <Type, FeedAttribute> entityTypeFeedAttributes =
                this.GetEntityTypeFeedAttributes(feedAsset);

            foreach (Type feedImplementation in
                     this.GetInterfaceImplementations(feedAsset.AssetType, typeof(IFeed <>)))
            {
                Type entityType = this.ExtractEntityType(feedImplementation);
                this.ValidateEntityType(entityType, entityTypes);
                IEnumerable <FeedAttribute> feedAttributes = this.GetFeedAttributes(
                    feedAsset.AssetType,
                    entityType,
                    defaultAttribute,
                    entityTypeFeedAttributes);
                Type sourceSystem = this.GetFeedSourceSystem(
                    feedAsset.AssetType,
                    entityType,
                    feedAttributes,
                    externalSystems);
                this.AddFeed(
                    feeds,
                    new Feed(
                        sourceSystem,
                        entityType,
                        feedAsset.AssetType,
                        feedAttributes));
            }
            this.VerifyEachEntityTypeHasMatchingInterfaceImplementation(
                feedAsset.AssetType, entityTypeFeedAttributes);
        }
Example #11
0
 private void AddEntityTypeConnectors(
     IDictionary <Type, Type> entityTypeConnectors,
     Type connectorAssetType,
     Type genericInterfaceType,
     EntityTypeSuite entityTypes,
     string multipleAssetsDefinedForEntityTypeExceptionMessageFormat)
 {
     foreach (Type interfaceImplementation in
              this.GetInterfaceImplementations(connectorAssetType, genericInterfaceType))
     {
         Type entityType = this.ExtractEntityType(interfaceImplementation);
         this.ValidateEntityType(entityType, entityTypes);
         if (!entityTypeConnectors.ContainsKey(entityType))
         {
             entityTypeConnectors.Add(entityType, connectorAssetType);
         }
         else
         {
             throw new InvalidOperationException(string.Format(
                                                     multipleAssetsDefinedForEntityTypeExceptionMessageFormat,
                                                     entityType.FullName));
         }
     }
 }