当前位置: 首页>>代码示例>>C#>>正文


C# Hosting.DirectoryCatalog类代码示例

本文整理汇总了C#中System.ComponentModel.Composition.Hosting.DirectoryCatalog的典型用法代码示例。如果您正苦于以下问题:C# DirectoryCatalog类的具体用法?C# DirectoryCatalog怎么用?C# DirectoryCatalog使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DirectoryCatalog类属于System.ComponentModel.Composition.Hosting命名空间,在下文中一共展示了DirectoryCatalog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MainApplication

        public MainApplication(string pluginFolder)
        {
            var catalog = new DirectoryCatalog(pluginFolder);
            _container = new CompositionContainer(catalog);

            LoadPlugins();
        }
开发者ID:volkanx,项目名称:ip-checker-with-mef,代码行数:7,代码来源:MainApplication.cs

示例2: DoImport

        public void DoImport()
        {
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();

            directoryCatalog = new DirectoryCatalog(GetDirectory());
            directoryCatalog.Changing += directoryCatalog_Changing;
            directoryCatalog.Changed += directoryCatalog_Changed;

            //Adds all the parts found in all assemblies in 
            //the same directory as the executing program
            catalog.Catalogs.Add(directoryCatalog);

            //Create the CompositionContainer with the parts in the catalog
            var container = new CompositionContainer(catalog);

            try
            {
                //Fill the imports of this object
                container.ComposeParts(this);
            }
            catch (Exception ex)
            {
                Out.WriteLine("Unable to load plugins: {0}", ex.Message);
            }

        }
开发者ID:Olezhka,项目名称:Hipbot,代码行数:27,代码来源:Program.cs

示例3: ComposeConnectionFactory

		private static void ComposeConnectionFactory()
		{
			try
			{
				using (var catalog = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory))
				using (var container = new CompositionContainer(catalog))
				{
					var export = container.GetExportedValueOrDefault<IConnectionFactory>();
					if (export != null)
					{
						Factory = export;
						Console.WriteLine("Using {0}", Factory.GetType());
					}
				}
			}
			catch (ImportCardinalityMismatchException)
			{
				Console.WriteLine("More than one IConnectionFactory import was found.");
			}
			catch (Exception e)
			{
				Console.WriteLine(e);
			}

			if (Factory == null)
			{
				Factory = new DefaultConnectionFactory();
				Console.WriteLine("Using default connection factory...");
			}
		}
开发者ID:ZixiangBoy,项目名称:SignalR-1,代码行数:30,代码来源:Client.cs

示例4: InitializePlugins

    private void InitializePlugins()
    {
      // We look for plugins in our own assembly and in any DLLs that live next to our EXE.
      // We could force all plugins to be in a "Plugins" directory, but it seems more straightforward
      // to just leave everything in one directory
      var builtinPlugins = new AssemblyCatalog(GetType().Assembly);
      var externalPlugins = new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
      
      _catalog = new AggregateCatalog(builtinPlugins, externalPlugins);
      _container = new CompositionContainer(_catalog);

      try
      {
        _container.SatisfyImportsOnce(this);       
      }
      catch (CompositionException ex)
      {
        if (_log.IsErrorEnabled)
        {
          _log.ErrorFormat("MEF Composition Exception: {0}", ex.Message);

          var errors = String.Join("\n    ", ex.Errors.Select(x => x.Description));
          _log.ErrorFormat("Composition Errors: {0}", errors);
        }
        throw;
      }
    }
开发者ID:BookSwapSteve,项目名称:statsd.net,代码行数:27,代码来源:StatsdnetConfiguration.cs

示例5: ConfigureAggregateCatalog

        protected override void ConfigureAggregateCatalog()
        {
            base.ConfigureAggregateCatalog();

            string AssemblyDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            AssemblyDir += System.IO.Path.DirectorySeparatorChar + "Modules";

            //Load files in module directory and all sub directories

            IEnumerable<string> ModuleDirectories = System.IO.Directory.EnumerateDirectories(AssemblyDir, "*", SearchOption.TopDirectoryOnly);
            foreach (string dir in ModuleDirectories)
            {
                /*
                string[] files = System.IO.Directory.GetFiles(dir, "*.dll");
                foreach(string dll in files)
                {
                    System.Reflection.Assembly a = System.Reflection.Assembly.LoadFile(dll);
                    AssemblyCatalog assemblyCat = new AssemblyCatalog(a);
                    AggregateCatalog.Catalogs.Add(assemblyCat);
                }
                 */

                Trace.WriteLine("Adding aggregate catalog for " + dir);
                DirectoryCatalog dirCat = new DirectoryCatalog(dir);

                AggregateCatalog.Catalogs.Add(dirCat);
            }
        }
开发者ID:abordt,项目名称:Viking,代码行数:28,代码来源:BootStrapper.cs

示例6: Configure

        /// <summary>
        /// By default, we are configured to use MEF
        /// </summary>
        protected override void Configure()
        {
            // Add all assemblies to AssemblySource (using a temporary DirectoryCatalog).
            var directoryCatalog = new DirectoryCatalog(@"./");
            AssemblySource.Instance.AddRange(
                directoryCatalog.Parts
                    .Select(part => ReflectionModelServices.GetPartType(part).Value.Assembly)
                    .Where(assembly => !AssemblySource.Instance.Contains(assembly)));

            // Prioritise the executable assembly. This allows the client project to override exports, including IShell.
            // The client project can override SelectAssemblies to choose which assemblies are prioritised.
            var priorityAssemblies = SelectAssemblies().ToList();
            var priorityCatalog = new AggregateCatalog(priorityAssemblies.Select(x => new AssemblyCatalog(x)));
            var priorityProvider = new CatalogExportProvider(priorityCatalog);

            // Now get all other assemblies (excluding the priority assemblies).
            var mainCatalog = new AggregateCatalog(
                AssemblySource.Instance
                    .Where(assembly => !priorityAssemblies.Contains(assembly))
                    .Select(x => new AssemblyCatalog(x)));
            var mainProvider = new CatalogExportProvider(mainCatalog);

            Container = new CompositionContainer(priorityProvider, mainProvider);
            priorityProvider.SourceProvider = Container;
            mainProvider.SourceProvider = Container;

            var batch = new CompositionBatch();

            BindServices(batch);
            batch.AddExportedValue(mainCatalog);

            Container.Compose(batch);
        }
开发者ID:4ux-nbIx,项目名称:gemini,代码行数:36,代码来源:AppBootstrapper.cs

示例7: Compose

        public void Compose()
        {
            AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string generatorsPath = Path.Combine(executionPath, "Generators");
            CreatePathIfRequied(generatorsPath);
            generatorsCatalog = new DirectoryCatalog(generatorsPath);

            string uiPath = Path.Combine(executionPath, "UI");
            CreatePathIfRequied(uiPath);
            UICatalog = new DirectoryCatalog(uiPath);

            AggregateCatalog catalog = new AggregateCatalog();
            catalog.Catalogs.Add(generatorsCatalog);
            catalog.Catalogs.Add(UICatalog);

            //Set the defaults....
            CatalogExportProvider mainProvider = new CatalogExportProvider(assemblyCatalog);
            CompositionContainer container = new CompositionContainer(catalog, mainProvider);
            mainProvider.SourceProvider = container;

            var batch = new CompositionBatch();
            batch.AddPart(this);

            RefreshCatalog refreshCatalog = new RefreshCatalog(generatorsCatalog, UICatalog);
            container.ComposeParts(refreshCatalog);
            container.Compose(batch);

            Logger.Write("Compose complete");
        }
开发者ID:BenHall,项目名称:ExtendViaMEF,代码行数:32,代码来源:Extender.cs

示例8: MefControllerFactory

 public MefControllerFactory(string pluginPath)
 {
     this._pluginPath = pluginPath;
     this._catalog = new DirectoryCatalog(pluginPath);
     this._container = new CompositionContainer(_catalog);
     this._defaultControllerFactory = new DefaultControllerFactory();
 }
开发者ID:romanservices,项目名称:CodeSamples,代码行数:7,代码来源:MefControllerFactory.cs

示例9: MainWindow

        public MainWindow()
        {
            InitializeComponent();

            pathToGit = new FileInfo(@"C:\Program Files (x86)\Git\bin\git.exe");
            try
            {
                DirectoryCatalog catalog =
                    new DirectoryCatalog(new FileInfo(Assembly.GetAssembly(typeof (MainWindow)).Location).DirectoryName);
                CompositionContainer container = new CompositionContainer(catalog);
                container.ComposeParts(this);
            }
            catch (CompositionException)
            {
                sqlParser = null;
            }

            var vm = new MainWindowViewModel(Properties.Settings.Default.Databases);
            vm.SourceChangeset = (DvcsScriptRepositoryBase.RevisionIdentifierBase)Properties.Settings.Default.LastChangeset ?? Properties.Settings.Default.LastTag;
            if (vm.SourceChangeset != null)
            {
                vm.SelectedSourceType = RevisionIdentifierConverter.GetLabelFromType(vm.SourceChangeset.GetType());
            }

            var riConverter = (RevisionIdentifierConverter)Resources["riConverter"];
            riConverter.DataContext = vm;
            DataContext = vm;
        }
开发者ID:Zocdoc,项目名称:ZocBuild.Database,代码行数:28,代码来源:MainWindow.xaml.cs

示例10: DiscoverServices

        public void DiscoverServices(IServicePool pool)
        {
            var registration = new RegistrationBuilder();

            registration.ForTypesDerivedFrom<IService>().SelectConstructor((ConstructorInfo[] cInfo) =>
            {
                if (cInfo.Length == 0)
                    return null;
                return cInfo[0];
            }).Export<IService>();

            var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
            var catalog = new DirectoryCatalog(path, registration);
            var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);
            var services = container.GetExportedValues<IService>();

            foreach (var service in services)
            {
                service.ServicePool = pool;
                var interfaces = service.GetType().GetInterfaces();
                Type interfaceType = null;
                foreach (var i in interfaces)
                {
                    var name = i.FullName;
                    if (!name.Contains("Contracts.IService") && !name.Contains("System."))
                    {
                        interfaceType = i;
                        break;
                    }
                }
                pool.AddService(interfaceType, service);
            }
        }
开发者ID:nagyistoce,项目名称:ArchitectureCampSample,代码行数:33,代码来源:ServiceDiscoveryService.cs

示例11: DemoProgram

        private static void DemoProgram(string serializedGraph = "AB5, BC4, CD8, DC8, DE6, AD5, CE2, EB3, AE7")
        {
            IRequestManager reqMan;
            // Production code would usually load the directory from config
            var catalog = new DirectoryCatalog(@"..\..\..\Plugins");
            var container = new CompositionContainer(catalog);
            reqMan = container.GetExportedValue<IRequestManager>();

            reqMan.LoadGraph(serializedGraph);

            //Questions 1 to 5
            string routes = "ABC,AD,ADC,AEBCD,AED";
            var number = 0;
            var answer = "";
            routes.Split(',').ToList().ForEach(r =>
            {
                number += 1;
                Console.WriteLine(reqMan.DistanceRequest(r, number));
            });

            //Question 6
            Console.WriteLine(reqMan.NumberofTripsMaxStops('C', 'C', 3, 6));

            //Question 7
            Console.WriteLine(reqMan.NumberofTripsExactStops('A', 'C', 4, 7));

            //Question 8
            Console.WriteLine(reqMan.ShortestRoute('A', 'C', 8));

            //Question 9
            Console.WriteLine(reqMan.ShortestRoute('B', 'B', 9));

            //Question 10
            Console.WriteLine(reqMan.NumberOfTripsMaxDistance('C', 'C', 30, 10));
        }
开发者ID:1coguH,项目名称:TW,代码行数:35,代码来源:Program.cs

示例12: MainViewModel

        public MainViewModel()
        {
            // Initialize MEF
            var catalog = new DirectoryCatalog("Tricks");
            _container = new CompositionContainer(catalog);

            _container.ComposeParts(this);

            var tricks = new List<TrickViewModel>();

            foreach (var trick in _tricks)
            {
                var Trick = new TrickViewModel
                {
                    Name = trick.Metadata.Name,
                    Description = trick.Metadata.Description
                };

                tricks.Add(Trick);
            }

            Tabs = new ObservableCollection<TabItem>
            {
                new TabItem
                {
                    Header = "All Tricks",
                    IsSelected = true,
                    Content = new TricksTab(tricks)
                }
            };

            Messenger.Default.Register<LoadMessage>(this, (m) => OnLoadTab(m.Trick));
        }
开发者ID:gotdibbs,项目名称:magician,代码行数:33,代码来源:MainViewModel.cs

示例13: ComposeParts

        public static void ComposeParts(params object[] attributedParts)
        {
            try
            {

                AssemblyCatalog catalog = new AssemblyCatalog(typeof(PluginLocator).Assembly);

                AggregateCatalog catalogs = new AggregateCatalog(catalog);
                var pluginDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins");
                if (Directory.Exists(pluginDirectory))
                {
                    DirectoryCatalog dirCatalog = new DirectoryCatalog(pluginDirectory);
                    catalogs.Catalogs.Add(dirCatalog);
                }

                //pluginDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
                //if (Directory.Exists(pluginDirectory))
                //{
                //    DirectoryCatalog dirCatalog = new DirectoryCatalog(pluginDirectory);
                //    catalogs.Catalogs.Add(dirCatalog);
                //}

                CompositionContainer container = new CompositionContainer(catalogs);

                container.ComposeParts(attributedParts);

            }
            catch (Exception)
            {
                System.Diagnostics.Debugger.Break();
                throw;
            }
        }
开发者ID:ishwormali,项目名称:practices,代码行数:33,代码来源:PluginLocator.cs

示例14: ModuleService

 public ModuleService()
 {
     var path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     var catalog = new DirectoryCatalog(path);
     _container = new CompositionContainer(catalog);
     _container.SatisfyImportsOnce(this);
 }
开发者ID:ChristianWeyer,项目名称:ArchitectureCampLive,代码行数:7,代码来源:ModuleService.cs

示例15: Initialize

        public void Initialize()
        {
            try
            {
                directoryCatalog = new DirectoryCatalog(PluginPath);

                var catalog = new AggregateCatalog();
                catalog.Catalogs.Add(directoryCatalog);
                container = new CompositionContainer(catalog);
                container.ComposeParts(this);
            }
            catch (ReflectionTypeLoadException ex)
            {
                if (ex.LoaderExceptions.Length == 1)
                {
                    throw ex.LoaderExceptions[0];
                }
                var sb = new StringBuilder();
                var i = 1;
                sb.AppendLine("Multiple Exception Occured Attempting to Intialize the Plugin Manager");
                foreach (var exception in ex.LoaderExceptions)
                {
                    sb.AppendLine("Exception " + i++);
                    sb.AppendLine(exception.ToString());
                    sb.AppendLine();
                    sb.AppendLine();
                }

                throw new ReflectionTypeLoadException(ex.Types, ex.LoaderExceptions, sb.ToString());
            }
        }
开发者ID:gfritz,项目名称:XrmToolBox,代码行数:31,代码来源:PluginManagerExtended.cs


注:本文中的System.ComponentModel.Composition.Hosting.DirectoryCatalog类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。