示例#1
0
 /// <summary>
 /// Import and update trails.
 /// </summary>
 /// <returns>Task for asyncrhonous completion.</returns>
 public async Task Get()
 {
     using (ApplicationCatalog catalog = new ApplicationCatalog())
     using (CompositionContainer container = new CompositionContainer(catalog))
     {
         ITrailsImporter importer = container.GetExportedValue<ITrailsImporter>();
         await importer.Run();
     }
 }
示例#2
0
文件: UseMef.cs 项目: binki/UseMef
    public static int Main(string[] args)
    {
        using (var catalog = new ApplicationCatalog())
	{
	    using (var container = new CompositionContainer(catalog))
	    {
	        return container.GetExportedValue<UseMef>().Run(args);
	    }
	}
    }
示例#3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            //# Initialize MEF
            var applicationCatalog = new ApplicationCatalog();
            var compositionContainer = new CompositionContainer(applicationCatalog);
            compositionContainer.Compose(new CompositionBatch());

            //# Import Xaml Resources
            ResourcesManager.ImportAndMergeAllResources(compositionContainer);
        }
示例#4
0
        /// <summary>
        /// Creates a <see cref="CompositionContainer"/> with an <see cref="ApplicationCatalog"/> a
        /// <see cref="ConfigurationExportProvider"/>. The 
        /// <see cref="ConfigurationExportProvider"/> is reads from the application's config file,
        /// either an App.Config or Web.Config file.
        /// </summary>
        /// <param name="additionalProviders"></param>
        /// <returns></returns>
        public static CompositionContainer CreateApplicationAndConfigFileContainer(params ExportProvider[] additionalProviders)
        {
            var applicationCatalog = new ApplicationCatalog();
            var configExportProvider = new ConfigurationExportProvider(new FileConfigurationSource());

            var exportProviders = new ExportProvider[1 + additionalProviders.Length];
            exportProviders[0] = configExportProvider;
            Array.Copy(additionalProviders, 0, exportProviders, 1, additionalProviders.Length);

            var result = new CompositionContainer(applicationCatalog, configExportProvider);
            return result;
        }
示例#5
0
        private void LoadPlugins()
        {
            _pluginsdirectoryCatalog = new DirectoryCatalog(_pluginsDirectory);
            var adapterdirectoryCatalog = new DirectoryCatalog(_adaptersDirectory);
            var applicationCatalog = new ApplicationCatalog();
            var catalog = new AggregateCatalog(applicationCatalog, _pluginsdirectoryCatalog, adapterdirectoryCatalog);

            var container = new CompositionContainer(catalog);
            container.ComposeExportedValue<IRobot>(_robot);
            container.ComposeParts(_robot);

            ShowLoadedPlugins(applicationCatalog, "Loaded the following Nubot plugins");
            ShowLoadedPlugins(_pluginsdirectoryCatalog, "Loaded the following plugins");
            ShowLoadedPlugins(adapterdirectoryCatalog, "Loaded the following adapter");
        }
示例#6
0
        private ComposablePartCatalog GetInterceptionCatalog()
        {
            _applicationCatalog = new ApplicationCatalog();
            _adapterdirectoryCatalog = new DirectoryCatalog(AdaptersDirectory);
            _pluginsdirectoryCatalog = new DirectoryCatalog(PluginsDirectory);

            var catalog = new AggregateCatalog(_applicationCatalog, _adapterdirectoryCatalog, _pluginsdirectoryCatalog);

            var cfg = new InterceptionConfiguration().AddInterceptionCriteria(
                            new PredicateInterceptionCriteria(
                                new CopyConfigInterceptor(_robot.Settings),
                                def => def.ExportDefinitions.First().ContractName.Contains("IAdapter") ||
                                       def.ExportDefinitions.First().ContractName.Contains("IRobotPlugin")));

            return new InterceptingCatalog(catalog, cfg);
        }
示例#7
0
        public ExtensionManager(string pluginFolder)
        {
            var directoryCatalog = new DirectoryCatalog(pluginFolder);
            var domainCatalog = new ApplicationCatalog();
            var aggregateCatalog = new AggregateCatalog(directoryCatalog, domainCatalog);
            _container = new CompositionContainer(aggregateCatalog);

            try
            {
                _container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }
        }
示例#8
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            //# Initialize MEF
            var applicationCatalog = new ApplicationCatalog();
            var compositionContainer = new CompositionContainer(applicationCatalog);
            compositionContainer.Compose(new CompositionBatch());

            //# Import Xaml Resources
            ResourcesManager.ImportAndLoadAllResources(compositionContainer);

            //# Alternative way to load default SquaredInfinity.Presentation.Foundation resources (without MEF)
            // var resources = new SquaredInfinity.Foundation.Presentation.XamlResources();
            // resources.LoadAndMergeResources();

            var modern_style_resources = new SquaredInfinity.Foundation.Presentation.Styles.Modern.DefaultXamlResources();
            modern_style_resources.LoadAndMergeResources();
            modern_style_resources.ApplyAllStyles();
        }
		public void ApplicationCatalog(Type contractType, bool expectedIsDisposableNormal, bool expectedIsDisposableWrapped)
		{
			// ApplicationCatalog is a good comprehensive test because it uses the following hierarchy:
			// + AggregateCatalog
			//   + DirectoryCatalog
			//     + AssemblyCatalog
			//       + TypeCatalog

			using (var innerCatalog = new ApplicationCatalog())
			using (var wrapperCatalog = new DisposableWrapperCatalog(innerCatalog, false))
			{
				const ImportCardinality cardinality = ImportCardinality.ExactlyOne;
				var metadata = new Dictionary<string, object>();
				var typeIdentity = AttributedModelServices.GetTypeIdentity(contractType);
				var contractName = AttributedModelServices.GetContractName(contractType);
				var definition = new ContractBasedImportDefinition(contractName, typeIdentity, null, cardinality, false, true, CreationPolicy.Any, metadata);

				var partNormal = innerCatalog.GetExports(definition).Single().Item1.CreatePart();
				var partWrapped = wrapperCatalog.GetExports(definition).Single().Item1.CreatePart();

				var isDisposableNormal = partNormal is IDisposable;
				var isDisposableWrapped = partWrapped is IDisposable;

				Assert.AreEqual(expectedIsDisposableNormal, isDisposableNormal, "Checking Normal Part");
				Assert.AreEqual(expectedIsDisposableWrapped, isDisposableWrapped, "Checking Wrapped Part");
			}
		}