<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Reflection;
using Thinktecture.IdentityServer.Core.Models;

namespace IdentityServer.MongoDb.AdminModule
{
    [Cmdlet(VerbsCommon.Get, "Scopes")]
    public class ReadScopes : MongoCmdlet
    {
        [Parameter(HelpMessage = "Gets the predefined standard scopes from identity server. These need to be persisted into the database using Set-Scope if you want them available to the application at runtime")]
        public SwitchParameter Predefined { get; set; }

        protected override void ProcessRecord()
        {
            IEnumerable<Scope> scopes;
            if (Predefined)
            {
                var builtin = BuiltInScopes();
                scopes = builtin;
            }
            else
            {
                scopes = ScopeStore.GetScopesAsync().Result;
            }

            foreach (var scope in scopes)
            {
                WriteObject(scope);
            }
        }

        public static List<Scope> BuiltInScopes(bool alwaysInclude = false)
        {
            var scopeAccessors =
                typeof (StandardScopes).GetProperties(BindingFlags.Static | BindingFlags.Public)
                    .Where(x => x.PropertyType == typeof (Scope)
                    && alwaysInclude == x.Name.EndsWith("AlwaysInclude")
                    );
            var builtin = scopeAccessors.Select(scopeAccessor => (Scope) scopeAccessor.GetValue(null)).ToList();
            return builtin;
        }
    }
}<commit_msg>Updated predefined scopes to use defined scopes instead of reflection<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Reflection;
using Thinktecture.IdentityServer.Core.Models;

namespace IdentityServer.MongoDb.AdminModule
{
    [Cmdlet(VerbsCommon.Get, "Scopes")]
    public class ReadScopes : MongoCmdlet
    {
        [Parameter(HelpMessage = "Gets the predefined standard scopes from identity server. These need to be persisted into the database using Set-Scope if you want them available to the application at runtime")]
        public SwitchParameter Predefined { get; set; }

        protected override void ProcessRecord()
        {
            IEnumerable<Scope> scopes;
            if (Predefined)
            {
                var builtin = BuiltInScopes();
                scopes = builtin;
            }
            else
            {
                scopes = ScopeStore.GetScopesAsync().Result;
            }

            foreach (var scope in scopes)
            {
                WriteObject(scope);
            }
        }

        public static IEnumerable<Scope> BuiltInScopes()
        {
            foreach (var scope in StandardScopes.All)
            {
                yield return scope;
            }
            yield return StandardScopes.AllClaims;
            yield return StandardScopes.OfflineAccess;
            yield return StandardScopes.Roles;
        }
    }
}
{'fraction_non_alphanumeric': 0.07437745740498033, 'fraction_numerical': 0.0, 'mean_word_length': 1.944069431051109, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1885385', 'n_tokens_mistral': 763, 'n_tokens_neox': 736, 'n_words': 202}