Ejemplo n.º 1
0
 public override async Task Process(TSqlCommand pipe)
 {
     if (this.countOnly)
     {
         await pipe.Sql(cmd).Stream(response.Body, "-1");
     }
     else if (metadata == Metadata.NONE)
     {
         response.ContentType = "application/json;odata.metadata=none;odata=nometadata";
         await pipe
         .Sql(cmd)
         .OnError(async e => await ReturnClientError(response, e))
         .Stream(response.Body, IsSingletonResponse ? "{}" : "{\"value\":[]}");
     }
     else if (metadata == Metadata.MINIMAL)
     {
         response.ContentType = "application/json;odata.metadata=minimal";
         var header = "{\"@odata.context\":\"" + this.metadataUrl + "#" + this.tableSpec.Name + "\",\"value\":";
         await pipe
         .Sql(cmd)
         .OnError(async e => await ReturnClientError(response, e))
         .Stream(response.Body, new Options()
         {
             Prefix = header, DefaultOutput = "[]", Suffix = "}"
         });
     }
     else
     {
         await ReturnClientError(response, new InvalidOperationException("Cannot generate response for metadata type: " + metadata));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Created IActionResult object that contains the processed response result.
        /// </summary>
        /// <param name="pipe">Sql Pipe that will be used to fetch the data.</param>
        /// <returns>ContentResult with the data processed by request.</returns>
        public virtual async Task <IActionResult> GetResult(TSqlCommand mapper)
        {
            IActionResult result = null;

            try
            {
                var json = await GetString(mapper);

                result = new ContentResult()
                {
                    Content     = json,
                    StatusCode  = StatusCodes.Status200OK,
                    ContentType = "application/json"
                };
            } catch (Exception ex)
            {
                result = new ContentResult()
                {
                    Content    = ex.Message,
                    StatusCode = StatusCodes.Status500InternalServerError
                };
            }

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Created IActionResult object that contains the processed response result.
        /// </summary>
        /// <param name="pipe">Sql Pipe that will be used to fetch the data.</param>
        /// <returns>ContentResult with the data processed by request.</returns>
        public virtual Task <string> GetString(TSqlCommand mapper)
        {
            var res = mapper
                      .Sql(cmd)
                      .GetString();

            return(res);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Process the current request and returns result using the target database.
 /// </summary>
 /// <param name="pipe">Sql Pipe that will be used to fetch the data.</param>
 /// <returns>Async task that will stream results.</returns>
 public virtual async Task Process(TSqlCommand pipe)
 {
     response.ContentType = "application/json";
     await pipe.Sql(cmd)
     .OnError(async e => await ReturnClientError(response, e))
     .Stream(response.Body, IsSingletonResponse?"{}":"[]")
     .ConfigureAwait(false);
 }
Ejemplo n.º 5
0
 public override async Task Process(TSqlCommand pipe)
 {
     await ReturnClientError(response, ex);
 }
 public TableSpecGenerator(TSqlCommand cmd, string schema, string table)
 {
     this.Command = cmd;
     this.SchemaName = schema;
     this.TableName = table;
 }