Ejemplo n.º 1
0
        public object CacheCatalog(ComposablePartCatalogCacheWriter writer)
        {
            ThrowIfDisposed();

            Requires.NotNull(writer, "writer");

            List <object> subordinateCacheTokens = new List <object>();

            foreach (ComposablePartCatalog catalog in this.Catalogs)
            {
                ICachedComposablePartCatalog cachedCatalog = catalog as ICachedComposablePartCatalog;
                if (cachedCatalog == null)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Strings.CatalogIsNotCacheable, catalog.GetType()));
                }
                object subordinateCacheToken = cachedCatalog.CacheCatalog(writer);
                subordinateCacheTokens.Add(subordinateCacheToken);
            }

            IDictionary <string, object> metadata = new Dictionary <string, object>();

            metadata.WriteEnumerable(AttributedCacheServices.CacheKeys.SubordinateTokens, subordinateCacheTokens);

            object cacheToken = writer.WriteCache(
                this.GetType(),
                null,
                metadata,
                null);

            writer.WriteRootCacheToken(cacheToken);
            return(cacheToken);
        }
        public static void CacheCatalog(ICachedComposablePartCatalog catalog, AssemblyName assemblyName, string cacheStorageDirectory)
        {
            Requires.NotNull(catalog, "catalog");
            Requires.NotNull(assemblyName, "assemblyName");
            Requires.NotNull(cacheStorageDirectory, "cacheStorageDirectory");

            ComposablePartCatalogAssemblyCacheWriter writer = new ComposablePartCatalogAssemblyCacheWriter(assemblyName, cacheStorageDirectory);
            catalog.CacheCatalog(writer);
            writer.Dispose();
        }
        public static void CacheCatalog(ICachedComposablePartCatalog catalog, AssemblyName assemblyName, string cacheStorageDirectory)
        {
            Requires.NotNull(catalog, "catalog");
            Requires.NotNull(assemblyName, "assemblyName");
            Requires.NotNull(cacheStorageDirectory, "cacheStorageDirectory");

            ComposablePartCatalogAssemblyCacheWriter writer = new ComposablePartCatalogAssemblyCacheWriter(assemblyName, cacheStorageDirectory);

            catalog.CacheCatalog(writer);
            writer.Dispose();
        }