• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Hosting.DirectoryCatalog类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Main

        static void Main(string[] args)
        {
            try
            {
                var parameters = GetParameters(args);
                var core = new Core(parameters);

                var extrasFolderCatalog = new DirectoryCatalog(@".\extras\");
                var currentAssemblyCatalog = new AssemblyCatalog(typeof(Program).Assembly);
                var aggregateCatalog = new AggregateCatalog(extrasFolderCatalog, currentAssemblyCatalog);

                var container = new CompositionContainer(aggregateCatalog);
                container.ComposeParts(core);

                core.Run();

                Console.WriteLine("Static site created successfully");

                if (Debugger.IsAttached)
                    Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());

                if (Debugger.IsAttached)
                    Console.ReadLine();

                Environment.ExitCode = 1;
            }
        }
开发者ID:huoxudong125,项目名称:graze,代码行数:31,代码来源:Program.cs


示例17: CreateContainer

        /// <summary>
        /// Creates a <see cref="CompositionContainer"/>.
        /// </summary>
        /// <returns>A <see cref="CompositionContainer"/>.</returns>
        public CompositionContainer CreateContainer()
        {
            string path = HostingEnvironment.MapPath("~/bin");
            var catalog = new DirectoryCatalog(path);

            return new CompositionContainer(catalog);
        }
开发者ID:blagojcej,项目名称:JBSolutions,代码行数:11,代码来源:DefaultCompositionContainerFactory.cs


示例18: AddSources

        private void AddSources()
        {
            var p = Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), "bin");
            var catalog = new DirectoryCatalog(p, "*.dll");

            var container = new CompositionContainer(catalog);
            container.ComposeParts(this);
            if (null != this._eventSource)
                this.Application.Add("EventSource", this._eventSource);
            if(null != this._picSource)
            {
                if(this._picSource.RequiresCredentials)
                {
                    PictureCredentials creds;
                    string apiKey = ConfigurationManager.AppSettings["photoAPIKey"];
                    string secretKey = ConfigurationManager.AppSettings["photoSecretKey"];
                    if (!string.IsNullOrEmpty(apiKey))
                        creds = new PictureCredentials(apiKey, secretKey);
                    else
                        creds = new PictureCredentials(System.IO.File.ReadAllLines(@"c:\temp\flickrcred.txt"));
                    this._picSource.Init(creds);
                }
                this.Application.Add("PhotoSource", this._picSource);
            }
            if(null != this._voteSource)
                this.Application.Add("VoteSource", this._voteSource);
            if(null != this._claimSource)
                this.Application.Add("ClaimSource", this._claimSource);
            if (null != this._doorSource)
                this.Application.Add("DoorSource", this._doorSource);
        }
开发者ID:jkuemerle,项目名称:DoorComp,代码行数:31,代码来源:Global.asax.cs


示例19: PluginContainer

        public PluginContainer()
        {
            var registration = new RegistrationBuilder();

            registration.ForTypesDerivedFrom<BasicPlugin>()
                .SetCreationPolicy(CreationPolicy.Shared)
                .Export<BasicPlugin>();

            bool tryAgain = true;

            while (tryAgain)
            {
                try
                {
                    DirectoryCatalog dircat = new DirectoryCatalog(PluginDirectory, registration);
                    tryAgain = false;

                    Container = new CompositionContainer(dircat, CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);
                    Container.ComposeParts();
                }
                catch (DirectoryNotFoundException)
                {
                    Directory.CreateDirectory(PluginDirectory);
                }
            }
        }
开发者ID:jmazouri,项目名称:Picofy,代码行数:26,代码来源:PluginContainer.cs


示例20: Init

        public void Init()
        {
            try
              {
            AggregateCatalog catalog = new AggregateCatalog();

            var c1 = new DirectoryCatalog("Extensions");
            c1.Refresh();
            var c2 = new DirectoryCatalog("EventHandlers");
            c2.Refresh();
            var c3 = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            catalog.Catalogs.Add(c1);
            catalog.Catalogs.Add(c2);
            catalog.Catalogs.Add(c3);

            CompositionContainer container = new CompositionContainer(catalog);
            container.ComposeParts(this);
              }
              catch (Exception ex)
              {
            WindowsLogWriter.LogMessage("Error occurred while composing Denso Extensions", System.Diagnostics.EventLogEntryType.Error);
            WindowsLogWriter.LogException(ex);
              }

              foreach (var plugin in Extensions)
              {
            plugin.Init();
              }

              EventHandlerManager.AnalyzeCommandHandlers(ImportedHandlers);
        }
开发者ID:MohammadHabbab,项目名称:DensoDB,代码行数:32,代码来源:DensoExtensions.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Hosting.ExportProvider类代码示例发布时间:2022-05-26
下一篇:
C# Hosting.AggregateCatalog类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap