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); }
protected async Task <RefreshInfo> RefreshRowInfo(RefreshInfo info) { var metadata = MetadataHelper.GetInitializedMetadata(this); info.dbSetInfo = metadata.dbSets[info.dbSetName]; var methodData = metadata.getOperationMethodInfo(info.dbSetName, MethodType.Refresh); if (methodData == null) { throw new InvalidOperationException(string.Format(ErrorStrings.ERR_REC_REFRESH_INVALID, info.dbSetInfo.EntityType.Name, GetType().Name)); } info.rowInfo.dbSetInfo = info.dbSetInfo; var authorizer = ServiceContainer.Authorizer; authorizer.CheckUserRightsToExecute(methodData); var req = new RequestContext(this, rowInfo: info.rowInfo, operation: ServiceOperationType.RowRefresh); using (var callContext = new RequestCallContext(req)) { var instance = _serviceHelper.GetMethodOwner(methodData); var invokeRes = methodData.methodInfo.Invoke(instance, new object[] { info }); var dbEntity = await ServiceOperationsHelper.GetMethodResult(invokeRes).ConfigureAwait(false); var rri = new RefreshInfo { rowInfo = info.rowInfo, dbSetName = info.dbSetName }; if (dbEntity != null) { _serviceHelper.UpdateRowInfoFromEntity(dbEntity, info.rowInfo); } else { rri.rowInfo = null; } return(rri); } }