Пример #1
0
        async Task InitializeInstanceAsync()
        {
            var assemblies = ReadAssembliesFromAddins();
            var caching    = new Caching(assemblies);

            // Try to use cached MEF data
            if (cacheEnabled && caching.CanUse())
            {
                RuntimeComposition = await TryCreateRuntimeCompositionFromCache(caching);
            }

            // Otherwise fallback to runtime discovery.
            if (RuntimeComposition == null)
            {
                RuntimeComposition = await CreateRuntimeCompositionFromDiscovery(caching);

                CachedComposition cacheManager = new CachedComposition();
                caching.Write(RuntimeComposition, cacheManager).Ignore();
            }

            ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory();
            ExportProvider        = ExportProviderFactory.CreateExportProvider();
            HostServices          = MefV1HostServices.Create(ExportProvider.AsExportProvider());
            ExportProviderV1      = NetFxAdapters.AsExportProvider(ExportProvider);
        }
Пример #2
0
        async Task InitializeInstanceAsync()
        {
            var timings  = new Dictionary <string, long> ();
            var metadata = new CompositionLoadMetadata(timings);

            using (var timer = Counters.CompositionLoad.BeginTiming(metadata)) {
                var fullTimer = System.Diagnostics.Stopwatch.StartNew();
                var stepTimer = System.Diagnostics.Stopwatch.StartNew();

                var mefAssemblies = ReadAssembliesFromAddins(timer);
                timings ["ReadFromAddins"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                var caching = new Caching(mefAssemblies);

                // Try to use cached MEF data

                var canUse = metadata.ValidCache = caching.CanUse();
                if (canUse)
                {
                    LoggingService.LogInfo("Creating MEF composition from cache");
                    RuntimeComposition = await TryCreateRuntimeCompositionFromCache(caching);
                }
                timings ["LoadFromCache"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                // Otherwise fallback to runtime discovery.
                if (RuntimeComposition == null)
                {
                    LoggingService.LogInfo("Creating MEF composition from runtime");
                    var(runtimeComposition, catalog) = await CreateRuntimeCompositionFromDiscovery(caching, timer);

                    RuntimeComposition = runtimeComposition;

                    CachedComposition cacheManager = new CachedComposition();
                    caching.Write(RuntimeComposition, catalog, cacheManager).Ignore();
                }
                timings ["LoadRuntimeComposition"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory();
                ExportProvider        = ExportProviderFactory.CreateExportProvider();
                HostServices          = MefV1HostServices.Create(ExportProvider.AsExportProvider());
                ExportProviderV1      = NetFxAdapters.AsExportProvider(ExportProvider);

                timings ["CreateServices"] = stepTimer.ElapsedMilliseconds;
                metadata.Duration          = fullTimer.ElapsedMilliseconds;
            }
        }
Пример #3
0
        async Task InitializeInstanceAsync(ITimeTracker <CompositionLoadMetadata> timer, HashSet <Assembly> mefAssemblies)
        {
            var metadata  = timer.Metadata;
            var fullTimer = System.Diagnostics.Stopwatch.StartNew();
            var stepTimer = System.Diagnostics.Stopwatch.StartNew();

            var caching = new Caching(mefAssemblies, new IdeRuntimeCompositionExceptionHandler());

            // Try to use cached MEF data
            using (timer) {
                var canUse = metadata.ValidCache = caching.CanUse();
                if (canUse)
                {
                    LoggingService.LogInfo("Creating MEF composition from cache");
                    RuntimeComposition = await TryCreateRuntimeCompositionFromCache(caching);
                }
                metadata.Timings ["LoadFromCache"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                // Otherwise fallback to runtime discovery.
                if (RuntimeComposition == null)
                {
                    LoggingService.LogInfo("Creating MEF composition from runtime");
                    var(runtimeComposition, catalog) = await CreateRuntimeCompositionFromDiscovery(caching, timer);

                    RuntimeComposition = runtimeComposition;

                    CachedComposition cacheManager = new CachedComposition();
                    caching.Write(RuntimeComposition, catalog, cacheManager).Ignore();
                }
                metadata.Timings ["LoadRuntimeComposition"] = stepTimer.ElapsedMilliseconds;
                stepTimer.Restart();

                ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory();
                ExportProvider        = ExportProviderFactory.CreateExportProvider();
                HostServices          = Microsoft.VisualStudio.LanguageServices.VisualStudioMefHostServices.Create(ExportProvider);

                metadata.Timings ["CreateServices"] = stepTimer.ElapsedMilliseconds;
                metadata.Duration = fullTimer.ElapsedMilliseconds;
            }
        }