Пример #1
0
 public CrudController(
     IServiceProvider locator,
     CommandConverter converter,
     IDomainModel domainModel,
     IWireSerialization serialization)
 {
     this.Locator       = locator;
     this.Converter     = converter;
     this.DomainModel   = domainModel;
     this.Serialization = serialization;
 }
 public ReportingMiddleware(
     IServiceProvider locator,
     CommandConverter converter,
     IDomainModel domainModel,
     IWireSerialization serialization)
 {
     this.Locator       = locator;
     this.Converter     = converter;
     this.DomainModel   = domainModel;
     this.Serialization = serialization;
 }
Пример #3
0
        public void Search(
            string domainObject,
            [FromQuery(Name = "specification")] string specification = null,
            [FromQuery(Name = "limit")] int?limit    = null,
            [FromQuery(Name = "offset")] int?offset  = null,
            [FromQuery(Name = "order")] string order = null,
            [FromQuery(Name = "count")] string count = null)
        {
            var request  = HttpContext.Request;
            var response = HttpContext.Response;
            var doType   = Utility.CheckDomainObject(DomainModel, domainObject, response);
            var specType = Utility.CheckDomainObject(DomainModel, doType, specification, response);
            var spec     = Utility.ParseObject(Serialization, specType, request.Body, true, Locator, request, response);
            var ordDict  = Utility.ParseOrder(order);

            if (spec.IsFailure)
            {
                return;
            }

            var additionalCommands = EmptyCommands;

            if (limit != null && Utility.IncludeCount(count, request))
            {
                additionalCommands = new[]
                {
                    new AdditionalCommand
                    {
                        Argument = new CountDomainObject.Argument <object>
                        {
                            Name = doType.Result.FullName,
                            SpecificationName = specType.Result != null ? specType.Result.FullName : null,
                            Specification     = spec.Result
                        },
                        CommandType = typeof(CountDomainObject),
                        ToHeader    = "Total-Results"
                    }
                };
            }
            Converter.PassThrough <SearchDomainObject, SearchDomainObject.Argument <object> >(
                new SearchDomainObject.Argument <object>
            {
                Name = doType.Result.FullName,
                SpecificationName = specType.Result != null ? specType.Result.FullName : null,
                Specification     = spec.Result,
                Limit             = limit,
                Offset            = offset,
                Order             = ordDict
            },
                CommandConverter.Accept(request.Headers),
                HttpContext,
                additionalCommands);
        }
Пример #4
0
        public Task SearchGeneric(string domainObject, HttpContext context)
        {
            var request = context.Request;
            var response = context.Response;
            var doType = Utility.CheckDomainObject(DomainModel, domainObject, response);
            var spec = Utility.ParseGenericSpecification(Serialization, doType, context);
            int?limit, offset;

            Utility.ParseLimitOffset(request.Query, out limit, out offset);
            var order   = request.Query.ContainsKey("order") ? request.Query["order"][0] : null;
            var count   = request.Query.ContainsKey("count") ? request.Query["count"][0] : null;
            var ordDict = Utility.ParseOrder(order);

            if (spec.IsFailure)
            {
                return(Task.CompletedTask);
            }

            var additionalCommands = EmptyCommands;

            if (limit != null && Utility.IncludeCount(count, request))
            {
                additionalCommands = new[]
                {
                    new AdditionalCommand
                    {
                        Argument = new CountDomainObject.Argument <object>
                        {
                            Name = doType.Result.FullName,
                            SpecificationName = null,
                            Specification     = spec.Result
                        },
                        CommandType = typeof(CountDomainObject),
                        ToHeader    = "Total-Results"
                    }
                };
            }
            return(Converter.PassThrough <SearchDomainObject, SearchDomainObject.Argument <object> >(
                       new SearchDomainObject.Argument <object>
            {
                Name = doType.Result.FullName,
                SpecificationName = null,
                Specification = spec.Result,
                Limit = limit,
                Offset = offset,
                Order = ordDict
            },
                       CommandConverter.Accept(request.Headers),
                       context,
                       additionalCommands));
        }