Carrotware.CMS.Core.CMSConfigHelper.GetModulesByDirectory C# (CSharp) Method

GetModulesByDirectory() private method

private GetModulesByDirectory ( ) : List
return List
        private List<CMSAdminModule> GetModulesByDirectory()
        {
            var _plugins = new List<CMSAdminModule>();

            CarrotCakeConfig config = CarrotCakeConfig.GetConfig();

            string sPlugCfg = HttpContext.Current.Server.MapPath(config.ConfigFileLocation.PluginPath);

            if (Directory.Exists(sPlugCfg)) {
                string[] subdirs;
                try {
                    subdirs = Directory.GetDirectories(sPlugCfg);
                } catch {
                    subdirs = null;
                }

                if (subdirs != null) {
                    foreach (string theDir in subdirs) {
                        string sTplDef = theDir + @"\Admin.config";

                        if (File.Exists(sTplDef)) {
                            string sPathPrefix = GetFolderPrefix(theDir);
                            DataSet ds = ReadDataSetConfig(CMSConfigFileType.AdminMod, sPathPrefix);

                            var _modules = (from d in ds.Tables[0].AsEnumerable()
                                            select new CMSAdminModule {
                                                PluginName = d.Field<string>("caption"),
                                                AreaKey = d.Field<string>("area")
                                            }).OrderBy(x => x.PluginName).ToList();

                            var _ctrls = (from d in ds.Tables[1].AsEnumerable()
                                          select new CMSAdminModuleMenu {
                                              Caption = d.Field<string>("pluginlabel"),
                                              SortOrder = String.IsNullOrEmpty(d.Field<string>("menuorder")) ? -1 : int.Parse(d.Field<string>("menuorder")),
                                              Action = d.Field<string>("action"),
                                              Controller = d.Field<string>("controller"),
                                              UsePopup = String.IsNullOrEmpty(d.Field<string>("usepopup")) ? false : Convert.ToBoolean(d.Field<string>("usepopup")),
                                              IsVisible = String.IsNullOrEmpty(d.Field<string>("visible")) ? false : Convert.ToBoolean(d.Field<string>("visible")),
                                              AreaKey = d.Field<string>("area")
                                          }).OrderBy(x => x.Caption).OrderBy(x => x.SortOrder).ToList();

                            foreach (var p in _modules) {
                                p.PluginMenus = (from c in _ctrls
                                                 where c.AreaKey == p.AreaKey
                                                 orderby c.Caption, c.SortOrder
                                                 select c).ToList();
                            }

                            _plugins = _plugins.Union(_modules).ToList();
                        }
                    }
                }
            }

            return _plugins;
        }