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


C# PluginManager.Discover方法代码示例

本文整理汇总了C#中PluginManager.Discover方法的典型用法代码示例。如果您正苦于以下问题:C# PluginManager.Discover方法的具体用法?C# PluginManager.Discover怎么用?C# PluginManager.Discover使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PluginManager的用法示例。


在下文中一共展示了PluginManager.Discover方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            #region Discover succeed due to a compatible version

            Console.WriteLine("Discover all ISamplePlugin plugins with version > 1.0 and version < 1.9.3 ...");

            var pm = new PluginManager(Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar + "SamplePlugin")
                .Register<ISamplePlugin.ISamplePlugin>(new Version(1, 0), new Version(1, 9, 3))
                    .Discover();

            var plugin = pm.GetPlugins<ISamplePlugin.ISamplePlugin>(p => p.GetType().Name == "SamplePlugin").FirstOrDefault();
            Console.WriteLine("Succeeded for: " + plugin.SampleMethod(1, ""));

            #endregion

            #region Discovering fail due to an incompatible version

            Console.WriteLine("");
            Console.WriteLine("Discover all ISamplePlugin plugins with version > 1.0 and version < 1.8 ...");

            pm = new PluginManager(Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar + "SamplePlugin")
                .Register<ISamplePlugin.ISamplePlugin>(new Version(1, 0), new Version(1, 8));

            pm.OnPluginIncompatibleVersion += (sender, e) =>
            {
                Console.WriteLine("Failed: [{0}] is not between [{1}] and [{2}]", e.PluginVersion, e.MinVersion, e.MaxVersion);
            };
            pm.Discover(false); // do not throw an axception

            #endregion

            Console.ReadKey();
        }
开发者ID:sones,项目名称:VersionedPluginManager,代码行数:33,代码来源:Program.cs

示例2: DBPluginManager

        public DBPluginManager(EntityUUID myUserID, Boolean myIncludePrivateClasses = false)
        {
            #region lookup dictionaries

            _Functions = new Dictionary<string, ABaseFunction>();
            _Aggregates = new Dictionary<string, ABaseAggregate>();
            _Operators = new Dictionary<string, ABinaryOperator>();
            _Settings = new Dictionary<string, ADBSettingsBase>();
            _EdgeTypes = new Dictionary<string, IEdgeType>();
            _Indices = new Dictionary<string, AAttributeIndex>();
            _GraphDBImporter = new Dictionary<string, AGraphDBImport>();
            _GraphDBExporter = new Dictionary<string, AGraphDBExport>();
            _UserID = myUserID;

            #endregion

            #region Register & Discover

            //FindAndFillReflections(myIncludePrivateClasses);

            // Change the version if there are ANY changes which will prevent loading the plugin.
            // As long as there are still some plugins which does not have their own assembly you need to change the compatibility of ALL plugins of the GraphDB and GraphFSInterface assembly.
            // So, if any plugin in the GraphDB changes you need to change the AssemblyVersion of the GraphDB AND modify the compatibility version of the other plugins.
            _PluginManager = new PluginManager()
                .Register<IGraphDBFunction>(IGraphDBFunctionVersionCompatibility.MinVersion, IGraphDBFunctionVersionCompatibility.MaxVersion)
                .Register<IGraphDBAggregate>(IGraphDBAggregateVersionCompatibility.MinVersion, IGraphDBAggregateVersionCompatibility.MaxVersion)
                .Register<IGraphDBSetting>(IGraphDBSettingVersionCompatibility.MinVersion, IGraphDBSettingVersionCompatibility.MaxVersion)
                .Register<ABinaryOperator>(new Version("1.0.0.0"))  // GraphDB assembly
                .Register<IEdgeType>(new Version("1.0.0.0"))        // GraphDB assembly
                .Register<AGraphDBImport>(new Version("1.0.0.0"))   // GraphDB assembly
                .Register<AGraphDBExport>(new Version("1.0.0.0"))   // GraphDB assembly

                .Register<AAttributeIndex>(new Version("1.0.0.0")) // GraphDB assembly
                ;

            _PluginManager.Discover(true, !myIncludePrivateClasses)
                .FailedAction(e => { throw new Exception(e.GetIErrorsAsString()); });

            #endregion

            #region Get all plugins and fill the lookup dictionaries

            #region Functions

            foreach (var func in _PluginManager.GetPlugins<IGraphDBFunction>())
            {
                var funcname = (func as ABaseFunction).FunctionName.ToUpper();

                #region Verify that there is no aggregate with the same name if the current function has parameters

                if (_Aggregates.ContainsKey(funcname) && (func as ABaseFunction).GetParameters().IsNotNullOrEmpty())
                {
                    throw new GraphDBException(new Error_DuplicateAggregateOrFunction(funcname, false));
                }

                #endregion

                #region Add function if the name does not exist

                if (!_Functions.ContainsKey(funcname))
                {
                    _Functions.Add(funcname, (func as ABaseFunction));
                }
                else
                {
                    throw new GraphDBException(new Error_DuplicateAggregateOrFunction(funcname));
                }

                #endregion

            }

            #endregion

            #region Aggregates

            foreach (var aggr in _PluginManager.GetPlugins<IGraphDBAggregate>())
            {
                var aggrname = (aggr as ABaseAggregate).FunctionName.ToUpper();

                #region Verify that there is no function with parameters and the same name

                if (_Functions.ContainsKey(aggrname) && _Functions[aggrname].GetParameters().IsNotNullOrEmpty())
                {
                    throw new GraphDBException(new Error_DuplicateAggregateOrFunction(aggrname));
                }

                #endregion

                #region Add aggregate if it does not exist

                if (!_Aggregates.ContainsKey(aggrname))
                {
                    _Aggregates.Add(aggrname, (aggr as ABaseAggregate));
                }
                else
                {
                    throw new GraphDBException(new Error_DuplicateAggregateOrFunction(aggrname, false));
                }

//.........这里部分代码省略.........
开发者ID:Vadi,项目名称:sones,代码行数:101,代码来源:DBPluginManager.cs


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