Example #1
0
        private FeedAttribute GetGenericFeedAttribute(
            CombinedAsset <FeedAttribute> feedAsset,
            IDictionary <Type, ExternalSystemAttribute> externalSystems)
        {
            FeedAttribute genericFeedAttribute = null;

            if (feedAsset.AssetAttributes.Count() == 1)
            {
                FeedAttribute singleAttribute =
                    feedAsset.AssetAttributes.Single();
                if (singleAttribute.SourceSystem != null &&
                    singleAttribute.EntityTypes.Count() > 0)
                {
                    this.ValidateExternalSystem(
                        singleAttribute.SourceSystem, externalSystems);
                    genericFeedAttribute = singleAttribute;
                }
            }
            if (genericFeedAttribute == null)
            {
                throw new InvalidOperationException(string.Format(
                                                        Resources.InvalidGenericFeedAttribute,
                                                        feedAsset.AssetType.FullName));
            }
            return(genericFeedAttribute);
        }
Example #2
0
 private FeedAttribute GetDefaultFeedAttribute(
     CombinedAsset <FeedAttribute> feedAsset)
 {
     FeedAttribute[] defaultAttributes =
         feedAsset
         .AssetAttributes
         .Where(fa => fa.EntityTypes.Count() == 0)
         .ToArray();
     if (defaultAttributes.Length > 1)
     {
         throw new InvalidOperationException(string.Format(
                                                 Resources.FeedHasMoreThanOneDefaultAttribute,
                                                 feedAsset.AssetType.FullName));
     }
     return(defaultAttributes.SingleOrDefault());
 }
Example #3
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 #4
0
        private IDictionary <Type, FeedAttribute> GetEntityTypeFeedAttributes(
            CombinedAsset <FeedAttribute> feedAsset)
        {
            var entityTypeFeedAttributes = new Dictionary <Type, FeedAttribute>();

            foreach (FeedAttribute feedAttribute in feedAsset.AssetAttributes)
            {
                foreach (Type entityType in feedAttribute.EntityTypes)
                {
                    if (!entityTypeFeedAttributes.ContainsKey(entityType))
                    {
                        entityTypeFeedAttributes.Add(entityType, feedAttribute);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format(
                                                                Resources.DuplicateFeedEntityType,
                                                                feedAsset.AssetType.FullName,
                                                                entityType.FullName));
                    }
                }
            }
            return(entityTypeFeedAttributes);
        }
Example #5
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);
        }