public async Task Invoke(InvokeContext <TService> ctx) { IDataHelper <TService> dataHelper = ctx.ServiceContainer.GetDataHelper(); IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper(); RunTimeMetadata metadata = ctx.Service.GetMetadata(); MethodDescription method = metadata.GetInvokeMethod(ctx.Request.methodName); List <object> methParams = new List <object>(); for (int i = 0; i < method.parameters.Count; ++i) { methParams.Add(ctx.Request.paramInfo.GetValue(method.parameters[i].name, method, dataHelper)); } RequestContext req = InvokeContext <TService> .CreateRequestContext(ctx.Service); using (RequestCallContext callContext = new RequestCallContext(req)) { MethodInfoData methodData = method.GetMethodData(); object instance = serviceHelper.GetMethodOwner(methodData); object invokeRes = methodData.MethodInfo.Invoke(instance, methParams.ToArray()); object methodResult = await serviceHelper.GetMethodResult(invokeRes); if (method.methodResult) { ctx.Response.result = methodResult; } } await _next(ctx); }
public async Task Invoke(QueryContext <TService> ctx) { Security.IAuthorizer <TService> authorizer = ctx.ServiceContainer.GetAuthorizer(); RunTimeMetadata metadata = ctx.Service.GetMetadata(); MethodDescription method = metadata.GetQueryMethod(ctx.Request.dbSetName, ctx.Request.queryName); await authorizer.CheckUserRightsToExecute(method.GetMethodData()); await _next(ctx); }
public async Task Invoke(QueryContext <TService> ctx) { DbSetInfo dbSetInfo = ctx.Request.GetDbSetInfo() ?? throw new InvalidOperationException($"Could not get the DbSet for {ctx.Request.dbSetName}"); IDataHelper <TService> dataHelper = ctx.ServiceContainer.GetDataHelper(); IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper(); RunTimeMetadata metadata = ctx.Service.GetMetadata(); MethodDescription method = metadata.GetQueryMethod(ctx.Request.dbSetName, ctx.Request.queryName); LinkedList <object> methParams = new LinkedList <object>(); for (int i = 0; i < method.parameters.Count; ++i) { methParams.AddLast(ctx.Request.paramInfo.GetValue(method.parameters[i].name, method, dataHelper)); } RequestContext req = QueryContext <TService> .CreateRequestContext(ctx.Service, ctx.Request); using (RequestCallContext callContext = new RequestCallContext(req)) { MethodInfoData methodData = method.GetMethodData(); object instance = serviceHelper.GetMethodOwner(methodData); object invokeRes = methodData.MethodInfo.Invoke(instance, methParams.ToArray()); QueryResult queryResult = (QueryResult)await serviceHelper.GetMethodResult(invokeRes); IEnumerable <object> entities = queryResult.Result; int? totalCount = queryResult.TotalCount; RowGenerator rowGenerator = new RowGenerator(dbSetInfo, entities, dataHelper); IEnumerable <Row> rows = rowGenerator.CreateRows(); SubsetsGenerator subsetsGenerator = new SubsetsGenerator(metadata, dataHelper); SubsetList subResults = subsetsGenerator.CreateSubsets(queryResult.subResults); ctx.Response.names = dbSetInfo.GetNames(); ctx.Response.totalCount = totalCount; ctx.Response.rows = rows; ctx.Response.subsets = subResults; ctx.Response.extraInfo = queryResult.extraInfo; } await _next(ctx); }