コード例 #1
0
        public static List<FeaturePermission> GetFeaturePermissions(this IRole role, Type baseFeatureType)
        {
            var featurePermissions = new List<FeaturePermission>();

            try
            {
                var types = Assembly.GetExecutingAssembly().GetTypes().Where(p => baseFeatureType.IsAssignableFrom(p) && p.Name != baseFeatureType.Name && !p.IsAbstract);
                foreach (var type in types)
                {
                    string featureDisplayName = FirmaBaseFeatureHelpers.GetDisplayName(type);
                    var hasPermission = FirmaBaseFeatureHelpers.DoesRoleHavePermissionsForFeature(role, type);

                    // Don't add duplicates to the list
                    if (featurePermissions.All(x => x.FeatureName != featureDisplayName))
                    {
                        featurePermissions.Add(new FeaturePermission(featureDisplayName, hasPermission));
                    }
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions)
                {
                    sb.AppendLine(exSub.Message);
                    FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                    if (exFileNotFound != null)
                    {
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog))
                        {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                Logger.Error($"Reflection error message: {errorMessage}");

                // re-throw; this detour is just to try to fish out the extra logging info
                throw ex;
            }
            return featurePermissions;
        }
コード例 #2
0
        public static List <FeaturePermission> GetFeaturePermissions(this IRole role, Type baseFeatureType)
        {
            var featurePermissions = new List <FeaturePermission>();

            var types = Assembly.GetExecutingAssembly().GetTypes().Where(p => baseFeatureType.IsAssignableFrom(p) && p.Name != baseFeatureType.Name && !p.IsAbstract);

            foreach (var type in types)
            {
                string featureDisplayName = FirmaBaseFeatureHelpers.GetDisplayName(type);
                var    hasPermission      = FirmaBaseFeatureHelpers.DoesRoleHavePermissionsForFeature(role, type);

                //Don't add duplicates to the list
                if (featurePermissions.All(x => x.FeatureName != featureDisplayName))
                {
                    featurePermissions.Add(new FeaturePermission(featureDisplayName, hasPermission));
                }
            }
            return(featurePermissions);
        }