-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathReportRenderController.cs
More file actions
127 lines (115 loc) · 5.38 KB
/
ReportRenderController.cs
File metadata and controls
127 lines (115 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using ExpressBase.Common;
using ExpressBase.Common.Constants;
using ExpressBase.Common.Data;
using ExpressBase.Common.ServiceClients;
using ExpressBase.Objects;
using ExpressBase.Objects.ServiceStack_Artifacts;
using ExpressBase.Security;
using ExpressBase.Web.BaseControllers;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using ServiceStack;
using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
namespace ExpressBase.Web.Controllers
{
public class ReportRenderController : EbBaseIntCommonController
{
private IActionResult Pdf { get; set; }
public ReportRenderController(IServiceClient sclient, IRedisClient redis, PooledRedisClientManager pooledRedisManager) : base(sclient, redis, pooledRedisManager) { }
public IActionResult Index(string refid, bool renderLimit = false)
{
ViewBag.Refid = refid;
EbReport Report = EbFormHelper.GetEbObject<EbReport>(refid, this.ServiceClient, this.Redis, null, this.PooledRedisManager);
//EbObjectParticularVersionResponse resultlist = this.ServiceClient.Get<EbObjectParticularVersionResponse>(new EbObjectParticularVersionRequest { RefId = refid });
//EbReport Report = EbSerializers.Json_Deserialize<EbReport>(resultlist.Data[0].Json);
using (var redisReadOnly = this.PooledRedisManager.GetReadOnlyClient())
Report.AfterRedisGet(Redis, this.ServiceClient, redisReadOnly as RedisClient);
ViewBag.Fd = Report;
ViewBag.RenderLimit = renderLimit;
ViewBag.DispName = Report.DisplayName;
return View();
}
public bool Render(string refid, List<Param> Params, bool useRwDb = false)
{
ReportRenderResponse Res = null;
try
{
ProtoBufServiceClient pclient = new ProtoBufServiceClient(this.ServiceClient);
Res = pclient.Get<ReportRenderResponse>(new ReportRenderRequest { Refid = refid, RenderingUserAuthId = this.LoggedInUser.AuthId, ReadingUserAuthId = this.LoggedInUser.AuthId, Params = Params, UseRwDb = useRwDb });
Res.StreamWrapper.Memorystream.Position = 0;
// Set the Content-Disposition header for the file name
Response.Headers.Add("Content-Disposition", $"inline; filename={Res.ReportName + ".pdf"}");
}
catch (Exception e)
{
Console.WriteLine("--------------REPORT exception TS --- " + e.Message + "\n" + e.StackTrace);
}
// Return the PDF file
Pdf = new FileStreamResult(Res.StreamWrapper.Memorystream, "application/pdf")
// { FileDownloadName = Res.ReportName }
;
return true;
}
public IActionResult RenderReport2(string refid, string Params)
{
List<Param> param = (Params == null) ? null : JsonConvert.DeserializeObject<List<Param>>(Params);
Render(refid, param);
return Pdf;
}
public IActionResult Renderlink(string refid, string _params, bool rw = false)
{
byte[] encodedDataAsBytes = System.Convert.FromBase64String(_params);
string returnValue = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
List<Param> param = (returnValue == null) ? null : JsonConvert.DeserializeObject<List<Param>>(returnValue);
Render(refid, param, rw);
// visualizations logic to be implemented
if ((Pdf as FileStreamResult).FileStream.Length > 0)
return Pdf;
else
return Redirect("/StatusCode/500");
}
public void RenderlinkMulti(string refid, string _params, string Sub)
{
try
{
ProtoBufServiceClient pclient = new ProtoBufServiceClient(this.ServiceClient);
ReportRenderResponse Res = pclient.Get<ReportRenderResponse>(new ReportRenderMultipleRequest
{
Refid = refid,
RenderingUserAuthId = this.LoggedInUser.AuthId,
ReadingUserAuthId = this.LoggedInUser.AuthId,
Params = _params,
SubscriptionId = Sub
});
}
catch (Exception e)
{
Console.WriteLine("--------------REPORT exception TS --- " + e.Message + "\n" + e.StackTrace);
}
}
public IActionResult RenderLinkMultiSync(string refId, string rowId)
{
try
{
using (ProtoBufServiceClient pclient = new ProtoBufServiceClient(this.ServiceClient))
{
List<Param> p = new List<Param> { new Param { Name = "id", Value = rowId, Type = "16" } };
ReportRenderMultipleSyncResponse Res = pclient.Get<ReportRenderMultipleSyncResponse>(new ReportRenderMultipleSyncRequest { Refid = refId, RenderingUserAuthId = this.LoggedInUser.AuthId, Params = p });
if (Res.Id > 0)
return Redirect(Res.Message);
}
}
catch (Exception e) { }
return Redirect("/StatusCode/500");
}
public IActionResult RenderforBot(string refid)
{
Render(refid, null);
return Pdf;
}
}
}