Esempio n. 1
0
        public CachedTypeCatalog(ComposablePartCatalogCache cache)
        {
            Requires.NotNull(cache, "cache");
            ComposablePartCatalog cacheCatalog = cache.GetCacheCatalog(AttributedComposablePartCatalogSite.CreateForReading());

            List<Type> notUpToDateTypes = new List<Type>();
            List<ComposablePartDefinition> upToDateParts = new List<ComposablePartDefinition>();
            foreach (ComposablePartDefinition partDefinition in cacheCatalog.Parts)
            {
                if (!partDefinition.IsPartDefinitionCacheUpToDate())
                {
                    notUpToDateTypes.Add(ReflectionModelServices.GetPartType(partDefinition).Value);
                }
                else
                {
                    upToDateParts.Add(partDefinition);
                }
            }

            if (notUpToDateTypes.Count == 0)
            {
                // everything is up to date, we can use the cached catalog
                this._cacheCatalog = cacheCatalog;
            }
            else
            {
                // some parts are not up-to-date, we will not query the catalog, but rather a combination of the type catalog and up-to-date parts
                this._upToDateParts = upToDateParts;
                this._typeCatalog = new TypeCatalog(notUpToDateTypes);
            }
        }
        public CachedAssemblyCatalog(ComposablePartCatalogCache cache)
        {
            Requires.NotNull(cache, "cache");

            this._useAssemblyIdentity = cache.Metadata.IsAssemblyIdentityStored();
            // if the assembly hasn't been changed since the caching, then load the cache
            if (cache.Metadata.IsAssemblyCacheUpToDate())
            {
                this._cacheCatalogMetadata = cache.Metadata;
                this._innerCatalog = cache.GetCacheCatalog(AttributedComposablePartCatalogSite.CreateForReading(() => this.Assembly));
                this._isCached = true;
            }
            else
            {
                // just load the assembly given the information we have
                this._innerCatalog = new AssemblyCatalog(cache.Metadata.ReadAssembly());
                this._isCached = false;
            }
        }