Exemple #1
0
        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);
        }
Exemple #2
0
        public async Task Invoke(RefreshContext <TService> ctx)
        {
            DbSetInfo dbSetInfo = ctx.Request.GetDbSetInfo() ?? throw new InvalidOperationException($"Could not get the DbSet for {ctx.Request.dbSetName}");
            IServiceOperationsHelper <TService> serviceHelper = ctx.ServiceContainer.GetServiceHelper();
            RunTimeMetadata metadata = ctx.Service.GetMetadata();

            RequestContext req = RefreshContext <TService> .CreateRequestContext(ctx.Service, ctx.Request.rowInfo);

            using (RequestCallContext callContext = new RequestCallContext(req))
            {
                MethodInfoData methodData = metadata.GetOperationMethodInfo(ctx.Request.dbSetName, MethodType.Refresh);
                object         instance   = serviceHelper.GetMethodOwner(methodData);
                object         invokeRes  = methodData.MethodInfo.Invoke(instance, new object[] { ctx.Request });
                object         dbEntity   = await serviceHelper.GetMethodResult(invokeRes);

                if (dbEntity != null)
                {
                    serviceHelper.UpdateRowInfoFromEntity(dbEntity, ctx.Request.rowInfo);
                }
                else
                {
                    throw new InvalidOperationException($"Refresh Operation for {ctx.Request.dbSetName} did not return a result");
                }
            }

            await _next(ctx);
        }
Exemple #3
0
        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);
        }