Here is my problem. Our shop has three environments that the development team must work with, development, testing and production. I have successfully been able to change the DataSource (WebServiceDataSource) of the master report by changing the ServiceUrl. For subreports I have been able to change the ReportSource based on the environment but I have not been able to locate a way to change the DataSource. Does anyone have an idea how this is done?
Here is the code I have right now:
public class TexasProtaxCustomReportResolver : Telerik.Reporting.Services.Engine.IReportResolver
{
private readonly string _path;
private readonly string _apiUrl;
public TexasProtaxCustomReportResolver(string path, string apiUrl)
{
_path = path;
_apiUrl = apiUrl;
}
public Telerik.Reporting.ReportSource Resolve(string reportName)
{
var reportPacker = new ReportPackager();
string reportPath = Path.Combine(_path, reportName);
using (var sourceStream = System.IO.File.OpenRead( reportPath))
{
var report = (Telerik.Reporting.Report)reportPacker.UnpackageDocument(sourceStream);
SetReportSource((ReportItemBase)report);
var irs = new InstanceReportSource
{
ReportDocument = report
};
return irs;
}
}
private void SetReportSource(ReportItemBase reportItemBase)
{
if (reportItemBase.Items.Count < 1)
return;
if (reportItemBase is Telerik.Reporting.Report)
{
var report = (Telerik.Reporting.Report)reportItemBase;
var webServiceDataSource = (WebServiceDataSource)report.DataSource;
string url = webServiceDataSource.ServiceUrl;
url = url.ToLower().Replace("localhost:5001", _apiUrl);
webServiceDataSource.ServiceUrl = url;
}
foreach (var item in reportItemBase.Items)
{
// recursively set the reportsource
SetReportSource(item);
if (item is SubReport subReport)
{
// Save Parameters
var clonable = subReport.ReportSource.Parameters as ICloneable;
var parameters = (ParameterCollection)clonable.Clone();
string fileName = Path.GetFileName(subReport.ReportSource.ToString());
var uriReportSource = new UriReportSource
{
Uri = Path.Combine(_path, fileName)
};
uriReportSource.Parameters.AddRange(parameters);
subReport.ReportSource = uriReportSource;
continue;
}
}
}
}