Last active
July 21, 2020 20:06
-
-
Save paulodiogo/ca9f9af2d309f3ce07ae74baa3d3b79d to your computer and use it in GitHub Desktop.
Revisions
-
diogo.leao revised this gist
Jun 8, 2017 . 3 changed files with 61 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ [Serializable] public enum Format { XML, CSV, PDF, EXCELOPENXML, WORDOPENXML } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,25 @@ //Project > References > Add Service Reference > http://<URL>/<APP_SSRS>/ReportExecution2005.asmx //Add the SOAP Execution client public class GenerateReportService { private readonly SSRSEX.ReportExecutionServiceSoapClient clientEX; //NetworkCredential => CredentialCache.DefaultNetworkCredentials or new System.Net.NetworkCredential("user", "pass", "domain") public GenerateReportService(System.Net.NetworkCredential clientCredentials) { clientEX = new SSRSEX.ReportExecutionServiceSoapClient(); clientEX.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; clientEX.ClientCredentials.Windows.ClientCredential = clientCredentials; } public Report Render(string reportName, IDictionary<string, string> parametros, Format format) { string mimeType = string.Empty; string extension = string.Empty; string historyID = null; string deviceInfo = null; byte[] results; @@ -34,23 +35,31 @@ public byte[] Render(string formato, out string mimeType, out string extension) clientEX.LoadReport(trustedUserHeader, reportName, historyID, out serverInfoHeader, out executionInfo); SSRSEX.ParameterValue[] parameters = new SSRSEX.ParameterValue[1]; List<ParameterValue> reportParameters = new List<ParameterValue>(); foreach (var item in parameters) { reportParameters.Add(new ParameterValue { Name = item.Key, Value = item.Value }); } SSRSEX.ExecutionHeader execHeader = new SSRSEX.ExecutionHeader(); execHeader.ExecutionID = executionInfo.ExecutionID; clientEX.SetExecutionParameters(execHeader, trustedUserHeader, reportParameters.ToArray(), "pt-BR", out executionInfo); clientEX.Render(execHeader, trustedUserHeader, format.ToString(), deviceInfo, out results, out extension, out mimeType, out encoding, out warnings, out streamIDs); return new Report(extension, mimeType, results); } public async System.Threading.Tasks.Task<Report> RenderAsync(string reportName, IDictionary<string, string> parameters, Format format) { string historyID = null; string deviceInfo = null; @@ -64,16 +73,24 @@ public async System.Threading.Tasks.Task<Report> RenderAsync(string formato) clientEX.LoadReport(trustedUserHeader, reportName, historyID, out serverInfoHeader, out executionInfo); SSRSEX.ParameterValue[] parameters = new SSRSEX.ParameterValue[1]; List<ParameterValue> reportParameters = new List<ParameterValue>(); foreach (var item in parameters) { reportParameters.Add(new ParameterValue { Name = item.Key, Value = item.Value }); } SSRSEX.ExecutionHeader execHeader = new SSRSEX.ExecutionHeader(); execHeader.ExecutionID = executionInfo.ExecutionID; clientEX.SetExecutionParameters(execHeader, trustedUserHeader, reportParameters.ToArray(), "pt-BR", out executionInfo); SSRSEX.RenderRequest renderReq = new SSRSEX.RenderRequest(execHeader, trustedUserHeader, format.ToString(), deviceInfo); SSRSEX.RenderResponse taskRender = await clientEX.RenderAsync(renderReq); return new Report(taskRender.Extension, taskRender.MimeType, taskRender.Result); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,28 +1,37 @@ public class UsingController { private readonly GenerateReportService executer; public UsingController(GenerateReportService executer) { this.executer = executer; } public async System.Threading.Tasks.Task<ActionResult> IndexOne(int year, string format) { var parameters = new Dictionary<string, string>(); parameters.Add("Year", year.ToString()); var reportFormat = (Format)Enum.Parse(typeof(Format), format); var relatorio = await this.executer.RenderAsync("reportName", parameters, format); return File(relatorio.Results, relatorio.MimeType, string.Format("relatorio.{0}", relatorio.Extension)); } public ActionResult IndexTwo(string format) { var parameters = new Dictionary<string, string>(); parameters.Add("Year", year.ToString()); var reportFormat = (Format)Enum.Parse(typeof(Format), format); var relatorio = this.executer.Render("reportName", parameters, format); return File(relatorio.Results, relatorio.MimeType, string.Format("relatorio.{0}", relatorio.Extension)); } -
paulodiogo revised this gist
May 31, 2017 . No changes.There are no files selected for viewing
-
paulodiogo revised this gist
May 31, 2017 . No changes.There are no files selected for viewing
-
paulodiogo revised this gist
May 31, 2017 . No changes.There are no files selected for viewing
-
paulodiogo revised this gist
May 31, 2017 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ public class UsingController { private readonly ExecuteReport executer; public UsingController(ExecuteReport executer) { this.executer = executer; } public async System.Threading.Tasks.Task<ActionResult> IndexOne(string format) { var relatorio = await this.executer.RenderAsync(format); return File(relatorio.Results, relatorio.MimeType, string.Format("relatorio.{0}", relatorio.Extension)); } public ActionResult IndexTwo(string format) { string mimeType = null; string extension = null; var bytes = this.executer.Render(format, out mimeType, out extension); return File(bytes, mimeType, string.Format("relatorio.{0}", extension)); } } -
paulodiogo revised this gist
May 31, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -50,7 +50,7 @@ public byte[] Render(string formato, out string mimeType, out string extension) } public async System.Threading.Tasks.Task<Report> RenderAsync(string formato) { string historyID = null; string deviceInfo = null; -
paulodiogo revised this gist
May 31, 2017 . No changes.There are no files selected for viewing
-
paulodiogo revised this gist
May 31, 2017 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ public class Report { public Report(string extension, string mimeType, byte[] results) { this.Extension = extension; this.MimeType = mimeType; this.Results = results; } public string Extension { get; private set; } public string MimeType { get; private set; } public byte[] Results { get; private set; } } -
paulodiogo created this gist
May 31, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,83 @@ //Project > References > Add Service Reference > http://<URL>/<APP_SSRS>/ReportExecution2005.asmx //Add the SOAP Execution client public class ExecuteReport { private const string reportName = @"<path>/name"; private readonly SSRSEX.ReportExecutionServiceSoapClient clientEX; //NetworkCredential => CredentialCache.DefaultNetworkCredentials or new System.Net.NetworkCredential("user", "pass", "domain") public ExecuteReport(System.Net.NetworkCredential clientCredentials) { clientEX = new SSRSEX.ReportExecutionServiceSoapClient(); clientEX.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; clientEX.ClientCredentials.Windows.ClientCredential = clientCredentials; } public byte[] Render(string formato, out string mimeType, out string extension) { string historyID = null; string deviceInfo = null; byte[] results; string encoding = string.Empty; SSRSEX.Warning[] warnings = null; string[] streamIDs = null; clientEX.Open(); SSRSEX.ServerInfoHeader serverInfoHeader = null; SSRSEX.ExecutionInfo executionInfo = null; SSRSEX.TrustedUserHeader trustedUserHeader = new SSRSEX.TrustedUserHeader(); clientEX.LoadReport(trustedUserHeader, reportName, historyID, out serverInfoHeader, out executionInfo); SSRSEX.ParameterValue[] parameters = new SSRSEX.ParameterValue[1]; parameters[0] = new SSRSEX.ParameterValue(); parameters[0].Name = "ParameterName"; parameters[0].Value = "ParameterValue"; SSRSEX.ExecutionHeader execHeader = new SSRSEX.ExecutionHeader(); execHeader.ExecutionID = executionInfo.ExecutionID; clientEX.SetExecutionParameters(execHeader, trustedUserHeader, parameters, "pt-BR", out executionInfo); clientEX.Render(execHeader, trustedUserHeader, formato, deviceInfo, out results, out extension, out mimeType, out encoding, out warnings, out streamIDs); return results; } public async System.Threading.Tasks.Task<Report> Render(string formato) { string historyID = null; string deviceInfo = null; string encoding = string.Empty; clientEX.Open(); SSRSEX.ServerInfoHeader serverInfoHeader = null; SSRSEX.ExecutionInfo executionInfo = null; SSRSEX.TrustedUserHeader trustedUserHeader = new SSRSEX.TrustedUserHeader(); clientEX.LoadReport(trustedUserHeader, reportName, historyID, out serverInfoHeader, out executionInfo); SSRSEX.ParameterValue[] parameters = new SSRSEX.ParameterValue[1]; parameters[0] = new SSRSEX.ParameterValue(); parameters[0].Name = "ParameterName"; parameters[0].Value = "ParameterValue"; SSRSEX.ExecutionHeader execHeader = new SSRSEX.ExecutionHeader(); execHeader.ExecutionID = executionInfo.ExecutionID; clientEX.SetExecutionParameters(execHeader, trustedUserHeader, parameters, "pt-BR", out executionInfo); SSRSEX.RenderRequest renderReq = new SSRSEX.RenderRequest(execHeader, trustedUserHeader, formato, deviceInfo); SSRSEX.RenderResponse taskRender = await clientEX.RenderAsync(renderReq); return new Report(taskRender.Extension, taskRender.MimeType, taskRender.Result); } }