public bool TryGetType(AccountOption ao, out Type type) { bool success = TryGetOptionProperty(ao, out PropertyInfo property); type = property.Exists() ? property.PropertyType : null; return(success); }
public static string ReadValue(this AccountOption ao) { AccountOptions acc = AccountOptions.Default; object value = ao.GetValue(); string s = "Undefined"; if (value.Exists()) { if (value.IsList()) { IEnumerable <object> v = (value as IEnumerable <object>).Cast <object>(); if (v.Funct()) { s = string.Join(", ", v); } else { s = "Empty"; } } else { s = value.ToString(); } } return(s); }
public async Task OptionResponseAsync ( [Name("context"), Summary("The option to view context for.")] AccountOption option ) { await ModuleManager.TryExecute(Context.Channel, OptionsService.ReadOptionAsync(Context, option)); }
public bool TryGetValue(AccountOption ao, out object value) { bool success = TryGetOptionProperty(ao, out PropertyInfo property); value = property.Exists() ? property.GetValue(this) : null; return(success); }
public void ReadSettings() { UserPreference = JsonConvert.DeserializeObject <UserPreference>(Properties.Settings.Default["preference"].ToString()); List <IController> all_ctrls = new List <IController>(); if (UserPreference != null) { Type t = typeof(Helper); string ns = t.Namespace; foreach (string vendor in UserPreference.Vendors) { AccountOption accOpt = (dynamic)UserPreference.GetType().GetProperty(vendor + "Account").GetValue(UserPreference); foreach (var acc in accOpt.Accounts) { if (acc.IsActivate) { string clsName = ns + "." + vendor + "Controller"; Type type = Type.GetType(clsName); IController ctrl = Activator.CreateInstance(type, this) as IController; ctrl.ConnParam = acc; // if some connection is connected, then remain unchanged IController ic = Controllers.FirstOrDefault(x => x.DisplayName == ctrl.DisplayName); if (ic != null) { ic.ConnParam = acc; all_ctrls.Add(ic); } else { all_ctrls.Add(ctrl); } } } // add new controllers foreach (var ctrl in all_ctrls) { IController ic = Controllers.FirstOrDefault(x => x.DisplayName == ctrl.DisplayName); if (ic == null) { Controllers.Add(ctrl); } } // remove out-of-date controllers foreach (var ctrl in Controllers.ToList()) { IController ic = all_ctrls.FirstOrDefault(x => x.DisplayName == ctrl.DisplayName); if (ic == null) { foreach (var symbol in SymbolInActions) { symbol.AppliedControllers.Remove(ctrl); } Controllers.Remove(ctrl); } } } } }
public async Task SetOptionAsync ( [Name("context"), Summary("The option to view context for.")] AccountOption option, [Name("value"), Summary("The new value to be set in place of the option.")] object value = null ) { await ModuleManager.TryExecute(Context.Channel, OptionsService.SetOptionAsync(Context, option, value)); }
public static bool TryParseOption(int i, out AccountOption ao) { if (!Enum.TryParse($"{i}", out ao)) { return(false); } return(true); }
public static bool TryParseOption(Emoji emoji, out AccountOption ao) { ao = AccountOption.AutoFix; if (emoji.TryGetAccountOption(out ao)) { return(true); } return(false); }
public static Type GetValueType(this AccountOption ao) { AccountOptions acc = AccountOptions.Default; if (acc.TryGetType(ao, out Type type)) { return(type); } throw new Exception("Invalid account option property."); }
public AccountService(IHttpContextAccessor httpContextAccessor, IIdentityServerInteractionService interaction, IClientStore clientStore, IOptions <AccountOption> options, IAuthenticationSchemeProvider schemeProvider) { _httpContextAccessor = httpContextAccessor; _interaction = interaction; _clientStore = clientStore; _schemeProvider = schemeProvider; _options = options.Value; }
public static Interpreter GetInterpreter(AccountOption ao) { AccountOptions opts = AccountOptions.Default; if (opts.TryGetOptionProperty(ao, out PropertyInfo p)) { return(Interpret(p)); } throw new Exception("Invalid account option property."); }
public static object GetValue(this AccountOption ao) { AccountOptions acc = AccountOptions.Default; if (acc.TryGetValue(ao, out object obj)) { return(obj); } throw new Exception("Invalid account option property."); }
public static bool TryGetAccountOption(this PropertyInfo property, out AccountOption option) { option = AccountOption.AutoFix; AccountOptionAttribute a = property.GetCustomAttribute <AccountOptionAttribute>(); if (a.Exists()) { option = a.Option; return(true); } return(false); }
public static async Task SetOptionAsync(OrikivoCommandContext Context, AccountOption option, object obj) { AccountOptions opts = AccountOptions.Default; opts.TryGetValue(option, out object value); if (opts.TrySetValue(option, obj)) { string msg = $"{option} - {(value.Exists() ? value.Read() : "Undefined")}"; opts.TryGetValue(option, out value); msg += $" => {(value.Exists() ? value.Read() : "Undefined")}"; await Context.Channel.SendMessageAsync(msg); } }
public AccountController(IUserService userService, IIdentityServerInteractionService interaction, AccountService accountService, IOptions <AccountOption> options, ILoggerFactory loggerFactory, IHttpContextAccessor httpContext, IEventService eventService) { _userService = userService; _interaction = interaction; _accountService = accountService; _eventService = eventService; _options = options.Value; _logger = loggerFactory.CreateLogger <AccountController>(); ; }
public static bool TryParseOption(string s, out AccountOption ao) { ao = AccountOption.AutoFix; Type option = typeof(AccountOption); foreach (string name in option.GetEnumNames()) { name.Debug(); if (name.Matches(s, MatchHandling.Match, MatchValueHandling.StartsWith)) { ao = (AccountOption)option.GetField(name).GetRawConstantValue(); return(true); } } return(false); }
public static bool TryGetAccountOption(this Emoji emoji, out AccountOption option) { option = AccountOption.AutoFix; foreach (PropertyInfo p in AccountOptions.DefaultProperties) { if (p.TryGetIcon(out Emoji e)) { if (emoji.Name == e.Name) { if (p.TryGetAccountOption(out option)) { return(true); } } } } return(false); }
public bool TryGetOptionProperty(AccountOption ao, out PropertyInfo property) { property = null; foreach (PropertyInfo p in Properties) { AccountOptionAttribute attribute = p.GetCustomAttribute <AccountOptionAttribute>(); if (attribute.Exists()) { if (ao.Equals(attribute.Option)) { property = p; "".Debug($"Found Property {property.Name}"); return(true); } } } return(false); }
public static async Task ReadOptionAsync(OrikivoCommandContext Context, AccountOption option) { await Context.Channel.ReadAsync(option.Interpret(), Context.Account); }
public AccountOptionAttribute(AccountOption option) { Option = option; }
public bool TrySetValue(AccountOption ao, object value = null) { if (TryGetOptionProperty(ao, out PropertyInfo property)) { object obj = property.GetValue(this); Type objT = property.PropertyType; value.Read().Debug(); if (value == null) { if (property.PropertyType == typeof(bool)) { return(TryToggleValue(property)); } objT.Debug(); if (!objT.IsNullable()) { "A value can only be left empty, in the case of a bool.".Debug(); // Delete. return(false); } } if (property.PropertyType.IsEnum) { Array enums = property.PropertyType.GetEnumValues(); for (int i = 0; i < enums.Length; i++) { object data = enums.GetValue(i); string name = data.GetType().GetEnumName(data); int raw = (int)data.GetType().GetField(name).GetRawConstantValue(); raw.Debug("The raw Enum value."); // Delete. name.Debug("The Enum name."); // Delete. value.Debug("The value specified."); // Delete. if ($"{value}" == $"{raw}") { try { obj.Read().Debug("The previous value."); // Delete. property.SetValue(this, data); property.GetValue(this).Debug("The new value."); // Delete. } catch (ArgumentException) { "Inbound enum type is not in par with the specified type.".Debug(); // Delete. return(false); } return(true); } if (name.Matches($"{value}", MatchHandling.Match, MatchValueHandling.Equals)) { try { obj.Read().Debug("The previous value."); // Delete. property.SetValue(this, data); property.GetValue(this).Read().Debug("The new value."); // Delete. } catch (ArgumentException) { "Inbound enum type is not in par with the specified type.".Debug(); // Delete. return(false); } return(true); } } return(false); } if (obj.IsList()) { if (value.IsList()) { return(TryAddValues(property, value)); } return(TryAddValue(property, value)); } try { obj.Read().Debug("The previous value."); // Delete. property.SetValue(this, value); property.GetValue(this).Read().Debug("The new value."); // Delete. } catch (ArgumentException) { return(false); } } return(true); }
public AppSettingsService(CafAppsettingDbContext dbContext, ICafCache cafCache, IOptionsSnapshot <AccountOption> options) { _dbContext = dbContext; _cafCache = cafCache; _accOption = options.Value; }
public static Interpreter Interpret(this AccountOption ao) => OptionsHelper.GetInterpreter(ao);