diff --git a/AYA.SlnSynor/ReportViewerForMvc/CopyPropertiesHelper.cs b/AYA.SlnSynor/ReportViewerForMvc/CopyPropertiesHelper.cs new file mode 100644 index 000000000..6dea1b9c6 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/CopyPropertiesHelper.cs @@ -0,0 +1,47 @@ +using System; +using System.Reflection; + +namespace ReportViewerForMvc +{ + internal static class CopyPropertiesHelper + { + internal static void Copy(ref T obj, T properties) + { + if (properties == null) + { + throw new ArgumentNullException("properties", "Value cannot be null."); + } + + Copy(ref obj, properties); + } + + internal static void Copy(ref T1 obj, T2 properties) + { + Type objType = obj.GetType(); + Type propertiesType = properties.GetType(); + BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance; + + foreach (PropertyInfo propertyInfo in propertiesType.GetProperties(bindingFlags)) + { + try + { + if (propertyInfo.CanRead) + { + var valueToCopy = propertyInfo.GetValue(properties); + var objProperty = objType.GetProperty(propertyInfo.Name); + + if (objProperty.CanWrite) + { + objProperty.SetValue(obj, valueToCopy); + } + } + } + catch (NullReferenceException ex) + { + throw ex; + } + catch (TargetInvocationException) { } //Do nothing, just like my boss. + } + } + } +} diff --git a/AYA.SlnSynor/ReportViewerForMvc/HtmlHelperExtensions.cs b/AYA.SlnSynor/ReportViewerForMvc/HtmlHelperExtensions.cs new file mode 100644 index 000000000..64936730f --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/HtmlHelperExtensions.cs @@ -0,0 +1,97 @@ +using Microsoft.Reporting.WebForms; +using System.Web; +using System.Web.Mvc; + +namespace ReportViewerForMvc +{ + /// + /// HTML helpers for ReportViewerForMvc + /// + public static class HtmlHelperExtensions + { + /// + /// Returns an HTML iframe that renders an ASP.NET ReportViewer control. + /// + /// The HTML helper instance that this method extends. + /// The object containing the ReportViewer control properties. + /// An HTML iframe that sets its heigh and width based on the content of the report. + public static HtmlString ReportViewer(this HtmlHelper helper, ReportViewer reportViewer) + { + return ReportViewerForMvc.GetIframe(reportViewer, null); + } + + /// + /// Returns an HTML iframe that renders an ASP.NET ReportViewer control. + /// + /// The HTML helper instance that this method extends. + /// The object containing the ReportViewer control properties. + /// The object containing the HTML attributes of the iframe. + /// An HTML iframe with the specified attributes that sets its heigh and width based on the content of the report. + public static HtmlString ReportViewer(this HtmlHelper helper, ReportViewer reportViewer, object htmlAttributes) + { + return ReportViewerForMvc.GetIframe(reportViewer, htmlAttributes); + } + + /// + /// Returns an HTML iframe that renders an ASP.NET ReportViewer control. + /// + /// The HTML helper instance that this method extends. + /// The object containing the ReportViewer control properties. + /// An object containing the LocalReport/ServerReport properties. + /// An HTML iframe that sets its heigh and width based on the content of the report. + public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewer, object report) + { + ReportViewer reportViewerControl = ReportViewerForMvc.AnonymousReportViewer(reportViewer, report); + + return ReportViewerForMvc.GetIframe(reportViewerControl, null); + } + + /// + /// Returns an HTML iframe that renders an ASP.NET ReportViewer control. + /// + /// The HTML helper instance that this method extends. + /// The object containing the ReportViewer control properties. + /// An object containing the LocalReport/ServerReport properties. + /// The object containing the HTML attributes of the iframe. + /// An HTML iframe with the specified attributes that sets its heigh and width based on the content of the report. + public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewer, object report, object htmlAttributes) + { + ReportViewer reportViewerControl = ReportViewerForMvc.AnonymousReportViewer(reportViewer, report); + + return ReportViewerForMvc.GetIframe(reportViewerControl, htmlAttributes); + } + + /// + /// Returns an HTML iframe that renders an ASP.NET ReportViewer control. + /// + /// The HTML helper instance that this method extends. + /// The object containing the ReportViewer control properties. + /// An object containing the LocalReport/ServerReport properties. + /// Object that contains the parameters for a report. + /// The object containing the HTML attributes of the iframe. + /// An HTML iframe with the specified attributes that sets its heigh and width based on the content of the report. + public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewer, object report, object parameters, object htmlAttributes) + { + ReportViewer reportViewerControl = ReportViewerForMvc.AnonymousReportViewer(reportViewer, report, parameters); + + return ReportViewerForMvc.GetIframe(reportViewerControl, htmlAttributes); + } + + /// + /// Returns an HTML iframe that renders an ASP.NET ReportViewer control. + /// + /// The HTML helper instance that this method extends. + /// The object containing the ReportViewer control properties. + /// An object containing the LocalReport/ServerReport properties. + /// Object that contains the parameters for a report. + /// The data sources to be added to the report. + /// The object containing the HTML attributes of the iframe. + /// An HTML iframe with the specified attributes that sets its heigh and width based on the content of the report. + public static HtmlString ReportViewer(this HtmlHelper helper, object reportViewer, object report, object parameters, object dataSources, object htmlAttributes) + { + ReportViewer reportViewerControl = ReportViewerForMvc.AnonymousReportViewer(reportViewer, report, parameters, dataSources); + + return ReportViewerForMvc.GetIframe(reportViewerControl, htmlAttributes); + } + } +} \ No newline at end of file diff --git a/AYA.SlnSynor/ReportViewerForMvc/IframeBuilder.cs b/AYA.SlnSynor/ReportViewerForMvc/IframeBuilder.cs new file mode 100644 index 000000000..51f31e1d2 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/IframeBuilder.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Web; +using System.Web.Mvc; + +namespace ReportViewerForMvc +{ + internal class IframeBuilder + { + internal static HtmlString Iframe(object htmlAttributes) + { + IDictionary parsedHtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); + + ReportViewerForMvc.IframeId = GetId(parsedHtmlAttributes); + + string parsedIframe = CreateIframeTag(parsedHtmlAttributes); + parsedIframe += ReceiveMessageScript(); + parsedIframe += SetIframeIdScript(); + + return new HtmlString(parsedIframe); + } + + private static string GetId(IDictionary htmlAttributes) + { + string id; + + if (htmlAttributes["id"] == null) + { + id = "r" + Guid.NewGuid().ToString(); + } + else + { + id = TagBuilder.CreateSanitizedId(htmlAttributes["id"].ToString()); + + if (id == null) + { + throw new ArgumentNullException("htmlAttributes.id", "Value cannot be null."); + } + } + + return id; + } + + private static string CreateIframeTag(IDictionary htmlAttributes) + { + string applicationPath = (HttpContext.Current.Request.ApplicationPath == "/") ? "" : HttpContext.Current.Request.ApplicationPath; + + TagBuilder tagBuilder = new TagBuilder("iframe"); + tagBuilder.GenerateId(ReportViewerForMvc.IframeId); + tagBuilder.MergeAttribute("src", applicationPath +"/ReportViewerWebForm.aspx"); + tagBuilder.MergeAttributes(htmlAttributes, false); + tagBuilder.SetInnerText("iframes not supported."); + + return tagBuilder.ToString(); + } + + private static string ReceiveMessageScript() + { + string script = ""; + + return script; + } + + private static string SetIframeIdScript() + { + string script = ""; + + return script; + } + } +} \ No newline at end of file diff --git a/AYA.SlnSynor/ReportViewerForMvc/ReportDataSourceCollectionExtensions.cs b/AYA.SlnSynor/ReportViewerForMvc/ReportDataSourceCollectionExtensions.cs new file mode 100644 index 000000000..26c9b6c50 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/ReportDataSourceCollectionExtensions.cs @@ -0,0 +1,34 @@ +using Microsoft.Reporting.WebForms; +using System; +using System.Collections.Generic; + +namespace ReportViewerForMvc +{ + /// + /// ReportDataSourceCollectionExtensions helpers for ReportViewerForMvc + /// + public static class ReportDataSourceCollectionExtensions + { + /// + /// Adds the elements of the specified collection to the end of the ReportDataSourceCollection. + /// + /// The ReportDataSourceCollection that this method extends. + /// The collection whose elements should be added to the end of the ReportDataSourceCollection. + public static void Add(this ReportDataSourceCollection reportDataSourceCollection, IEnumerable collection) + { + if (reportDataSourceCollection == null) + { + throw new ArgumentNullException("reportDataSourceCollection", "Value cannot be null."); + } + if (collection == null) + { + throw new ArgumentNullException("collection", "Value cannot be null."); + } + + foreach (ReportDataSource reportDataSource in collection) + { + reportDataSourceCollection.Add(reportDataSource); + } + } + } +} diff --git a/AYA.SlnSynor/ReportViewerForMvc/ReportExtensions.cs b/AYA.SlnSynor/ReportViewerForMvc/ReportExtensions.cs new file mode 100644 index 000000000..80a88e43e --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/ReportExtensions.cs @@ -0,0 +1,59 @@ +using Microsoft.Reporting.WebForms; +using System; +using System.Linq; + +namespace ReportViewerForMvc +{ + /// + /// ReportExtensions helpers for ReportViewerForMvc + /// + public static class ReportExtensions + { + /// + /// Set the ReportParameters of the specified ReportParameterInfoCollection. + /// + /// The Report that this method extends. + /// The collection whose ReportParameters should be added to the Report. + public static void SetParameters(this Report report, ReportParameterInfoCollection collection) + { + if (report == null) + { + throw new ArgumentNullException("report", "Value cannot be null."); + } + if (collection == null) + { + throw new ArgumentNullException("collection", "Value cannot be null."); + } + + foreach (ReportParameterInfo reportParameterInfo in collection) + { + report.SetParameters(reportParameterInfo); + } + } + + /// + /// Set the ReportParameter of the specified ReportParameterInfo. + /// + /// The Report that this method extends. + /// The ReportParameterInfor whose parameter should be added to the Report. + public static void SetParameters(this Report report, ReportParameterInfo reportParameterInfo) + { + if (report == null) + { + throw new ArgumentNullException("report", "Value cannot be null."); + } + + if (reportParameterInfo == null) + { + throw new ArgumentNullException("reportParameterInfo", "Value cannot be null."); + } + + ReportParameter reportParameter = new ReportParameter( + reportParameterInfo.Name, + reportParameterInfo.Values.ToArray(), + reportParameterInfo.Visible); + + report.SetParameters(reportParameter); + } + } +} diff --git a/AYA.SlnSynor/ReportViewerForMvc/ReportViewerExtensions.cs b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerExtensions.cs new file mode 100644 index 000000000..a6547e9f7 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerExtensions.cs @@ -0,0 +1,74 @@ +using Microsoft.Reporting.WebForms; +using System; +using System.Linq; + +namespace ReportViewerForMvc +{ + /// + /// ReportViewerExtensions helpers for ReportViewerForMvc + /// + public static class ReportViewerExtensions + { + /// + /// Copy the properties of the specified ReportViewer to the ReportViewer. + /// + /// The ReportViewer that this method extends. + /// The ReportViewer whose properties should be copied to the ReportViewer. + public static void SetProperties(this ReportViewer reportViewer, ReportViewer properties) + { + if (reportViewer == null) + { + throw new ArgumentNullException("reportViewer", "Value cannot be null."); + } + + CopyPropertiesHelper.Copy(ref reportViewer, properties); + + reportViewer.LocalReport.SetProperties(properties.LocalReport); + reportViewer.ServerReport.SetProperties(properties.ServerReport); + } + + /// + /// Copy the properties of the specified LocalReport to the LocalReport. + /// + /// The LocalReport that this method extends. + /// The LocalReport whose properties should be copied to the LocalReport. + public static void SetProperties(this LocalReport localReport, LocalReport properties) + { + if (localReport == null) + { + throw new ArgumentNullException("localReport", "Value cannot be null."); + } + + CopyPropertiesHelper.Copy(ref localReport, properties); + + localReport.DataSources.Add(properties.DataSources.ToList()); + + try + { + localReport.SetParameters(properties.GetParameters()); + } + catch (MissingReportSourceException) { } //Do nothing + } + + /// + /// Copy the properties of the specified ServerReport to the ServerReport. + /// + /// The ServerReport that this method extends. + /// The ServerReport whose properties should be copied to the ServerReport. + public static void SetProperties(this ServerReport serverReport, ServerReport properties) + { + if (serverReport == null) + { + throw new ArgumentNullException("serverReport", "Value cannot be null."); + } + + CopyPropertiesHelper.Copy(ref serverReport, properties); + + try + { + serverReport.SetParameters(properties.GetParameters()); + } + catch (MissingReportSourceException) { } //Do nothing + } + } +} diff --git a/AYA.SlnSynor/ReportViewerForMvc/ReportViewerForMvc.cs b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerForMvc.cs new file mode 100644 index 000000000..02e78d812 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerForMvc.cs @@ -0,0 +1,107 @@ +using Microsoft.Reporting.WebForms; +using System; +using System.Web; + +namespace ReportViewerForMvc +{ + /// + /// Encapsulates the methods and properties used for the ReportViewerForMvc extension. + /// + public static class ReportViewerForMvc + { + internal static string IframeId { get; set; } + + private static ReportViewer reportViewer; + internal static ReportViewer ReportViewer + { + get { return reportViewer; } + set + { + //TODO: Implement dynamic ID + reportViewer = value; + reportViewer.ID = "ReportViewer1"; + } + } + + internal static HtmlString GetIframe(ReportViewer reportViewer, object htmlAttributes) + { + if (reportViewer == null) + { + throw new ArgumentNullException("reportViewer", "Value cannot be null."); + } + + ReportViewerForMvc.ReportViewer = reportViewer; + return IframeBuilder.Iframe(htmlAttributes); + } + + /// + /// Constructs a ReporViewer + /// + /// The object containing the ReportViewer properties. + /// An object containing the LocalReport/ServerReport properties. + /// An instance of ReportViewer with the specified properties + public static ReportViewer AnonymousReportViewer(object reportViewer, object report) + { + return AnonymousReportViewer(reportViewer, report, null, null); + } + + /// + /// Constructs a ReporViewer with parameters + /// + /// The object containing the ReportViewer properties. + /// An object containing the LocalReport/ServerReport properties. + /// Object that contains the parameters for a report. + /// An instance of ReportViewer with the specified properties + public static ReportViewer AnonymousReportViewer(object reportViewer, object report, object parameters) + { + return AnonymousReportViewer(reportViewer, report, parameters, null); + } + + /// + /// Constructs a ReporViewer with parameters and data sources. + /// + /// The object containing the ReportViewer properties. + /// An object containing the LocalReport/ServerReport properties. + /// Object that contains the parameters for a report. + /// The data sources to be added to the report. + /// An instance of ReportViewer with the specified properties + public static ReportViewer AnonymousReportViewer(object reportViewer, object report, object parameters, object dataSources) + { + if (reportViewer == null) + { + throw new ArgumentNullException("reportViewer", "Value cannot be null."); + } + if (report == null) + { + throw new ArgumentNullException("report", "Value cannot be null."); + } + + ReportViewer reportViewerControl = ReportViewerHelper.AnonymousToReportViewer(reportViewer); + + if (reportViewerControl.ProcessingMode == ProcessingMode.Local) + { + reportViewerControl.LocalReport.SetProperties(ReportViewerHelper.AnonymousToLocalReport(report)); + + if (parameters != null) + { + reportViewerControl.LocalReport.SetParameters(ReportViewerHelper.AnonymousToReportParameter(parameters)); + } + if (dataSources != null) + { + reportViewerControl.LocalReport.DataSources.Add(ReportViewerHelper.AnonymousToReportDataSourceList(dataSources)); + } + } + else if (reportViewerControl.ProcessingMode == ProcessingMode.Remote) + { + reportViewerControl.ServerReport.SetProperties(ReportViewerHelper.AnonymousToServerReport(report)); + + if (parameters != null) + { + reportViewerControl.ServerReport.SetParameters(ReportViewerHelper.AnonymousToReportParameter(parameters)); + } + } + + return reportViewerControl; + } + } +} diff --git a/AYA.SlnSynor/ReportViewerForMvc/ReportViewerHelpers.cs b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerHelpers.cs new file mode 100644 index 000000000..f298146e0 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerHelpers.cs @@ -0,0 +1,121 @@ +using Microsoft.Reporting.WebForms; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; + +namespace ReportViewerForMvc +{ + internal static class ReportViewerHelper + { + internal static ReportViewer AnonymousToReportViewer(object obj) + { + try + { + return obj.ToType(); + } + catch (ArgumentException ex) + { + throw new ArgumentException("Could not convert anonymous object to type ReportViewer", ex); + } + } + + internal static LocalReport AnonymousToLocalReport(object obj) + { + try + { + return obj.ToType(); + } + catch (ArgumentException ex) + { + throw new ArgumentException("Could not convert anonymous object to type LocalReport", ex); + } + } + + internal static ServerReport AnonymousToServerReport(object obj) + { + try + { + return obj.ToType(); + } + catch (ArgumentException ex) + { + throw new ArgumentException("Could not convert anonymous object to type ServerReport", ex); + } + + } + + internal static List AnonymousToReportParameter(object obj) + { + List reportParameters = new List(); + + foreach (KeyValuePair keyValuePair in obj.ToDictionary()) + { + reportParameters.Add(new ReportParameter(keyValuePair.Key, keyValuePair.Value)); + } + + return reportParameters; + } + + internal static List AnonymousToReportDataSourceList(object obj) + { + List reportDataSourceList = new List(); + + try + { + if (obj.GetType().IsArray) + { + foreach (var reportDataSource in (IEnumerable)obj) + { + reportDataSourceList.Add(reportDataSource.ToType()); + } + } + else + { + reportDataSourceList.Add(obj.ToType()); + } + } + catch (ArgumentException ex) + { + throw new ArgumentException("Could not convert anonymous object to type ReportDataSource", ex); + } + + return reportDataSourceList; + } + + private static T ToType(this object obj) + { + if (obj == null) + { + throw new ArgumentNullException("obj", "Value cannot be null."); + } + + T instance = Activator.CreateInstance(); + + foreach (PropertyInfo propertyInfo in obj.GetType().GetProperties()) + { + var property = typeof(T).GetProperty(propertyInfo.Name); + if (property == null) + { + throw new ArgumentException("An attempt was made to set the property '" + propertyInfo.Name + "' that is not found on object type '" + typeof(T).Name + "'"); + } + + property.SetValue(instance, propertyInfo.GetValue(obj)); + } + + return instance; + } + + private static IDictionary ToDictionary(this object obj) + { + IDictionary dic = new Dictionary(); + + foreach (PropertyInfo propertyInfo in obj.GetType().GetProperties()) + { + dic.Add(propertyInfo.Name, propertyInfo.GetValue(obj).ToString()); + } + + return dic; + } + } +} diff --git a/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx new file mode 100644 index 000000000..d33b60afb --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx @@ -0,0 +1,23 @@ +<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="ReportViewerWebForm.aspx.cs" Inherits="ReportViewerForMvc.ReportViewerWebForm" %> + +<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %> + + + + + + + + +
+
+ + + + + + +
+
+ + diff --git a/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx.cs b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx.cs new file mode 100644 index 000000000..9a9b3e09a --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx.cs @@ -0,0 +1,27 @@ +using Microsoft.Reporting.WebForms; +using System; +using System.Web.UI.WebControls; + +namespace ReportViewerForMvc +{ + /// + /// The Web Form used for rendering a ReportViewer control. + /// + public partial class ReportViewerWebForm : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + BuildReportViewer(); + } + + private void BuildReportViewer() + { + if (!IsPostBack) + { + ReportViewerForMvc.ReportViewer.ID = ReportViewer1.ID; + + ReportViewer1.SetProperties(ReportViewerForMvc.ReportViewer); + } + } + } +} \ No newline at end of file diff --git a/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx.designer.cs b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx.designer.cs new file mode 100644 index 000000000..f1611c508 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/ReportViewerWebForm.aspx.designer.cs @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ReportViewerForMvc { + + + public partial class ReportViewerWebForm { + + /// + /// form1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// + /// ScriptManager1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.ScriptManager ScriptManager1; + + /// + /// ReportViewer1 control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::Microsoft.Reporting.WebForms.ReportViewer ReportViewer1; + } +} diff --git a/AYA.SlnSynor/ReportViewerForMvc/Scripts/PostMessage.js b/AYA.SlnSynor/ReportViewerForMvc/Scripts/PostMessage.js new file mode 100644 index 000000000..5afd51727 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/Scripts/PostMessage.js @@ -0,0 +1,11 @@ +Sys.Application.add_load(function () { + $find("ReportViewer1").add_propertyChanged(viewerPropertyChanged); +}); + +function viewerPropertyChanged(sender, e) { + if (e.get_propertyName() === "isLoading") { + top.postMessage("", '*'); //Trigger resize. + } +} + +//TODO: Get control ID dynamically. \ No newline at end of file diff --git a/AYA.SlnSynor/ReportViewerForMvc/Scripts/ReceiveMessage.js b/AYA.SlnSynor/ReportViewerForMvc/Scripts/ReceiveMessage.js new file mode 100644 index 000000000..5f81c3585 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/Scripts/ReceiveMessage.js @@ -0,0 +1,35 @@ +var ReportViewerForMvc = ReportViewerForMvc || (new function () { + + var _iframeId = {}; + + var resizeIframe = function (msg) { + var height = msg.source.document.body.scrollHeight; + var width = msg.source.document.body.scrollWidth; + + $(ReportViewerForMvc.getIframeId()).height(height); + $(ReportViewerForMvc.getIframeId()).width(width); + } + + var addEvent = function (element, eventName, eventHandler) { + if (element.addEventListener) { + element.addEventListener(eventName, eventHandler); + } else if (element.attachEvent) { + element.attachEvent('on' + eventName, eventHandler); + } + } + + this.setIframeId = function (value) { + _iframeId = '#' + value; + }; + + this.getIframeId = function () { + return _iframeId; + }; + + this.setAutoSize = function () { + addEvent(window, 'message', resizeIframe); + } + +}()); + +ReportViewerForMvc.setAutoSize(); \ No newline at end of file diff --git a/AYA.SlnSynor/ReportViewerForMvc/WebResourceHelper.cs b/AYA.SlnSynor/ReportViewerForMvc/WebResourceHelper.cs new file mode 100644 index 000000000..f29bea697 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/WebResourceHelper.cs @@ -0,0 +1,27 @@ +using System; +using System.Web.UI; + +namespace ReportViewerForMvc +{ + internal static class WebResourceHelper + { + internal static string GetWebResourceUrl(Type type, string resourceName) + { + string resourceUrl = null; + + Page page = new Page(); + try + { + resourceUrl = page.ClientScript.GetWebResourceUrl(type, resourceName); + } + catch (ArgumentNullException) + { + //TODO: Validate if IIS is not running. Unit testing fails due basepath is null. + //in the meanwhile do nothing ...like my boss. + } + + return resourceUrl; + } + } + +} \ No newline at end of file diff --git a/AYA.SlnSynor/ReportViewerForMvc/packages.config b/AYA.SlnSynor/ReportViewerForMvc/packages.config new file mode 100644 index 000000000..58543ef54 --- /dev/null +++ b/AYA.SlnSynor/ReportViewerForMvc/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file