public void RemoveApiScopeApi(ApiSingle apiSingle) { if (ApiSingles == null) { throw new Exception("Api域Api为空"); } ApiSingles.Remove(apiSingle); }
public void AddApiScopeApi(ApiSingle apiSingle) { if (ApiSingles == null) { ApiSingles = new List <ApiSingle>(); } ApiSingles.Add(apiSingle); }
public void AddApiScopeApi(string apiScopeName, ApiSingle apiSingle) { var apiScope = ApiScopeRepository.FirstOrDefault(e => e.Name == apiScopeName); if (apiScope == null) { throw new Exception("找不到Api域"); } apiScope.AddApiScopeApi(apiSingle); }
private void RegisterApiSingleByType(Type controllerType) { string controllerName = controllerType.Name; // 如果api已注册过,则返回 if (_apiSingleManager.ApiSingleRepository.FirstOrDefault(e => e.Name == controllerName) != null) { return; } ApiSingle apiSingle = new ApiSingle(controllerName); List <ApiSingleAction> apiSingleActions = new List <ApiSingleAction>(); foreach (var methodInfo in controllerType.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) { apiSingleActions.Add(new ApiSingleAction(methodInfo.Name) { IsQueryAction = IsQueryMethod(methodInfo) }); } apiSingle.ApiSingleActions = apiSingleActions; _apiSingleManager.Register(apiSingle); string apiScopeName = null; foreach (var attribute in controllerType.CustomAttributes) { if (attribute.AttributeType == typeof(ApiAuthorizationAttribute)) { if (attribute.ConstructorArguments.Count > 0) { apiScopeName = attribute.ConstructorArguments[0].Value.ToString(); } } } if (string.IsNullOrEmpty(apiScopeName)) { return; } _apiScopeManager.AddApiScopeApi(apiScopeName, apiSingle); }
public ApiScope GetApiScopesForApiSingle(ApiSingle apiSingle) { return(ApiScopeRepository.GetAll().FirstOrDefault(e => e.ApiSingles.Where(ie => ie.Id == apiSingle.Id).Any())); }