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); } }
/// <summary> /// Reads the catalog from the cache given the specified cache token. This methos trows if thew catalog with the given /// token doesn't exist. /// </summary> /// <param name="cacheToken">The cache token.</param> /// <returns>The catalog corresponding to the specified cache token.</returns> public ComposablePartCatalog ReadCatalog(object cacheToken) { ComposablePartCatalogCache catalogCache = this.ReadCacheCore(cacheToken); Type catalogType = catalogCache.Metadata.GetValue <Type>(ComposablePartCatalogCacheReader.CatalogTypeMetadataKey); return((ComposablePartCatalog)Activator.CreateInstance( catalogType, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] { catalogCache }, null)); }
public CachedAggregateCatalog(ComposablePartCatalogCache cache) { Requires.NotNull(cache, "cache"); IEnumerable<object> subordinateCacheTokens = cache.Metadata.ReadEnumerable<object>(AttributedCacheServices.CacheKeys.SubordinateTokens); List<ComposablePartCatalog> subordinateCatalogs = new List<ComposablePartCatalog>(); foreach (object subordinateCacheToken in subordinateCacheTokens) { subordinateCatalogs.Add(cache.Reader.ReadCatalog(subordinateCacheToken)); } this._innerCatalog = new AggregateCatalog(subordinateCatalogs); this._readFromCache = true; this._innerCatalog.Changed += OnInnerCatalogsChanged; this._innerCatalog.Changing += OnInnerCatalogsChanging; }
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; } }