Exemple #1
0
        public async Task <bool> Handle(RefreshRequest message, IOutputPort <RefreshResponse> outputPort)
        {
            RefreshResponse response = new RefreshResponse {
                rowInfo = message.rowInfo, dbSetName = message.dbSetName
            };

            try
            {
                Metadata.RunTimeMetadata metadata = _service.GetMetadata();
                DbSetInfo dbSetInfo = metadata.DbSets.Get(message.dbSetName) ?? throw new InvalidOperationException($"The DbSet {message.dbSetName} was not found in metadata");
                message.SetDbSetInfo(dbSetInfo);
                message.rowInfo.SetDbSetInfo(dbSetInfo);

                RefreshContext <TService> context = new RefreshContext <TService>(message,
                                                                                  response,
                                                                                  (TService)_service,
                                                                                  _serviceContainer);

                await _pipeline(context);
            }
            catch (Exception ex)
            {
                if (ex is System.Reflection.TargetInvocationException)
                {
                    ex = ex.InnerException;
                }

                string err = _onError(ex);
                response.error = new ErrorInfo(err, ex.GetType().Name);
            }

            outputPort.Handle(response);

            return(true);
        }
        public async Task <bool> Handle(QueryRequest message, IOutputPort <QueryResponse> outputPort)
        {
            QueryResponse response = new QueryResponse
            {
                pageIndex  = message.pageIndex,
                pageCount  = message.pageCount,
                dbSetName  = message.dbSetName,
                rows       = new Row[0],
                totalCount = null,
                error      = null
            };

            try
            {
                Metadata.RunTimeMetadata metadata = _service.GetMetadata();
                DbSetInfo dbSetInfo = metadata.DbSets.Get(message.dbSetName) ?? throw new InvalidOperationException($"The DbSet {message.dbSetName} was not found in metadata");
                message.SetDbSetInfo(dbSetInfo);

                bool isMultyPageRequest = dbSetInfo.enablePaging && message.pageCount > 1;

                QueryContext <TService> context = new QueryContext <TService>(message,
                                                                              response,
                                                                              (TService)_service,
                                                                              _serviceContainer,
                                                                              isMultyPageRequest);

                await _pipeline(context);
            }
            catch (Exception ex)
            {
                if (ex is TargetInvocationException)
                {
                    ex = ex.InnerException;
                }

                string err = _onError(ex);
                response.error = new ErrorInfo(err, ex.GetType().Name);
            }

            outputPort.Handle(response);

            return(true);
        }