Esempio n. 1
0
        /// <summary>
        /// 根据关键字创建程序对象
        /// </summary>
        /// <param name="key"></param>
        /// <param name="PluginId"></param>
        /// <returns></returns>
        public static List <object> CreateInstancesByKey(string key, string PluginId = "")
        {
            var           models      = ApplicationAssembly.ToArray();
            var           modelsByKey = models.GetModelsByKey(key);
            List <object> lstObj      = new List <object>();

            if (modelsByKey != null && modelsByKey.Count > 0)
            {
                modelsByKey.ForEach(modelByKey =>
                {
                    var assemblyPluginAttribute = modelByKey.GetAssemblyPluginAttribute();
                    if (!String.IsNullOrWhiteSpace(PluginId))
                    {
                        var obj = CreateInstanceByAssemblyIdAndPluginId(assemblyPluginAttribute.ID, PluginId);
                        lstObj.Add(obj);
                    }
                    else if (!String.IsNullOrWhiteSpace(assemblyPluginAttribute.DefaultPluginID))
                    {
                        var obj = CreateInstanceByAssemblyIdAndPluginId(assemblyPluginAttribute.ID, assemblyPluginAttribute.DefaultPluginID);
                        lstObj.Add(obj);
                    }
                });
            }
            return(lstObj);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据插件类型获取相同类型的所有插件
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Type"></param>
        /// <returns></returns>
        public static List <T> CreateInstancesByPluginType <T>(string Type = "") where T : class
        {
            var models  = ApplicationAssembly.ToArray();
            var lstObjs = models.CreateInstancesByPluginType <T>(Type);

            return(lstObjs);
            //return AppDomain.CurrentDomain.GetAssemblies().CreateInstancesByPluginType<T>(Type);
        }
Esempio n. 3
0
        /// <summary>
        /// 根据ID创建对象
        /// </summary>
        /// <param name="AssemblyId"></param>
        /// <param name="PluginId"></param>
        /// <returns></returns>
        public static object CreateInstanceByAssemblyIdAndPluginId(string AssemblyId, string PluginId = "")
        {
            var models = ApplicationAssembly.ToArray();
            var obj    = models.CreateInstanceByAssemblyIdAndPluginId(AssemblyId, PluginId);

            return(obj);
            //return AppDomain.CurrentDomain.GetAssemblies().CreateInstanceByAssemblyIdAndPluginId(AssemblyId, PluginId);
        }
Esempio n. 4
0
        /// <summary>
        /// 获取所有插件内插件类插件信息
        /// </summary>
        /// <returns></returns>
        public static List <PluginAttribute> GetPluginAttributes()
        {
            //var models = AppDomain.CurrentDomain.GetAssemblies();

            var models = ApplicationAssembly.ToArray();
            List <PluginAttribute> lstObject = new List <PluginAttribute>();

            System.Threading.Tasks.Parallel.ForEach(models, model =>
            {
                model.GetPluginAttributes().ForEach(pluginAttribute => lstObject.Add(pluginAttribute));
            });
            return(lstObject);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取所有插件信息
        /// </summary>
        /// <returns></returns>
        public static List <AssemblyPluginAttribute> GetAssemblyPluginAttributes()
        {
            //var models = AppDomain.CurrentDomain.GetAssemblies();

            var models = ApplicationAssembly.ToArray();
            List <AssemblyPluginAttribute> lstObject = new List <AssemblyPluginAttribute>();

            System.Threading.Tasks.Parallel.ForEach(models, model =>
            {
                var assemblyPluginAttribute = model.GetAssemblyPluginAttribute();
                if (assemblyPluginAttribute != null)
                {
                    lstObject.Add(assemblyPluginAttribute);
                }
            });
            return(lstObject);
        }
Esempio n. 6
0
        /// <summary>
        /// 根据关键字创建程序对象
        /// </summary>
        /// <param name="key"></param>
        /// <param name="PluginId"></param>
        /// <returns></returns>
        public static object CreateInstanceByKey(string key, string PluginId = "")
        {
            var models = ApplicationAssembly.ToArray();//_AppDomain.GetAssemblies();
            var model  = models.GetModelByKey(key);

            object obj = null;

            if (model != null)
            {
                var assemblyPluginAttribute = model.GetAssemblyPluginAttribute();
                if (!String.IsNullOrWhiteSpace(PluginId))
                {
                    obj = CreateInstanceByAssemblyIdAndPluginId(assemblyPluginAttribute.ID, PluginId);
                }
                else if (!String.IsNullOrWhiteSpace(assemblyPluginAttribute.DefaultPluginID))
                {
                    obj = CreateInstanceByAssemblyIdAndPluginId(assemblyPluginAttribute.ID, assemblyPluginAttribute.DefaultPluginID);
                }
            }
            return(obj);
        }