private Task SearchTemplater(
            string file,
            string domainObject,
            Try <object> spec,
            HttpContext context)
        {
            if (spec.IsFailure)
            {
                return(Task.CompletedTask);
            }
            var accept     = CommandConverter.Accept(context.Request.Headers);
            var requestPdf = accept == "application/pdf";

            return(Converter.PassThrough <TemplaterProcessDocument, TemplaterProcessDocument.Argument <object> >(
                       new TemplaterProcessDocument.Argument <object>
            {
                File = Path.GetFileName(file),
                SearchSources =
                    new[] {
                    new SearchDomainObject.Argument <object>
                    {
                        SpecificationName = null,
                        Specification = spec.Result,
                        Name = domainObject
                    }
                },
                ToPdf = requestPdf
            },
                       "application/octet-stream",
                       context,
                       EmptyCommands,
                       requestPdf ? "application/pdf" : null));
        }
        //TODO: should use uri of query parameter
        public Task FindTemplater(string file, string domainObject, string uri, HttpContext context)
        {
            var request  = context.Request;
            var response = context.Response;
            var type     = Utility.CheckIdentifiable(DomainModel, domainObject, response);

            if (type.IsFailure)
            {
                return(Task.CompletedTask);
            }
            var accept     = CommandConverter.Accept(request.Headers);
            var requestPdf = accept == "application/pdf";

            return(Converter.PassThrough <TemplaterProcessDocument, TemplaterProcessDocument.Argument <object> >(
                       new TemplaterProcessDocument.Argument <object>
            {
                File = Path.GetFileName(file),
                GetSources = new[] { new GetDomainObject.Argument {
                                         Name = domainObject, Uri = new[] { uri }
                                     } },
                ToPdf = requestPdf
            },
                       "application/octet-stream",
                       context,
                       EmptyCommands,
                       requestPdf ? "application/pdf" : null));
        }
        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));
        }