internal InteractiveWindowTestHost()
        {
            _exportProvider = new CompositionContainer(
                s_lazyCatalog.Value,
                CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);

            var contentTypeRegistryService = _exportProvider.GetExport<IContentTypeRegistryService>().Value;
            Evaluator = new TestInteractiveEvaluator();
            Window = _exportProvider.GetExport<IInteractiveWindowFactoryService>().Value.CreateWindow(Evaluator);
            Window.InitializeAsync().Wait();
        }
        internal InteractiveWindowTestHost(Action<InteractiveWindow.State> stateChangedHandler = null)
        {
            ExportProvider = new CompositionContainer(
                s_lazyCatalog.Value,
                CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);

            var contentTypeRegistryService = ExportProvider.GetExport<IContentTypeRegistryService>().Value;
            Evaluator = new TestInteractiveEngine(contentTypeRegistryService);
            Window = ExportProvider.GetExport<IInteractiveWindowFactoryService>().Value.CreateWindow(Evaluator);
            ((InteractiveWindow)Window).StateChanged += stateChangedHandler;
            Window.InitializeAsync().Wait();
        }
Exemplo n.º 3
0
        public MainWindow() {
            InitializeComponent();

            EnvironmentsToolWindow.ViewCreated += EnvironmentsToolWindow_ViewCreated;

            _container = new CompositionContainer(new AggregateCatalog(
                new AssemblyCatalog(typeof(IInterpreterRegistryService).Assembly),
                new AssemblyCatalog(typeof(IInterpreterOptionsService).Assembly)
            ));

            EnvironmentsToolWindow.Interpreters = _container.GetExport<IInterpreterRegistryService>().Value;
            EnvironmentsToolWindow.Service = _container.GetExport<IInterpreterOptionsService>().Value;
        }
Exemplo n.º 4
0
        internal InteractiveWindowTestHost(Action<InteractiveWindow.State> stateChangedHandler = null)
        {
            SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());

            _exportProvider = new CompositionContainer(
                _lazyCatalog.Value,
                CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);

            var contentTypeRegistryService = _exportProvider.GetExport<IContentTypeRegistryService>().Value;
            _window = _exportProvider.GetExport<IInteractiveWindowFactoryService>().Value.CreateWindow(new TestInteractiveEngine(contentTypeRegistryService));
            ((InteractiveWindow)_window).StateChanged += stateChangedHandler;
            _window.InitializeAsync().PumpingWait();
        }
Exemplo n.º 5
0
        public InteractiveWindowTestHost()
        {
            SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext());

            var types = new[] { typeof(TestInteractiveEngine), typeof(InteractiveWindow) }.Concat(GetVisualStudioTypes());
            _exportProvider = new CompositionContainer(
                new AggregateCatalog(types.Select(t => new AssemblyCatalog(t.Assembly))),
                CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);

            var contentTypeRegistryService = _exportProvider.GetExport<IContentTypeRegistryService>().Value;
            _window = _exportProvider.GetExport<IInteractiveWindowFactoryService>().Value.CreateWindow(new TestInteractiveEngine(contentTypeRegistryService));

            _window.InitializeAsync().PumpingWait();
        }
Exemplo n.º 6
0
        public void Start()
        {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(SearchDemo).Assembly));
            var container = new CompositionContainer(catalog);
            container.ComposeParts();

            try
            {
                var component = container.GetExport<ITestComponent>();
                if (component != null)
                    Console.WriteLine(component.Value.Message);
            }
            catch (Exception exp)
            {
                //Why does our call to 'GetExport' throw an exception?

                //Search for the string "Test" on the container variable
                //You'll find 3 instances in the Catalog.
                //Then search for ITestComponent.
                //You'll need to click "Search Deeper" to expand the search.

                //Another way to do this is to view "container.Catalog.Parts", right click it,
                //select 'Edit Filter' and enter the following predicate:
                //         [obj].Exports(typoef(ITestComponent)

                MessageBox.Show(exp.Message, "Exception caught!");
            }
        }
Exemplo n.º 7
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            catalog.Catalogs.Add(new DirectoryCatalog("."));

            var container = new CompositionContainer(catalog);

            try
            {
                container.ComposeParts(this);
                container.ComposeExportedValue("container", container);

                Lazy<IModuleController> controller = container.GetExport<IModuleController>();
                if (controller == null) return;

                controller.Value.CompositionContainer = container;
                controller.Value.Run();
            }
            catch (CompositionException exception)
            {
                MessageBox.Show(exception.ToString());
            }
        }
Exemplo n.º 8
0
		static void Main()
		{
            var engine = new GUILayer.EngineDevice();
            GC.KeepAlive(engine);

            var catalog = new TypeCatalog(
                typeof(ShaderPatcherLayer.Manager),
                typeof(ShaderFragmentArchive.Archive),
                typeof(NodeEditorCore.ShaderFragmentArchiveModel),
                typeof(NodeEditorCore.ModelConversion),
                typeof(NodeEditorCore.ShaderFragmentNodeCreator),
                typeof(NodeEditorCore.DiagramDocument),
                typeof(ExampleForm)
            );

            using (var container = new CompositionContainer(catalog))
            {
                container.ComposeExportedValue<ExportProvider>(container);
                container.ComposeExportedValue<CompositionContainer>(container);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(container.GetExport<ExampleForm>().Value);
            }

            engine.Dispose();
		}
        public static ServerEntry LoadServer(string path)
        {
            try
            {
                //  Create a server entry for the server.
                var serverEntry = new ServerEntry();

                //  Set the data.
                serverEntry.ServerName = Path.GetFileNameWithoutExtension(path);
                serverEntry.ServerPath = path;

                //  Create an assembly catalog for the assembly and a container from it.
                var catalog = new AssemblyCatalog(Path.GetFullPath(path));
                var container = new CompositionContainer(catalog);

                //  Get the exported server.
                var server = container.GetExport<ISharpShellServer>().Value;

                serverEntry.ServerType = server.ServerType;
                serverEntry.ClassId = server.GetType().GUID;
                serverEntry.Server = server;

                return serverEntry;
            }
            catch (Exception)
            {
                //  It's almost certainly not a COM server.
                MessageBox.Show("The file '" + Path.GetFileName(path) + "' is not a SharpShell Server.", "Warning");
                return null;
            }
        }
Exemplo n.º 10
0
        public void GetValuesByType()
        {
            var cat = CatalogFactory.CreateDefaultAttributed();

            var container = new CompositionContainer(cat);

            string itestName = AttributedModelServices.GetContractName(typeof(ITest));

            var e1 = container.GetExportedValues<ITest>();
            var e2 = container.GetExports<ITest, object>(itestName);

            Assert.IsInstanceOfType(e1.First(), typeof(T1), "First should be T1");
            Assert.IsInstanceOfType(e1.Skip(1).First(), typeof(T2), "Second should be T2");

            Assert.IsInstanceOfType(e2.First().Value, typeof(T1), "First should be T1");
            Assert.IsInstanceOfType(e2.Skip(1).First().Value, typeof(T2), "Second should be T2");

            CompositionContainer childContainer = new CompositionContainer(container);
            CompositionBatch batch = new CompositionBatch();
            batch.AddPart(new T1());
            container.Compose(batch);
            var t1 = childContainer.GetExportedValue<ITest>();
            var t2 = childContainer.GetExport<ITest, object>(itestName);

            Assert.IsInstanceOfType(t1, typeof(T1), "First (resolved) should be T1");
            Assert.IsInstanceOfType(t2.Value, typeof(T1), "First (resolved) should be T1");
        }
Exemplo n.º 11
0
        public void CanMakeSweetShopWithVanillaJellybeans()
        {
            TypeCatalog catalog = new TypeCatalog(typeof(VanillaJellybeanDispenser), typeof(SweetVendingMachine), typeof(SweetShop));
            CompositionContainer container = new CompositionContainer(catalog);

            SweetShop sweetShop = container.GetExport<SweetShop>().Value;

            Assert.AreEqual(Jellybean.Vanilla, sweetShop.DispenseJellyBean());
        }
Exemplo n.º 12
0
        public void CanMakeAniseedRootObject()
        {
            TypeCatalog catalog = new TypeCatalog(typeof(AniseedSweetShop));
            CompositionContainer container = new CompositionContainer(catalog);

            SweetShop sweetShop = container.GetExport<SweetShop>().Value;

            Assert.AreEqual(Jellybean.Aniseed, sweetShop.DispenseJellyBean());
        }
Exemplo n.º 13
0
 public void ClassExportsITemplateEditorOptionsForConsumptionByEditorClasses()
 {
     using (var catalog = new TypeCatalog(typeof(T4ToolboxOptions)))
     using (var container = new CompositionContainer(catalog))
     {
         Lazy<ITemplateEditorOptions> export = container.GetExport<ITemplateEditorOptions>();
         Assert.IsInstanceOfType(export.Value, typeof(T4ToolboxOptions));
     }
 }
        public void SimpleExport_part_with_metadata_is_properly_exported()
        {
            var registry = new ConfigurationPartRegistry("mef.configuration");
            var catalog = new ConventionCatalog(registry);
            var container = new CompositionContainer(catalog);

            var simpleExport = container.GetExport<SimpleExportWithMetadata, ISimpleMetadata>("simple-export");
            Assert.That(simpleExport, Is.Not.Null);
            Assert.That(simpleExport.Metadata.IntValue, Is.EqualTo(1234));
            Assert.That(simpleExport.Metadata.StrValue, Is.EqualTo("some string"));
        }
Exemplo n.º 15
0
        public void ContainerCanGetExportForSauceBéarnaise()
        {
            var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Concrete.SauceBéarnaise));
            var container = new CompositionContainer(catalog);

            Lazy<SauceBéarnaise> export =
                container.GetExport<SauceBéarnaise>();
            SauceBéarnaise sauce = export.Value;

            Assert.NotNull(sauce);
        }
 public static void TemplateQuickInfoSourceProviderCanBeConstructedByVisualStudio()
 {
     using (var catalog = new TypeCatalog(
         typeof(TemplateQuickInfoSourceProvider),
         typeof(SubstituteExporter<ITemplateEditorOptions>)))
     using (var container = new CompositionContainer(catalog))
     {
         Lazy<IQuickInfoSourceProvider> export = container.GetExport<IQuickInfoSourceProvider>();
         Assert.IsType<TemplateQuickInfoSourceProvider>(export.Value);
     }
 }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(ISqlHelper).Assembly));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));

            var container = new CompositionContainer(catalog);
            var sqlHelper = container.GetExport<ISqlHelper>("SqlServer").Value;

            Console.WriteLine(sqlHelper.ConnectionString);
            Console.Read();
        }
 public static void TemplateClassificationTaggerProviderCanBeConstructedByVisualStudio()
 {
     using (var catalog = new TypeCatalog(
         typeof(TemplateClassificationTaggerProvider),
         typeof(SubstituteExporter<ITemplateEditorOptions>),
         typeof(SubstituteExporter<IClassificationTypeRegistryService>)))
     using (var container = new CompositionContainer(catalog))
     {
         Lazy<ITaggerProvider> export = container.GetExport<ITaggerProvider>();
         Assert.IsType<TemplateClassificationTaggerProvider>(export.Value);
     }
 }
Exemplo n.º 19
0
        protected void Application_Start(object sender, EventArgs e)
        {
            EngineLogger4j.Config();

            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(Engine).Assembly));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));

            container = new CompositionContainer(catalog);

            var engine = container.GetExport<Engine>().Value;
            engine.Setup(container, new string[] { "Demo" });
        }
Exemplo n.º 20
0
        protected override void OnStartup(StartupEventArgs e)
        {
            RegisterLoadedHandler();
            base.OnStartup(e);

            // bootstrap MEF composition
            var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            Container = new CompositionContainer(catalog);

            // retrieve the MefContentLoader export and assign to global resources (so {DynamicResource MefContentLoader} can be resolved)
            var contentLoader = Container.GetExport<MefContentLoader>().Value;
            Resources.Add("MefContentLoader", contentLoader);

            // same for MefLinkNavigator
            var navigator = Container.GetExport<MefLinkNavigator>().Value;
            Resources.Add("MefLinkNavigator", navigator);

            _viewModelLoader = Container.GetExport<MefViewModelLoader>().Value;

            DebuggerSession.Instance.OnDetach += OnDetach;
            AppearanceManager.Current.AccentColor = Color.FromRgb(0xf0, 0x96, 0x09);
        }
 public static void ClassCanBeConstructedByVisualStudio()
 {
     using (var catalog = new TypeCatalog(
         typeof(TemplateErrorReporterProvider),
         typeof(SubstituteExporter<ITemplateEditorOptions>),
         typeof(SubstituteExporter<SVsServiceProvider>),
         typeof(SubstituteExporter<ITextDocumentFactoryService>)))
     using (var container = new CompositionContainer(catalog))
     {
         Lazy<ITaggerProvider> export = container.GetExport<ITaggerProvider>();
         Assert.IsType<TemplateErrorReporterProvider>(export.Value);
     }
 }
 public static void ClassCanBeConstructedByVisualStudio()
 {
     using (var catalog = new TypeCatalog(
         typeof(TemplateCompletionHandlerProvider),
         typeof(SubstituteExporter<ITemplateEditorOptions>),
         typeof(SubstituteExporter<IVsEditorAdaptersFactoryService>),
         typeof(SubstituteExporter<SVsServiceProvider>),
         typeof(SubstituteExporter<ICompletionBroker>)))
     using (var container = new CompositionContainer(catalog))
     {
         Lazy<IVsTextViewCreationListener> export = container.GetExport<IVsTextViewCreationListener>();
         Assert.IsType<TemplateCompletionHandlerProvider>(export.Value);
     }
 }
Exemplo n.º 23
0
        public HiClockMainController(CompositionContainer aContainer, Lazy<HiClockMainViewModel> aHiClockMainViewModel, SleepService aSleepSvr, Lazy<IShellService> aShellService)
        {
            FContainer = aContainer;
            FHiClockMainViewModel = aHiClockMainViewModel;            
            FShellService = aShellService;
            aSleepSvr.SleepAction = new Action(ShowSleepScreen);
            FAboutViewModel = FContainer.GetExport<AboutViewModel>();

            FCloseSleepCommand = new DelegateCommand(StopSleep);
            FExitSettingCommand = new DelegateCommand(ExitSetting);
            FSetAutoStartCommand = new DelegateCommand(SetAutoStart);

            FAlarmTimer = new DispatcherTimer();
            FAlarmTimer.Tick += FAlarmTimer_Tick;
            FSleepDurationTimer = new DispatcherTimer();
            FSleepDurationTimer.Tick += FSleepDurationTimer_Tick;
        }
        public void SimpleContract_part_with_metadata_is_properly_imported()
        {
            var registry = new ConfigurationPartRegistry("mef.configuration");
            var catalog = new ConventionCatalog(registry);
            var container = new CompositionContainer(catalog);

            var simpleExport = container.GetExport<SimpleContractImporter>();
            Assert.That(simpleExport, Is.Not.Null);
            Assert.That(simpleExport.Value.SimpleContracts, Is.Not.Null);
            Assert.That(simpleExport.Value.SimpleContracts.Length, Is.EqualTo(1));
            Assert.That(simpleExport.Value.SimpleContracts[0].Metadata.IntValue, Is.EqualTo(1234));
            Assert.That(simpleExport.Value.SimpleContracts[0].Metadata.StrValue, Is.EqualTo("some string"));

            Assert.That(simpleExport.Value.SimpleContractsNoMetadataInterface, Is.Not.Null);
            Assert.That(simpleExport.Value.SimpleContractsNoMetadataInterface.Length, Is.EqualTo(1));
            Assert.That(simpleExport.Value.SimpleContractsNoMetadataInterface[0].GetType(), Is.EqualTo(typeof(SimpleContract1)));
        }
        public void MefCanResolveLazyTypeRegisteredInUnityTest()
        {
            // Setup
            var unityContainer = new UnityContainer();
            var adapter = new UnityContainerAdapter(unityContainer);
            var provider = new ContainerExportProvider(adapter);
            var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            var container = new CompositionContainer(assemblyCatalog, provider);

            UnityOnlyComponent1.InstanceCount = 0;
            unityContainer.RegisterType<IUnityOnlyComponent, UnityOnlyComponent1>();

            var lazyUnityComponent = container.GetExport<IUnityOnlyComponent>();
            Assert.That(lazyUnityComponent, Is.Not.Null);
            Assert.That(UnityOnlyComponent1.InstanceCount, Is.EqualTo(0));

            Assert.That(lazyUnityComponent.Value, Is.Not.Null);
            Assert.That(lazyUnityComponent.Value.GetType(), Is.EqualTo(typeof(UnityOnlyComponent1)));
            Assert.That(UnityOnlyComponent1.InstanceCount, Is.EqualTo(1));
        }
        public void MefCanResolveLazyTypeRegisteredInAutofacTest()
        {
            // Setup
            var builder = new ContainerBuilder();
            builder.RegisterType<AutofacOnlyComponent1>().As<IAutofacOnlyComponent>();
            var autofacContainer = builder.Build();
            var adapter = new AutofacContainerAdapter(autofacContainer);
            var provider = new ContainerExportProvider(adapter);
            var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            var container = new CompositionContainer(assemblyCatalog, provider);

            AutofacOnlyComponent1.InstanceCount = 0;

            var lazyAutofacComponent = container.GetExport<IAutofacOnlyComponent>();
            Assert.That(lazyAutofacComponent, Is.Not.Null);
            Assert.That(AutofacOnlyComponent1.InstanceCount, Is.EqualTo(0));

            Assert.That(lazyAutofacComponent.Value, Is.Not.Null);
            Assert.That(lazyAutofacComponent.Value.GetType(), Is.EqualTo(typeof(AutofacOnlyComponent1)));
            Assert.That(AutofacOnlyComponent1.InstanceCount, Is.EqualTo(1));
        }
        public void ComposeWithTwoContainerExportProvidersTest()
        {
            var unityContainer1 = new UnityContainer();
            var exportProvider1 = new ContainerExportProvider(new UnityContainerAdapter(unityContainer1));

            var a = new A();
            unityContainer1.RegisterInstance<A>(a);

            var unityContainer2 = new UnityContainer();
            var exportProvider2 = new ContainerExportProvider(new UnityContainerAdapter(unityContainer2));

            var b = new B();
            unityContainer2.RegisterInstance<B>(b);

            var catalog = new TypeCatalog(typeof(C));
            var compositionContainer = new CompositionContainer(catalog, exportProvider1, exportProvider2);
            var instance = compositionContainer.GetExport<C>();
            Assert.IsNotNull(instance.Value);
            Assert.AreEqual(a, instance.Value.ThingA, "Instance of A is the same as that registered with the DI container.");
            Assert.AreEqual(b, instance.Value.ThingB, "Instance of B is the same as that registered with the DI container.");
        }
Exemplo n.º 28
0
        public IRazorHost CreateHost(string fullPath, string projectRelativePath, CodeDomProvider codeDomProvider)
        {
            var directives = DirectivesParser.ParseDirectives(_baseDirectory, fullPath);

            string hostName;
            RazorRuntime runtime = _defaultRuntime;
            if (!directives.TryGetValue("Generator", out hostName))
            {
                // Determine the host and runtime from the file \ project
                hostName = GuessHost(_baseDirectory, projectRelativePath, out runtime);
            }
            string razorVersion;
            if (directives.TryGetValue("RazorVersion", out razorVersion))
            {
                // If the directive explicitly specifies a host, use that.
                switch (razorVersion)
                {
                    case "1":
                        runtime = RazorRuntime.Version1;
                        break;
                    case "2":
                        runtime = RazorRuntime.Version2;
                        break;
                    default:
                        runtime = RazorRuntime.Version3;
                        break;
                }
            }

            if (_catalog == null)
            {
                _catalog = InitCompositionCatalog(_baseDirectory, _loadExtensions, runtime);
            }

            using (var container = new CompositionContainer(_catalog))
            {
                var codeTransformer = GetRazorCodeTransformer(container, projectRelativePath, hostName);
                var host = container.GetExport<IHostProvider>().Value;
                return host.GetRazorHost(projectRelativePath, fullPath, codeTransformer, codeDomProvider, directives);
            }
        }
Exemplo n.º 29
0
        public void ReleaseParsleyAsTransientDisposesParsley()
        {
            var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Lifetime.NonShared.Parsley));
            var container = new CompositionContainer(catalog);

            var x = container.GetExport<IIngredient>();
            var ingredient = x.Value;

            container.ReleaseExport(x);

            var parsley = Assert.IsAssignableFrom<Parsley>(ingredient);
            Assert.True(parsley.IsDisposed);
        }
Exemplo n.º 30
0
        public void GetExportThrowsOnMultipleExports()
        {
            var catalog = new TypeCatalog(typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Abstract.SauceBéarnaise),
                typeof(Ploeh.Samples.Menu.Mef.Attributed.Unmodified.Abstract.Steak));
            var container = new CompositionContainer(catalog);

            Assert.Throws<ImportCardinalityMismatchException>(() =>
                container.GetExport<IIngredient>());
        }