/// <summary> /// 应用模块服务 /// </summary> /// <param name="provider">服务提供者</param> public override void UsePack(IServiceProvider provider) { IModuleHandler moduleHandler = provider.GetService <IModuleHandler>(); moduleHandler.Initialize(); //初始化各种缓存 IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); functionHandler.RefreshCache(); IEntityInfoHandler entityInfoHandler = provider.GetService <IEntityInfoHandler>(); entityInfoHandler.RefreshCache(); IFunctionAuthCache functionAuthCache = provider.GetService <IFunctionAuthCache>(); functionAuthCache.BuildRoleCaches(); IDataAuthCache dataAuthCache = provider.GetService <IDataAuthCache>(); dataAuthCache.BuildCaches(); IsEnabled = true; }
public LoggingFunctionDecorator( IFunctionHandler <TCommand, TOutput> decorateeHandler, IEventLogger <LoggingFunctionDecorator <TCommand, TOutput> > logger ) : base(decorateeHandler, logger, true) { this.decorateeHandler = decorateeHandler; }
/// <summary> /// 获取MVC操作的相关功能信息 /// </summary> public static IFunction GetExecuteFunction(this ControllerContext context, IServiceProvider provider) { const string key = Constants.CurrentMvcFunctionKey; IDictionary items = context.HttpContext.Items; if (items.Contains(key)) { return((IFunction)items[key]); } string area = context.GetAreaName(); string controller = context.GetControllerName(); string action = context.GetActionName(); IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); if (functionHandler == null) { return(null); } IFunction function = functionHandler.GetFunction(area, controller, action); if (function != null) { items.Add(key, function); } return(function); }
/// <summary> /// 获取指定URL的功能信息 /// </summary> public static IFunction GetFunction(this ControllerBase controller, string url) { url = url.StartsWith("https://") || url.StartsWith("http://") ? new Uri(url).AbsolutePath : !url.StartsWith("/") ? $"/{url}" : url; IServiceProvider provider = controller.HttpContext.RequestServices; IHttpContextFactory factory = provider.GetService <IHttpContextFactory>(); HttpContext httpContext = factory.Create(controller.HttpContext.Features); httpContext.Request.Path = url; httpContext.Request.Method = "POST"; RouteContext routeContext = new RouteContext(httpContext); IRouteCollection router = controller.RouteData.Routers.OfType <IRouteCollection>().FirstOrDefault(); if (router == null) { return(null); } router.RouteAsync(routeContext).Wait(); if (routeContext.Handler == null) { return(null); } RouteValueDictionary dict = routeContext.RouteData.Values; string areaName = dict.GetOrDefault("area")?.ToString(); string controllerName = dict.GetOrDefault("controller")?.ToString(); string actionName = dict.GetOrDefault("action")?.ToString(); IFunctionHandler handler = provider.GetService <IFunctionHandler>(); return(handler?.GetFunction(areaName, controllerName, actionName)); }
/// <summary> /// 删除功能信息信息 /// </summary> /// <param name="ids">要删除的功能信息编号</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> DeleteFunctions(params Guid[] ids) { ids.CheckNotNull(nameof(ids)); List <string> names = new List <string>(); FunctionRepository.UnitOfWork.TransactionEnabled = true; foreach (Guid id in ids) { Function entity = await FunctionRepository.GetByKeyAsync(id); if (entity == null) { return(new OperationResult(OperationResultType.QueryNull)); } await FunctionRepository.DeleteAsync(entity); names.Add(entity.Name); } int count = await FunctionRepository.UnitOfWork.SaveChangesAsync(); OperationResult result = count > 0 ? new OperationResult(OperationResultType.Success, $"功能“{names.ExpandAndToString()}”删除成功") : new OperationResult(OperationResultType.NoChanged); if (result.ResultType == OperationResultType.Success) { IFunctionHandler handler = ServiceProvider.GetService <IFunctionHandler>(); handler.RefreshCache(); } return(result); }
/// <summary> /// 获取正在执行的Action相关功能信息 /// </summary> public static IFunction GetExecuteFunction(this RouteEndpoint endpoint, HttpContext context) { IServiceProvider provider = context.RequestServices; ScopedDictionary dict = provider.GetService <ScopedDictionary>(); if (dict.Function != null) { return(dict.Function); } string area = endpoint.GetAreaName(), controller = endpoint.GetControllerName(), action = endpoint.GetActionName(); IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); if (functionHandler == null) { throw new OsharpException("获取正在执行的功能时 IFunctionHandler 无法解析"); } IFunction function = functionHandler.GetFunction(area, controller, action); if (function != null) { dict.Function = function; } return(function); }
/// <summary> /// 获取正在执行的Action的相关功能信息 /// </summary> public static IFunction GetExecuteFunction(this ActionContext context) { Check.NotNull(context, nameof(context)); IServiceProvider provider = context.HttpContext.RequestServices; ScopedDictionary dict = provider.GetService <ScopedDictionary>(); if (dict.Function != null) { return(dict.Function); } string area = context.GetAreaName(); string controller = context.GetControllerName(); string action = context.GetActionName(); // todo: 当权限模块没启用时,应取消权限验证,如何判断权限模块已启用? IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); if (functionHandler == null) { return(null); } IFunction function = functionHandler.GetFunction(area, controller, action); if (function != null) { dict.Function = function; } return(function); }
/// <summary> /// 删除功能信息信息 /// </summary> /// <param name="ids">要删除的功能信息编号</param> /// <returns>业务操作结果</returns> public OperationResult DeleteFunctions(params Guid[] ids) { ids.CheckNotNull("ids"); List <string> names = new List <string>(); FunctionRepository.UnitOfWork.TransactionEnabled = true; foreach (Guid id in ids) { Function entity = FunctionRepository.GetByKey(id); if (entity == null) { return(new OperationResult(OperationResultType.QueryNull)); } if (!entity.IsCustom) { return(new OperationResult(OperationResultType.Error, "功能“{0}”不是自定义功能,不能删除".FormatWith(entity.Name))); } FunctionRepository.Delete(entity); names.Add(entity.Name); } int count = FunctionRepository.UnitOfWork.SaveChanges(); OperationResult result = count > 0 ? new OperationResult(OperationResultType.Success, "功能“{0}”删除成功".FormatWith(names.ExpandAndToString())) : new OperationResult(OperationResultType.NoChanged); if (result.ResultType == OperationResultType.Success) { IFunctionHandler handler = ServiceProvider.GetService <IFunctionHandler>(); handler.RefreshCache(); } return(result); }
internal static void Init() { GsSerializer.OnNewEventHandler += OnNewEventHandler; GsSerializer.OnNewSnapShotReceived += OnNewSnapShotReceived; GsSerializer.CurrentPlayerLeftRoom += CurrentPlayerLeftRoom; GsSerializer.CurrentPlayerJoinRoom += CurrentPlayerJoinRoom; RealTimeEventHandlers.JoinedRoom += JoinedRoom; RealTimeEventHandlers.LeftRoom += LeftRoom; RealTimeEventHandlers.RoomMembersDetailReceived += RoomMembersDetailReceived; _monoBehaviourHandler = new MonoBehaviourHandler(); _prefabHandler = new PrefabHandler(); _functionHandler = new FunctionHandler(); _propertyHandler = new PropertyHandler(); _memberHandler = new MemberHandler(); _monoBehaviourHandler.Init(); _memberHandler.Init(); _propertyHandler.Init(_memberHandler); TypeUtil.Init(); ObjectUtil.Init(); IsAvailable = true; }
public void GetAllFunctionTypesTest() { IFunctionHandler handler = GetHandler(); Type[] types = handler.GetAllFunctionTypes(); Assert.NotEmpty(types); }
/** * Given a handler registered to handle the function, try to coerce the function arguments into * one of the prototypes defined by the handler. If no suitable prototype found, throw an eval * exception. Otherwise, evaluate. * * Note that if the handler supports 'raw args', it will receive the full, unaltered argument * list if no prototype matches. (this lets functions support variable-length argument lists) * * @param handler * @param args * @return */ private static Object evalCustomFunction(IFunctionHandler handler, Object[] args) { ArrayList prototypes = handler.Prototypes; IEnumerator e = prototypes.GetEnumerator(); Object[] typedArgs = null; while (typedArgs == null && e.MoveNext()) { typedArgs = matchPrototype(args, (Type[])e.Current); } if (typedArgs != null) { return(handler.eval(typedArgs, new EvaluationContext())); } else if (handler.rawArgs()) { return(handler.eval(args, new EvaluationContext())); //should we have support for expanding nodesets here? } else { throw new XPathTypeMismatchException("for function \'" + handler.Name + "\'"); } }
/// <summary> /// 获取当前执行的功能信息 /// </summary> public static IFunction GetExecuteFunction(this HttpRequestMessage request, IServiceProvider provider) { const string key = Constants.CurrentWebApiFunctionKey; IDictionary <string, object> items = request.Properties; if (items.ContainsKey(key)) { return((IFunction)items[key]); } string area = request.GetAreaName(); string controller = request.GetControllerName(); string action = request.GetActionName(); IFunctionHandler handler = provider.GetService <IFunctionHandler>(); if (handler == null) { return(null); } IFunction function = handler.GetFunction(area, controller, action); if (function != null) { items.Add(key, function); } return(function); }
/// <summary> /// 获取正在执行的Action的相关功能信息 /// </summary> public static IFunction GetExecuteFunction(this ActionContext context) { IServiceProvider provider = context.HttpContext.RequestServices; ScopedDictionary dict = provider.GetService <ScopedDictionary>(); if (dict.Function != null) { return(dict.Function); } string area = context.GetAreaName(); string controller = context.GetControllerName(); string action = context.GetActionName(); // todo: 当权限模块没启用时,应取消权限验证,如何判断权限模块已启用? IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); if (functionHandler == null) { throw new OsharpException("获取正在执行的功能时 IFunctionHandler 无法解析"); } IFunction function = functionHandler.GetFunction(area, controller, action); if (function != null) { dict.Function = function; } return(function); }
/// <summary> /// 获取正在执行的Action的相关功能信息 /// </summary> public static IFunction GetExecuteFunction(this ActionContext context) { const string key = OsharpConstants.CurrentMvcFunctionKey; IDictionary <object, object> items = context.HttpContext.Items; if (items.ContainsKey(key)) { return(items[key] as IFunction); } string area = context.GetAreaName(); string controller = context.GetControllerName(); string action = context.GetActionName(); IFunctionHandler functionHandler = ServiceLocator.Instance.GetService <IFunctionHandler>(); if (functionHandler == null) { throw new OsharpException("获取正在执行的功能时 IFunctionHandler 无法解析"); } IFunction function = functionHandler.GetFunction(area, controller, action); if (function != null) { items.Add(key, function); } return(function); }
private static TOutput ExecuteFunctionShim <TFunction, TOutput>( IFunctionHandler <TFunction, TOutput> handler, TFunction function ) where TFunction : IFunction <TOutput> { return(handler.Execute(function)); }
/// <summary> /// 开始执行框架初始化 /// </summary> /// <param name="iocBuilder">依赖注入构建器</param> public void Initialize(IIocBuilder iocBuilder) { iocBuilder.CheckNotNull("iocBuilder"); OSharpConfig config = OSharpConfig.Instance; //依赖注入初始化 IServiceProvider provider = iocBuilder.Build(); //对象映射功能初始化 IMappersBuilder mappersBuilder = provider.GetService <IMappersBuilder>(); IMapper mapper = provider.GetService <IMapper>(); if (!_mapperInitialized && mapper != null) { if (mappersBuilder != null) { IEnumerable <IMapTuple> mapTuples = provider.GetServices <IMapTuple>(); mappersBuilder.Build(mapTuples); } MapperExtensions.SetMaper(mapper); _mapperInitialized = true; } //日志功能初始化 IBasicLoggingInitializer loggingInitializer = provider.GetService <IBasicLoggingInitializer>(); if (!_basicLoggingInitialized && loggingInitializer != null) { loggingInitializer.Initialize(config.LoggingConfig); _basicLoggingInitialized = true; } //数据库初始化 IDatabaseInitializer databaseInitializer = provider.GetService <IDatabaseInitializer>(); if (!_databaseInitialized && databaseInitializer != null) { databaseInitializer.Initialize(config.DataConfig); _databaseInitialized = true; } //实体信息初始化 IEntityInfoHandler entityInfoHandler = provider.GetService <IEntityInfoHandler>(); if (!_entityInfoInitialized && entityInfoHandler != null) { entityInfoHandler.Initialize(); _entityInfoInitialized = true; } //功能信息初始化 IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); if (functionHandler != null) { functionHandler.Initialize(); } }
/// <summary> /// 事件处理 /// </summary> /// <param name="eventData">事件源数据</param> public override void Handle(FunctionCacheRefreshEventData eventData) { if (!_provider.InHttpRequest()) { return; } IFunctionHandler functionHandler = _provider.GetService <IFunctionHandler>(); functionHandler.RefreshCache(); }
/// <summary> /// 事件处理 /// </summary> /// <param name="eventData">事件源数据</param> public override void Handle(FunctionCacheRefreshEventData eventData) { if (!ServiceLocator.InScoped()) { return; } IFunctionHandler functionHandler = _provider.GetService <IFunctionHandler>(); functionHandler.RefreshCache(); }
/// <summary> /// 开始执行框架初始化 /// </summary> /// <param name="services">服务映射集合</param> /// <param name="iocBuilder">依赖注入构建器</param> public void Initialize(IServiceCollection services, IIocBuilder iocBuilder) { services.CheckNotNull("services"); iocBuilder.CheckNotNull("iocBuilder"); OSharpConfig config = OSharpConfig.Instance; //使用副本进行初始化,防止不同平台间的相互污染 IServiceCollection newServices = services.Clone(); //依赖注入初始化 IServiceProvider provider = iocBuilder.Build(newServices); //日志功能初始化 IBasicLoggingInitializer loggingInitializer = provider.GetService <IBasicLoggingInitializer>(); if (!_basicLoggingInitialized && loggingInitializer != null) { loggingInitializer.Initialize(config.LoggingConfig); _basicLoggingInitialized = true; } //数据库初始化 IDatabaseInitializer databaseInitializer = provider.GetService <IDatabaseInitializer>(); if (!_databaseInitialized) { if (databaseInitializer == null) { throw new InvalidOperationException(Resources.FrameworkInitializerBase_DatabaseInitializeIsNull); } databaseInitializer.Initialize(config.DataConfig); _databaseInitialized = true; } //实体信息初始化 if (!_entityInfoInitialized) { IEntityInfoHandler entityInfoHandler = provider.GetService <IEntityInfoHandler>(); if (entityInfoHandler == null) { throw new InvalidOperationException(Resources.FrameworkInitializerBase_EntityInfoHandlerIsNull); } entityInfoHandler.Initialize(); _entityInfoInitialized = true; } //功能信息初始化 IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); if (functionHandler == null) { throw new InvalidOperationException(Resources.FrameworkInitializerBase_FunctionHandlerIsNull); } functionHandler.Initialize(); }
/// <summary> /// 更新功能信息信息 /// </summary> /// <param name="dtos">包含更新信息的功能信息DTO信息</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> EditFunctions(params FunctionDto[] dtos) { dtos.CheckNotNull("dtos"); List <string> names = new List <string>(); FunctionRepository.UnitOfWork.TransactionEnabled = true; foreach (FunctionDto dto in dtos) { //if (FunctionRepository.CheckExists(m => m.Name == dto.Name, dto.Id)) //{ // return new OperationResult(OperationResultType.Error, "名称为“{0}”的功能信息已存在".FormatWith(dto.Name)); //} Function entity = FunctionRepository.GetByKey(dto.Id); if (entity == null) { return(new OperationResult(OperationResultType.QueryNull)); } FunctionType oldType = entity.FunctionType; bool oldIsMenu = entity.IsMenu; int oldOrderNo = entity.OrderNo; if (dto.DataLogEnabled && !dto.OperateLogEnabled && !entity.OperateLogEnabled && !entity.DataLogEnabled) { dto.OperateLogEnabled = true; } else if (!dto.OperateLogEnabled && dto.DataLogEnabled && entity.OperateLogEnabled && entity.DataLogEnabled) { dto.DataLogEnabled = false; } entity = dto.MapTo(entity); if (entity.Url.IsNullOrEmpty()) { entity.Url = null; } if (oldType != entity.FunctionType || oldIsMenu != entity.IsMenu || oldOrderNo != entity.OrderNo) { entity.IsTypeChanged = true; } FunctionRepository.Update(entity); names.Add(entity.Name); } int count = await FunctionRepository.UnitOfWork.SaveChangesAsync(); OperationResult result = count > 0 ? new OperationResult(OperationResultType.Success, "功能“{0}”更新成功".FormatWith(names.ExpandAndToString())) : new OperationResult(OperationResultType.NoChanged); if (result.ResultType == OperationResultType.Success) { IFunctionHandler handler = ServiceProvider.GetService <IFunctionHandler>(); handler.RefreshCache(); } return(result); }
private IFunctionHandler GetHandler() { IServiceCollection services = new ServiceCollection(); services.AddLogging(); services.AddSingleton <IFunctionHandler, MvcFunctionHandler>(); IServiceProvider provider = services.BuildServiceProvider(); IFunctionHandler handler = provider.GetRequiredService <IFunctionHandler>(); return(handler); }
/// <summary> /// 应用模块服务 /// </summary> /// <param name="app">应用程序构建器</param> public override void UsePack(IApplicationBuilder app) { IFunctionHandler functionHandler = app.ApplicationServices.GetServices <IFunctionHandler>().FirstOrDefault(m => m.GetType() == typeof(MvcFunctionHandler)); if (functionHandler == null) { return; } functionHandler.Initialize(); IsEnabled = true; }
/// <summary> /// 使用模块服务 /// </summary> /// <param name="provider"></param> public override void UsePack(IServiceProvider provider) { IFunctionHandler functionHandler = provider.GetServices <IFunctionHandler>().FirstOrDefault(m => m.GetType() == typeof(MvcFunctionHandler)); if (functionHandler == null) { return; } functionHandler.Initialize(); IsEnabled = true; }
/// <summary> /// 更新功能信息信息 /// </summary> /// <param name="dtos">包含更新信息的功能信息DTO信息</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> UpdateFunctions(params FunctionInputDto[] dtos) { dtos.CheckNotNull(nameof(dtos)); List <string> names = new List <string>(); FunctionRepository.UnitOfWork.TransactionEnabled = true; foreach (FunctionInputDto dto in dtos) { if (await FunctionRepository.CheckExistsAsync(m => m.Name == dto.Name, dto.Id)) { return(new OperationResult(OperationResultType.Error, $"名称为“{dto.Name}”的功能信息已存在")); } Function entity = await FunctionRepository.GetByKeyAsync(dto.Id); if (entity == null) { return(new OperationResult(OperationResultType.QueryNull)); } FunctionType oldType = entity.FunctionType; if (dto.DataLogEnabled && !dto.OperateLogEnabled && !entity.OperateLogEnabled && !entity.DataLogEnabled) { dto.OperateLogEnabled = true; } else if (!dto.OperateLogEnabled && dto.DataLogEnabled && entity.OperateLogEnabled && entity.DataLogEnabled) { dto.DataLogEnabled = false; } entity = dto.MapTo(entity); if (entity.Url.IsNullOrEmpty()) { entity.Url = null; } if (oldType != entity.FunctionType) { entity.IsTypeChanged = true; } await FunctionRepository.UpdateAsync(entity); names.Add(entity.Name); } int count = await FunctionRepository.UnitOfWork.SaveChangesAsync(); OperationResult result = count > 0 ? new OperationResult(OperationResultType.Success, $"功能“{names.ExpandAndToString()}”更新成功") : new OperationResult(OperationResultType.NoChanged); if (result.ResultType == OperationResultType.Success) { IFunctionHandler handler = ServiceProvider.GetService <IFunctionHandler>(); handler.RefreshCache(); } return(result); }
/// <summary> /// 检测当前用户是否有指定功能的功能权限 /// </summary> public static bool CheckFunctionAuth(this ControllerBase controller, string actionName, string controllerName, string areaName = null) { IServiceProvider provider = controller.HttpContext.RequestServices; IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); IFunction function = functionHandler?.GetFunction(areaName, controllerName, actionName); if (function == null) { return(false); } IFunctionAuthorization authorization = provider.GetService <IFunctionAuthorization>(); return(authorization.Authorize(function, controller.User).IsOk); }
/// <summary> /// 应用功能权限授权 /// </summary> public static IApplicationBuilder UseFunctionAuthorization(this IApplicationBuilder app) { app.UseAuthorization(); IServiceProvider provider = app.ApplicationServices; IModuleHandler moduleHandler = provider.GetService <IModuleHandler>(); moduleHandler.Initialize(); IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); functionHandler.RefreshCache(); return(app); }
public int Add(IFunctionHandler lambda) { if (_identifiers.TryGetValue(lambda.UniqueIdentifier(), out int existingIdentifier)) { return(existingIdentifier); } _functionIdentifier++; _identifiers.Add(lambda.UniqueIdentifier(), _functionIdentifier); // Update the parameter count. _parameterCount = Math.Max(_parameterCount, lambda.ParameterCount()); // Add the function handler. _functionHandlers.Add(lambda); return(_functionIdentifier); }
/// <summary> /// 应用AspNetCore的服务业务 /// </summary> /// <param name="app">Asp应用程序构建器</param> public override void UsePack(IApplicationBuilder app) { app.UseAuthorization(); app.UseCookiePolicy(); IServiceProvider provider = app.ApplicationServices; IModuleHandler moduleHandler = provider.GetService <IModuleHandler>(); moduleHandler.Initialize(); IFunctionHandler functionHandler = provider.GetService <IFunctionHandler>(); functionHandler.RefreshCache(); IsEnabled = true; }
public void Subcall(ActionSet actionSet, IFunctionHandler function) { // We use a new actionSet rather than _actionSet in case the caller needs special adjustments. if (function.IsSubroutine()) { ExecuteSubroutine(function, CallHandler?.ParallelMode ?? CallParallel.NoParallel); // Bridge the returned value. if (Determiner.ReturnsValue()) { ReturnHandler.ReturnValue(function.GetSubroutineInfo().ReturnHandler.GetReturnedValue()); } } else { function.ParseInner(actionSet); } }
public void GetLambdaStatement(PortableLambdaType expecting) { bool found = false; _type = expecting; foreach (var func in Group.Functions) { if (func.Parameters.Length == expecting.Parameters.Length) { // Make sure the method implements the target lambda. for (int i = 0; i < func.Parameters.Length; i++) { if (!func.Parameters[i].Type.Implements(expecting.Parameters[i])) { continue; } } _chosenFunction = func; found = true; break; } } // If a compatible function was found, get the handler. if (found) { _functionHandler = GetLambdaHandler(_chosenFunction); _identifier = _parseInfo.TranslateInfo.GetComponent <LambdaGroup>().Add(_functionHandler); // Get the variable's invoke info from the parameters. InvokedState = new IBridgeInvocable[_functionHandler.ParameterCount()]; for (int i = 0; i < _functionHandler.ParameterCount(); i++) { if (_functionHandler.GetParameterVar(i) is Var var) { InvokedState[i] = var.BridgeInvocable; } } } else { _parseInfo.Script.Diagnostics.Error("No overload for '" + Group.Name + "' implements " + expecting.GetName(), _range); } }