Skip to content

Commit

Permalink
#11 - Find only works for current page. #13 - Unicode in report name …
Browse files Browse the repository at this point in the history
…not supported. #16 - attempt at fixing the HTTPS server issue.
  • Loading branch information
Alan Juden committed Feb 28, 2017
1 parent d53c259 commit c741c6e
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<link type="text/css" rel="stylesheet" href="~/css/select2.min.css" />
<link type="text/css" rel="stylesheet" href="~/css/select2-bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="~/css/mvcreportviewer-bootstrap.css" />
<style type="text/css">
.row {
margin-left: 0;
margin-right: 0;
}
</style>
<script type="text/javascript" src="~/js/select2.min.4.0.3.js"></script>
<script type="text/javascript" src="~/js/jquery.highlight-5.js"></script>
<script type="text/javascript">
Expand Down Expand Up @@ -58,8 +64,12 @@
exportReport($(this));
});
$('#ReportViewerSearchText').change(function () {
findText();
$('#ReportViewerSearchText').on("keypress", function (e) {
if (e.keyCode == 13) {
// Cancel the default action on keypress event
e.preventDefault();
findText();
}
});
$('.FindTextButton').click(function () {
Expand All @@ -72,8 +82,10 @@
});
function showLoadingProgress(message) {
hideLoadingProgress();
$('.ReportViewerContent').hide();
$('.ReportViewerContentContainer').append('<div class="loadingContainer"><div style="margin: 0 auto; width: 100%; text-align: center; vertical-align: middle;"><h2><i class="glyphicon glyphicon-cog gly-spin"></i>' + message + '</h2></div></div>');
$('.ReportViewerContentContainer').append('<div class="loadingContainer"><div style="margin: 0 auto; width: 100%; text-align: center; vertical-align: middle;"><h2><i class="glyphicon glyphicon-refresh gly-spin"></i>' + message + '</h2></div></div>');
}
function hideLoadingProgress() {
Expand All @@ -85,7 +97,7 @@
var params = $('.ParametersContainer :input').serializeArray();
var urlParams = $.param(params);
window.open("/Report/PrintReport/[email protected]&" + urlParams, "_blank");
window.open("/Report/PrintReport/[email protected].UrlEncode()&" + urlParams, "_blank");
}
function findText() {
Expand All @@ -96,19 +108,23 @@
var params = $('.ParametersContainer :input').serializeArray();
var urlParams = $.param(params);
var page = parseInt($('#ReportViewerCurrentPage').val()) + 1;
var page = parseInt($('#ReportViewerCurrentPage').val());
$.get("/Report/FindStringInReport/[email protected]&page=" + page + "&" + urlParams).done(function (data) {
$.get("/Report/FindStringInReport/[email protected].UrlEncode()&page=" + page + "&searchText=" + searchText + "&" + urlParams).done(function (data) {
if (data > 0) {
viewReportPage(data);
viewReportPage(data, function () {
$('.ReportViewerContent').highlight(searchText);
hideLoadingProgress();
});
} else {
$('.ReportViewerContent').highlight(searchText);
hideLoadingProgress();
}
$('.ReportViewerContent').highlight(searchText);
hideLoadingProgress();
});
}
}
function viewReportPage(page) {
function viewReportPage(page, afterReportLoadedCallback) {
showLoadingProgress('Loading Report Page...');
var params = $('.ParametersContainer :input').serializeArray();
var urlParams = $.param(params);
Expand All @@ -120,10 +136,14 @@
page = totalPages;
}
$.get("/Report/ViewReportPage/[email protected]&page=" + page + "&" + urlParams)
$.get("/Report/ViewReportPage/[email protected].UrlEncode()&page=" + page + "&" + urlParams)
.done(function (data) {
updateReportContent(data);
hideLoadingProgress();
if (afterReportLoadedCallback && typeof (afterReportLoadedCallback) == "function") {
afterReportLoadedCallback();
}
})
.fail(function (data) {
$('.ReportViewerContent').html("<div class='ReportViewerError'>Report failed to load, check report parameters...</div>");
Expand All @@ -136,7 +156,7 @@
var urlParams = $.param(params);
var format = $(element).attr('class').replace("Export", "");
window.location.href = "/Report/ExportReport/[email protected]&format=" + format + "&" + urlParams;
window.location.href = "/Report/ExportReport/[email protected].UrlEncode()&format=" + format + "&" + urlParams;
}
function updateReportContent(data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@

span a[disabled=disabled] {
color: grey;
}

.loadingContainer i {
margin-right: .5em;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@

span a[disabled=disabled] {
color: grey;
}

.loadingContainer i {
margin-right: .5em;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<link type="text/css" rel="stylesheet" href="~/Content/select2.min.css" />
<link type="text/css" rel="stylesheet" href="~/Content/select2-bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="~/Content/mvcreportviewer-bootstrap.css" />
<style type="text/css">
.row {
margin-left: 0;
margin-right: 0;
}
</style>
<script type="text/javascript" src="~/Scripts/select2.min.4.0.3.js"></script>
<script type="text/javascript" src="~/Scripts/jquery.highlight-5.js"></script>
<script type="text/javascript">
Expand Down Expand Up @@ -58,8 +64,12 @@
exportReport($(this));
});
$('#ReportViewerSearchText').change(function () {
findText();
$('#ReportViewerSearchText').on("keypress", function (e) {
if (e.keyCode == 13) {
// Cancel the default action on keypress event
e.preventDefault();
findText();
}
});
$('.FindTextButton').click(function () {
Expand All @@ -72,8 +82,10 @@
});
function showLoadingProgress(message) {
hideLoadingProgress();
$('.ReportViewerContent').hide();
$('.ReportViewerContentContainer').append('<div class="loadingContainer"><div style="margin: 0 auto; width: 100%; text-align: center; vertical-align: middle;"><h2><i class="glyphicon glyphicon-cog gly-spin"></i>' + message + '</h2></div></div>');
$('.ReportViewerContentContainer').append('<div class="loadingContainer"><div style="margin: 0 auto; width: 100%; text-align: center; vertical-align: middle;"><h2><i class="glyphicon glyphicon-refresh gly-spin"></i>' + message + '</h2></div></div>');
}
function hideLoadingProgress() {
Expand All @@ -85,7 +97,7 @@
var params = $('.ParametersContainer :input').serializeArray();
var urlParams = $.param(params);
window.open("/Report/PrintReport/[email protected]&" + urlParams, "_blank");
window.open("/Report/PrintReport/[email protected].UrlEncode()&" + urlParams, "_blank");
}
function findText() {
Expand All @@ -96,19 +108,23 @@
var params = $('.ParametersContainer :input').serializeArray();
var urlParams = $.param(params);
var page = parseInt($('#ReportViewerCurrentPage').val()) + 1;
var page = parseInt($('#ReportViewerCurrentPage').val());
$.get("/Report/FindStringInReport/[email protected]&page=" + page + "&" + urlParams).done(function (data) {
$.get("/Report/FindStringInReport/[email protected].UrlEncode()&page=" + page + "&searchText=" + searchText + "&" + urlParams).done(function (data) {
if (data > 0) {
viewReportPage(data);
viewReportPage(data, function () {
$('.ReportViewerContent').highlight(searchText);
hideLoadingProgress();
});
} else {
$('.ReportViewerContent').highlight(searchText);
hideLoadingProgress();
}
$('.ReportViewerContent').highlight(searchText);
hideLoadingProgress();
});
}
}
function viewReportPage(page) {
function viewReportPage(page, afterReportLoadedCallback) {
showLoadingProgress('Loading Report Page...');
var params = $('.ParametersContainer :input').serializeArray();
var urlParams = $.param(params);
Expand All @@ -120,10 +136,14 @@
page = totalPages;
}
$.get("/Report/ViewReportPage/[email protected]&page=" + page + "&" + urlParams)
$.get("/Report/ViewReportPage/[email protected].UrlEncode()&page=" + page + "&" + urlParams)
.done(function (data) {
updateReportContent(data);
hideLoadingProgress();
if (afterReportLoadedCallback && typeof (afterReportLoadedCallback) == "function") {
afterReportLoadedCallback();
}
})
.fail(function (data) {
$('.ReportViewerContent').html("<div class='ReportViewerError'>Report failed to load, check report parameters...</div>");
Expand All @@ -136,7 +156,7 @@
var urlParams = $.param(params);
var format = $(element).attr('class').replace("Export", "");
window.location.href = "/Report/ExportReport/[email protected]&format=" + format + "&" + urlParams;
window.location.href = "/Report/ExportReport/[email protected].UrlEncode()&format=" + format + "&" + urlParams;
}
function updateReportContent(data) {
Expand All @@ -162,5 +182,5 @@
}

@section Content {
@Html.RenderReportViewer(Model)
@Html.RenderReportViewer(Model)
}
4 changes: 2 additions & 2 deletions AlanJuden.MvcReportViewer.NetCore/ReportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public FileResult ExportReport(string reportPath, string format)
return File(contentData.ReportData, contentData.MimeType, filename);
}

public JsonResult FindStringInReport(string reportPath, string searchText, int? startPage = 0)
public JsonResult FindStringInReport(string reportPath, string searchText, int? page = 0)
{
var model = this.GetReportViewerModel(Request);
model.ViewMode = ReportViewModes.View;
model.ReportPath = reportPath;

return Json(ReportServiceHelpers.FindStringInReport(model, searchText, startPage).ToInt32());
return Json(ReportServiceHelpers.FindStringInReport(model, searchText, page).ToInt32());
}

public ActionResult PrintReport(string reportPath)
Expand Down
56 changes: 46 additions & 10 deletions AlanJuden.MvcReportViewer.NetCore/ReportServiceHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@ namespace AlanJuden.MvcReportViewer
{
public static class ReportServiceHelpers
{
private static System.ServiceModel.BasicHttpBinding _initializeHttpBinding()
private static System.ServiceModel.HttpBindingBase _initializeHttpBinding(string url)
{
var basicHttpBinding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly);
basicHttpBinding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
if (url.ToLower().StartsWith("https"))
{
var binding = new System.ServiceModel.BasicHttpsBinding(System.ServiceModel.BasicHttpsSecurityMode.Transport);
binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
binding.MaxReceivedMessageSize = int.MaxValue;

return binding;
}
else
{
var binding = new System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.TransportCredentialOnly);
binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.Windows;
binding.MaxReceivedMessageSize = int.MaxValue;

return basicHttpBinding;
return binding;
}
}

public static ReportService.ReportParameter[] GetReportParameters(ReportViewerModel model, bool forRendering = false)
{
var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportService2005.asmx";

var basicHttpBinding = _initializeHttpBinding();
var basicHttpBinding = _initializeHttpBinding(url);
var service = new ReportService.ReportingService2005SoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url));
service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
service.ClientCredentials.Windows.ClientCredential = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials);
Expand All @@ -46,7 +57,7 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s

var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportExecution2005.asmx";

var basicHttpBinding = _initializeHttpBinding();
var basicHttpBinding = _initializeHttpBinding(url);
var service = new ReportServiceExecution.ReportExecutionServiceSoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url));
service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
service.ClientCredentials.Windows.ClientCredential = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials);
Expand All @@ -66,8 +77,9 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s
}

var outputFormat = $"<OutputFormat>{format}</OutputFormat>";
var encodingFormat = $"<Encoding>{model.Encoding.EncodingName}</Encoding>";
var htmlFragment = ((format.ToUpper() == "HTML4.0" && model.UseCustomReportImagePath == false && model.ViewMode == ReportViewModes.View) ? "<HTMLFragment>true</HTMLFragment>" : "");
var deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";
var deviceInfo = $"<DeviceInfo>{outputFormat}{encodingFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";
if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0)
{
deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}<Section>{startPage}</Section></DeviceInfo>";
Expand Down Expand Up @@ -155,7 +167,7 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s
{
var url = model.ServerUrl + ((model.ServerUrl.ToSafeString().EndsWith("/")) ? "" : "/") + "ReportExecution2005.asmx";

var basicHttpBinding = _initializeHttpBinding();
var basicHttpBinding = _initializeHttpBinding(url);
var service = new ReportServiceExecution.ReportExecutionServiceSoapClient(basicHttpBinding, new System.ServiceModel.EndpointAddress(url));
service.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
service.ClientCredentials.Windows.ClientCredential = (System.Net.NetworkCredential)(model.Credentials ?? System.Net.CredentialCache.DefaultCredentials);
Expand All @@ -171,7 +183,15 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s
exportResult.CurrentPage = startPage.ToInt32();
exportResult.SetParameters(definedReportParameters, model.Parameters);

var deviceInfo = $"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
var format = "HTML4.0";
var outputFormat = $"<OutputFormat>{format}</OutputFormat>";
var encodingFormat = $"<Encoding>{model.Encoding.EncodingName}</Encoding>";
var htmlFragment = ((format.ToUpper() == "HTML4.0" && model.UseCustomReportImagePath == false && model.ViewMode == ReportViewModes.View) ? "<HTMLFragment>true</HTMLFragment>" : "");
var deviceInfo = $"<DeviceInfo>{outputFormat}{encodingFormat}<Toolbar>False</Toolbar>{htmlFragment}</DeviceInfo>";
if (model.ViewMode == ReportViewModes.View && startPage.HasValue && startPage > 0)
{
deviceInfo = $"<DeviceInfo>{outputFormat}<Toolbar>False</Toolbar>{htmlFragment}<Section>{startPage}</Section></DeviceInfo>";
}

var reportParameters = new List<ReportServiceExecution.ParameterValue>();
foreach (var parameter in exportResult.Parameters)
Expand All @@ -198,6 +218,11 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s
var executionHeader = new ReportServiceExecution.ExecutionHeader();

ReportServiceExecution.ExecutionInfo executionInfo = null;
string extension = null;
string encoding = null;
string mimeType = null;
string[] streamIDs = null;
ReportServiceExecution.Warning[] warnings = null;

try
{
Expand All @@ -206,6 +231,17 @@ public static ReportExportResult ExportReportToFormat(ReportViewerModel model, s
executionHeader.ExecutionID = executionInfo.ExecutionID;
var executionParameterResult = service.SetReportParameters(executionInfo.ExecutionID, reportParameters.ToArray(), "en-us").Result;

var renderRequest = new ReportServiceExecution.Render2Request(format, deviceInfo, ReportServiceExecution.PageCountMode.Actual);
var result = service.Render2(executionInfo.ExecutionID, renderRequest).Result;

extension = result.Extension;
mimeType = result.MimeType;
encoding = result.Encoding;
warnings = result.Warnings;
streamIDs = result.StreamIds;

executionInfo = service.GetExecutionInfo(executionHeader.ExecutionID).Result;

return service.FindString(executionInfo.ExecutionID, startPage.ToInt32(), executionInfo.NumPages, searchText).Result;
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions AlanJuden.MvcReportViewer/ReportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ public FileResult ExportReport(string reportPath, string format)
return File(contentData.ReportData, contentData.MimeType, filename);
}

public JsonResult FindStringInReport(string reportPath, string searchText, int? startPage = 0)
public JsonResult FindStringInReport(string reportPath, string searchText, int? page = 0)
{
var model = this.GetReportViewerModel(Request);
model.ViewMode = ReportViewModes.View;
model.ReportPath = reportPath;

return Json(ReportServiceHelpers.FindStringInReport(model, searchText, startPage).ToInt32(), JsonRequestBehavior.AllowGet);
return Json(ReportServiceHelpers.FindStringInReport(model, searchText, page).ToInt32(), JsonRequestBehavior.AllowGet);
}

public ActionResult PrintReport(string reportPath)
Expand Down
Loading

0 comments on commit c741c6e

Please sign in to comment.