コード例 #1
0
        async Task InitializeInstanceAsync()
        {
            ComposableCatalog catalog = ComposableCatalog.Create(StandardResolver)
                                        .WithCompositionService()
                                        .WithDesktopSupport();

            var assemblies = new HashSet <Assembly> ();

            ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/TypeService/PlatformMefHostServices");
            ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/TypeService/MefHostServices");
            ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/Composition");

            // spawn discovery tasks in parallel for each assembly
            var tasks = new List <Task <DiscoveredParts> > (assemblies.Count);

            foreach (var assembly in assemblies)
            {
                var task = Task.Run(() => Discovery.CreatePartsAsync(assembly));
                tasks.Add(task);
            }

            foreach (var task in tasks)
            {
                catalog = catalog.AddParts(await task);
            }

            var discoveryErrors = catalog.DiscoveredParts.DiscoveryErrors;

            if (!discoveryErrors.IsEmpty)
            {
                foreach (var error in discoveryErrors)
                {
                    LoggingService.LogInfo("MEF discovery error", error);
                }

                // throw new ApplicationException ("MEF discovery errors");
            }

            CompositionConfiguration configuration = CompositionConfiguration.Create(catalog);

            if (!configuration.CompositionErrors.IsEmpty)
            {
                // capture the errors in an array for easier debugging
                var errors = configuration.CompositionErrors.SelectMany(e => e).ToArray();
                foreach (var error in errors)
                {
                    LoggingService.LogInfo("MEF composition error: " + error.Message);
                }

                // For now while we're still transitioning to VSMEF it's useful to work
                // even if the composition has some errors. TODO: re-enable this.
                //configuration.ThrowOnErrors ();
            }

            RuntimeComposition    = RuntimeComposition.CreateRuntimeComposition(configuration);
            ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory();
            ExportProvider        = ExportProviderFactory.CreateExportProvider();
            HostServices          = MefV1HostServices.Create(ExportProvider.AsExportProvider());
            ExportProviderV1      = NetFxAdapters.AsExportProvider(ExportProvider);
        }
コード例 #2
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);
        }
コード例 #3
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;
            }
        }