using BuddyFinance.Integration.Models.Enums; using BuddyFinance.Integration.Models.ReportingServices; using BuddyFinance.Integration.Models.Statements; using Microsoft.Reporting.WebForms.Internal.Soap.ReportingServices2005.Execution; //using Microsoft.Reporting.WinForms.Internal.Soap.ReportingServices2005.Execution; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; namespace BuddyFinance.Integration { public class ReportServiceIntergrator { public GetPDF GetReport(GetStatement statement) { var results = new GetPDF(); try { using (var service = new ReportExecutionService()) { string path = $"/BuddyFinance/{ConfigurationManager.AppSettings["env"]}/Transactions"; ParameterValue[] params_ = new ParameterValue[3]; params_[0] = new ParameterValue() { Name = "profileId", Value = statement.ProfileId.ToString() }; params_[1] = new ParameterValue() { Name = "startDate", Value = statement.StartDate?.ToString("yyyy-MM-dd hh:mm") ?? null }; params_[2] = new ParameterValue() { Name = "endDate", Value = statement.EndDate?.ToString("yyyy-MM-dd hh:mm") ?? null }; service.UseDefaultCredentials = true; service.LoadReport(path, null); service.SetExecutionParameters(params_, "EN-US"); string ext = ""; string mime = ""; string encoding = ""; Warning[] warning = null; string[] streams = null; var reprtBytes = service.Render("PDF", "", out ext, out mime, out encoding, out warning, out streams); if (reprtBytes != null) { results.Result = reprtBytes;//Convert.ToBase64String(reprtBytes); results.ErrorCode = (int)ResponseCodes.Success; results.ErrorMessage = "Success"; } else { results.ErrorCode = (int)ResponseCodes.NotFound; results.ErrorMessage = "Not found"; } } } catch (Exception ex) { results.ErrorCode = (int)ResponseCodes.Exception; results.ErrorMessage = ex.Message; } return results; } } }