コード例 #1
0
        /// <summary>
        /// Overload for more sophisticated rendering.
        /// </summary>
        /// <param name="request">ram name="request">Description of rendering process <see cref="RenderRequest"/></param>
        /// <exception cref="JsReportException"></exception>
        /// <returns>Report result promise</returns>
        public async Task <Report> RenderAsync(RenderRequest request)
        {
            request.options = request.options ?? new RenderOptions();
            request.CopyDynamicAttributes();

            request.Validate();

            var client   = CreateClient();
            var settings = new JsonSerializerSettings()
            {
                NullValueHandling          = NullValueHandling.Ignore,
                ReferenceLoopHandling      = Newtonsoft.Json.ReferenceLoopHandling.Serialize,
                PreserveReferencesHandling = PreserveReferencesHandling.All
            };

            var response =
                await
                client.PostAsync("api/report",
                                 new StringContent(JsonConvert.SerializeObject(request, settings), Encoding.UTF8,
                                                   "application/json")).ConfigureAwait(false);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw JsReportException.Create("Unable to render template. ", response);
            }

            response.EnsureSuccessStatusCode();

            return(await ReportFromResponse(response).ConfigureAwait(false));
        }
コード例 #2
0
        /// <summary>
        /// Reads previously rendered report. see http://jsreport.net/learn/reports
        /// </summary>
        /// <param name="permanentLink">link Report.PernamentLink from previously rendered report</param>
        /// <exception cref="JsReportException"></exception>
        /// <returns>Report result promise</returns>
        public async Task <Report> ReadReportAsync(string permanentLink)
        {
            var client = CreateClient();

            var response = await client.GetAsync(permanentLink).ConfigureAwait(false);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw JsReportException.Create("Unable to retrieve report content. ", response);
            }

            response.EnsureSuccessStatusCode();

            return(await ReportFromResponse(response).ConfigureAwait(false));
        }
コード例 #3
0
ファイル: ReportingService.cs プロジェクト: BerendWouters/net
        /// <summary>
        /// Specify comnpletely the rendering requests, see http://jsreport.net/learn/api for details
        /// </summary>
        /// <param name="request">ram name="request">Description of rendering process</param>
        /// <exception cref="JsReportException"></exception>
        /// <returns>Report result promise</returns>
        public async Task <Report> RenderAsync(object request, CancellationToken ct = default(CancellationToken))
        {
            var client = CreateClient();

            var response =
                await
                client.PostAsync("api/report",
                                 new StringContent(ValidateAndSerializeRequest(request), Encoding.UTF8,
                                                   "application/json"), ct).ConfigureAwait(false);


            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw JsReportException.Create("Unable to render template. ", response);
            }

            response.EnsureSuccessStatusCode();

            return(await ReportFromResponse(response).ConfigureAwait(false));
        }
コード例 #4
0
ファイル: ReportingService.cs プロジェクト: vavachi/net
        /// <summary>
        /// Specify comnpletely the rendering requests, see http://jsreport.net/learn/api for details
        /// </summary>
        /// <param name="request">ram name="request">Description of rendering process</param>
        /// <exception cref="JsReportException"></exception>
        /// <returns>Report result promise</returns>
        public async Task <Report> RenderAsync(object request, CancellationToken ct = default(CancellationToken))
        {
            var         client = CreateClient();
            HttpContent content;

            if (Compression)
            {
                byte[] jsonBytes = Encoding.UTF8.GetBytes(ValidateAndSerializeRequest(request));
                var    ms        = new MemoryStream();
                using (var gzip = new GZipStream(ms, CompressionMode.Compress, true))
                {
                    gzip.Write(jsonBytes, 0, jsonBytes.Length);
                }
                ms.Position = 0;

                content = new StreamContent(ms);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                content.Headers.ContentEncoding.Add("gzip");
            }
            else
            {
                content = new StringContent(ValidateAndSerializeRequest(request), Encoding.UTF8,
                                            "application/json");
            }

            var response =
                await
                client.PostAsync("api/report", content, ct).ConfigureAwait(false);


            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw JsReportException.Create("Unable to render template. ", response);
            }

            response.EnsureSuccessStatusCode();

            return(await ReportFromResponse(response).ConfigureAwait(false));
        }