Ejemplo n.º 1
0
        /// <summary>
        /// 加载模块列表
        /// </summary>
        /// <returns></returns>
        public static void LoadModules()
        {
            string currentfilename = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string modulepath      = currentfilename.Remove(currentfilename.LastIndexOf("\\")) + "\\Modules";

            string[] groupnamepaths = Directory.GetDirectories(modulepath);
            foreach (string groupnamepath in groupnamepaths)
            {
                string        groupname      = new DirectoryInfo(groupnamepath).Name;
                List <string> modulefilelist = FileHelper.GetFileList(groupnamepath, "*.dll", true);
                foreach (string modulefile in modulefilelist)
                {
                    try
                    {
                        var xmodulelist = XModuleHelper.LoadXModules(modulefile);
                        foreach (XModule xmodule in xmodulelist)
                        {
                            var modulecontent = (XModule)xmodule.Clone();
                            var module        = new Module();
                            module.Md5         = StrHelper.Md5(groupnamepath + modulecontent.GetType().FullName, false);
                            module.Name        = modulecontent.Name();
                            module.GroupName   = groupname;
                            module.Description = modulecontent.Description();
                            module.XModule     = modulecontent;
                            module.Icon        = modulecontent.Icon();
                            Client.Modules.Add(module);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("模块加载失败:" + e);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载模块
        /// </summary>
        public static void LoadModules()
        {
            var currentfilename = System.Diagnostics.Process.GetCurrentProcess().MainModule?.FileName;
            var modulepath      = currentfilename?.Remove(currentfilename.LastIndexOf("\\", StringComparison.Ordinal)) +
                                  "\\Modules";
            var groupnamepaths = Directory.GetDirectories(modulepath);

            foreach (var groupnamepath in groupnamepaths)
            {
                var groupname      = new DirectoryInfo(groupnamepath).Name;
                var modulefilelist = FileHelper.GetFileList(groupnamepath, "*.dll", true);
                foreach (var modulefile in modulefilelist)
                {
                    try
                    {
                        var xmodulelist = XModuleHelper.LoadXModules(modulefile);
                        foreach (var xmodule in xmodulelist)
                        {
                            var modulecontent = (XModule)xmodule.Clone();
                            var module        = new Module
                            {
                                Md5         = StrHelper.Md5(groupnamepath + modulecontent.GetType().FullName, false),
                                Name        = modulecontent.Name(),
                                GroupName   = groupname,
                                Description = modulecontent.Description(),
                                XModule     = modulecontent,
                                Icon        = modulecontent.Icon()
                            };
                            Client.Modules.Add(module);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("模块加载失败:" + e);
                    }
                }
            }
        }