From 9b0fe2efa23f06750f87485734f69994a18f8193 Mon Sep 17 00:00:00 2001 From: Peter Gill Date: Sat, 11 Jan 2025 10:37:25 -0330 Subject: [PATCH] wip; Add support for async database calls, requiring widespread use of async/await. Refactor to use async/await for improved performance Converted synchronous methods to asynchronous across multiple files to enhance performance and responsiveness. Updated method signatures to return Task or Task and used await for asynchronous operations. Added using System.Threading.Tasks; to support async programming. Modified test methods to be asynchronous. Improved handling of long-running operations, particularly I/O-bound tasks, to prevent blocking the main thread. Added GlobalSuppressions.cs to manage platform compatibility warnings for System.Drawing. --- LibRdlWpfViewer/RdlWpfViewer.xaml.cs | 18 +- RdlAsp.Mvc/RdlReport.cs | 15 +- RdlCmd/GlobalSuppressions.cs | 11 + RdlCmd/RdlCmd.cs | 51 +- RdlCreator.Tests/DataProviderTest.cs | 57 +- .../ManualReportDefinitionTest.cs | 9 +- RdlCreator/Create.cs | 20 +- RdlCri/GlobalSuppressions.cs | 11 + RdlDesign/DialogDatabase.Designer.cs | 1 - RdlDesign/DialogDatabase.cs | 9 +- RdlDesign/DrillParametersDialog.cs | 9 +- RdlDesign/RdlEditPreview.cs | 13 +- RdlDesign/SubreportCtl.cs | 9 +- RdlDesktop/ConnectionThread.cs | 38 +- RdlDesktop/RdlDesktop.cs | 4 +- RdlEngine/Definition/Action.cs | 23 +- RdlEngine/Definition/Axis.cs | 29 +- RdlEngine/Definition/Body.cs | 15 +- RdlEngine/Definition/CategoryAxis.cs | 5 +- RdlEngine/Definition/CategoryGrouping.cs | 7 +- RdlEngine/Definition/CategoryGroupings.cs | 5 +- RdlEngine/Definition/Chart.cs | 81 +- RdlEngine/Definition/ChartBar.cs | 916 +++--- RdlEngine/Definition/ChartBase.cs | 2221 +++++++------- RdlEngine/Definition/ChartBubble.cs | 339 ++- RdlEngine/Definition/ChartColumn.cs | 1104 +++---- RdlEngine/Definition/ChartData.cs | 5 +- RdlEngine/Definition/ChartExpression.cs | 25 +- RdlEngine/Definition/ChartGridLines.cs | 5 +- RdlEngine/Definition/ChartLine.cs | 593 ++-- RdlEngine/Definition/ChartMap.cs | 39 +- RdlEngine/Definition/ChartPie.cs | 74 +- RdlEngine/Definition/ChartSeries.cs | 5 +- RdlEngine/Definition/Classes.cs | 5 +- RdlEngine/Definition/Code.cs | 5 +- RdlEngine/Definition/CodeModule.cs | 5 +- RdlEngine/Definition/CodeModules.cs | 5 +- RdlEngine/Definition/ColumnGrouping.cs | 7 +- RdlEngine/Definition/ColumnGroupings.cs | 5 +- RdlEngine/Definition/ConnectionProperties.cs | 9 +- RdlEngine/Definition/Corner.cs | 5 +- RdlEngine/Definition/Custom.cs | 5 +- RdlEngine/Definition/CustomReportItem.cs | 34 +- RdlEngine/Definition/DataLabel.cs | 11 +- RdlEngine/Definition/DataPoint.cs | 13 +- RdlEngine/Definition/DataPoints.cs | 5 +- RdlEngine/Definition/DataRegion.cs | 35 +- RdlEngine/Definition/DataSetDefn.cs | 33 +- RdlEngine/Definition/DataSetReference.cs | 22 +- RdlEngine/Definition/DataSetsDefn.cs | 9 +- RdlEngine/Definition/DataSourceDefn.cs | 29 +- RdlEngine/Definition/DataSourcesDefn.cs | 4 +- RdlEngine/Definition/DataValue.cs | 5 +- RdlEngine/Definition/DataValues.cs | 5 +- RdlEngine/Definition/DefaultValue.cs | 11 +- RdlEngine/Definition/Details.cs | 41 +- RdlEngine/Definition/Drillthrough.cs | 5 +- RdlEngine/Definition/DrillthroughParameter.cs | 15 +- .../Definition/DrillthroughParameters.cs | 5 +- RdlEngine/Definition/DynamicCategories.cs | 9 +- RdlEngine/Definition/DynamicColumns.cs | 13 +- RdlEngine/Definition/DynamicExpression.cs | 46 +- RdlEngine/Definition/DynamicRows.cs | 13 +- RdlEngine/Definition/DynamicSeries.cs | 9 +- RdlEngine/Definition/EmbeddedImage.cs | 5 +- RdlEngine/Definition/EmbeddedImages.cs | 5 +- RdlEngine/Definition/Expression.cs | 49 +- RdlEngine/Definition/Field.cs | 5 +- RdlEngine/Definition/Fields.cs | 5 +- RdlEngine/Definition/Filter.cs | 15 +- RdlEngine/Definition/FilterValue.cs | 5 +- RdlEngine/Definition/FilterValues.cs | 5 +- RdlEngine/Definition/Filters.cs | 9 +- RdlEngine/Definition/Footer.cs | 21 +- RdlEngine/Definition/GroupExpression.cs | 5 +- RdlEngine/Definition/GroupExpressions.cs | 5 +- RdlEngine/Definition/Grouping.cs | 19 +- RdlEngine/Definition/Header.cs | 25 +- RdlEngine/Definition/Image.cs | 684 ++--- RdlEngine/Definition/Legend.cs | 5 +- RdlEngine/Definition/Line.cs | 10 +- RdlEngine/Definition/List.cs | 70 +- RdlEngine/Definition/Marker.cs | 5 +- RdlEngine/Definition/Matrix.cs | 2430 +++++++-------- RdlEngine/Definition/MatrixCell.cs | 5 +- RdlEngine/Definition/MatrixCells.cs | 5 +- RdlEngine/Definition/MatrixColumn.cs | 5 +- RdlEngine/Definition/MatrixColumns.cs | 5 +- RdlEngine/Definition/MatrixRow.cs | 5 +- RdlEngine/Definition/MatrixRows.cs | 5 +- RdlEngine/Definition/PageFooter.cs | 17 +- RdlEngine/Definition/PageHeader.cs | 17 +- RdlEngine/Definition/ParameterValue.cs | 7 +- RdlEngine/Definition/ParameterValues.cs | 151 +- RdlEngine/Definition/PlotArea.cs | 5 +- RdlEngine/Definition/Query.cs | 54 +- RdlEngine/Definition/QueryParameter.cs | 5 +- RdlEngine/Definition/QueryParameters.cs | 5 +- RdlEngine/Definition/RDLParser.cs | 8 +- RdlEngine/Definition/Rectangle.cs | 27 +- RdlEngine/Definition/ReportClass.cs | 5 +- RdlEngine/Definition/ReportDefn.cs | 117 +- RdlEngine/Definition/ReportItem.cs | 60 +- RdlEngine/Definition/ReportItems.cs | 15 +- RdlEngine/Definition/ReportLink.cs | 4 +- RdlEngine/Definition/ReportParameter.cs | 30 +- RdlEngine/Definition/ReportParameters.cs | 11 +- RdlEngine/Definition/RowGrouping.cs | 7 +- RdlEngine/Definition/RowGroupings.cs | 5 +- RdlEngine/Definition/SeriesGrouping.cs | 9 +- RdlEngine/Definition/SeriesGroupings.cs | 5 +- RdlEngine/Definition/SortBy.cs | 5 +- RdlEngine/Definition/Sorting.cs | 5 +- RdlEngine/Definition/StaticCategories.cs | 5 +- RdlEngine/Definition/StaticColumn.cs | 5 +- RdlEngine/Definition/StaticColumns.cs | 5 +- RdlEngine/Definition/StaticMember.cs | 5 +- RdlEngine/Definition/StaticRow.cs | 5 +- RdlEngine/Definition/StaticRows.cs | 5 +- RdlEngine/Definition/StaticSeries.cs | 5 +- RdlEngine/Definition/Style.cs | 422 +-- RdlEngine/Definition/StyleBackgroundImage.cs | 39 +- RdlEngine/Definition/StyleBorderColor.cs | 54 +- RdlEngine/Definition/StyleBorderStyle.cs | 53 +- RdlEngine/Definition/StyleBorderWidth.cs | 53 +- RdlEngine/Definition/Subreport.cs | 38 +- RdlEngine/Definition/SubreportParameter.cs | 9 +- RdlEngine/Definition/SubreportParameters.cs | 5 +- RdlEngine/Definition/Subtotal.cs | 7 +- RdlEngine/Definition/Table.cs | 150 +- RdlEngine/Definition/TableCell.cs | 21 +- RdlEngine/Definition/TableCells.cs | 13 +- RdlEngine/Definition/TableColumn.cs | 9 +- RdlEngine/Definition/TableColumns.cs | 9 +- RdlEngine/Definition/TableGroup.cs | 13 +- RdlEngine/Definition/TableGroups.cs | 5 +- RdlEngine/Definition/TableRow.cs | 34 +- RdlEngine/Definition/TableRows.cs | 27 +- RdlEngine/Definition/Textbox.cs | 68 +- RdlEngine/Definition/ThreeDProperties.cs | 5 +- RdlEngine/Definition/Title.cs | 7 +- RdlEngine/Definition/ToggleImage.cs | 5 +- RdlEngine/Definition/ValidValues.cs | 119 +- RdlEngine/Definition/ValueAxis.cs | 5 +- RdlEngine/Definition/Values.cs | 7 +- RdlEngine/Definition/Visibility.cs | 9 +- RdlEngine/ExprParser/Parser.cs | 182 +- RdlEngine/Functions/Constant.cs | 39 +- RdlEngine/Functions/ConstantBoolean.cs | 39 +- RdlEngine/Functions/ConstantDateTime.cs | 39 +- RdlEngine/Functions/ConstantDecimal.cs | 37 +- RdlEngine/Functions/ConstantDouble.cs | 37 +- RdlEngine/Functions/ConstantError.cs | 39 +- RdlEngine/Functions/ConstantInteger.cs | 39 +- RdlEngine/Functions/ConstantString.cs | 39 +- RdlEngine/Functions/FunctionAggr.cs | 14 +- RdlEngine/Functions/FunctionAggrArray.cs | 24 +- RdlEngine/Functions/FunctionAggrAvg.cs | 26 +- RdlEngine/Functions/FunctionAggrCount.cs | 26 +- .../Functions/FunctionAggrCountDistinct.cs | 27 +- RdlEngine/Functions/FunctionAggrCountRows.cs | 29 +- RdlEngine/Functions/FunctionAggrFirst.cs | 30 +- RdlEngine/Functions/FunctionAggrLast.cs | 30 +- RdlEngine/Functions/FunctionAggrLevel.cs | 31 +- RdlEngine/Functions/FunctionAggrMax.cs | 26 +- RdlEngine/Functions/FunctionAggrMin.cs | 26 +- RdlEngine/Functions/FunctionAggrNext.cs | 30 +- RdlEngine/Functions/FunctionAggrPrevious.cs | 30 +- RdlEngine/Functions/FunctionAggrRvAvg.cs | 26 +- RdlEngine/Functions/FunctionAggrRvCount.cs | 26 +- RdlEngine/Functions/FunctionAggrRvMax.cs | 26 +- RdlEngine/Functions/FunctionAggrRvMin.cs | 26 +- RdlEngine/Functions/FunctionAggrRvStdev.cs | 26 +- RdlEngine/Functions/FunctionAggrRvStdevp.cs | 26 +- RdlEngine/Functions/FunctionAggrRvSum.cs | 26 +- RdlEngine/Functions/FunctionAggrRvVar.cs | 26 +- RdlEngine/Functions/FunctionAggrRvVarp.cs | 26 +- RdlEngine/Functions/FunctionAggrStdev.cs | 26 +- RdlEngine/Functions/FunctionAggrStdevp.cs | 26 +- RdlEngine/Functions/FunctionAggrSum.cs | 31 +- RdlEngine/Functions/FunctionAggrVar.cs | 26 +- RdlEngine/Functions/FunctionAggrVarp.cs | 26 +- RdlEngine/Functions/FunctionAnd.cs | 49 +- RdlEngine/Functions/FunctionBinary.cs | 9 +- RdlEngine/Functions/FunctionChoose.cs | 39 +- RdlEngine/Functions/FunctionCode.cs | 37 +- RdlEngine/Functions/FunctionCustomInstance.cs | 37 +- RdlEngine/Functions/FunctionCustomStatic.cs | 37 +- RdlEngine/Functions/FunctionDiv.cs | 49 +- RdlEngine/Functions/FunctionDivDecimal.cs | 49 +- RdlEngine/Functions/FunctionExecutionTime.cs | 38 +- RdlEngine/Functions/FunctionExp.cs | 49 +- RdlEngine/Functions/FunctionField.cs | 37 +- .../Functions/FunctionFieldCollection.cs | 43 +- RdlEngine/Functions/FunctionFieldIsMissing.cs | 35 +- RdlEngine/Functions/FunctionFormat.cs | 49 +- .../Functions/FunctionGlobalCollection.cs | 41 +- RdlEngine/Functions/FunctionIif.cs | 51 +- RdlEngine/Functions/FunctionMinus.cs | 47 +- RdlEngine/Functions/FunctionMinusDecimal.cs | 47 +- RdlEngine/Functions/FunctionMinusInt32.cs | 47 +- RdlEngine/Functions/FunctionModulus.cs | 49 +- RdlEngine/Functions/FunctionMult.cs | 49 +- RdlEngine/Functions/FunctionMultDecimal.cs | 49 +- RdlEngine/Functions/FunctionNot.cs | 43 +- RdlEngine/Functions/FunctionOr.cs | 49 +- RdlEngine/Functions/FunctionPageNumber.cs | 38 +- .../Functions/FunctionParameterCollection.cs | 41 +- RdlEngine/Functions/FunctionPlus.cs | 49 +- RdlEngine/Functions/FunctionPlusDecimal.cs | 49 +- RdlEngine/Functions/FunctionPlusInt32.cs | 49 +- RdlEngine/Functions/FunctionPlusString.cs | 43 +- RdlEngine/Functions/FunctionRelopEQ.cs | 43 +- RdlEngine/Functions/FunctionRelopGT.cs | 43 +- RdlEngine/Functions/FunctionRelopGTE.cs | 43 +- RdlEngine/Functions/FunctionRelopLT.cs | 43 +- RdlEngine/Functions/FunctionRelopLTE.cs | 43 +- RdlEngine/Functions/FunctionRelopNE.cs | 43 +- RdlEngine/Functions/FunctionReportFolder.cs | 38 +- .../Functions/FunctionReportItemCollection.cs | 41 +- RdlEngine/Functions/FunctionReportName.cs | 38 +- .../Functions/FunctionReportParameter.cs | 41 +- .../Functions/FunctionReportParameterLabel.cs | 39 +- RdlEngine/Functions/FunctionSwitch.cs | 39 +- RdlEngine/Functions/FunctionSystem.cs | 37 +- RdlEngine/Functions/FunctionTextbox.cs | 39 +- RdlEngine/Functions/FunctionTotalPages.cs | 38 +- RdlEngine/Functions/FunctionUnaryMinus.cs | 45 +- .../Functions/FunctionUnaryMinusDecimal.cs | 43 +- .../Functions/FunctionUnaryMinusInteger.cs | 43 +- RdlEngine/Functions/FunctionUserCollection.cs | 41 +- RdlEngine/Functions/FunctionUserID.cs | 40 +- RdlEngine/Functions/FunctionUserLanguage.cs | 29 +- RdlEngine/Functions/IExpr.cs | 19 +- RdlEngine/Functions/Identifier.cs | 39 +- RdlEngine/Functions/IdentifierKey.cs | 37 +- RdlEngine/GlobalSuppressions.cs | 11 + RdlEngine/RdlEngine.csproj | 1 + .../ExcelConverter/ExcelCellsBuilder.cs | 24 +- .../Render/HtmlConverter/RenderHtmlTable.cs | 2660 +++++++++-------- RdlEngine/Render/IPresent.cs | 35 +- RdlEngine/Render/ProcessReport.cs | 2 +- RdlEngine/Render/RenderBase.cs | 117 +- RdlEngine/Render/RenderCsv.cs | 57 +- RdlEngine/Render/RenderExcel2007.cs | 73 +- RdlEngine/Render/RenderExcel2007DataOnly.cs | 71 +- RdlEngine/Render/RenderHtml.cs | 93 +- RdlEngine/Render/RenderRtf.cs | 78 +- RdlEngine/Render/RenderTif.cs | 57 +- RdlEngine/Render/RenderXml.cs | 98 +- RdlEngine/Runtime/DataSet.cs | 21 +- RdlEngine/Runtime/Report.cs | 51 +- RdlGtk3/CairoPdfWriter.cs | 5 +- RdlGtk3/MainWindow.cs | 6 +- RdlGtk3/ReportExporter.cs | 57 +- RdlGtk3/ReportViewer.cs | 18 +- RdlReader/RdlReader.cs | 23 +- RdlViewer/RdlViewer.cs | 141 +- RdlViewer/RdlViewerFind.cs | 37 +- RdlViewer/ViewerToolstrip.cs | 12 +- ReportTests/ExcelValetTests.cs | 11 +- ReportTests/RenderPdf_iTextSharpTests.cs | 11 +- ReportTests/ReportTests.csproj | 1 + ReportTests/Utils/RdlUtils.cs | 5 +- ReportTests/iTextSharpTests.cs | 11 +- 265 files changed, 9490 insertions(+), 9143 deletions(-) create mode 100644 RdlCmd/GlobalSuppressions.cs create mode 100644 RdlCri/GlobalSuppressions.cs create mode 100644 RdlEngine/GlobalSuppressions.cs diff --git a/LibRdlWpfViewer/RdlWpfViewer.xaml.cs b/LibRdlWpfViewer/RdlWpfViewer.xaml.cs index 22ee5b24..4feeb431 100644 --- a/LibRdlWpfViewer/RdlWpfViewer.xaml.cs +++ b/LibRdlWpfViewer/RdlWpfViewer.xaml.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -24,14 +25,14 @@ public RdlWpfViewer() InitializeComponent(); } - public void Rebuild() + public async Task Rebuild() { - this.reportViewer.Rebuild(); + await this.reportViewer.Rebuild(); } - public void SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type) + public async Task SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type) { - this.reportViewer.SaveAs(FileName, type); + await this.reportViewer.SaveAs(FileName, type); } public Uri SourceFile @@ -52,10 +53,11 @@ public string SourceRdl { return this.reportViewer.SourceRdl; } - set - { - this.reportViewer.SourceRdl = value; - } + } + + public async Task SetSourceRdl(string value) + { + await this.reportViewer.SetSourceRdl(value); } public string Parameters diff --git a/RdlAsp.Mvc/RdlReport.cs b/RdlAsp.Mvc/RdlReport.cs index 1e8504a7..cf760930 100644 --- a/RdlAsp.Mvc/RdlReport.cs +++ b/RdlAsp.Mvc/RdlReport.cs @@ -33,6 +33,7 @@ the website www.fyiReporting.com. using Microsoft.Extensions.Caching.Memory; using System.Reflection; using System.Collections.Generic; +using System.Threading.Tasks; namespace fyiReporting.RdlAsp { @@ -179,7 +180,9 @@ public string ReportFile // Build the new report string contentRootPath = _webHostEnvironment.ContentRootPath; string pfile = Path.Combine(contentRootPath, _ReportFile); - DoRender(pfile); + + // HACK: async + Task.Run(async () => await DoRender(pfile)).GetAwaiter().GetResult(); } } @@ -244,7 +247,7 @@ public string ParameterHtml // Render the report files with the requested types - private void DoRender(string file) + private async Task DoRender(string file) { string source; @@ -270,7 +273,7 @@ private void DoRender(string file) return; // GetSource reported the error // Compile the report - report = this.GetReport(source, file); + report = await this.GetReport(source, file); if (report == null) return; @@ -282,7 +285,7 @@ private void DoRender(string file) // Obtain the data if report is being generated if (!_NoShow) { - report.RunGetData(ld); + await report.RunGetData(ld); Generate(report); } } @@ -455,7 +458,7 @@ private OutputPresentationType GetRenderType(string type) } - private Report GetReport(string prog, string file) + private async Task GetReport(string prog, string file) { // Now parse the file RDLParser rdlp; @@ -474,7 +477,7 @@ private Report GetReport(string prog, string file) rdlp.Folder = folder; rdlp.DataSourceReferencePassword = new NeedPassword(this.GetPassword); - r = rdlp.Parse(); + r = await rdlp.Parse(); if (r.ErrorMaxSeverity > 0) { AddError(r.ErrorMaxSeverity, r.ErrorItems); diff --git a/RdlCmd/GlobalSuppressions.cs b/RdlCmd/GlobalSuppressions.cs new file mode 100644 index 00000000..2e2dabb4 --- /dev/null +++ b/RdlCmd/GlobalSuppressions.cs @@ -0,0 +1,11 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +#if !DRAWINGCOMPAT +[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", + Justification = "System.Drawing usage is intentional")] +#endif diff --git a/RdlCmd/RdlCmd.cs b/RdlCmd/RdlCmd.cs index 686b5eb8..9de21755 100644 --- a/RdlCmd/RdlCmd.cs +++ b/RdlCmd/RdlCmd.cs @@ -28,6 +28,7 @@ the website www.fyiReporting.com. using System.Text.RegularExpressions; using System.Globalization; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RdlCmd { @@ -48,7 +49,7 @@ public class RdlCmd private string _user = null; // Allow the user to be set via a command line param GJL AJM 12062008 [STAThread] - static public int Main(string[] args) + static public async Task Main(string[] args) { // Handle the arguments if (args == null || args.Length==0) @@ -133,7 +134,7 @@ static public int Main(string[] args) rc.returnCode = returnCode; - rc.DoRender(dir, files, types); + await rc.DoRender(dir, files, types); return rc.returnCode; } @@ -144,7 +145,7 @@ private string GetPassword() } // Render the report files with the requested types - private void DoRender(string dir, string[] files, string[] types) + private async Task DoRender(string dir, string[] files, string[] types) { string source; Report report; @@ -183,7 +184,7 @@ private void DoRender(string dir, string[] files, string[] types) continue; // error: process the rest of the files // Compile the report - report = this.GetReport(source, file); + report = await this.GetReport(source, file); report.UserID = _user; //Set the user of the report based on the parameter passed in GJL AJM 12062008 if (this._ShowStats) { @@ -204,7 +205,7 @@ private void DoRender(string dir, string[] files, string[] types) ld.Remove("rc:ofile"); // don't pass this as an argument to the report } - report.RunGetData(ld); + await report.RunGetData(ld); if (this._ShowStats) { DateTime temp = DateTime.Now; @@ -220,7 +221,7 @@ private void DoRender(string dir, string[] files, string[] types) foreach (string stype in types) { - SaveAs(report, fileNoExt+"."+stype, stype); + await SaveAs(report, fileNoExt+"."+stype, stype); if (this._ShowStats) { DateTime temp = DateTime.Now; @@ -282,7 +283,7 @@ private string GetSource(string file) return prog; } - private Report GetReport(string prog, string file) + private async Task GetReport(string prog, string file) { // Now parse the file RDLParser rdlp; @@ -296,7 +297,7 @@ private Report GetReport(string prog, string file) rdlp.Folder = folder; rdlp.DataSourceReferencePassword = new NeedPassword(this.GetPassword); - r = rdlp.Parse(); + r = await rdlp.Parse(); if (r.ErrorMaxSeverity > 0) { // have errors fill out the msgs @@ -335,7 +336,7 @@ private Report GetReport(string prog, string file) /// /// Name of the file to be saved to. /// Type of file to save. Should be "pdf", "xml", "html", mht. - private void SaveAs(Report report, string FileName, string type) + private async Task SaveAs(Report report, string FileName, string type) { string ext = type.ToLower(); OneFileStreamGen sg=null; @@ -363,43 +364,43 @@ private void SaveAs(Report report, string FileName, string type) { if (isOldPdf) { - report.RunRender(sg, OutputPresentationType.PDFOldStyle); + await report.RunRender(sg, OutputPresentationType.PDFOldStyle); } else { - report.RunRender(sg, OutputPresentationType.PDF); + await report.RunRender(sg, OutputPresentationType.PDF); } } else - SaveAsPdf(report, sg); + await SaveAsPdf(report, sg); break; - case "xml": - report.RunRender(sg, OutputPresentationType.XML); + case "xml": + await report.RunRender(sg, OutputPresentationType.XML); break; - case "mht": - report.RunRender(sg, OutputPresentationType.MHTML); + case "mht": + await report.RunRender(sg, OutputPresentationType.MHTML); break; case "html": case "htm": - report.RunRender(sg, OutputPresentationType.HTML); + await report.RunRender(sg, OutputPresentationType.HTML); break; case "csv": - report.RunRender(sg, OutputPresentationType.CSV); + await report.RunRender(sg, OutputPresentationType.CSV); break; case "xlsx_table": - report.RunRender(sg, OutputPresentationType.ExcelTableOnly); + await report.RunRender(sg, OutputPresentationType.ExcelTableOnly); break; case "xlsx": - report.RunRender(sg, OutputPresentationType.Excel2007); + await report.RunRender(sg, OutputPresentationType.Excel2007); break; case "rtf": - report.RunRender(sg, OutputPresentationType.RTF); + await report.RunRender(sg, OutputPresentationType.RTF); break; case "tif": case "tiff": - report.RunRender(sg, OutputPresentationType.TIF); + await report.RunRender(sg, OutputPresentationType.TIF); break; case "tifb": - report.RunRender(sg, OutputPresentationType.TIFBW); + await report.RunRender(sg, OutputPresentationType.TIFBW); break; default: Console.WriteLine("Unsupported file extension '{0}'. Must be 'pdf', 'xml', 'mht', 'csv', 'xslx', 'xlsx_table', 'rtf', 'tif', 'tifb' or 'html'", type); @@ -433,9 +434,9 @@ private void SaveAs(Report report, string FileName, string type) return; } - private void SaveAsPdf(Report report, OneFileStreamGen sg) + private async Task SaveAsPdf(Report report, OneFileStreamGen sg) { - Pages pgs = report.BuildPages(); + Pages pgs = await report.BuildPages(); FileStream strm=null; Drawing.Image im=null; diff --git a/RdlCreator.Tests/DataProviderTest.cs b/RdlCreator.Tests/DataProviderTest.cs index 346a3a19..226f8e5d 100644 --- a/RdlCreator.Tests/DataProviderTest.cs +++ b/RdlCreator.Tests/DataProviderTest.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using System.Text.RegularExpressions; using Microsoft.Identity.Client; +using System.Threading.Tasks; namespace fyiReporting.RdlCreator.Tests { @@ -37,17 +38,17 @@ public void Setup() } [Test] - public void TestMethodCsv() + public async Task TestMethodCsv() { var create = new RdlCreator.Create(); - var fyiReport = create.GenerateRdl(dataProvider, + var fyiReport = await create.GenerateRdl(dataProvider, connectionString, "SELECT CategoryID, CategoryName, Description FROM Categories", pageHeaderText: "DataProviderTest TestMethod1"); var ms = new fyiReporting.RDL.MemoryStreamGen(); - fyiReport.RunGetData(null); - fyiReport.RunRender(ms, fyiReporting.RDL.OutputPresentationType.CSV); + await fyiReport.RunGetData(null); + await fyiReport.RunRender(ms, fyiReporting.RDL.OutputPresentationType.CSV); var text = ms.GetText(); Assert.That(text, Is.Not.Null); @@ -66,19 +67,19 @@ public void TestMethodCsv() } [Test] - public void TestMethodExcelLegacy() + public async Task TestMethodExcelLegacy() { var create = new RdlCreator.Create(); - var fyiReport = create.GenerateRdl(dataProvider, + var fyiReport = await create.GenerateRdl(dataProvider, connectionString, "SELECT CategoryID, CategoryName, Description FROM Categories", pageHeaderText: "DataProviderTest TestMethod1"); string filepath = System.IO.Path.Combine(Environment.CurrentDirectory, "TestMethodExcelLegacy.xls"); var ofs = new fyiReporting.RDL.OneFileStreamGen(filepath, true); - fyiReport.RunGetData(null); - fyiReport.RunRender(ofs, fyiReporting.RDL.OutputPresentationType.ExcelTableOnly); + await fyiReport.RunGetData(null); + await fyiReport.RunRender(ofs, fyiReporting.RDL.OutputPresentationType.ExcelTableOnly); Assert.Multiple(() => { @@ -88,55 +89,55 @@ public void TestMethodExcelLegacy() } [Test] - public void TestMethodExcel2007() + public async Task TestMethodExcel2007() { var create = new RdlCreator.Create(); - var fyiReport = create.GenerateRdl(dataProvider, + var fyiReport = await create.GenerateRdl(dataProvider, connectionString, "SELECT CategoryID, CategoryName, Description FROM Categories", pageHeaderText: "DataProviderTest TestMethod1"); string filepath = System.IO.Path.Combine(Environment.CurrentDirectory, "TestMethodExcel.xlsx"); var ofs = new fyiReporting.RDL.OneFileStreamGen(filepath, true); - fyiReport.RunGetData(null); - fyiReport.RunRender(ofs, fyiReporting.RDL.OutputPresentationType.Excel2007); + await fyiReport.RunGetData(null); + await fyiReport.RunRender(ofs, fyiReporting.RDL.OutputPresentationType.Excel2007); Assert.That(System.IO.File.Exists(filepath), Is.True); } [Test] - public void TestMethodExcel2007DataOnly() + public async Task TestMethodExcel2007DataOnly() { var create = new RdlCreator.Create(); - var fyiReport = create.GenerateRdl(dataProvider, + var fyiReport = await create.GenerateRdl(dataProvider, connectionString, "SELECT CategoryID, CategoryName, Description FROM Categories", pageHeaderText: "DataProviderTest TestMethod1"); string filepath = System.IO.Path.Combine(Environment.CurrentDirectory, "TestMethodExcelDataOnly.xlsx"); var ofs = new fyiReporting.RDL.OneFileStreamGen(filepath, true); - fyiReport.RunGetData(null); - fyiReport.RunRender(ofs, fyiReporting.RDL.OutputPresentationType.Excel2007DataOnly); + await fyiReport.RunGetData(null); + await fyiReport.RunRender(ofs, fyiReporting.RDL.OutputPresentationType.Excel2007DataOnly); Assert.That(System.IO.File.Exists(filepath), Is.True); } [Test] - public void TestMethodPdf() + public async Task TestMethodPdf() { var create = new RdlCreator.Create(); - var fyiReport = create.GenerateRdl(dataProvider, + var fyiReport = await create.GenerateRdl(dataProvider, connectionString, "SELECT CategoryID, CategoryName, Description FROM Categories", pageHeaderText: "DataProviderTest TestMethod1"); string filepath = System.IO.Path.Combine(Environment.CurrentDirectory, "TestMethodPdf.pdf"); var ofs = new fyiReporting.RDL.OneFileStreamGen(filepath, true); - fyiReport.RunGetData(null); - fyiReport.RunRender(ofs, fyiReporting.RDL.OutputPresentationType.PDF); + await fyiReport.RunGetData(null); + await fyiReport.RunRender(ofs, fyiReporting.RDL.OutputPresentationType.PDF); Assert.Multiple(() => { @@ -146,7 +147,7 @@ public void TestMethodPdf() } [Test] - public void TestReportFromDataTable() + public async Task TestReportFromDataTable() { var dt = new System.Data.DataTable(); dt.Columns.Add("CategoryID", typeof(int)); @@ -162,11 +163,11 @@ public void TestReportFromDataTable() dt.Rows.Add(8, "Seafood", "Seaweed and fish"); var create = new RdlCreator.Create(); - var fyiReport = create.GenerateRdl(dt, + var fyiReport = await create.GenerateRdl(dt, pageHeaderText: "DataProviderTest TestMethod1"); var ms = new fyiReporting.RDL.MemoryStreamGen(); - fyiReport.RunGetData(null); - fyiReport.RunRender(ms, fyiReporting.RDL.OutputPresentationType.CSV); + await fyiReport.RunGetData(null); + await fyiReport.RunRender(ms, fyiReporting.RDL.OutputPresentationType.CSV); var text = ms.GetText(); Assert.That(text, Is.Not.Null); @@ -192,7 +193,7 @@ class Category } [Test] - public void TestReportFromEnumerable() + public async Task TestReportFromEnumerable() { var data = new List { @@ -207,11 +208,11 @@ public void TestReportFromEnumerable() }; var create = new RdlCreator.Create(); - var fyiReport = create.GenerateRdl(data, + var fyiReport = await create.GenerateRdl(data, pageHeaderText: "DataProviderTest TestMethod1"); var ms = new fyiReporting.RDL.MemoryStreamGen(); - fyiReport.RunGetData(null); - fyiReport.RunRender(ms, fyiReporting.RDL.OutputPresentationType.CSV); + await fyiReport.RunGetData(null); + await fyiReport.RunRender(ms, fyiReporting.RDL.OutputPresentationType.CSV); var text = ms.GetText(); Assert.That(text, Is.Not.Null); diff --git a/RdlCreator.Tests/ManualReportDefinitionTest.cs b/RdlCreator.Tests/ManualReportDefinitionTest.cs index 15f974bd..b2e11ac9 100644 --- a/RdlCreator.Tests/ManualReportDefinitionTest.cs +++ b/RdlCreator.Tests/ManualReportDefinitionTest.cs @@ -5,6 +5,7 @@ using fyiReporting.RdlCreator; using NUnit.Framework; using System.Text.RegularExpressions; +using System.Threading.Tasks; namespace fyiReporting.RdlCreator.Tests { @@ -15,14 +16,14 @@ public class ManualReportDefinitionTest string dataProvider = "Microsoft.Data.Sqlite"; [Test] - public void TestMethod1() + public async Task TestMethod1() { var create = new RdlCreator.Create(); var report = GenerateTestData(); - var fyiReport = create.GenerateRdl(report); + var fyiReport = await create.GenerateRdl(report); var ms = new fyiReporting.RDL.MemoryStreamGen(); - fyiReport.RunGetData(null); - fyiReport.RunRender(ms, fyiReporting.RDL.OutputPresentationType.CSV); + await fyiReport.RunGetData(null); + await fyiReport.RunRender(ms, fyiReporting.RDL.OutputPresentationType.CSV); var text = ms.GetText(); Assert.That(text, Is.Not.Null); diff --git a/RdlCreator/Create.cs b/RdlCreator/Create.cs index c287cf4c..b4bec80a 100644 --- a/RdlCreator/Create.cs +++ b/RdlCreator/Create.cs @@ -13,7 +13,7 @@ namespace fyiReporting.RdlCreator { public class Create { - public fyiReporting.RDL.Report GenerateRdl(Report report) + public async Task GenerateRdl(Report report) { var serializer = new XmlSerializer(typeof(Report)); string xml; @@ -24,11 +24,11 @@ public fyiReporting.RDL.Report GenerateRdl(Report report) } var rdlp = new RDLParser(xml); - var fyiReport = rdlp.Parse(); + var fyiReport = await rdlp.Parse(); return fyiReport; } - public fyiReporting.RDL.Report GenerateRdl(DataTable data, + public async Task GenerateRdl(DataTable data, string description = "", string author = "", string pageHeight = "11in", @@ -88,12 +88,12 @@ public fyiReporting.RDL.Report GenerateRdl(DataTable data, var rdlp = new RDLParser(xml); - var fyiReport = rdlp.Parse(); - fyiReport.DataSets["Data"].SetData(data); + var fyiReport = await rdlp.Parse(); + await fyiReport.DataSets["Data"].SetData(data); return fyiReport; } - public fyiReporting.RDL.Report GenerateRdl(IEnumerable data, + public async Task GenerateRdl(IEnumerable data, string description = "", string author = "", string pageHeight = "11in", @@ -155,12 +155,12 @@ public fyiReporting.RDL.Report GenerateRdl(IEnumerable data, var rdlp = new RDLParser(xml); - var fyiReport = rdlp.Parse(); - fyiReport.DataSets["Data"].SetData(data); + var fyiReport = await rdlp.Parse(); + await fyiReport.DataSets["Data"].SetData(data); return fyiReport; } - public fyiReporting.RDL.Report GenerateRdl(string dataProvider, + public async Task GenerateRdl(string dataProvider, string connectionString, string commandText, CommandType commandType = CommandType.Text, @@ -238,7 +238,7 @@ public fyiReporting.RDL.Report GenerateRdl(string dataProvider, rightMargin, bottomMargin, pageHeaderText, headerTableCells, bodyTableCells, fields); var rdlp = new RDLParser(xml); - var fyiReport = rdlp.Parse(); + var fyiReport = await rdlp.Parse(); return fyiReport; } diff --git a/RdlCri/GlobalSuppressions.cs b/RdlCri/GlobalSuppressions.cs new file mode 100644 index 00000000..2e2dabb4 --- /dev/null +++ b/RdlCri/GlobalSuppressions.cs @@ -0,0 +1,11 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +#if !DRAWINGCOMPAT +[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", + Justification = "System.Drawing usage is intentional")] +#endif diff --git a/RdlDesign/DialogDatabase.Designer.cs b/RdlDesign/DialogDatabase.Designer.cs index b2a2e371..b2ffcd5a 100644 --- a/RdlDesign/DialogDatabase.Designer.cs +++ b/RdlDesign/DialogDatabase.Designer.cs @@ -525,7 +525,6 @@ private void InitializeComponent() this.rdlViewer1.ShowParameterPanel = true; this.rdlViewer1.ShowWaitDialog = true; this.rdlViewer1.SourceFile = null; - this.rdlViewer1.SourceRdl = null; this.rdlViewer1.UseTrueMargins = true; this.rdlViewer1.Zoom = 0.7061753F; this.rdlViewer1.ZoomMode = fyiReporting.RdlViewer.ZoomEnum.FitWidth; diff --git a/RdlDesign/DialogDatabase.cs b/RdlDesign/DialogDatabase.cs index 90d59c96..91bc198e 100644 --- a/RdlDesign/DialogDatabase.cs +++ b/RdlDesign/DialogDatabase.cs @@ -36,6 +36,7 @@ the website www.fyiReporting.com. using System.Xml; using fyiReporting.RDL; using fyiReporting.RdlDesign.Resources; +using System.Threading.Tasks; namespace fyiReporting.RdlDesign { @@ -381,7 +382,7 @@ private void btnOK_Click(object sender, System.EventArgs e) this.Close(); } - private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e) + private async void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e) { TabControl tc = (TabControl)sender; string tag = (string)tc.TabPages[tc.SelectedIndex].Tag; @@ -401,7 +402,7 @@ private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e) DoReportSyntax(false); break; case "preview": // run report using generated report syntax - DoReportPreview(); + await DoReportPreview(); break; default: break; @@ -939,7 +940,7 @@ private void DoReportSyntaxQParameters(CultureInfo cinfo, StringBuilder sb, stri sb.Append(""); } - private bool DoReportPreview() + private async Task DoReportPreview() { if (!DoReportSyntax(true)) return false; @@ -952,7 +953,7 @@ private bool DoReportPreview() { rdlViewer1.GetDataSourceReferencePassword = _rUserControl.SharedDatasetPassword; } - rdlViewer1.SourceRdl = tbReportSyntax.Text; + await rdlViewer1.SetSourceRdl(tbReportSyntax.Text); return true; } diff --git a/RdlDesign/DrillParametersDialog.cs b/RdlDesign/DrillParametersDialog.cs index 5d45e586..8c5f84a7 100644 --- a/RdlDesign/DrillParametersDialog.cs +++ b/RdlDesign/DrillParametersDialog.cs @@ -32,6 +32,7 @@ the website www.fyiReporting.com. using System.IO; using fyiReporting.RDL; using fyiReporting.RdlDesign.Resources; +using System.Threading.Tasks; namespace fyiReporting.RdlDesign { @@ -142,7 +143,7 @@ private void bFile_Click(object sender, System.EventArgs e) } } - private void bRefreshParms_Click(object sender, System.EventArgs e) + private async void bRefreshParms_Click(object sender, System.EventArgs e) { // Obtain the source Cursor savec = Cursor.Current; @@ -160,7 +161,7 @@ private void bRefreshParms_Click(object sender, System.EventArgs e) return; // error: message already displayed // Compile the report - Report report = this.GetReport(source, filename); + Report report = await this.GetReport(source, filename); if (report == null) return; // error: message already displayed @@ -213,7 +214,7 @@ private string GetSource(string file) return prog; } - private Report GetReport(string prog, string file) + private async Task GetReport(string prog, string file) { // Now parse the file RDLParser rdlp; @@ -228,7 +229,7 @@ private Report GetReport(string prog, string file) } rdlp.Folder = folder; - r = rdlp.Parse(); + r = await rdlp.Parse(); if (r.ErrorMaxSeverity > 4) { MessageBox.Show(Strings.DrillParametersDialog_ShowC_ReportHasErrors); diff --git a/RdlDesign/RdlEditPreview.cs b/RdlDesign/RdlEditPreview.cs index b62ad527..f25e0899 100644 --- a/RdlDesign/RdlEditPreview.cs +++ b/RdlDesign/RdlEditPreview.cs @@ -773,7 +773,6 @@ private void InitializeComponent() this.rdlPreview.ShowParameterPanel = true; this.rdlPreview.ShowWaitDialog = true; this.rdlPreview.SourceFile = null; - this.rdlPreview.SourceRdl = null; this.rdlPreview.UseTrueMargins = true; this.rdlPreview.Zoom = 0.5495112F; this.rdlPreview.ZoomMode = fyiReporting.RdlViewer.ZoomEnum.FitWidth; @@ -856,7 +855,7 @@ private void dcDesign_SelectionMoved(object sender, System.EventArgs e) } } - private void tcEHP_SelectedIndexChanged(object sender, System.EventArgs e) + private async void tcEHP_SelectedIndexChanged(object sender, System.EventArgs e) { TabControl tc = (TabControl) sender; DesignTabs tag = (DesignTabs)tc.SelectedIndex; @@ -877,7 +876,7 @@ private void tcEHP_SelectedIndexChanged(object sender, System.EventArgs e) if (tag == DesignTabs.Preview) { if (rdlPreview.SourceRdl != scintilla1.Text) // sync up preview - this.rdlPreview.SourceRdl = scintilla1.Text; + await this.rdlPreview.SetSourceRdl(scintilla1.Text); } else if (tag == DesignTabs.Design) { @@ -904,14 +903,14 @@ private void tcEHP_SelectedIndexChanged(object sender, System.EventArgs e) /// /// Print the report. /// - public void Print(PrintDocument pd) + public async void Print(PrintDocument pd) { - this.rdlPreview.Print(pd); + await this.rdlPreview.Print(pd); } - public void SaveAs(string filename, OutputPresentationType type) + public async void SaveAs(string filename, OutputPresentationType type) { - this.rdlPreview.SaveAs(filename, type); + await this.rdlPreview.SaveAs(filename, type); } public string GetRdlText() diff --git a/RdlDesign/SubreportCtl.cs b/RdlDesign/SubreportCtl.cs index c2099c06..97d56b97 100644 --- a/RdlDesign/SubreportCtl.cs +++ b/RdlDesign/SubreportCtl.cs @@ -31,6 +31,7 @@ the website www.fyiReporting.com. using System.IO; using fyiReporting.RDL; using fyiReporting.RdlDesign.Resources; +using System.Threading.Tasks; namespace fyiReporting.RdlDesign { @@ -262,7 +263,7 @@ private void bFile_Click(object sender, System.EventArgs e) } } - private void bRefreshParms_Click(object sender, System.EventArgs e) + private async void bRefreshParms_Click(object sender, System.EventArgs e) { // Obtain the source string filename=""; @@ -277,7 +278,7 @@ private void bRefreshParms_Click(object sender, System.EventArgs e) return; // error: message already displayed // Compile the report - Report report = this.GetReport(source, filename); + Report report = await this.GetReport(source, filename); if (report == null) return; // error: message already displayed @@ -316,7 +317,7 @@ private string GetSource(string file) return prog; } - private Report GetReport(string prog, string file) + private async Task GetReport(string prog, string file) { // Now parse the file RDLParser rdlp; @@ -329,7 +330,7 @@ private Report GetReport(string prog, string file) folder = Environment.CurrentDirectory; rdlp.Folder = folder; - r = rdlp.Parse(); + r = await rdlp.Parse(); if (r.ErrorMaxSeverity > 4) { MessageBox.Show(Strings.DrillParametersDialog_ShowC_ReportHasErrors); diff --git a/RdlDesktop/ConnectionThread.cs b/RdlDesktop/ConnectionThread.cs index 6be14cb8..c2e33101 100644 --- a/RdlDesktop/ConnectionThread.cs +++ b/RdlDesktop/ConnectionThread.cs @@ -30,6 +30,7 @@ the website www.fyiReporting.com. using System.Collections.Specialized; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RdlDesktop @@ -96,7 +97,7 @@ public string WorkingDir } // Build an HTML page for directories - public string ProcessDirectory(string directory) + public async Task ProcessDirectory(string directory) { StringWriter sw = new StringWriter(); DirectoryInfo di; @@ -123,8 +124,8 @@ public string ProcessDirectory(string directory) fi = new FileInfo(filename); if (fi.Exists) { - string mimeType; - byte[] ba = ProcessReportFile(directory + "index.rdl", filename, null, fi.LastWriteTime, out mimeType); + + (byte[] ba, string mimeType) = await ProcessReportFile(directory + "index.rdl", filename, null, fi.LastWriteTime); result = Encoding.ASCII.GetString(ba); } } @@ -184,12 +185,12 @@ public string ProcessDirectory(string directory) } // Handle the processing of a report - private byte[] ProcessReportFile(string url, string file, string parms, DateTime lastUpdateTime, out string mimeType) + private async Task<(byte[] Report, string MimeType)> ProcessReportFile(string url, string file, string parms, DateTime lastUpdateTime) { byte[] result=null; string source; - mimeType = "text/html"; // set the default + string mimeType = "text/html"; // set the default // try finding report in the server cache! IList il = _server.Cache.Find(url + (parms==null?"":parms), lastUpdateTime); @@ -206,22 +207,21 @@ private byte[] ProcessReportFile(string url, string file, string parms, DateTime if (_server.TraceLevel >= 0) Console.WriteLine("Cache read exception in ProcessReportFile: {0} {1}", il[0], ex.Message); } - return result; + return (result,mimeType); } // Obtain the source if (!ProcessReportGetSource(file, out source)) { - return Encoding.ASCII.GetBytes(source); // we got an error opening file; source contains html error text + return (Encoding.ASCII.GetBytes(source), mimeType); // we got an error opening file; source contains html error text } // Compile the report - string msgs=""; - Report report = ProcessReportCompile(file, source, out msgs); + (Report report, string msgs) = await ProcessReportCompile(file, source); if (report == null) { mimeType = "text/html"; // force to html - return Encoding.ASCII.GetBytes(String.Format("

Report '{0}' has the following syntax errors.

{1}", url, msgs)); + return (Encoding.ASCII.GetBytes(String.Format("

Report '{0}' has the following syntax errors.

{1}", url, msgs)), mimeType); } // Obtain the result HTML from running the report @@ -260,7 +260,7 @@ private byte[] ProcessReportFile(string url, string file, string parms, DateTime ProcessReport pr = new ProcessReport(report, sg); - pr.Run(ld, type); + await pr.Run(ld, type); // handle any error messages if (report.ErrorMaxSeverity > 0) @@ -338,7 +338,7 @@ private byte[] ProcessReportFile(string url, string file, string parms, DateTime mimeType = "text/html"; // force to html } - return result; + return (result, mimeType); } private ListDictionary ProcessReportGetParms(string parms) @@ -386,19 +386,19 @@ private bool ProcessReportGetSource(string file, out string source) return true; } - private Report ProcessReportCompile(string file, string prog, out string msgs) + private async Task<(Report Report, string Msgs)> ProcessReportCompile(string file, string prog) { // Now parse the file RDLParser rdlp; Report r; - msgs = ""; + string msgs = ""; try { rdlp = new RDLParser(prog); rdlp.Folder = Path.GetDirectoryName(file); rdlp.DataSourceReferencePassword = new NeedPassword(this.GetPassword); - r = rdlp.Parse(); + r = await rdlp.Parse(); if (r.ErrorMaxSeverity > 0) { // have errors fill out the msgs @@ -428,7 +428,7 @@ private Report ProcessReportCompile(string file, string prog, out string msgs) } - return r; + return (r, msgs); } private string GetPassword() @@ -533,7 +533,7 @@ public void SendToBrowser(Byte[] bSendData, ref Socket mySocket) } //This method Accepts new connection - public void HandleConnection(object state) + public async Task HandleConnection() { DateTime sDateTime; // start date time int iStartPos = 0; @@ -636,7 +636,7 @@ public void HandleConnection(object state) if (sRequestedFile.Length == 0 ) { string directoryHTML; - directoryHTML = ProcessDirectory(sDirName); + directoryHTML = await ProcessDirectory(sDirName); SendHeader(sHttpVersion, "text/html", directoryHTML.Length, " 200 OK", null, ref mySocket); SendToBrowser(directoryHTML, ref mySocket); @@ -690,7 +690,7 @@ public void HandleConnection(object state) else url = sRequest; string mtype; - byte[] ba = ProcessReportFile(url, sPhysicalFilePath, sParameters, fi.LastWriteTime, out mtype); + (byte[] ba, mtype) = await ProcessReportFile(url, sPhysicalFilePath, sParameters, fi.LastWriteTime); SendHeader(sHttpVersion, mtype, ba.Length, " 200 OK", fileTime, ref mySocket); SendToBrowser(ba, ref mySocket); mySocket.Close(); diff --git a/RdlDesktop/RdlDesktop.cs b/RdlDesktop/RdlDesktop.cs index 1ec8459c..b3f6cec3 100644 --- a/RdlDesktop/RdlDesktop.cs +++ b/RdlDesktop/RdlDesktop.cs @@ -133,8 +133,8 @@ public void RunServer() if (_continue) { ConnectionThread c = new ConnectionThread(this, myListener, sr, wd); - ThreadPool.QueueUserWorkItem(new WaitCallback(c.HandleConnection)); - } + ThreadPool.QueueUserWorkItem(async _ => await c.HandleConnection()); + } } } catch(Exception e) diff --git a/RdlEngine/Definition/Action.cs b/RdlEngine/Definition/Action.cs index 236feb53..1dc2c70c 100644 --- a/RdlEngine/Definition/Action.cs +++ b/RdlEngine/Definition/Action.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -75,14 +76,14 @@ internal Action(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { - if (_Hyperlink != null) - _Hyperlink.FinalPass(); - if (_Drillthrough != null) - _Drillthrough.FinalPass(); - if (_BookmarkLink != null) - _BookmarkLink.FinalPass(); + if (_Hyperlink != null) + await _Hyperlink.FinalPass(); + if (_Drillthrough != null) + await _Drillthrough.FinalPass(); + if (_BookmarkLink != null) + await _BookmarkLink.FinalPass(); return; } @@ -92,12 +93,12 @@ internal Expression Hyperlink set { _Hyperlink = value; } } - internal String HyperLinkValue(Report rpt, Row r) + internal async Task HyperLinkValue(Report rpt, Row r) { if (_Hyperlink == null) return null; - return _Hyperlink.EvaluateString(rpt, r); + return await _Hyperlink.EvaluateString(rpt, r); } internal Drillthrough Drill @@ -112,12 +113,12 @@ internal Expression BookmarkLink set { _BookmarkLink = value; } } - internal String BookmarkLinkValue(Report rpt, Row r) + internal async Task BookmarkLinkValue(Report rpt, Row r) { if (_BookmarkLink == null) return null; - return _BookmarkLink.EvaluateString(rpt, r); + return await _BookmarkLink.EvaluateString(rpt, r); } } } diff --git a/RdlEngine/Definition/Axis.cs b/RdlEngine/Definition/Axis.cs index 0299a9a7..b7031f27 100644 --- a/RdlEngine/Definition/Axis.cs +++ b/RdlEngine/Definition/Axis.cs @@ -21,6 +21,7 @@ limitations under the License. the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -178,27 +179,27 @@ internal Axis(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_MajorInterval != null) - _MajorInterval.FinalPass(); + await _MajorInterval.FinalPass(); if (_MinorInterval != null) - _MinorInterval.FinalPass(); + await _MinorInterval.FinalPass(); if (_Max != null) - _Max.FinalPass(); + await _Max.FinalPass(); if (_Min != null) - _Min.FinalPass(); + await _Min.FinalPass(); if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); if (_Title != null) - _Title.FinalPass(); + await _Title.FinalPass(); // 20022008 AJM GJL - Second Y axis if (_Title2 != null) - _Title2.FinalPass(); + await _Title2.FinalPass(); if (_MajorGridLines != null) - _MajorGridLines.FinalPass(); + await _MajorGridLines.FinalPass(); if (_MinorGridLines != null) - _MinorGridLines.FinalPass(); + await _MinorGridLines.FinalPass(); return; } @@ -304,18 +305,18 @@ internal Expression Max set { _Max = value; } } //GJL 010308 --- Changed from int... We may want to start / stop a chart on a decimal - internal double MaxEval(Report r, Row row) + internal async Task MaxEval(Report r, Row row) { if (_Max == null) return (double)int.MinValue; - return _Max.EvaluateDouble(r, row); + return await _Max.EvaluateDouble(r, row); } - internal double MinEval(Report r, Row row) + internal async Task MinEval(Report r, Row row) { if (_Min == null) return (double)int.MinValue; - return _Min.EvaluateDouble(r, row); + return await _Min.EvaluateDouble(r, row); } //WP 12 may 2008 -- set up month gridlines for report internal bool Month diff --git a/RdlEngine/Definition/Body.cs b/RdlEngine/Definition/Body.cs index 3deec1f8..bc51772f 100644 --- a/RdlEngine/Definition/Body.cs +++ b/RdlEngine/Definition/Body.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -81,27 +82,27 @@ internal Body(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "Body Height not specified."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { ip.BodyStart(this); if (_ReportItems != null) - _ReportItems.Run(ip, null); // not sure about the row here? + await _ReportItems.Run(ip, null); // not sure about the row here? ip.BodyEnd(this); return ; } - internal void RunPage(Pages pgs) + internal async Task RunPage(Pages pgs) { if (OwnerReport.Subreport == null) { // Only set bottom of pages when on top level report @@ -111,7 +112,7 @@ internal void RunPage(Pages pgs) this.SetCurrentColumn(pgs.Report, 0); if (_ReportItems != null) - _ReportItems.RunPage(pgs, null, OwnerReport.LeftMargin.Points); + await _ReportItems.RunPage(pgs, null, OwnerReport.LeftMargin.Points); return ; } diff --git a/RdlEngine/Definition/CategoryAxis.cs b/RdlEngine/Definition/CategoryAxis.cs index 8c37ad94..80965792 100644 --- a/RdlEngine/Definition/CategoryAxis.cs +++ b/RdlEngine/Definition/CategoryAxis.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -56,10 +57,10 @@ internal CategoryAxis(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Axis != null) - _Axis.FinalPass(); + await _Axis.FinalPass(); return; } diff --git a/RdlEngine/Definition/CategoryGrouping.cs b/RdlEngine/Definition/CategoryGrouping.cs index e14facb4..4f8ec1bc 100644 --- a/RdlEngine/Definition/CategoryGrouping.cs +++ b/RdlEngine/Definition/CategoryGrouping.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -66,12 +67,12 @@ internal CategoryGrouping(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p OwnerReport.rl.LogError(8, "CategoryGrouping requires either DynamicCategories element or StaticCategories element, but not both."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DynamicCategories != null) - _DynamicCategories.FinalPass(); + await _DynamicCategories.FinalPass(); if (_StaticCategories != null) - _StaticCategories.FinalPass(); + await _StaticCategories.FinalPass(); return; } diff --git a/RdlEngine/Definition/CategoryGroupings.cs b/RdlEngine/Definition/CategoryGroupings.cs index 2e2b6a81..43d7a5ec 100644 --- a/RdlEngine/Definition/CategoryGroupings.cs +++ b/RdlEngine/Definition/CategoryGroupings.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -62,11 +63,11 @@ internal CategoryGroupings(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (CategoryGrouping cg in _Items) { - cg.FinalPass(); + await cg.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Chart.cs b/RdlEngine/Definition/Chart.cs index 4d133ed4..a7b210b4 100644 --- a/RdlEngine/Definition/Chart.cs +++ b/RdlEngine/Definition/Chart.cs @@ -24,6 +24,8 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; @@ -198,70 +200,70 @@ internal Chart(ReportDefn r, ReportLink p, XmlNode xNode):base(r, p, xNode) } - override internal void FinalPass() + async override internal Task FinalPass() { - base.FinalPass(); + await base.FinalPass(); if (_SeriesGroupings != null) - _SeriesGroupings.FinalPass(); + await _SeriesGroupings.FinalPass(); if (_CategoryGroupings != null) - _CategoryGroupings.FinalPass(); + await _CategoryGroupings.FinalPass(); if (_ChartData != null) - _ChartData.FinalPass(); + await _ChartData.FinalPass(); if (_Legend != null) - _Legend.FinalPass(); + await _Legend.FinalPass(); if (_CategoryAxis != null) - _CategoryAxis.FinalPass(); + await _CategoryAxis.FinalPass(); if (_ValueAxis != null) - _ValueAxis.FinalPass(); + await _ValueAxis.FinalPass(); if (_Title != null) - _Title.FinalPass(); + await _Title.FinalPass(); if (_ThreeDProperties != null) - _ThreeDProperties.FinalPass(); + await _ThreeDProperties.FinalPass(); if (_PlotArea != null) - _PlotArea.FinalPass(); + await _PlotArea.FinalPass(); //AJM GJL 14082008 if (_Palette != null) - _Palette.FinalPass(); + await _Palette.FinalPass(); if (_isHYNEsWonderfulVector != null) - _isHYNEsWonderfulVector.FinalPass(); + await _isHYNEsWonderfulVector.FinalPass(); if (_showTooltips != null) - _showTooltips.FinalPass(); + await _showTooltips.FinalPass(); if (_showTooltipsX != null) - _showTooltipsX.FinalPass(); + await _showTooltipsX.FinalPass(); if (_Subtype != null) - _Subtype.FinalPass(); + await _Subtype.FinalPass(); if (_ToolTipXFormat != null) - _ToolTipXFormat.FinalPass(); + await _ToolTipXFormat.FinalPass(); if (_ToolTipYFormat != null) - _ToolTipYFormat.FinalPass(); + await _ToolTipYFormat.FinalPass(); if (this.OwnerReport.rl.MaxSeverity < 8) // Don't take this step if already have errors { - _ChartMatrix = GenerateMatrix(); // GenerateMatrix() needs no error in defn to date - _ChartMatrix.FinalPass(); + _ChartMatrix = GenerateMatrix(); // GenerateMatrix() needs no error in defn to date + await _ChartMatrix.FinalPass(); } return; } - override internal void Run(IPresent ip, Row row) + override internal async Task Run(IPresent ip, Row row) { Report rpt = ip.Report(); _ChartMatrix.RunReset(rpt); - Rows _Data = GetFilteredData(ip.Report(), row); + Rows _Data = await GetFilteredData(ip.Report(), row); SetMyData(ip.Report(), _Data); - if (!AnyRows(ip, _Data)) // if no rows, return + if (!await AnyRows(ip, _Data)) // if no rows, return return; // Build the Chart bitmap, along with data regions ChartBase cb=null; try { - cb = RunChartBuild(rpt, row); + cb = await RunChartBuild(rpt, row); - ip.Chart(this, row, cb); + await ip.Chart(this, row, cb); } catch (Exception ex) { @@ -275,20 +277,20 @@ override internal void Run(IPresent ip, Row row) return; } - override internal void RunPage(Pages pgs, Row row) + override internal async Task RunPage(Pages pgs, Row row) { Report rpt = pgs.Report; - if (IsHidden(pgs.Report, row)) + if (await IsHidden(pgs.Report, row)) return; _ChartMatrix.RunReset(rpt); - Rows _Data = GetFilteredData(rpt, row); + Rows _Data = await GetFilteredData(rpt, row); SetMyData(rpt, _Data); SetPagePositionBegin(pgs); - if (!AnyRowsPage(pgs, _Data)) // if no rows return + if (!await AnyRowsPage(pgs, _Data)) // if no rows return return; // nothing left to do // Build the Chart bitmap, along with data regions @@ -296,18 +298,18 @@ override internal void RunPage(Pages pgs, Row row) ChartBase cb=null; try { - cb = RunChartBuild(rpt, row); // Build the chart + cb = await RunChartBuild(rpt, row); // Build the chart #if DRAWINGCOMPAT p = RunPage_Bitmap(pgs, row, rpt, cb); #else - if (!_isHYNEsWonderfulVector.EvaluateBoolean(rpt,row)) //AJM GJL 14082008 'Classic' Rendering + if (!await _isHYNEsWonderfulVector.EvaluateBoolean(rpt,row)) //AJM GJL 14082008 'Classic' Rendering { - p = RunPage_Bitmap(pgs, row, rpt, cb); + p = await RunPage_Bitmap(pgs, row, rpt, cb); } else //Ultimate Rendering - Vector //AJM GJL 14082008 { - p = RunPage_Emf(pgs, row, rpt, cb); + p = await RunPage_Emf(pgs, row, rpt, cb); } #endif @@ -326,7 +328,7 @@ override internal void RunPage(Pages pgs, Row row) } #if !DRAWINGCOMPAT - private Page RunPage_Emf(Pages pgs, Row row, Report rpt, ChartBase cb) + private async Task RunPage_Emf(Pages pgs, Row row, Report rpt, ChartBase cb) { Page p; var im = cb.Image(rpt); // Grab the image @@ -343,7 +345,7 @@ private Page RunPage_Emf(Pages pgs, Row row, Report rpt, ChartBase cb) RunPageRegionBegin(pgs); - SetPagePositionAndStyle(rpt, pi, row); + await SetPagePositionAndStyle(rpt, pi, row); pi.SI.BackgroundImage = null; // chart already has the background image if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty()) @@ -383,7 +385,7 @@ private Page RunPage_Emf(Pages pgs, Row row, Report rpt, ChartBase cb) } #endif - private Page RunPage_Bitmap(Pages pgs, Row row, Report rpt, ChartBase cb) + private async Task RunPage_Bitmap(Pages pgs, Row row, Report rpt, ChartBase cb) { Page p; Drawing.Image im = cb.Image(rpt); // Grab the image @@ -421,7 +423,7 @@ private Page RunPage_Bitmap(Pages pgs, Row row, Report rpt, ChartBase cb) RunPageRegionBegin(pgs); - SetPagePositionAndStyle(rpt, pi, row); + await SetPagePositionAndStyle(rpt, pi, row); pi.SI.BackgroundImage = null; // chart already has the background image if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty()) @@ -447,13 +449,14 @@ private Page RunPage_Bitmap(Pages pgs, Row row, Report rpt, ChartBase cb) return p; } - ChartBase RunChartBuild(Report rpt, Row row) + async Task RunChartBuild(Report rpt, Row row) { // Get the matrix that defines the data; _ChartMatrix.SetMyData(rpt, GetMyData(rpt)); // set the data in the matrix int maxColumns; int maxRows; - MatrixCellEntry[,] matrix = _ChartMatrix.RunBuild(rpt, out maxRows, out maxColumns); + MatrixCellEntry[,] matrix; + (matrix, maxRows, maxColumns)= await _ChartMatrix.RunBuild(rpt); // Build the Chart bitmap, along with data regions ChartBase cb=null; diff --git a/RdlEngine/Definition/ChartBar.cs b/RdlEngine/Definition/ChartBar.cs index 3fcffb9e..aef5592f 100644 --- a/RdlEngine/Definition/ChartBar.cs +++ b/RdlEngine/Definition/ChartBar.cs @@ -23,6 +23,8 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Runtime.InteropServices; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; #else @@ -32,38 +34,38 @@ the website www.fyiReporting.com. namespace fyiReporting.RDL { - ///

- /// Bar chart definition and processing. - /// - internal class ChartBar: ChartBase - { - int _GapSize = 6; // TODO: hard code for now - - internal ChartBar(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX,Expression _ToolTipYFormat, Expression _ToolTipXFormat) - : base(r, row, c, m,showTooltips,showTooltipsX,_ToolTipYFormat,_ToolTipXFormat) - { - } - - override internal void Draw(Report rpt) - { - CreateSizedBitmap(); + /// + /// Bar chart definition and processing. + /// + internal class ChartBar : ChartBase + { + int _GapSize = 6; // TODO: hard code for now + + internal ChartBar(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX, Expression _ToolTipYFormat, Expression _ToolTipXFormat) + : base(r, row, c, m, showTooltips, showTooltipsX, _ToolTipYFormat, _ToolTipXFormat) + { + } + + override internal async Task Draw(Report rpt) + { + CreateSizedBitmap(); #if !DRAWINGCOMPAT //AJM GJL 14082008 Using Vector Graphics if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - using (Drawing.Graphics g1 = Drawing.Graphics.FromImage(_bm)) - { - _aStream = new System.IO.MemoryStream(); - IntPtr HDC = g1.GetHdc(); - _mf = new Drawing.Imaging.Metafile(_aStream, HDC, - new Drawing.RectangleF(0, 0, _bm.Width, _bm.Height), Drawing.Imaging.MetafileFrameUnit.Pixel); - g1.ReleaseHdc(HDC); - } - } - - - using (Drawing.Graphics g = Drawing.Graphics.FromImage(_mf != null ? _mf : _bm)) + { + using (Drawing.Graphics g1 = Drawing.Graphics.FromImage(_bm)) + { + _aStream = new System.IO.MemoryStream(); + IntPtr HDC = g1.GetHdc(); + _mf = new Drawing.Imaging.Metafile(_aStream, HDC, + new Drawing.RectangleF(0, 0, _bm.Width, _bm.Height), Drawing.Imaging.MetafileFrameUnit.Pixel); + g1.ReleaseHdc(HDC); + } + } + + + using (Drawing.Graphics g = Drawing.Graphics.FromImage(_mf != null ? _mf : _bm)) #else using (Drawing.Graphics g = Drawing.Graphics.FromImage(_bm)) #endif @@ -74,93 +76,93 @@ override internal void Draw(Report rpt) g.PixelOffsetMode = Drawing.Drawing2D.PixelOffsetMode.None; g.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality; - // Adjust the top margin to depend on the title height - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, ChartDefn.Title); - Layout.TopMargin = titleSize.Height; - - double max=0,min=0; // Get the max and min values - // 20022008 AJM GJL - Now requires Y axis identifier - GetValueMaxMin(rpt, ref max, ref min, 0,1); - - DrawChartStyle(rpt, g); - - // Draw title; routine determines if necessary - DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, _bm.Width, Layout.TopMargin)); - - // Adjust the left margin to depend on the Category Axis - Drawing.Size caSize = CategoryAxisSize(rpt, g); - Layout.LeftMargin = caSize.Width; - - // Adjust the bottom margin to depend on the Value Axis - Drawing.Size vaSize = ValueAxisSize(rpt, g, min, max); - Layout.BottomMargin = vaSize.Height; - - // Draw legend - Drawing.Rectangle lRect = DrawLegend(rpt, g, false, true); - // 20022008 AJM GJL - Requires Rpt and Graphics - AdjustMargins(lRect,rpt,g ); // Adjust margins based on legend. - - // Draw Plot area - DrawPlotAreaStyle(rpt, g, lRect); - - // Draw Value Axis - if (vaSize.Width > 0) // If we made room for the axis - we need to draw it - DrawValueAxis(rpt, g, min, max, - new Drawing.Rectangle(Layout.LeftMargin, _bm.Height-Layout.BottomMargin, _bm.Width - Layout.LeftMargin - Layout.RightMargin, vaSize.Height), Layout.TopMargin, _bm.Height - Layout.BottomMargin); - - // Draw Category Axis - if (caSize.Height > 0) - DrawCategoryAxis(rpt, g, - new Drawing.Rectangle(Layout.LeftMargin - caSize.Width, Layout.TopMargin, caSize.Width, _bm.Height - Layout.TopMargin - Layout.BottomMargin)); - - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked) - DrawPlotAreaStacked(rpt, g, min, max); - else if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) - DrawPlotAreaPercentStacked(rpt, g); - else - DrawPlotAreaPlain(rpt, g, min, max); - - DrawLegend(rpt, g, false, false); // after the plot is drawn - } - } - - void DrawPlotAreaPercentStacked(Report rpt, Drawing.Graphics g) - { - int barsNeeded = CategoryCount; - int gapsNeeded = CategoryCount * 2; - - // Draw Plot area data - double max = 1; - - int heightBar = (int) ((Layout.PlotArea.Height - (gapsNeeded*_GapSize)) / barsNeeded); - int maxBarWidth = (int) (Layout.PlotArea.Width); - - // Loop thru calculating all the data points - for (int iRow = 1; iRow <= CategoryCount; iRow++) - { - int barLoc=(int) (Layout.PlotArea.Top + ((iRow-1) * ((double) (Layout.PlotArea.Height) / CategoryCount))); - barLoc += _GapSize; // space before series - - double sum=0; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - sum += GetDataValue(rpt, iRow, iCol); - } - double v=0; - int saveX=0; - double t=0; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - t = GetDataValue(rpt, iRow, iCol); + // Adjust the top margin to depend on the title height + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, ChartDefn.Title); + Layout.TopMargin = titleSize.Height; + + double max = 0, min = 0; // Get the max and min values + // 20022008 AJM GJL - Now requires Y axis identifier + (max, min) = await GetValueMaxMin(rpt, max, min, 0, 1); + + await DrawChartStyle(rpt, g); + + // Draw title; routine determines if necessary + await DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, _bm.Width, Layout.TopMargin)); + + // Adjust the left margin to depend on the Category Axis + Drawing.Size caSize = await CategoryAxisSize(rpt, g); + Layout.LeftMargin = caSize.Width; + + // Adjust the bottom margin to depend on the Value Axis + Drawing.Size vaSize = await ValueAxisSize(rpt, g, min, max); + Layout.BottomMargin = vaSize.Height; + + // Draw legend + Drawing.Rectangle lRect = await DrawLegend(rpt, g, false, true); + // 20022008 AJM GJL - Requires Rpt and Graphics + AdjustMargins(lRect, rpt, g); // Adjust margins based on legend. + + // Draw Plot area + await DrawPlotAreaStyle(rpt, g, lRect); + + // Draw Value Axis + if (vaSize.Width > 0) // If we made room for the axis - we need to draw it + await DrawValueAxis(rpt, g, min, max, + new Drawing.Rectangle(Layout.LeftMargin, _bm.Height - Layout.BottomMargin, _bm.Width - Layout.LeftMargin - Layout.RightMargin, vaSize.Height), Layout.TopMargin, _bm.Height - Layout.BottomMargin); + + // Draw Category Axis + if (caSize.Height > 0) + await DrawCategoryAxis(rpt, g, + new Drawing.Rectangle(Layout.LeftMargin - caSize.Width, Layout.TopMargin, caSize.Width, _bm.Height - Layout.TopMargin - Layout.BottomMargin)); + + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked) + await DrawPlotAreaStacked(rpt, g, min, max); + else if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) + await DrawPlotAreaPercentStacked(rpt, g); + else + await DrawPlotAreaPlain(rpt, g, min, max); + + await DrawLegend(rpt, g, false, false); // after the plot is drawn + } + } + + async Task DrawPlotAreaPercentStacked(Report rpt, Drawing.Graphics g) + { + int barsNeeded = CategoryCount; + int gapsNeeded = CategoryCount * 2; + + // Draw Plot area data + double max = 1; + + int heightBar = (int)((Layout.PlotArea.Height - (gapsNeeded * _GapSize)) / barsNeeded); + int maxBarWidth = (int)(Layout.PlotArea.Width); + + // Loop thru calculating all the data points + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + int barLoc = (int)(Layout.PlotArea.Top + ((iRow - 1) * ((double)(Layout.PlotArea.Height) / CategoryCount))); + barLoc += _GapSize; // space before series + + double sum = 0; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + sum += await GetDataValue(rpt, iRow, iCol); + } + double v = 0; + int saveX = 0; + double t = 0; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + t = await GetDataValue(rpt, iRow, iCol); v += t; - int x = (int) ((Math.Min(v/sum,max) / max) * maxBarWidth); + int x = (int)((Math.Min(v / sum, max) / max) * maxBarWidth); - Drawing.Rectangle rect; - rect = new Drawing.Rectangle(Layout.PlotArea.Left + saveX, barLoc, x - saveX, heightBar); + Drawing.Rectangle rect; + rect = new Drawing.Rectangle(Layout.PlotArea.Left + saveX, barLoc, x - saveX, heightBar); - DrawColumnBar(rpt, g, - GetSeriesBrush(rpt, iRow, iCol), + await DrawColumnBar(rpt, g, + await GetSeriesBrush(rpt, iRow, iCol), rect, iRow, iCol); //Add a metafilecomment to use as a tooltip GJL 26092008 @@ -169,375 +171,375 @@ void DrawPlotAreaPercentStacked(Report rpt, Drawing.Graphics g) String val = "ToolTip:" + t.ToString(_tooltipYFormat) + "|X:" + (int)rect.X + "|Y:" + (int)rect.Y + "|W:" + rect.Width + "|H:" + rect.Height; g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - - saveX = x; - } - } - - return; - } - - void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double min, double max) - { - int barsNeeded = SeriesCount * CategoryCount; - int gapsNeeded = CategoryCount * 2; - - // Draw Plot area data - int heightBar = (int) ((Layout.PlotArea.Height - (gapsNeeded*_GapSize)) / barsNeeded); - int maxBarWidth = (int) (Layout.PlotArea.Width); - - //int barLoc=Layout.LeftMargin; - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - int barLoc=(int) (Layout.PlotArea.Top + ((iRow-1) * ((double) (Layout.PlotArea.Height) / CategoryCount))); - barLoc += _GapSize; // space before series - for (int iCol=1; iCol <= SeriesCount; iCol++) - { - double v = this.GetDataValue(rpt, iRow, iCol); - int x = (int) (((Math.Min(v,max)-min) / (max-min)) * maxBarWidth); - - DrawColumnBar(rpt, g, GetSeriesBrush(rpt, iRow, iCol), - new Drawing.Rectangle(Layout.PlotArea.Left, barLoc, x, heightBar), iRow, iCol); + + saveX = x; + } + } + + return; + } + + async Task DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double min, double max) + { + int barsNeeded = SeriesCount * CategoryCount; + int gapsNeeded = CategoryCount * 2; + + // Draw Plot area data + int heightBar = (int)((Layout.PlotArea.Height - (gapsNeeded * _GapSize)) / barsNeeded); + int maxBarWidth = (int)(Layout.PlotArea.Width); + + //int barLoc=Layout.LeftMargin; + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + int barLoc = (int)(Layout.PlotArea.Top + ((iRow - 1) * ((double)(Layout.PlotArea.Height) / CategoryCount))); + barLoc += _GapSize; // space before series + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + double v = await this.GetDataValue(rpt, iRow, iCol); + int x = (int)(((Math.Min(v, max) - min) / (max - min)) * maxBarWidth); + + await DrawColumnBar(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), + new Drawing.Rectangle(Layout.PlotArea.Left, barLoc, x, heightBar), iRow, iCol); //Add a metafilecomment to use as a tooltip GJL 26092008 if (_showToolTips) { String val = "ToolTip:" + v.ToString(_tooltipYFormat) + "|X:" + (int)Layout.PlotArea.Left + "|Y:" + (int)(barLoc) + "|W:" + x + "|H:" + heightBar; g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - barLoc += heightBar; - } - } + barLoc += heightBar; + } + } - return; - } + return; + } - void DrawPlotAreaStacked(Report rpt, Drawing.Graphics g, double min, double max) - { - int barsNeeded = CategoryCount; - int gapsNeeded = CategoryCount * 2; + async Task DrawPlotAreaStacked(Report rpt, Drawing.Graphics g, double min, double max) + { + int barsNeeded = CategoryCount; + int gapsNeeded = CategoryCount * 2; - int heightBar = (int) ((Layout.PlotArea.Height - (gapsNeeded*_GapSize)) / barsNeeded); - int maxBarWidth = (int) (Layout.PlotArea.Width); + int heightBar = (int)((Layout.PlotArea.Height - (gapsNeeded * _GapSize)) / barsNeeded); + int maxBarWidth = (int)(Layout.PlotArea.Width); - // Loop thru calculating all the data points - for (int iRow = 1; iRow <= CategoryCount; iRow++) - { - int barLoc=(int) (Layout.PlotArea.Top + ((iRow-1) * ((double) (Layout.PlotArea.Height) / CategoryCount))); - barLoc += _GapSize; // space before series + // Loop thru calculating all the data points + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + int barLoc = (int)(Layout.PlotArea.Top + ((iRow - 1) * ((double)(Layout.PlotArea.Height) / CategoryCount))); + barLoc += _GapSize; // space before series - double v=0; + double v = 0; double t = 0; - int saveX=0; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - t = GetDataValue(rpt, iRow, iCol); + int saveX = 0; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + t = await GetDataValue(rpt, iRow, iCol); v += t; - int x = (int) (((Math.Min(v,max)-min) / (max-min)) * maxBarWidth); + int x = (int)(((Math.Min(v, max) - min) / (max - min)) * maxBarWidth); - Drawing.Rectangle rect; - rect = new Drawing.Rectangle(Layout.PlotArea.Left + saveX, barLoc, x - saveX, heightBar); + Drawing.Rectangle rect; + rect = new Drawing.Rectangle(Layout.PlotArea.Left + saveX, barLoc, x - saveX, heightBar); - DrawColumnBar(rpt, g, GetSeriesBrush(rpt, iRow, iCol), rect, iRow, iCol); + await DrawColumnBar(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), rect, iRow, iCol); if (_showToolTips) { String val = "ToolTip:" + v.ToString(_tooltipYFormat) + "|X:" + (int)rect.X + "|Y:" + (int)rect.Y + "|W:" + rect.Width + "|H:" + rect.Height; g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - saveX = x; - } - } - - return; - } - - // Calculate the size of the category axis - Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g) - { - _LastCategoryWidth = 0; - - Drawing.Size size=Drawing.Size.Empty; - if (this.ChartDefn.CategoryAxis == null) - return size; - Axis a = this.ChartDefn.CategoryAxis.Axis; - if (a == null) - return size; - Style s = a.Style; - - // Measure the title - size = DrawTitleMeasure(rpt, g, a.Title); - - if (!a.Visible) // don't need to calculate the height - return size; - - // Calculate the tallest category name - TypeCode tc; - int maxWidth=0; - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - object v = this.GetCategoryValue(rpt, iRow, out tc); - Drawing.Size tSize; - if (s == null) - tSize = Style.MeasureStringDefaults(rpt, g, v, tc, null, int.MaxValue); - - else - tSize =s.MeasureString(rpt, g, v, tc, null, int.MaxValue); - - if (tSize.Width > maxWidth) - maxWidth = tSize.Width; - - if (iRow == CategoryCount) - _LastCategoryWidth = tSize.Width; - } - - // Add on the widest category name - size.Width += maxWidth; - return size; - } - - // DrawCategoryAxis - void DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangle rect) - { - if (this.ChartDefn.CategoryAxis == null) - return; - Axis a = this.ChartDefn.CategoryAxis.Axis; - if (a == null) - return; - Style s = a.Style; - - Drawing.Size tSize = DrawTitleMeasure(rpt, g, a.Title); - DrawTitle(rpt, g, a.Title, - new Drawing.Rectangle(rect.Left, rect.Top, tSize.Width, rect.Height)); - - int drawHeight = rect.Height / CategoryCount; - TypeCode tc; - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - object v = this.GetCategoryValue(rpt, iRow, out tc); - - int drawLoc=(int) (rect.Top + ((iRow-1) * ((double) rect.Height / CategoryCount))); - - // Draw the category text - if (a.Visible) - { - Drawing.Rectangle drawRect = new Drawing.Rectangle(rect.Left + tSize.Width, drawLoc, rect.Width-tSize.Width, drawHeight); - if (s == null) - Style.DrawStringDefaults(g, v, drawRect); - else - s.DrawString(rpt, g, v, tc, null, drawRect); - } - // Draw the Major Tick Marks (if necessary) - DrawCategoryAxisTick(g, true, a.MajorTickMarks, new Drawing.Point(rect.Right, drawLoc)); - } - - // Draw the end on (if necessary) - DrawCategoryAxisTick(g, true, a.MajorTickMarks, new Drawing.Point(rect.Right, rect.Bottom)); - - return; - } - - protected void DrawCategoryAxisTick(Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, Drawing.Point p) - { - int len = bMajor? AxisTickMarkMajorLen: AxisTickMarkMinorLen; - switch (tickType) - { - case AxisTickMarksEnum.Outside: - g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y), new Drawing.Point(p.X-len, p.Y)); - break; - case AxisTickMarksEnum.Inside: - g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y), new Drawing.Point(p.X+len, p.Y)); - break; - case AxisTickMarksEnum.Cross: - g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X-len, p.Y), new Drawing.Point(p.X+len, p.Y)); - break; - case AxisTickMarksEnum.None: - default: - break; - } - return; - } - - void DrawColumnBar(Report rpt, Drawing.Graphics g, Drawing.Brush brush, Drawing.Rectangle rect, int iRow, int iCol) - { - g.FillRectangle(brush, rect); - g.DrawRectangle(Drawing.Pens.Black, rect); - - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked || - (ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) - { - DrawDataPoint(rpt, g, rect, iRow, iCol); - } - else - { - Drawing.Point p; - p = new Drawing.Point(rect.Right, rect.Top); - DrawDataPoint(rpt, g, p, iRow, iCol); - } - - - return; - } - - protected void DrawValueAxis(Report rpt, Drawing.Graphics g, double min, double max, Drawing.Rectangle rect, int plotTop, int plotBottom) - { - if (this.ChartDefn.ValueAxis == null) - return; - Axis a = this.ChartDefn.ValueAxis.Axis; - if (a == null) - return; - Style s = a.Style; - - // Account for tick marks - int tickSize=0; - if (a.MajorTickMarks == AxisTickMarksEnum.Cross || - a.MajorTickMarks == AxisTickMarksEnum.Outside) - tickSize = this.AxisTickMarkMajorLen; - else if (a.MinorTickMarks == AxisTickMarksEnum.Cross || - a.MinorTickMarks == AxisTickMarksEnum.Outside) - tickSize += this.AxisTickMarkMinorLen; + saveX = x; + } + } + + return; + } + + // Calculate the size of the category axis + async Task CategoryAxisSize(Report rpt, Drawing.Graphics g) + { + _LastCategoryWidth = 0; + + Drawing.Size size = Drawing.Size.Empty; + if (this.ChartDefn.CategoryAxis == null) + return size; + Axis a = this.ChartDefn.CategoryAxis.Axis; + if (a == null) + return size; + Style s = a.Style; + + // Measure the title + size = await DrawTitleMeasure(rpt, g, a.Title); + + if (!a.Visible) // don't need to calculate the height + return size; + + // Calculate the tallest category name + TypeCode tc; + int maxWidth = 0; + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + object v = this.GetCategoryValue(rpt, iRow, out tc); + Drawing.Size tSize; + if (s == null) + tSize = await Style.MeasureStringDefaults(rpt, g, v, tc, null, int.MaxValue); + + else + tSize = await s.MeasureString(rpt, g, v, tc, null, int.MaxValue); + + if (tSize.Width > maxWidth) + maxWidth = tSize.Width; + + if (iRow == CategoryCount) + _LastCategoryWidth = tSize.Width; + } + + // Add on the widest category name + size.Width += maxWidth; + return size; + } + + // DrawCategoryAxis + async Task DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangle rect) + { + if (this.ChartDefn.CategoryAxis == null) + return; + Axis a = this.ChartDefn.CategoryAxis.Axis; + if (a == null) + return; + Style s = a.Style; + + Drawing.Size tSize = await DrawTitleMeasure(rpt, g, a.Title); + await DrawTitle(rpt, g, a.Title, + new Drawing.Rectangle(rect.Left, rect.Top, tSize.Width, rect.Height)); + + int drawHeight = rect.Height / CategoryCount; + TypeCode tc; + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + object v = this.GetCategoryValue(rpt, iRow, out tc); + + int drawLoc = (int)(rect.Top + ((iRow - 1) * ((double)rect.Height / CategoryCount))); + + // Draw the category text + if (a.Visible) + { + Drawing.Rectangle drawRect = new Drawing.Rectangle(rect.Left + tSize.Width, drawLoc, rect.Width - tSize.Width, drawHeight); + if (s == null) + Style.DrawStringDefaults(g, v, drawRect); + else + await s.DrawString(rpt, g, v, tc, null, drawRect); + } + // Draw the Major Tick Marks (if necessary) + DrawCategoryAxisTick(g, true, a.MajorTickMarks, new Drawing.Point(rect.Right, drawLoc)); + } + + // Draw the end on (if necessary) + DrawCategoryAxisTick(g, true, a.MajorTickMarks, new Drawing.Point(rect.Right, rect.Bottom)); + + return; + } + + protected void DrawCategoryAxisTick(Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, Drawing.Point p) + { + int len = bMajor ? AxisTickMarkMajorLen : AxisTickMarkMinorLen; + switch (tickType) + { + case AxisTickMarksEnum.Outside: + g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y), new Drawing.Point(p.X - len, p.Y)); + break; + case AxisTickMarksEnum.Inside: + g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y), new Drawing.Point(p.X + len, p.Y)); + break; + case AxisTickMarksEnum.Cross: + g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X - len, p.Y), new Drawing.Point(p.X + len, p.Y)); + break; + case AxisTickMarksEnum.None: + default: + break; + } + return; + } + + async Task DrawColumnBar(Report rpt, Drawing.Graphics g, Drawing.Brush brush, Drawing.Rectangle rect, int iRow, int iCol) + { + g.FillRectangle(brush, rect); + g.DrawRectangle(Drawing.Pens.Black, rect); + + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked || + (ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) + { + await DrawDataPoint(rpt, g, rect, iRow, iCol); + } + else + { + Drawing.Point p; + p = new Drawing.Point(rect.Right, rect.Top); + await DrawDataPoint(rpt, g, p, iRow, iCol); + } + + + return; + } + + protected async Task DrawValueAxis(Report rpt, Drawing.Graphics g, double min, double max, Drawing.Rectangle rect, int plotTop, int plotBottom) + { + if (this.ChartDefn.ValueAxis == null) + return; + Axis a = this.ChartDefn.ValueAxis.Axis; + if (a == null) + return; + Style s = a.Style; + + // Account for tick marks + int tickSize = 0; + if (a.MajorTickMarks == AxisTickMarksEnum.Cross || + a.MajorTickMarks == AxisTickMarksEnum.Outside) + tickSize = this.AxisTickMarkMajorLen; + else if (a.MinorTickMarks == AxisTickMarksEnum.Cross || + a.MinorTickMarks == AxisTickMarksEnum.Outside) + tickSize += this.AxisTickMarkMinorLen; int intervalCount; double incr; - SetIncrementAndInterval(rpt, a, min, max, out incr, out intervalCount); // Calculate the interval count - - int maxValueHeight = 0; - double v = min; - Drawing.Size size= Drawing.Size.Empty; - - for (int i = 0; i < intervalCount+1; i++) - { - int x = (int) (((Math.Min(v,max)-min) / (max-min)) * rect.Width); - - if (!a.Visible) - { - // nothing to do - } - else if (s != null) - { - size = s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); - Drawing.Rectangle vRect = - new Drawing.Rectangle(rect.Left + x - (size.Width/2), rect.Top+tickSize, size.Width, size.Height); - s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); - } - else - { - size = Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); - Drawing.Rectangle vRect = - new Drawing.Rectangle(rect.Left + x - (size.Width/2), rect.Top+tickSize, size.Width, size.Height); - Style.DrawStringDefaults(g, v, vRect); - } - if (size.Height > maxValueHeight) // Need to keep track of the maximum height - maxValueHeight = size.Height; // this is probably overkill since it should always be the same?? - - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Left + x, plotTop), new Drawing.Point(rect.Left + x, plotBottom)); - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Left + x, plotBottom )); - - v += incr; - } - - // Draw the end points of the major grid lines - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Left, plotTop), new Drawing.Point(rect.Left, plotBottom)); - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Left, plotBottom)); - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Right, plotTop), new Drawing.Point(rect.Right, plotBottom)); - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Right, plotBottom)); - - Drawing.Size tSize = DrawTitleMeasure(rpt, g, a.Title); - DrawTitle(rpt, g, a.Title, - new Drawing.Rectangle(rect.Left, rect.Top+maxValueHeight+tickSize, rect.Width, tSize.Height)); - - return; - } - - protected void DrawValueAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) - { - if (gl == null || !gl.ShowGridLines) - return; - - if (gl.Style != null) - gl.Style.DrawStyleLine(rpt, g, null, s, e); - else - g.DrawLine(Drawing.Pens.Black, s, e); - - return; - } - - protected void DrawValueAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, ChartGridLines gl, Drawing.Point p) - { - if (tickType == AxisTickMarksEnum.None) - return; - - int len = bMajor? AxisTickMarkMajorLen: AxisTickMarkMinorLen; - Drawing.Point s, e; - switch (tickType) - { - case AxisTickMarksEnum.Inside: - s = new Drawing.Point(p.X, p.Y); - e = new Drawing.Point(p.X, p.Y-len); - break; - case AxisTickMarksEnum.Cross: - s = new Drawing.Point(p.X, p.Y-len); - e = new Drawing.Point(p.X, p.Y+len); - break; - case AxisTickMarksEnum.Outside: - default: - s = new Drawing.Point(p.X, p.Y+len); - e = new Drawing.Point(p.X, p.Y); - break; - } - Style style = gl.Style; - - if (style != null) - style.DrawStyleLine(rpt, g, null, s, e); - else - g.DrawLine(Drawing.Pens.Black, s, e); - - return; - } - - // Calculate the size of the value axis; width is max value width + title width - // height is max value height - protected Drawing.Size ValueAxisSize(Report rpt, Drawing.Graphics g, double min, double max) - { - Drawing.Size size=Drawing.Size.Empty; - if (ChartDefn.ValueAxis == null) - return size; - Axis a = ChartDefn.ValueAxis.Axis; - if (a == null) - return size; - - Drawing.Size minSize; - Drawing.Size maxSize; - if (!a.Visible) - { - minSize = maxSize = Drawing.Size.Empty; - } - else if (a.Style != null) - { - minSize = a.Style.MeasureString(rpt, g, min, TypeCode.Double, null, int.MaxValue); - maxSize = a.Style.MeasureString(rpt, g, max, TypeCode.Double, null, int.MaxValue); - } - else - { - minSize = Style.MeasureStringDefaults(rpt, g, min, TypeCode.Double, null, int.MaxValue); - maxSize = Style.MeasureStringDefaults(rpt, g, max, TypeCode.Double, null, int.MaxValue); - } - // Choose the largest - size.Width = Math.Max(minSize.Width, maxSize.Width); - size.Height = Math.Max(minSize.Height, maxSize.Height); - - // Now we need to add in the height of the title (if any) - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, a.Title); - size.Height += titleSize.Height; - - if (a.MajorTickMarks == AxisTickMarksEnum.Cross || - a.MajorTickMarks == AxisTickMarksEnum.Outside) - size.Height += this.AxisTickMarkMajorLen; - else if (a.MinorTickMarks == AxisTickMarksEnum.Cross || - a.MinorTickMarks == AxisTickMarksEnum.Outside) - size.Height += this.AxisTickMarkMinorLen; - - return size; - } - } + (incr, intervalCount) = await SetIncrementAndInterval(rpt, a, min, max); // Calculate the interval count + + int maxValueHeight = 0; + double v = min; + Drawing.Size size = Drawing.Size.Empty; + + for (int i = 0; i < intervalCount + 1; i++) + { + int x = (int)(((Math.Min(v, max) - min) / (max - min)) * rect.Width); + + if (!a.Visible) + { + // nothing to do + } + else if (s != null) + { + size = await s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); + Drawing.Rectangle vRect = + new Drawing.Rectangle(rect.Left + x - (size.Width / 2), rect.Top + tickSize, size.Width, size.Height); + await s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); + } + else + { + size = await Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); + Drawing.Rectangle vRect = + new Drawing.Rectangle(rect.Left + x - (size.Width / 2), rect.Top + tickSize, size.Width, size.Height); + Style.DrawStringDefaults(g, v, vRect); + } + if (size.Height > maxValueHeight) // Need to keep track of the maximum height + maxValueHeight = size.Height; // this is probably overkill since it should always be the same?? + + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Left + x, plotTop), new Drawing.Point(rect.Left + x, plotBottom)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Left + x, plotBottom)); + + v += incr; + } + + // Draw the end points of the major grid lines + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Left, plotTop), new Drawing.Point(rect.Left, plotBottom)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Left, plotBottom)); + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Right, plotTop), new Drawing.Point(rect.Right, plotBottom)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Right, plotBottom)); + + Drawing.Size tSize = await DrawTitleMeasure(rpt, g, a.Title); + await DrawTitle(rpt, g, a.Title, + new Drawing.Rectangle(rect.Left, rect.Top + maxValueHeight + tickSize, rect.Width, tSize.Height)); + + return; + } + + protected async Task DrawValueAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) + { + if (gl == null || !gl.ShowGridLines) + return; + + if (gl.Style != null) + await gl.Style.DrawStyleLine(rpt, g, null, s, e); + else + g.DrawLine(Drawing.Pens.Black, s, e); + + return; + } + + protected async Task DrawValueAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, ChartGridLines gl, Drawing.Point p) + { + if (tickType == AxisTickMarksEnum.None) + return; + + int len = bMajor ? AxisTickMarkMajorLen : AxisTickMarkMinorLen; + Drawing.Point s, e; + switch (tickType) + { + case AxisTickMarksEnum.Inside: + s = new Drawing.Point(p.X, p.Y); + e = new Drawing.Point(p.X, p.Y - len); + break; + case AxisTickMarksEnum.Cross: + s = new Drawing.Point(p.X, p.Y - len); + e = new Drawing.Point(p.X, p.Y + len); + break; + case AxisTickMarksEnum.Outside: + default: + s = new Drawing.Point(p.X, p.Y + len); + e = new Drawing.Point(p.X, p.Y); + break; + } + Style style = gl.Style; + + if (style != null) + await style.DrawStyleLine(rpt, g, null, s, e); + else + g.DrawLine(Drawing.Pens.Black, s, e); + + return; + } + + // Calculate the size of the value axis; width is max value width + title width + // height is max value height + protected async Task ValueAxisSize(Report rpt, Drawing.Graphics g, double min, double max) + { + Drawing.Size size = Drawing.Size.Empty; + if (ChartDefn.ValueAxis == null) + return size; + Axis a = ChartDefn.ValueAxis.Axis; + if (a == null) + return size; + + Drawing.Size minSize; + Drawing.Size maxSize; + if (!a.Visible) + { + minSize = maxSize = Drawing.Size.Empty; + } + else if (a.Style != null) + { + minSize = await a.Style.MeasureString(rpt, g, min, TypeCode.Double, null, int.MaxValue); + maxSize = await a.Style.MeasureString(rpt, g, max, TypeCode.Double, null, int.MaxValue); + } + else + { + minSize = await Style.MeasureStringDefaults(rpt, g, min, TypeCode.Double, null, int.MaxValue); + maxSize = await Style.MeasureStringDefaults(rpt, g, max, TypeCode.Double, null, int.MaxValue); + } + // Choose the largest + size.Width = Math.Max(minSize.Width, maxSize.Width); + size.Height = Math.Max(minSize.Height, maxSize.Height); + + // Now we need to add in the height of the title (if any) + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, a.Title); + size.Height += titleSize.Height; + + if (a.MajorTickMarks == AxisTickMarksEnum.Cross || + a.MajorTickMarks == AxisTickMarksEnum.Outside) + size.Height += this.AxisTickMarkMajorLen; + else if (a.MinorTickMarks == AxisTickMarksEnum.Cross || + a.MinorTickMarks == AxisTickMarksEnum.Outside) + size.Height += this.AxisTickMarkMinorLen; + + return size; + } + } } diff --git a/RdlEngine/Definition/ChartBase.cs b/RdlEngine/Definition/ChartBase.cs index bb3f71a8..a08165d2 100644 --- a/RdlEngine/Definition/ChartBase.cs +++ b/RdlEngine/Definition/ChartBase.cs @@ -20,8 +20,11 @@ limitations under the License. For additional information, email info@fyireporting.com or visit the website www.fyiReporting.com. */ +using NPOI.SS.Formula.Functions; using System; using System.Collections; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; using Drawing2D = Majorsilence.Drawing.Drawing2D; @@ -36,84 +39,88 @@ the website www.fyiReporting.com. namespace fyiReporting.RDL { - /// - /// Base class of all charts. - /// - internal abstract class ChartBase : IDisposable - { - protected Chart _ChartDefn; // GJL 14082008 Using Vector Graphics - MatrixCellEntry[,] _DataDefn; - protected Drawing.Bitmap _bm; + /// + /// Base class of all charts. + /// + internal abstract class ChartBase : IDisposable + { + protected Chart _ChartDefn; // GJL 14082008 Using Vector Graphics + MatrixCellEntry[,] _DataDefn; + protected Drawing.Bitmap _bm; #if !DRAWINGCOMPAT - protected Imaging.Metafile _mf = null; // GJL 14082008 Using Vector Graphics + protected Imaging.Metafile _mf = null; // GJL 14082008 Using Vector Graphics #endif public System.IO.MemoryStream _aStream; // GJL 14082008 Using Vector Graphics - protected ChartLayout Layout; - Drawing.Brush[] _SeriesBrush; - ChartMarkerEnum[] _SeriesMarker; - protected int _LastCategoryWidth=0; - protected Row _row; // row chart created on + protected ChartLayout Layout; + Drawing.Brush[] _SeriesBrush; + ChartMarkerEnum[] _SeriesMarker; + protected int _LastCategoryWidth = 0; + protected Row _row; // row chart created on protected int _gridIncrs = 10; //PJR 20071113 - made global to class so it can be "adjusted" to fit MAX value protected bool _showToolTips; protected bool _showToolTipsX; protected string _tooltipXFormat; protected string _tooltipYFormat; - internal ChartBase(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX,Expression _ToolTipYFormat, Expression _ToolTipXFormat) - { - _ChartDefn = c; - _row = row; - _DataDefn = m; - _bm = null; - int width = _ChartDefn.WidthCalc(r, null); - int height = RSize.PixelsFromPoints(_ChartDefn.HeightOrOwnerHeight); - Layout = new ChartLayout(width, height); - _SeriesBrush = null; - _SeriesMarker = null; - _showToolTips = showTooltips.EvaluateBoolean(r, row); - _showToolTipsX = showTooltipsX.EvaluateBoolean(r, row); - _tooltipYFormat = _ToolTipYFormat.EvaluateString(r, row); - _tooltipXFormat = _ToolTipXFormat.EvaluateString(r, row); - - } - - internal virtual void Draw(Report rpt) - { - } + internal ChartBase(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX, Expression _ToolTipYFormat, Expression _ToolTipXFormat) + { + _ChartDefn = c; + _row = row; + _DataDefn = m; + _bm = null; + int width = _ChartDefn.WidthCalc(r, null); + int height = RSize.PixelsFromPoints(_ChartDefn.HeightOrOwnerHeight); + Layout = new ChartLayout(width, height); + _SeriesBrush = null; + _SeriesMarker = null; + + // HACK: async + Task.Run(async () => { + _showToolTips = await showTooltips.EvaluateBoolean(r, row); + _showToolTipsX = await showTooltipsX.EvaluateBoolean(r, row); + _tooltipYFormat = await _ToolTipYFormat.EvaluateString(r, row); + _tooltipXFormat = await _ToolTipXFormat.EvaluateString(r, row); + }).GetAwaiter().GetResult(); + } + + internal virtual Task Draw(Report rpt) + { + return Task.CompletedTask; + } protected Row ChartRow { get { return _row; } } - internal void Save(Report rpt, System.IO.Stream stream, Imaging.ImageFormat im) - { - if (_bm == null) - Draw(rpt); - // _mf.Save(stream, im); - _bm.Save(stream, im); - } + internal void Save(Report rpt, System.IO.Stream stream, Imaging.ImageFormat im) + { + if (_bm == null) + Draw(rpt); + // _mf.Save(stream, im); + _bm.Save(stream, im); + } - internal Drawing.Image Image(Report rpt) // GJL 14082008 Using Vector Graphics - { - if (_bm == null) - Draw(rpt); + internal Drawing.Image Image(Report rpt) // GJL 14082008 Using Vector Graphics + { + if (_bm == null) + Draw(rpt); - return _bm; + return _bm; //return _mf; - } + } - protected Drawing.Bitmap CreateSizedBitmap() - { - if (_bm != null) - { - _bm.Dispose(); - _bm = null; - } - _bm = new Drawing.Bitmap(Layout.Width, Layout.Height); - return _bm; - } + protected Drawing.Bitmap CreateSizedBitmap() + { + if (_bm != null) + { + _bm.Dispose(); + _bm = null; + } + _bm = new Drawing.Bitmap(Layout.Width, Layout.Height); + return _bm; + } protected Drawing.Bitmap CreateSizedBitmap(int W, int H) { @@ -126,267 +133,269 @@ protected Drawing.Bitmap CreateSizedBitmap(int W, int H) return _bm; } - protected int AxisTickMarkMajorLen - { - get{return 6;} - } - - protected int AxisTickMarkMinorLen - { - get{return 3;} - } - - protected int CategoryCount - { - get{return (_DataDefn.GetLength(0) - 1);} - } - - protected Chart ChartDefn - { - get{return _ChartDefn;} - } - - protected MatrixCellEntry[,] DataDefn - { - get{return _DataDefn;} - } - - protected Drawing.Brush[] SeriesBrush(Report rpt, Row row, ReportDefn defn) - { - if (_SeriesBrush == null) - _SeriesBrush = GetSeriesBrushes(rpt,row,defn); // These are all from Brushes class; so no Dispose should be used - return _SeriesBrush; - } - - protected ChartMarkerEnum[] SeriesMarker - { - get - { - if (_SeriesMarker == null) - _SeriesMarker = GetSeriesMarkers(); - return _SeriesMarker; - } - } - - protected int SeriesCount - { - get{return (_DataDefn.GetLength(1) - 1);} - } - - protected void DrawChartStyle(Report rpt, Drawing.Graphics g) - { - Drawing.Rectangle rect = new Drawing.Rectangle(0, 0, Layout.Width, Layout.Height); - if (_ChartDefn.Style == null) - { - g.FillRectangle(Drawing.Brushes.White, rect); - } - else - { - Row r = FirstChartRow(rpt); - _ChartDefn.Style.DrawBorder(rpt, g, r, rect); - _ChartDefn.Style.DrawBackground(rpt, g, r, rect); - } - - return; - } - - // Draws the Legend and then returns the rectangle it drew in - protected Drawing.Rectangle DrawLegend(Report rpt, Drawing.Graphics g, bool bMarker, bool bBeforePlotDrawn) - { - Legend l = _ChartDefn.Legend; - if (l == null) - return Drawing.Rectangle.Empty; - if (!l.Visible) - return Drawing.Rectangle.Empty; - if (_ChartDefn.SeriesGroupings == null) - return Drawing.Rectangle.Empty; - if (bBeforePlotDrawn) - { - if (this.IsLegendInsidePlotArea()) - return Drawing.Rectangle.Empty; - } - else if (!IsLegendInsidePlotArea()) // Only draw legend after if inside the plot - return Drawing.Rectangle.Empty; - - Drawing.Font drawFont = null; - Drawing.Brush drawBrush = null; - Drawing.StringFormat drawFormat = null; - - // calculated bounding rectangle of the legend - Drawing.Rectangle rRect; - Style s = l.Style; - try // no matter what we want to dispose of the graphic resources - { - if (s == null) - { - drawFont = new Drawing.Font("Arial", 10); - drawBrush = new Drawing.SolidBrush(Drawing.Color.Black); - drawFormat = new Drawing.StringFormat(); - drawFormat.Alignment = Drawing.StringAlignment.Near; - } - else - { - drawFont = s.GetFont(rpt, null); - drawBrush = s.GetBrush(rpt, null); - drawFormat = s.GetStringFormat(rpt, null, Drawing.StringAlignment.Near); - } - - int x, y, h; - int maxTextWidth, maxTextHeight; - drawFormat.FormatFlags |= Drawing.StringFormatFlags.NoWrap; - Drawing.Size[] sizes = DrawLegendMeasure(rpt, g, drawFont, drawFormat, - new Drawing.SizeF(Layout.Width, Layout.Height), out maxTextWidth, out maxTextHeight); - int boxSize = (int) (maxTextHeight * .8); - int totalItemWidth = 0; // width of a legend item - int totalWidth, totalHeight; // final height and width of legend - - // calculate the height and width of the rectangle - switch (l.Layout) - { - case LegendLayoutEnum.Row: - // we need to loop thru all the width - totalWidth=0; - for (int i = 0; i < SeriesCount; i++) - { - if (sizes[i].Width !=0) //14052008WRP when legend valeus are 0 don't add extra boxsize - totalWidth += (sizes[i].Width + (boxSize * 2)); - } - totalHeight = (int) (maxTextHeight + (maxTextHeight * .1)); - h = totalHeight; - totalItemWidth = maxTextWidth + (boxSize * 2); - drawFormat.Alignment = Drawing.StringAlignment.Near; // Force alignment to near - break; - case LegendLayoutEnum.Table: + protected int AxisTickMarkMajorLen + { + get { return 6; } + } + + protected int AxisTickMarkMinorLen + { + get { return 3; } + } + + protected int CategoryCount + { + get { return (_DataDefn.GetLength(0) - 1); } + } + + protected Chart ChartDefn + { + get { return _ChartDefn; } + } + + protected MatrixCellEntry[,] DataDefn + { + get { return _DataDefn; } + } + + protected async Task SeriesBrush(Report rpt, Row row, ReportDefn defn) + { + if (_SeriesBrush == null) + _SeriesBrush = await GetSeriesBrushes(rpt, row, defn); // These are all from Brushes class; so no Dispose should be used + return _SeriesBrush; + } + + protected ChartMarkerEnum[] SeriesMarker + { + get + { + if (_SeriesMarker == null) + _SeriesMarker = GetSeriesMarkers(); + return _SeriesMarker; + } + } + + protected int SeriesCount + { + get { return (_DataDefn.GetLength(1) - 1); } + } + + protected async Task DrawChartStyle(Report rpt, Drawing.Graphics g) + { + Drawing.Rectangle rect = new Drawing.Rectangle(0, 0, Layout.Width, Layout.Height); + if (_ChartDefn.Style == null) + { + g.FillRectangle(Drawing.Brushes.White, rect); + } + else + { + Row r = FirstChartRow(rpt); + await _ChartDefn.Style.DrawBorder(rpt, g, r, rect); + await _ChartDefn.Style.DrawBackground(rpt, g, r, rect); + } + + return; + } + + // Draws the Legend and then returns the rectangle it drew in + protected async Task DrawLegend(Report rpt, Drawing.Graphics g, bool bMarker, bool bBeforePlotDrawn) + { + Legend l = _ChartDefn.Legend; + if (l == null) + return Drawing.Rectangle.Empty; + if (!l.Visible) + return Drawing.Rectangle.Empty; + if (_ChartDefn.SeriesGroupings == null) + return Drawing.Rectangle.Empty; + if (bBeforePlotDrawn) + { + if (this.IsLegendInsidePlotArea()) + return Drawing.Rectangle.Empty; + } + else if (!IsLegendInsidePlotArea()) // Only draw legend after if inside the plot + return Drawing.Rectangle.Empty; + + Drawing.Font drawFont = null; + Drawing.Brush drawBrush = null; + Drawing.StringFormat drawFormat = null; + + // calculated bounding rectangle of the legend + Drawing.Rectangle rRect; + Style s = l.Style; + try // no matter what we want to dispose of the graphic resources + { + if (s == null) + { + drawFont = new Drawing.Font("Arial", 10); + drawBrush = new Drawing.SolidBrush(Drawing.Color.Black); + drawFormat = new Drawing.StringFormat(); + drawFormat.Alignment = Drawing.StringAlignment.Near; + } + else + { + drawFont = await s.GetFont(rpt, null); + drawBrush = await s.GetBrush(rpt, null); + drawFormat = await s.GetStringFormat(rpt, null, Drawing.StringAlignment.Near); + } + + int x, y, h; + int maxTextWidth, maxTextHeight; + drawFormat.FormatFlags |= Drawing.StringFormatFlags.NoWrap; + Drawing.Size[] sizes; + + (sizes, maxTextWidth, maxTextHeight) = await DrawLegendMeasure(rpt, g, drawFont, drawFormat, + new Drawing.SizeF(Layout.Width, Layout.Height)); + int boxSize = (int)(maxTextHeight * .8); + int totalItemWidth = 0; // width of a legend item + int totalWidth, totalHeight; // final height and width of legend + + // calculate the height and width of the rectangle + switch (l.Layout) + { + case LegendLayoutEnum.Row: + // we need to loop thru all the width + totalWidth = 0; + for (int i = 0; i < SeriesCount; i++) + { + if (sizes[i].Width != 0) //14052008WRP when legend valeus are 0 don't add extra boxsize + totalWidth += (sizes[i].Width + (boxSize * 2)); + } + totalHeight = (int)(maxTextHeight + (maxTextHeight * .1)); + h = totalHeight; + totalItemWidth = maxTextWidth + (boxSize * 2); + drawFormat.Alignment = Drawing.StringAlignment.Near; // Force alignment to near + break; + case LegendLayoutEnum.Table: // for table we simplify to have TWO columns (i.e. don't do anything too tricky totalWidth = totalItemWidth = (maxTextWidth + (boxSize * 2)) * 2; // make width twice as big as longest entry h = (int)(maxTextHeight + (maxTextHeight * .1)); totalHeight = h * (SeriesCount + (SeriesCount % 2)) / 2; break; - case LegendLayoutEnum.Column: - default: - totalWidth = totalItemWidth = maxTextWidth + (boxSize * 2); - h = (int) (maxTextHeight + (maxTextHeight * .1)); - totalHeight = h * SeriesCount; - break; - } - - // calculate the location of the legend rectangle - if (this.IsLegendInsidePlotArea()) - switch (l.Position) - { - case LegendPositionEnum.BottomCenter: - x = Layout.PlotArea.X + (Layout.PlotArea.Width / 2) - (totalWidth / 2); - y = Layout.PlotArea.Y + Layout.PlotArea.Height - totalHeight - 2; - break; - case LegendPositionEnum.BottomLeft: - case LegendPositionEnum.LeftBottom: - x = Layout.PlotArea.X+2; - y = Layout.PlotArea.Y + Layout.PlotArea.Height - totalHeight - 2; - break; - case LegendPositionEnum.BottomRight: - case LegendPositionEnum.RightBottom: - x = Layout.PlotArea.X + Layout.PlotArea.Width - totalWidth; - y = Layout.PlotArea.Y + Layout.PlotArea.Height - totalHeight - 2; - break; - case LegendPositionEnum.LeftCenter: - x = Layout.PlotArea.X + 2; - y = Layout.PlotArea.Y + (Layout.PlotArea.Height / 2) - (totalHeight/2); - break; - case LegendPositionEnum.LeftTop: - case LegendPositionEnum.TopLeft: - x = Layout.PlotArea.X + 2; - y = Layout.PlotArea.Y+2; - break; - case LegendPositionEnum.RightCenter: - x = Layout.PlotArea.X + Layout.PlotArea.Width - totalWidth - 2; - y = Layout.PlotArea.Y + (Layout.PlotArea.Height / 2) - (totalHeight/2); - break; - case LegendPositionEnum.TopCenter: - x = Layout.PlotArea.X + (Layout.PlotArea.Width / 2) - (totalWidth / 2); - y = Layout.PlotArea.Y + +2; - break; - case LegendPositionEnum.TopRight: - case LegendPositionEnum.RightTop: - default: - x = Layout.PlotArea.X + Layout.PlotArea.Width-totalWidth - 2; - y = Layout.PlotArea.Y + +2; - break; - } - else switch (l.Position) - { - case LegendPositionEnum.BottomCenter: - x = (Layout.Width / 2) - (totalWidth / 2); - y = Layout.Height - totalHeight - 2; - break; - case LegendPositionEnum.BottomLeft: - case LegendPositionEnum.LeftBottom: - if (IsLegendInsidePlotArea()) - x = Layout.LeftMargin; - else - x = 0; - y = Layout.Height - totalHeight - 2; - break; - case LegendPositionEnum.BottomRight: - case LegendPositionEnum.RightBottom: - x = Layout.Width - totalWidth; - y = Layout.Height - totalHeight - 2; - break; - case LegendPositionEnum.LeftCenter: - x = 2; - y = (Layout.Height / 2) - (totalHeight/2); - break; - case LegendPositionEnum.LeftTop: - case LegendPositionEnum.TopLeft: - x = 2; - y = Layout.TopMargin+2; - break; - case LegendPositionEnum.RightCenter: - x = Layout.Width - totalWidth - 2; - y = (Layout.Height / 2) - (totalHeight/2); - break; - case LegendPositionEnum.TopCenter: - x = (Layout.Width / 2) - (totalWidth / 2); - y = Layout.TopMargin+2; - break; - case LegendPositionEnum.TopRight: - case LegendPositionEnum.RightTop: - default: - x = Layout.Width-totalWidth - 2; - y = Layout.TopMargin+2; - break; - } - - // We now know enough to calc the bounding rectangle of the legend - rRect = new Drawing.Rectangle(x-1, y-1, totalWidth+2, totalHeight+2); - if (s != null) - { - s.DrawBackground(rpt, g, null, rRect); // draw (or not draw) background - s.DrawBorder(rpt, g, null, rRect); // draw (or not draw) border depending on style - } + case LegendLayoutEnum.Column: + default: + totalWidth = totalItemWidth = maxTextWidth + (boxSize * 2); + h = (int)(maxTextHeight + (maxTextHeight * .1)); + totalHeight = h * SeriesCount; + break; + } + + // calculate the location of the legend rectangle + if (this.IsLegendInsidePlotArea()) + switch (l.Position) + { + case LegendPositionEnum.BottomCenter: + x = Layout.PlotArea.X + (Layout.PlotArea.Width / 2) - (totalWidth / 2); + y = Layout.PlotArea.Y + Layout.PlotArea.Height - totalHeight - 2; + break; + case LegendPositionEnum.BottomLeft: + case LegendPositionEnum.LeftBottom: + x = Layout.PlotArea.X + 2; + y = Layout.PlotArea.Y + Layout.PlotArea.Height - totalHeight - 2; + break; + case LegendPositionEnum.BottomRight: + case LegendPositionEnum.RightBottom: + x = Layout.PlotArea.X + Layout.PlotArea.Width - totalWidth; + y = Layout.PlotArea.Y + Layout.PlotArea.Height - totalHeight - 2; + break; + case LegendPositionEnum.LeftCenter: + x = Layout.PlotArea.X + 2; + y = Layout.PlotArea.Y + (Layout.PlotArea.Height / 2) - (totalHeight / 2); + break; + case LegendPositionEnum.LeftTop: + case LegendPositionEnum.TopLeft: + x = Layout.PlotArea.X + 2; + y = Layout.PlotArea.Y + 2; + break; + case LegendPositionEnum.RightCenter: + x = Layout.PlotArea.X + Layout.PlotArea.Width - totalWidth - 2; + y = Layout.PlotArea.Y + (Layout.PlotArea.Height / 2) - (totalHeight / 2); + break; + case LegendPositionEnum.TopCenter: + x = Layout.PlotArea.X + (Layout.PlotArea.Width / 2) - (totalWidth / 2); + y = Layout.PlotArea.Y + +2; + break; + case LegendPositionEnum.TopRight: + case LegendPositionEnum.RightTop: + default: + x = Layout.PlotArea.X + Layout.PlotArea.Width - totalWidth - 2; + y = Layout.PlotArea.Y + +2; + break; + } + else switch (l.Position) + { + case LegendPositionEnum.BottomCenter: + x = (Layout.Width / 2) - (totalWidth / 2); + y = Layout.Height - totalHeight - 2; + break; + case LegendPositionEnum.BottomLeft: + case LegendPositionEnum.LeftBottom: + if (IsLegendInsidePlotArea()) + x = Layout.LeftMargin; + else + x = 0; + y = Layout.Height - totalHeight - 2; + break; + case LegendPositionEnum.BottomRight: + case LegendPositionEnum.RightBottom: + x = Layout.Width - totalWidth; + y = Layout.Height - totalHeight - 2; + break; + case LegendPositionEnum.LeftCenter: + x = 2; + y = (Layout.Height / 2) - (totalHeight / 2); + break; + case LegendPositionEnum.LeftTop: + case LegendPositionEnum.TopLeft: + x = 2; + y = Layout.TopMargin + 2; + break; + case LegendPositionEnum.RightCenter: + x = Layout.Width - totalWidth - 2; + y = (Layout.Height / 2) - (totalHeight / 2); + break; + case LegendPositionEnum.TopCenter: + x = (Layout.Width / 2) - (totalWidth / 2); + y = Layout.TopMargin + 2; + break; + case LegendPositionEnum.TopRight: + case LegendPositionEnum.RightTop: + default: + x = Layout.Width - totalWidth - 2; + y = Layout.TopMargin + 2; + break; + } + + // We now know enough to calc the bounding rectangle of the legend + rRect = new Drawing.Rectangle(x - 1, y - 1, totalWidth + 2, totalHeight + 2); + if (s != null) + { + await s.DrawBackground(rpt, g, null, rRect); // draw (or not draw) background + await s.DrawBorder(rpt, g, null, rRect); // draw (or not draw) border depending on style + } int saveX = x; ChartMarkerEnum cm = this.ChartDefn.Type == ChartTypeEnum.Bubble ? ChartMarkerEnum.Bubble : ChartMarkerEnum.None; - for (int iCol=1; iCol <= SeriesCount; iCol++) - { - string c = GetSeriesValue(rpt, iCol); + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + string c = await GetSeriesValue(rpt, iCol); if (c != "") //14052008WRP Cater for empty strings in the legend { - Drawing.Rectangle rect; + Drawing.Rectangle rect; // 20022008 AJM GJL - Draw correct legend icon (Column\Line) Type t = null; t = GetSeriesBrush(rpt, 1, iCol).GetType(); - /* The following 2 lines have been added to draw the correct legend for column chart with line plot types - * 06122007AJM */ - cm = ChartMarkerEnum.None; - bool isLine = GetPlotType(rpt, iCol, 1).ToUpper() == "LINE"; + /* The following 2 lines have been added to draw the correct legend for column chart with line plot types + * 06122007AJM */ + cm = ChartMarkerEnum.None; + bool isLine = GetPlotType(rpt, iCol, 1).ToUpper() == "LINE"; if ((bMarker || isLine) || (this.ChartDefn.Type == ChartTypeEnum.Scatter && t == typeof(Drawing2D.HatchBrush))) - cm = SeriesMarker[iCol - 1]; + cm = SeriesMarker[iCol - 1]; if (isLine && this.ChartDefn.Type == ChartTypeEnum.Scatter) { cm = ChartMarkerEnum.Line; - } - + } + bool NoMarker = getNoMarkerVal(rpt, iCol, 1); if (NoMarker) { cm = ChartMarkerEnum.Line; } @@ -394,315 +403,321 @@ protected Drawing.Rectangle DrawLegend(Report rpt, Drawing.Graphics g, bool bMar int intLineSize = 2; switch (LineSize) { - case "Small": intLineSize = 1; + case "Small": + intLineSize = 1; break; - case "Regular": intLineSize = 2; + case "Regular": + intLineSize = 2; break; - case "Large": intLineSize = 3; + case "Large": + intLineSize = 3; break; - case "Extra Large": intLineSize = 4; + case "Extra Large": + intLineSize = 4; break; - case "Super Size": intLineSize = 5; + case "Super Size": + intLineSize = 5; break; } Drawing.SolidBrush b; - switch (l.Layout) - { - case LegendLayoutEnum.Row: - rect = new Drawing.Rectangle(x + boxSize + (boxSize/2), y, totalItemWidth - boxSize - (boxSize/2), h); + switch (l.Layout) + { + case LegendLayoutEnum.Row: + rect = new Drawing.Rectangle(x + boxSize + (boxSize / 2), y, totalItemWidth - boxSize - (boxSize / 2), h); if (c != "") //14052008WRP to cater for empty strings in the legend { - g.DrawString(c, drawFont, drawBrush, rect, drawFormat); + g.DrawString(c, drawFont, drawBrush, rect, drawFormat); if ((cm != ChartMarkerEnum.None || this.ChartDefn.Type == ChartTypeEnum.Scatter) && (t == typeof(Drawing2D.HatchBrush))) //GJL 110208 - Don't draw pattern for lines or Bubbles { - Drawing2D.HatchBrush hb = (Drawing2D.HatchBrush)GetSeriesBrush(rpt, 1, iCol); + Drawing2D.HatchBrush hb = (Drawing2D.HatchBrush)await GetSeriesBrush(rpt, 1, iCol); b = new Drawing.SolidBrush(hb.ForegroundColor); DrawLegendBox(g, b, - cm, x, y + 1, boxSize,intLineSize); + cm, x, y + 1, boxSize, intLineSize); } else { - DrawLegendBox(g, GetSeriesBrush(rpt, 1, iCol), - cm, x, y+1, boxSize,intLineSize); + DrawLegendBox(g, await GetSeriesBrush(rpt, 1, iCol), + cm, x, y + 1, boxSize, intLineSize); } - x += (sizes[iCol-1].Width + (boxSize*2)); + x += (sizes[iCol - 1].Width + (boxSize * 2)); } - break; - case LegendLayoutEnum.Table: - rect = new Drawing.Rectangle(x + boxSize + (boxSize / 2), y, maxTextWidth, h); - g.DrawString(c, drawFont, drawBrush, rect, drawFormat); + break; + case LegendLayoutEnum.Table: + rect = new Drawing.Rectangle(x + boxSize + (boxSize / 2), y, maxTextWidth, h); + g.DrawString(c, drawFont, drawBrush, rect, drawFormat); if (cm != ChartMarkerEnum.None && (t == typeof(Drawing2D.HatchBrush))) //GJL 110208 - Don't draw pattern for lines { - Drawing2D.HatchBrush hb = (Drawing2D.HatchBrush)GetSeriesBrush(rpt, 1, iCol); + Drawing2D.HatchBrush hb = (Drawing2D.HatchBrush)await GetSeriesBrush(rpt, 1, iCol); b = new Drawing.SolidBrush(hb.ForegroundColor); DrawLegendBox(g, /*GetSeriesBrushesExcel(iCol - 1)*/ b, - cm, x, y + 1, boxSize,intLineSize); + cm, x, y + 1, boxSize, intLineSize); } else - { DrawLegendBox(g, GetSeriesBrush(rpt, 1, iCol), cm, x + 1, y, boxSize,intLineSize); } + { DrawLegendBox(g, await GetSeriesBrush(rpt, 1, iCol), cm, x + 1, y, boxSize, intLineSize); } - if (iCol % 2 == 0) - { - y += h; - x = saveX; - } - else - { - x = saveX + (rRect.Width / 2); - } - break; - case LegendLayoutEnum.Column: - default: - rect = new Drawing.Rectangle(x + boxSize + (boxSize/2), y, maxTextWidth, h); - g.DrawString(c, drawFont, drawBrush, rect, drawFormat); + if (iCol % 2 == 0) + { + y += h; + x = saveX; + } + else + { + x = saveX + (rRect.Width / 2); + } + break; + case LegendLayoutEnum.Column: + default: + rect = new Drawing.Rectangle(x + boxSize + (boxSize / 2), y, maxTextWidth, h); + g.DrawString(c, drawFont, drawBrush, rect, drawFormat); if (cm != ChartMarkerEnum.None && (t == typeof(Drawing2D.HatchBrush))) //GJL 110208 - Don't draw pattern for lines { - Drawing2D.HatchBrush hb = (Drawing2D.HatchBrush)GetSeriesBrush(rpt, 1, iCol); + Drawing2D.HatchBrush hb = (Drawing2D.HatchBrush)await GetSeriesBrush(rpt, 1, iCol); b = new Drawing.SolidBrush(hb.ForegroundColor); DrawLegendBox(g, /*GetSeriesBrushesExcel(iCol - 1)*/ b, - cm, x, y + 1, boxSize,intLineSize); + cm, x, y + 1, boxSize, intLineSize); } else { - DrawLegendBox(g, GetSeriesBrush(rpt, 1, iCol), - cm, x+1, y, boxSize,intLineSize); + DrawLegendBox(g, await GetSeriesBrush(rpt, 1, iCol), + cm, x + 1, y, boxSize, intLineSize); } - y += h; - break; - } - } - } + y += h; + break; + } + } + } + } + finally + { + if (drawFont != null) + drawFont.Dispose(); + if (drawBrush != null) + drawBrush.Dispose(); + if (drawFormat != null) + drawFormat.Dispose(); } - finally - { - if (drawFont != null) - drawFont.Dispose(); - if (drawBrush != null) - drawBrush.Dispose(); - if (drawFormat != null) - drawFormat.Dispose(); - } - if (s != null) - rRect = s.PaddingAdjust(rpt, null, rRect, true); - return rRect; - - } + if (s != null) + rRect = await s.PaddingAdjust(rpt, null, rRect, true); + return rRect; + + } void DrawLegendBox(Drawing.Graphics g, Drawing.Brush b, ChartMarkerEnum marker, int x, int y, int boxSize) { DrawLegendBox(g, b, marker, x, y, boxSize, 2); } - void DrawLegendBox(Drawing.Graphics g, Drawing.Brush b, ChartMarkerEnum marker, int x, int y, int boxSize, int intLineSize) - { - Drawing.Pen p=null; - int mSize= boxSize / 2; // Marker size is 1/2 of box size - try - { - if (marker < ChartMarkerEnum.Count) - { - p = new Drawing.Pen(b,intLineSize); + void DrawLegendBox(Drawing.Graphics g, Drawing.Brush b, ChartMarkerEnum marker, int x, int y, int boxSize, int intLineSize) + { + Drawing.Pen p = null; + int mSize = boxSize / 2; // Marker size is 1/2 of box size + try + { + if (marker < ChartMarkerEnum.Count) + { + p = new Drawing.Pen(b, intLineSize); if (this.ChartDefn.Type != ChartTypeEnum.Scatter) { - g.DrawLine(p, new Drawing.Point(x, y + ((boxSize + 1)/2)), new Drawing.Point(x + boxSize, y + ((boxSize + 1)/2))); + g.DrawLine(p, new Drawing.Point(x, y + ((boxSize + 1) / 2)), new Drawing.Point(x + boxSize, y + ((boxSize + 1) / 2))); } - x = x + ((boxSize - mSize)/2); - y = y + ((boxSize - mSize)/2); - if (mSize % 2 == 0) - mSize++; - } - - if (marker == ChartMarkerEnum.None) - { - g.FillRectangle(b, x, y, boxSize, boxSize); - } + x = x + ((boxSize - mSize) / 2); + y = y + ((boxSize - mSize) / 2); + if (mSize % 2 == 0) + mSize++; + } + + if (marker == ChartMarkerEnum.None) + { + g.FillRectangle(b, x, y, boxSize, boxSize); + } else if (marker == ChartMarkerEnum.Bubble) - { - g.FillEllipse(b, x, y, boxSize, boxSize); - } + { + g.FillEllipse(b, x, y, boxSize, boxSize); + } else if (marker == ChartMarkerEnum.Line) { // this is only to draw lines for line plot types on scatter charts p = new Drawing.Pen(b, intLineSize); g.DrawLine(p, new Drawing.Point(x, y + ((boxSize + 1) / 2)), new Drawing.Point(x + boxSize, y + ((boxSize + 1) / 2))); } - else - { - DrawLegendMarker(g, b, p, marker, x, y, mSize); - } - } - finally - { - if (p != null) - p.Dispose(); - } - } - - internal void DrawLegendMarker(Drawing.Graphics g, Drawing.Brush b, Drawing.Pen p, ChartMarkerEnum marker, int x, int y, int mSize) - { - Drawing.PointF[] points; - switch (marker) - { + else + { + DrawLegendMarker(g, b, p, marker, x, y, mSize); + } + } + finally + { + if (p != null) + p.Dispose(); + } + } + + internal void DrawLegendMarker(Drawing.Graphics g, Drawing.Brush b, Drawing.Pen p, ChartMarkerEnum marker, int x, int y, int mSize) + { + Drawing.PointF[] points; + switch (marker) + { case ChartMarkerEnum.Bubble: case ChartMarkerEnum.Circle: - g.FillEllipse(b, x, y, mSize, mSize); - break; - case ChartMarkerEnum.Square: - g.FillRectangle(b, x, y, mSize, mSize); - break; - case ChartMarkerEnum.Plus: - // 20022008 AJM GJL - Changed to line - plus is hard to see + g.FillEllipse(b, x, y, mSize, mSize); + break; + case ChartMarkerEnum.Square: + g.FillRectangle(b, x, y, mSize, mSize); + break; + case ChartMarkerEnum.Plus: + // 20022008 AJM GJL - Changed to line - plus is hard to see p = new Drawing.Pen(p.Brush, 2); - g.DrawLine(p, new Drawing.Point(x + ((mSize + 1)/2), y), new Drawing.Point(x + ((mSize + 1)/2), y + mSize)); - //g.DrawLine(p, new Point(x + (mSize + 1)/2, y + (mSize+1)/2), new Point(x + mSize, y + (mSize+1)/2)); - break; - case ChartMarkerEnum.Diamond: - points = new Drawing.PointF[5]; - points[0] = points[4] = new Drawing.Point(x + ((mSize + 1)/2), y); // starting and ending point - points[1] = new Drawing.PointF(x, y + ((mSize+1)/2)); - points[2] = new Drawing.PointF(x + ((mSize+1)/2), y+mSize); - points[3] = new Drawing.PointF(x + mSize, y + ((mSize+1)/2)); - g.FillPolygon(b, points); - break; - case ChartMarkerEnum.Triangle: - points = new Drawing.PointF[4]; - points[0] = points[3] = new Drawing.PointF(x + ((mSize + 1)/2), y); // starting and ending point - points[1] = new Drawing.PointF(x, y + mSize); - points[2] = new Drawing.PointF(x + mSize, y + mSize); - g.FillPolygon(b, points); + g.DrawLine(p, new Drawing.Point(x + ((mSize + 1) / 2), y), new Drawing.Point(x + ((mSize + 1) / 2), y + mSize)); + //g.DrawLine(p, new Point(x + (mSize + 1)/2, y + (mSize+1)/2), new Point(x + mSize, y + (mSize+1)/2)); + break; + case ChartMarkerEnum.Diamond: + points = new Drawing.PointF[5]; + points[0] = points[4] = new Drawing.Point(x + ((mSize + 1) / 2), y); // starting and ending point + points[1] = new Drawing.PointF(x, y + ((mSize + 1) / 2)); + points[2] = new Drawing.PointF(x + ((mSize + 1) / 2), y + mSize); + points[3] = new Drawing.PointF(x + mSize, y + ((mSize + 1) / 2)); + g.FillPolygon(b, points); + break; + case ChartMarkerEnum.Triangle: + points = new Drawing.PointF[4]; + points[0] = points[3] = new Drawing.PointF(x + ((mSize + 1) / 2), y); // starting and ending point + points[1] = new Drawing.PointF(x, y + mSize); + points[2] = new Drawing.PointF(x + mSize, y + mSize); + g.FillPolygon(b, points); break; - case ChartMarkerEnum.X: + case ChartMarkerEnum.X: p = new Drawing.Pen(p.Brush, 2);// 20022008 AJM GJL - g.DrawLine(p, new Drawing.Point(x, y), new Drawing.Point(x + mSize, y + mSize)); - g.DrawLine(p, new Drawing.Point(x, y + mSize), new Drawing.Point(x + mSize, y));// 20022008 AJM GJL - break; - } - return; - } - - // Measures the Legend and then returns the rectangle it drew in - protected Drawing.Size[] DrawLegendMeasure(Report rpt, Drawing.Graphics g, Drawing.Font f, Drawing.StringFormat sf, Drawing.SizeF maxSize, out int maxWidth, out int maxHeight) - { - Drawing.Size[] sizes = new Drawing.Size[SeriesCount]; - maxWidth = maxHeight = 0; - - for (int iCol=1; iCol <= SeriesCount; iCol++) - { - string c = GetSeriesValue(rpt, iCol); + g.DrawLine(p, new Drawing.Point(x, y), new Drawing.Point(x + mSize, y + mSize)); + g.DrawLine(p, new Drawing.Point(x, y + mSize), new Drawing.Point(x + mSize, y));// 20022008 AJM GJL + break; + } + return; + } + + // Measures the Legend and then returns the rectangle it drew in + protected async Task<(Drawing.Size[] sizes, int maxWidth, int maxHeight)> DrawLegendMeasure(Report rpt, Drawing.Graphics g, Drawing.Font f, Drawing.StringFormat sf, Drawing.SizeF maxSize) + { + Drawing.Size[] sizes = new Drawing.Size[SeriesCount]; + int maxHeight = 0; + int maxWidth = maxHeight = 0; + + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + string c = await GetSeriesValue(rpt, iCol); if (c != "") //14052008WRP cater for empty strings in legend names { - Drawing.SizeF ms = g.MeasureString(c, f, maxSize, sf); - sizes[iCol-1] = new Drawing.Size((int) Math.Ceiling(ms.Width), - (int) Math.Ceiling(ms.Height)); - if (sizes[iCol-1].Width > maxWidth) - maxWidth = sizes[iCol-1].Width; - if (sizes[iCol-1].Height > maxHeight) - maxHeight = sizes[iCol-1].Height; - } - - } - return sizes; - } - - protected void DrawPlotAreaStyle(Report rpt, Drawing.Graphics g, Drawing.Rectangle crect) - { - if (_ChartDefn.PlotArea == null || _ChartDefn.PlotArea.Style == null) - return; - Drawing.Rectangle rect = Layout.PlotArea; - Style s = _ChartDefn.PlotArea.Style; + Drawing.SizeF ms = g.MeasureString(c, f, maxSize, sf); + sizes[iCol - 1] = new Drawing.Size((int)Math.Ceiling(ms.Width), + (int)Math.Ceiling(ms.Height)); + if (sizes[iCol - 1].Width > maxWidth) + maxWidth = sizes[iCol - 1].Width; + if (sizes[iCol - 1].Height > maxHeight) + maxHeight = sizes[iCol - 1].Height; + } + + } + return (sizes, maxWidth, maxHeight); + } + + protected async Task DrawPlotAreaStyle(Report rpt, Drawing.Graphics g, Drawing.Rectangle crect) + { + if (_ChartDefn.PlotArea == null || _ChartDefn.PlotArea.Style == null) + return; + Drawing.Rectangle rect = Layout.PlotArea; + Style s = _ChartDefn.PlotArea.Style; + + Row r = FirstChartRow(rpt); + + if (rect.IntersectsWith(crect)) + { + // This occurs when the legend is drawn inside the plot area + // we don't want to draw in the legend + Drawing.Region rg = null; + try + { + // rg = new Region(rect); // TODO: this doesn't work; nothing draws + // rg.Complement(crect); + // Region saver = g.Clip; + // g.Clip = rg; + await s.DrawBackground(rpt, g, r, rect); + // g.Clip = saver; + } + finally + { + if (rg != null) + rg.Dispose(); + } + } + else + await s.DrawBackground(rpt, g, r, rect); + + return; + } + + protected async Task DrawTitle(Report rpt, Drawing.Graphics g, Title t, Drawing.Rectangle rect) + { + if (t == null) + return; + + if (t.Caption == null) + return; + + Row r = FirstChartRow(rpt); + object title = t.Caption.Evaluate(rpt, r); + if (t.Style != null) + { + await t.Style.DrawString(rpt, g, title, t.Caption.GetTypeCode(), r, rect); + await t.Style.DrawBorder(rpt, g, r, rect); + } + else + Style.DrawStringDefaults(g, title, rect); + + return; + } + + protected async Task DrawTitleMeasure(Report rpt, Drawing.Graphics g, Title t) + { + Drawing.Size size = Drawing.Size.Empty; + + if (t == null || t.Caption == null) + return size; Row r = FirstChartRow(rpt); + object title = t.Caption.Evaluate(rpt, r); + if (t.Style != null) + size = await t.Style.MeasureString(rpt, g, title, t.Caption.GetTypeCode(), r, int.MaxValue); + else + size = await Style.MeasureStringDefaults(rpt, g, title, t.Caption.GetTypeCode(), r, int.MaxValue); - if (rect.IntersectsWith(crect)) - { - // This occurs when the legend is drawn inside the plot area - // we don't want to draw in the legend - Drawing.Region rg=null; - try - { - // rg = new Region(rect); // TODO: this doesn't work; nothing draws - // rg.Complement(crect); - // Region saver = g.Clip; - // g.Clip = rg; - s.DrawBackground(rpt, g, r, rect); - // g.Clip = saver; - } - finally - { - if (rg != null) - rg.Dispose(); - } - } - else - s.DrawBackground(rpt, g, r, rect); - - return; - } - - protected void DrawTitle(Report rpt, Drawing.Graphics g, Title t, Drawing.Rectangle rect) - { - if (t == null) - return; - - if (t.Caption == null) - return; - - Row r = FirstChartRow(rpt); - object title = t.Caption.Evaluate(rpt, r); - if (t.Style != null) - { - t.Style.DrawString(rpt, g, title, t.Caption.GetTypeCode(), r, rect); - t.Style.DrawBorder(rpt, g, r, rect); - } - else - Style.DrawStringDefaults(g, title, rect); - - return; - } - - protected Drawing.Size DrawTitleMeasure(Report rpt, Drawing.Graphics g, Title t) - { - Drawing.Size size=Drawing.Size.Empty; - - if (t == null || t.Caption == null) - return size; - - Row r = FirstChartRow(rpt); - object title = t.Caption.Evaluate(rpt, r); - if (t.Style != null) - size = t.Style.MeasureString(rpt, g, title, t.Caption.GetTypeCode(), r, int.MaxValue); - else - size = Style.MeasureStringDefaults(rpt, g, title, t.Caption.GetTypeCode(), r, int.MaxValue); - - return size; - } + return size; + } //15052008WRP - Draw category month labels - protected void DrawCategoryLabel(Report rpt, Drawing.Graphics g, string t, Style a, Drawing.Rectangle rect) + protected async Task DrawCategoryLabel(Report rpt, Drawing.Graphics g, string t, Style a, Drawing.Rectangle rect) { - + if (t == null) return; Row r = FirstChartRow(rpt); - + if (a != null) { - a.DrawString(rpt, g, t, t.GetTypeCode(), r, rect); - a.DrawBorder(rpt, g, r, rect); + await a.DrawString(rpt, g, t, t.GetTypeCode(), r, rect); + await a.DrawBorder(rpt, g, r, rect); } else Style.DrawStringDefaults(g, t, rect); @@ -710,68 +725,68 @@ protected void DrawCategoryLabel(Report rpt, Drawing.Graphics g, string t, Style } //15052008WRP - Measure category title size - protected Drawing.Size DrawCategoryTitleMeasure(Report rpt, Drawing.Graphics g, string t, Style a) + protected async Task DrawCategoryTitleMeasure(Report rpt, Drawing.Graphics g, string t, Style a) { - Drawing.Size size = Drawing.Size.Empty; + Drawing.Size size = Drawing.Size.Empty; Row r = FirstChartRow(rpt); if (t == null || t == "") return size; if (a != null) - size = a.MeasureString(rpt, g, t, t.GetTypeCode(), r, int.MaxValue); + size = await a.MeasureString(rpt, g, t, t.GetTypeCode(), r, int.MaxValue); else - size = Style.MeasureStringDefaults(rpt, g, t, t.GetTypeCode(), r, int.MaxValue); + size = await Style.MeasureStringDefaults(rpt, g, t, t.GetTypeCode(), r, int.MaxValue); return size; - } - - protected object GetCategoryValue(Report rpt, int row, out TypeCode tc) - { - MatrixCellEntry mce = _DataDefn[row, 0]; - if (mce == null) - { - tc = TypeCode.String; - return ""; // Not sure what this really means TODO: - } - - Row lrow; - this._ChartDefn.ChartMatrix.SetMyData(rpt, mce.Data); // Must set this for evaluation - if (mce.Data.Data.Count > 0) - lrow = mce.Data.Data[0]; - else - lrow = null; - ChartExpression ce = (ChartExpression) (mce.DisplayItem); - - object v = ce.Value.Evaluate(rpt, lrow); - tc = ce.Value.GetTypeCode(); - return v; - } - - protected double GetDataValue(Report rpt, int row, int col) - { - return GetDataValue(rpt, row, col, 0); - } - - /* Added this function to return the plot type + } + + protected object GetCategoryValue(Report rpt, int row, out TypeCode tc) + { + MatrixCellEntry mce = _DataDefn[row, 0]; + if (mce == null) + { + tc = TypeCode.String; + return ""; // Not sure what this really means TODO: + } + + Row lrow; + this._ChartDefn.ChartMatrix.SetMyData(rpt, mce.Data); // Must set this for evaluation + if (mce.Data.Data.Count > 0) + lrow = mce.Data.Data[0]; + else + lrow = null; + ChartExpression ce = (ChartExpression)(mce.DisplayItem); + + object v = ce.Value.Evaluate(rpt, lrow); + tc = ce.Value.GetTypeCode(); + return v; + } + + protected async Task GetDataValue(Report rpt, int row, int col) + { + return await GetDataValue(rpt, row, col, 0); + } + + /* Added this function to return the plot type * 05122007AJM */ protected string GetPlotType(Report rpt, int row, int col) { try { - if (this is ChartColumn || this is ChartBubble) + if (this is ChartColumn || this is ChartBubble) { return ((ChartExpression)_DataDefn[col, row].DisplayItem).PlotType.Source; } } catch //(Exception e) { - //ignore + //ignore } return "Auto"; } -// 20022008 AJM GJL + // 20022008 AJM GJL protected string GetYAxis(Report rpt, int row, int col) { try @@ -792,11 +807,11 @@ protected bool getNoMarkerVal(Report rpt, int row, int col) { try { - return Boolean.Parse(((ChartExpression)_DataDefn[col, row].DisplayItem).NoMarker.Source); - + return Boolean.Parse(((ChartExpression)_DataDefn[col, row].DisplayItem).NoMarker.Source); + } catch - { + { } return false; } @@ -822,11 +837,11 @@ protected String getColour(Report rpt, int row, int col) return ((ChartExpression)_DataDefn[row, col].DisplayItem).Colour.Source; } catch - { + { } return ""; } - protected double GetDataValue(Report rpt, int row, int col, int xyb) + protected async Task GetDataValue(Report rpt, int row, int col, int xyb) { MatrixCellEntry mce = _DataDefn[row, col]; if (mce == null) @@ -845,20 +860,20 @@ protected double GetDataValue(Report rpt, int row, int col, int xyb) lrow = null; ChartExpression ce = (ChartExpression)(mce.DisplayItem); - double v=double.MinValue; + double v = double.MinValue; if (xyb == 0) { - v = ce.Value.EvaluateDouble(rpt, lrow); + v = await ce.Value.EvaluateDouble(rpt, lrow); mce.Value = v; // cache so we don't need to calculate again } else if (xyb == 1) - v = ce.Value2.EvaluateDouble(rpt, lrow); + v = await ce.Value2.EvaluateDouble(rpt, lrow); else if (xyb == 2) - v = ce.Value3.EvaluateDouble(rpt, lrow); + v = await ce.Value3.EvaluateDouble(rpt, lrow); return v; } - protected string GetDataValueString(Report rpt, int row, int col) + protected async Task GetDataValueString(Report rpt, int row, int col) { MatrixCellEntry mce = _DataDefn[row, col]; if (mce == null) @@ -875,13 +890,13 @@ protected string GetDataValueString(Report rpt, int row, int col) lrow = null; ChartExpression ce = (ChartExpression)(mce.DisplayItem); - string v = ce.Value.EvaluateString(rpt, lrow); + string v = await ce.Value.EvaluateString(rpt, lrow); return v; } - protected Drawing.Brush GetSeriesBrush(Report rpt, int row, int col) + protected async Task GetSeriesBrush(Report rpt, int row, int col) { - Drawing.Brush br = SeriesBrush(rpt, _row, ChartDefn.OwnerReport)[col - 1]; // this will be the default brush + Drawing.Brush br = (await SeriesBrush(rpt, _row, ChartDefn.OwnerReport))[col - 1]; // this will be the default brush // obtain the rows we're acting upon MatrixCellEntry mce = _DataDefn[row, col]; @@ -896,99 +911,99 @@ protected Drawing.Brush GetSeriesBrush(Report rpt, int row, int col) Row lrow = (mce.Data.Data.Count > 0) ? mce.Data.Data[0] : null; Style s = ce.DP.Style; - string sc = s.BackgroundColor.EvaluateString(rpt, lrow); + string sc = await s.BackgroundColor.EvaluateString(rpt, lrow); Drawing.Color rc = XmlUtil.ColorFromHtml(sc, Drawing.Color.Empty, rpt); if (rc != Drawing.Color.Empty) br = new Drawing.SolidBrush(rc); - - return br; + + return br; + } + + protected async Task DrawDataPoint(Report rpt, Drawing.Graphics g, Drawing.Point p, int row, int col) + { + await DrawDataPoint(rpt, g, p, Drawing.Rectangle.Empty, row, col); + } + + protected async Task DrawDataPoint(Report rpt, Drawing.Graphics g, Drawing.Rectangle rect, int row, int col) + { + await DrawDataPoint(rpt, g, Drawing.Point.Empty, rect, row, col); } - protected void DrawDataPoint(Report rpt, Drawing.Graphics g, Drawing.Point p, int row, int col) - { - DrawDataPoint(rpt, g, p, Drawing.Rectangle.Empty, row, col); - } - - protected void DrawDataPoint(Report rpt, Drawing.Graphics g, Drawing.Rectangle rect, int row, int col) - { - DrawDataPoint(rpt, g, Drawing.Point.Empty, rect, row, col); - } - - void DrawDataPoint(Report rpt, Drawing.Graphics g, Drawing.Point p, Drawing.Rectangle rect, int row, int col) - { - MatrixCellEntry mce = _DataDefn[row, col]; - if (mce == null) - return; // Not sure what this really means TODO: - - ChartExpression ce = (ChartExpression) (mce.DisplayItem); - DataPoint dp = ce.DP; - - if (dp.DataLabel == null || !dp.DataLabel.Visible) - return; - - // Calculate the DataPoint value; usually a fairly expensive operation - // due to the common use of aggregate values. - Row lrow; - this._ChartDefn.ChartMatrix.SetMyData(rpt, mce.Data); // Must set this for evaluation - if (mce.Data.Data.Count > 0) - lrow = mce.Data.Data[0]; - else - lrow = null; - - object v=null; - TypeCode tc; - if (dp.DataLabel.Value == null) - { // No DataLabel value specified so we use the actual value - v = ce.Value.EvaluateDouble(rpt, lrow); - tc = TypeCode.Double; - } - else - { // Evaluate the DataLable value for the display - v = dp.DataLabel.Value.Evaluate(rpt, lrow); - tc = dp.DataLabel.Value.GetTypeCode(); - } - - if (dp.DataLabel.Style == null) - { - if (rect == Drawing.Rectangle.Empty) - { - Drawing.Size size = Style.MeasureStringDefaults(rpt, g, v, tc, lrow, int.MaxValue); - rect = new Drawing.Rectangle(p, size); - } - Style.DrawStringDefaults(g, v, rect); - } - else - { - if (rect == Drawing.Rectangle.Empty) - { - Drawing.Size size = dp.DataLabel.Style.MeasureString(rpt, g, v, tc, lrow, int.MaxValue); - rect = new Drawing.Rectangle(p, size); - } - dp.DataLabel.Style.DrawString(rpt, g, v, tc, lrow, rect); - } - - return; - } - - protected string GetSeriesValue(Report rpt, int iCol) - { - MatrixCellEntry mce = _DataDefn[0, iCol]; - Row lrow; - if (mce.Data.Data.Count > 0) - lrow = mce.Data.Data[0]; - else - lrow = null; - ChartExpression ce = (ChartExpression) (mce.DisplayItem); - - string v = ce.ChartLabel == null ? - ce.Value.EvaluateString(rpt, lrow) : - ce.ChartLabel.EvaluateString(rpt, lrow); - + async Task DrawDataPoint(Report rpt, Drawing.Graphics g, Drawing.Point p, Drawing.Rectangle rect, int row, int col) + { + MatrixCellEntry mce = _DataDefn[row, col]; + if (mce == null) + return; // Not sure what this really means TODO: + + ChartExpression ce = (ChartExpression)(mce.DisplayItem); + DataPoint dp = ce.DP; + + if (dp.DataLabel == null || !dp.DataLabel.Visible) + return; + + // Calculate the DataPoint value; usually a fairly expensive operation + // due to the common use of aggregate values. + Row lrow; + this._ChartDefn.ChartMatrix.SetMyData(rpt, mce.Data); // Must set this for evaluation + if (mce.Data.Data.Count > 0) + lrow = mce.Data.Data[0]; + else + lrow = null; + + object v = null; + TypeCode tc; + if (dp.DataLabel.Value == null) + { // No DataLabel value specified so we use the actual value + v = ce.Value.EvaluateDouble(rpt, lrow); + tc = TypeCode.Double; + } + else + { // Evaluate the DataLable value for the display + v = dp.DataLabel.Value.Evaluate(rpt, lrow); + tc = dp.DataLabel.Value.GetTypeCode(); + } + + if (dp.DataLabel.Style == null) + { + if (rect == Drawing.Rectangle.Empty) + { + Drawing.Size size = await Style.MeasureStringDefaults(rpt, g, v, tc, lrow, int.MaxValue); + rect = new Drawing.Rectangle(p, size); + } + Style.DrawStringDefaults(g, v, rect); + } + else + { + if (rect == Drawing.Rectangle.Empty) + { + Drawing.Size size = await dp.DataLabel.Style.MeasureString(rpt, g, v, tc, lrow, int.MaxValue); + rect = new Drawing.Rectangle(p, size); + } + await dp.DataLabel.Style.DrawString(rpt, g, v, tc, lrow, rect); + } + + return; + } + + protected async Task GetSeriesValue(Report rpt, int iCol) + { + MatrixCellEntry mce = _DataDefn[0, iCol]; + Row lrow; + if (mce.Data.Data.Count > 0) + lrow = mce.Data.Data[0]; + else + lrow = null; + ChartExpression ce = (ChartExpression)(mce.DisplayItem); + + string v = ce.ChartLabel == null ? + await ce.Value.EvaluateString(rpt, lrow) : + await ce.ChartLabel.EvaluateString(rpt, lrow); + return v; - } + } - // 20022008 AJM GJL - Should the Second Y axis be shown? + // 20022008 AJM GJL - Should the Second Y axis be shown? protected bool ShowRightYAxis(Report rpt) { for (int iRow = 1; iRow <= CategoryCount; iRow++) @@ -997,150 +1012,153 @@ protected bool ShowRightYAxis(Report rpt) { if (GetYAxis(rpt, iCol, 1).ToUpper() == "RIGHT") { - return true; + return true; } } } return false; } - protected void GetMaxMinDataValue(Report rpt, out double max, out double min, int xyb,int WhichYAxis) - { - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked) - { - GetMaxMinDataValueStacked(rpt, out max, out min); - return; - } - min = double.MaxValue; - max = double.MinValue; - - double v = 0;// 20022008 AJM GJL - for (int iRow = 1; iRow <= CategoryCount; iRow++) - { - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - // 20022008 AJM GJL + protected async Task<(double max, double min)> GetMaxMinDataValue(Report rpt, int xyb, int WhichYAxis) + { + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked) + { + var result = await GetMaxMinDataValueStacked(rpt); + return (result.max, result.min); + } + double min = double.MaxValue; + double max = double.MinValue; + + double v = 0;// 20022008 AJM GJL + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + // 20022008 AJM GJL if (WhichYAxis == 2) { if (GetYAxis(rpt, iCol, 1).ToUpper() == "RIGHT") { - v = GetDataValue(rpt, iRow, iCol, xyb); + v = await GetDataValue(rpt, iRow, iCol, xyb); if (v < min) min = v; if (v > max) max = v; - + } } else { if (GetYAxis(rpt, iCol, 1).ToUpper() != "RIGHT") { - v = GetDataValue(rpt, iRow, iCol, xyb); - if (v < min) - min = v; - if (v > max) - max = v; + v = await GetDataValue(rpt, iRow, iCol, xyb); + if (v < min) + min = v; + if (v > max) + max = v; } - } - } - } - } - - void GetMaxMinDataValueStacked(Report rpt, out double max, out double min) - { - min = double.MaxValue; - max = double.MinValue; - - double v; - for (int iRow = 1; iRow <= CategoryCount; iRow++) - { - v=0; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - v += GetDataValue(rpt, iRow, iCol); - } - if (v < min) - min = v; - if (v > max) - max = v; - } - } - - protected Drawing.Brush[] GetSeriesBrushes(Report rpt, Row row, ReportDefn defn) - { - Drawing.Brush[] b = new Drawing.Brush[SeriesCount]; - - for (int i=0; i < SeriesCount; i++) - { - // TODO: In general all the palettes could use a good going over - // both in terms of the colors in the lists and their order - switch (ChartPalette.GetStyle(ChartDefn.Palette.EvaluateString(rpt, row), defn.rl)) - { - case ChartPaletteEnum.Default: - b[i] = GetSeriesBrushesExcel(i); break; - case ChartPaletteEnum.EarthTones: - b[i] = GetSeriesBrushesEarthTones(i); break; - case ChartPaletteEnum.Excel: - b[i] = GetSeriesBrushesExcel(i); break; - case ChartPaletteEnum.GrayScale: - b[i] = GetSeriesBrushesGrayScale(i); break; - case ChartPaletteEnum.Light: - b[i] = GetSeriesBrushesLight(i); break; - case ChartPaletteEnum.Pastel: - b[i] = GetSeriesBrushesPastel(i); break; - case ChartPaletteEnum.SemiTransparent: - b[i] = GetSeriesBrushesExcel(i); break; // TODO - // 20022008 AJM GJL - New black & white printer friendly palette (NOT TO RDL SPEC BUT REQUIRED!) + } + } + } + return (max, min); + } + + async Task<(double max, double min)> GetMaxMinDataValueStacked(Report rpt) + { + double min = double.MaxValue; + double max = double.MinValue; + + double v; + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + v = 0; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + v += await GetDataValue(rpt, iRow, iCol); + } + if (v < min) + min = v; + if (v > max) + max = v; + } + + return (max, min); + } + + protected async Task GetSeriesBrushes(Report rpt, Row row, ReportDefn defn) + { + Drawing.Brush[] b = new Drawing.Brush[SeriesCount]; + + for (int i = 0; i < SeriesCount; i++) + { + // TODO: In general all the palettes could use a good going over + // both in terms of the colors in the lists and their order + switch (ChartPalette.GetStyle(await ChartDefn.Palette.EvaluateString(rpt, row), defn.rl)) + { + case ChartPaletteEnum.Default: + b[i] = GetSeriesBrushesExcel(i); break; + case ChartPaletteEnum.EarthTones: + b[i] = GetSeriesBrushesEarthTones(i); break; + case ChartPaletteEnum.Excel: + b[i] = GetSeriesBrushesExcel(i); break; + case ChartPaletteEnum.GrayScale: + b[i] = GetSeriesBrushesGrayScale(i); break; + case ChartPaletteEnum.Light: + b[i] = GetSeriesBrushesLight(i); break; + case ChartPaletteEnum.Pastel: + b[i] = GetSeriesBrushesPastel(i); break; + case ChartPaletteEnum.SemiTransparent: + b[i] = GetSeriesBrushesExcel(i); break; // TODO + // 20022008 AJM GJL - New black & white printer friendly palette (NOT TO RDL SPEC BUT REQUIRED!) case ChartPaletteEnum.Patterned: - b[i] = GetSeriesBrushesPatterned(i);break; + b[i] = GetSeriesBrushesPatterned(i); break; case ChartPaletteEnum.PatternedBlack: b[i] = GetSeriesBrushesPatternedBlack(i); break; case ChartPaletteEnum.Custom: b[i] = new Drawing.SolidBrush(Drawing.Color.FromName(getColour(rpt, 1, i + 1))); break; - default: - b[i] = GetSeriesBrushesExcel(i); break; - } - } - - return b; - } - - Drawing.Brush GetSeriesBrushesEarthTones(int i) - { - switch (i % 22) - { - case 0: return Drawing.Brushes.Maroon; - case 1: return Drawing.Brushes.Brown; - case 2: return Drawing.Brushes.Chocolate; - case 3: return Drawing.Brushes.IndianRed; - case 4: return Drawing.Brushes.Peru; - case 5: return Drawing.Brushes.BurlyWood; - case 6: return Drawing.Brushes.AntiqueWhite; - case 7: return Drawing.Brushes.FloralWhite; - case 8: return Drawing.Brushes.Ivory; - case 9: return Drawing.Brushes.LightCoral; - case 10:return Drawing.Brushes.DarkSalmon; - case 11: return Drawing.Brushes.LightSalmon; - case 12: return Drawing.Brushes.PeachPuff; - case 13: return Drawing.Brushes.NavajoWhite; - case 14: return Drawing.Brushes.Moccasin; - case 15: return Drawing.Brushes.PapayaWhip; - case 16: return Drawing.Brushes.Goldenrod; - case 17: return Drawing.Brushes.DarkGoldenrod; - case 18: return Drawing.Brushes.DarkKhaki; - case 19: return Drawing.Brushes.Khaki; - case 20: return Drawing.Brushes.Beige; - case 21: return Drawing.Brushes.Cornsilk; - default: return Drawing.Brushes.Brown; - } - } - - Drawing.Brush GetSeriesBrushesExcel(int i) - { - switch (i % 11) // Just a guess at what these might actually be - { + default: + b[i] = GetSeriesBrushesExcel(i); break; + } + } + + return b; + } + + Drawing.Brush GetSeriesBrushesEarthTones(int i) + { + switch (i % 22) + { + case 0: return Drawing.Brushes.Maroon; + case 1: return Drawing.Brushes.Brown; + case 2: return Drawing.Brushes.Chocolate; + case 3: return Drawing.Brushes.IndianRed; + case 4: return Drawing.Brushes.Peru; + case 5: return Drawing.Brushes.BurlyWood; + case 6: return Drawing.Brushes.AntiqueWhite; + case 7: return Drawing.Brushes.FloralWhite; + case 8: return Drawing.Brushes.Ivory; + case 9: return Drawing.Brushes.LightCoral; + case 10: return Drawing.Brushes.DarkSalmon; + case 11: return Drawing.Brushes.LightSalmon; + case 12: return Drawing.Brushes.PeachPuff; + case 13: return Drawing.Brushes.NavajoWhite; + case 14: return Drawing.Brushes.Moccasin; + case 15: return Drawing.Brushes.PapayaWhip; + case 16: return Drawing.Brushes.Goldenrod; + case 17: return Drawing.Brushes.DarkGoldenrod; + case 18: return Drawing.Brushes.DarkKhaki; + case 19: return Drawing.Brushes.Khaki; + case 20: return Drawing.Brushes.Beige; + case 21: return Drawing.Brushes.Cornsilk; + default: return Drawing.Brushes.Brown; + } + } + + Drawing.Brush GetSeriesBrushesExcel(int i) + { + switch (i % 11) // Just a guess at what these might actually be + { //Gil's Excel 080208 - from excel 2007 case 0: return Drawing.Brushes.Blue; case 1: return Drawing.Brushes.Red; @@ -1153,17 +1171,17 @@ Drawing.Brush GetSeriesBrushesExcel(int i) case 8: return Drawing.Brushes.Lime; case 9: return Drawing.Brushes.Teal; case 10: return Drawing.Brushes.Pink; - default: return Drawing.Brushes.Blue; - } - } -// 20022008 AJM GJL - Drawing.Brush GetSeriesBrushesPatterned(int i) + default: return Drawing.Brushes.Blue; + } + } + // 20022008 AJM GJL + Drawing.Brush GetSeriesBrushesPatterned(int i) { - Drawing2D.HatchBrush PatternBrush; + Drawing2D.HatchBrush PatternBrush; switch (i % 10) { case 0: - PatternBrush = new Drawing2D.HatchBrush(Drawing2D.HatchStyle.LargeConfetti, Drawing.Color.Blue,Drawing.Color.White); + PatternBrush = new Drawing2D.HatchBrush(Drawing2D.HatchStyle.LargeConfetti, Drawing.Color.Blue, Drawing.Color.White); break; case 1: PatternBrush = new Drawing2D.HatchBrush(Drawing2D.HatchStyle.Cross, Drawing.Color.Red, Drawing.Color.White); // was weave... but I Especially didn't want to draw that in PDF - GJL @@ -1198,15 +1216,15 @@ Drawing.Brush GetSeriesBrushesPatterned(int i) default: PatternBrush = new Drawing2D.HatchBrush(Drawing2D.HatchStyle.BackwardDiagonal, Drawing.Color.Blue, Drawing.Color.White); break; - - } + + } return PatternBrush; } - Drawing.Brush GetSeriesBrushesPatternedBlack(int i) + Drawing.Brush GetSeriesBrushesPatternedBlack(int i) { - Drawing2D.HatchBrush PatternBrush; + Drawing2D.HatchBrush PatternBrush; switch (i % 10) { case 0: @@ -1246,104 +1264,104 @@ Drawing.Brush GetSeriesBrushesPatternedBlack(int i) PatternBrush = new Drawing2D.HatchBrush(Drawing2D.HatchStyle.BackwardDiagonal, Drawing.Color.Black, Drawing.Color.White); break; - } + } return PatternBrush; - } - - Drawing.Brush GetSeriesBrushesGrayScale(int i) - { - switch (i % 10) - { - case 0: return Drawing.Brushes.Gray; - case 1: return Drawing.Brushes.SlateGray; - case 2: return Drawing.Brushes.DarkGray; - case 3: return Drawing.Brushes.LightGray; - case 4: return Drawing.Brushes.DarkSlateGray; - case 5: return Drawing.Brushes.DimGray; - case 6: return Drawing.Brushes.LightSlateGray; - case 7: return Drawing.Brushes.Black; - case 8: return Drawing.Brushes.White; - case 9: return Drawing.Brushes.Gainsboro; - default: return Drawing.Brushes.Gray; - } - } - - Drawing.Brush GetSeriesBrushesLight(int i) - { - switch (i % 13) - { - case 0: return Drawing.Brushes.LightBlue; - case 1: return Drawing.Brushes.LightCoral; - case 2: return Drawing.Brushes.LightCyan; - case 3: return Drawing.Brushes.LightGoldenrodYellow; - case 4: return Drawing.Brushes.LightGray; - case 5: return Drawing.Brushes.LightGreen; - case 6: return Drawing.Brushes.LightPink; - case 7: return Drawing.Brushes.LightSalmon; - case 8: return Drawing.Brushes.LightSeaGreen; - case 9: return Drawing.Brushes.LightSkyBlue; - case 10: return Drawing.Brushes.LightSlateGray; - case 11: return Drawing.Brushes.LightSteelBlue; - case 12: return Drawing.Brushes.LightYellow; - default: return Drawing.Brushes.LightBlue; - } - } - - Drawing.Brush GetSeriesBrushesPastel(int i) - { - switch (i % 26) - { - case 0: return Drawing.Brushes.CadetBlue; - case 1: return Drawing.Brushes.MediumTurquoise; - case 2: return Drawing.Brushes.Aquamarine; - case 3: return Drawing.Brushes.LightCyan; - case 4: return Drawing.Brushes.Azure; - case 5: return Drawing.Brushes.AliceBlue; - case 6: return Drawing.Brushes.MintCream; - case 7: return Drawing.Brushes.DarkSeaGreen; - case 8: return Drawing.Brushes.PaleGreen; - case 9: return Drawing.Brushes.LightGreen; - case 10: return Drawing.Brushes.MediumPurple; - case 11: return Drawing.Brushes.CornflowerBlue; - case 12: return Drawing.Brushes.Lavender; - case 13: return Drawing.Brushes.GhostWhite; - case 14: return Drawing.Brushes.PaleGoldenrod; - case 15: return Drawing.Brushes.LightGoldenrodYellow; - case 16: return Drawing.Brushes.LemonChiffon; - case 17: return Drawing.Brushes.LightYellow; - case 18: return Drawing.Brushes.Orchid; - case 19: return Drawing.Brushes.Plum; - case 20: return Drawing.Brushes.LightPink; - case 21: return Drawing.Brushes.Pink; - case 22: return Drawing.Brushes.LavenderBlush; - case 23: return Drawing.Brushes.Linen; - case 24: return Drawing.Brushes.PaleTurquoise; - case 25: return Drawing.Brushes.OldLace; - default: return Drawing.Brushes.CadetBlue; - } - } - - protected ChartMarkerEnum[] GetSeriesMarkers() - { - ChartMarkerEnum[] m = new ChartMarkerEnum[SeriesCount]; - - for (int i=0; i < SeriesCount; i++) - { - m[i] = (ChartMarkerEnum) ( i % (int) ChartMarkerEnum.Count); - } - - return m; - } - - protected void GetValueMaxMin(Report rpt, ref double max, ref double min, int xyb, int WhichYAxis)// 20022008 AJM GJL - { - - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) - { // Percent stacked is easy; and overrides user provided values - max = 1; - min = 0; - return; - } + } + + Drawing.Brush GetSeriesBrushesGrayScale(int i) + { + switch (i % 10) + { + case 0: return Drawing.Brushes.Gray; + case 1: return Drawing.Brushes.SlateGray; + case 2: return Drawing.Brushes.DarkGray; + case 3: return Drawing.Brushes.LightGray; + case 4: return Drawing.Brushes.DarkSlateGray; + case 5: return Drawing.Brushes.DimGray; + case 6: return Drawing.Brushes.LightSlateGray; + case 7: return Drawing.Brushes.Black; + case 8: return Drawing.Brushes.White; + case 9: return Drawing.Brushes.Gainsboro; + default: return Drawing.Brushes.Gray; + } + } + + Drawing.Brush GetSeriesBrushesLight(int i) + { + switch (i % 13) + { + case 0: return Drawing.Brushes.LightBlue; + case 1: return Drawing.Brushes.LightCoral; + case 2: return Drawing.Brushes.LightCyan; + case 3: return Drawing.Brushes.LightGoldenrodYellow; + case 4: return Drawing.Brushes.LightGray; + case 5: return Drawing.Brushes.LightGreen; + case 6: return Drawing.Brushes.LightPink; + case 7: return Drawing.Brushes.LightSalmon; + case 8: return Drawing.Brushes.LightSeaGreen; + case 9: return Drawing.Brushes.LightSkyBlue; + case 10: return Drawing.Brushes.LightSlateGray; + case 11: return Drawing.Brushes.LightSteelBlue; + case 12: return Drawing.Brushes.LightYellow; + default: return Drawing.Brushes.LightBlue; + } + } + + Drawing.Brush GetSeriesBrushesPastel(int i) + { + switch (i % 26) + { + case 0: return Drawing.Brushes.CadetBlue; + case 1: return Drawing.Brushes.MediumTurquoise; + case 2: return Drawing.Brushes.Aquamarine; + case 3: return Drawing.Brushes.LightCyan; + case 4: return Drawing.Brushes.Azure; + case 5: return Drawing.Brushes.AliceBlue; + case 6: return Drawing.Brushes.MintCream; + case 7: return Drawing.Brushes.DarkSeaGreen; + case 8: return Drawing.Brushes.PaleGreen; + case 9: return Drawing.Brushes.LightGreen; + case 10: return Drawing.Brushes.MediumPurple; + case 11: return Drawing.Brushes.CornflowerBlue; + case 12: return Drawing.Brushes.Lavender; + case 13: return Drawing.Brushes.GhostWhite; + case 14: return Drawing.Brushes.PaleGoldenrod; + case 15: return Drawing.Brushes.LightGoldenrodYellow; + case 16: return Drawing.Brushes.LemonChiffon; + case 17: return Drawing.Brushes.LightYellow; + case 18: return Drawing.Brushes.Orchid; + case 19: return Drawing.Brushes.Plum; + case 20: return Drawing.Brushes.LightPink; + case 21: return Drawing.Brushes.Pink; + case 22: return Drawing.Brushes.LavenderBlush; + case 23: return Drawing.Brushes.Linen; + case 24: return Drawing.Brushes.PaleTurquoise; + case 25: return Drawing.Brushes.OldLace; + default: return Drawing.Brushes.CadetBlue; + } + } + + protected ChartMarkerEnum[] GetSeriesMarkers() + { + ChartMarkerEnum[] m = new ChartMarkerEnum[SeriesCount]; + + for (int i = 0; i < SeriesCount; i++) + { + m[i] = (ChartMarkerEnum)(i % (int)ChartMarkerEnum.Count); + } + + return m; + } + + protected async Task<(double max, double min)> GetValueMaxMin(Report rpt, double max, double min, int xyb, int WhichYAxis)// 20022008 AJM GJL + { + + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) + { // Percent stacked is easy; and overrides user provided values + max = 1; + min = 0; + return (max, min); + } Axis ax; if (_ChartDefn.Type == ChartTypeEnum.Bubble || _ChartDefn.Type == ChartTypeEnum.Scatter) @@ -1357,51 +1375,51 @@ protected void GetValueMaxMin(Report rpt, ref double max, ref double min, int xy ax = null; } else - { + { ax = _ChartDefn.ValueAxis != null ? _ChartDefn.ValueAxis.Axis : null; } - - double vAxisMax; + + double vAxisMax; double vAxisMin; - if (ax != null) - { - vAxisMax = ax.MaxEval(rpt, _row); - vAxisMin = ax.MinEval(rpt, _row); - } - else - { - vAxisMax = vAxisMin = int.MinValue; - } - - // Check for case where both min and max are provided - if (vAxisMax != int.MinValue && ! vAxisMax.Equals(double.NaN) && - vAxisMin != int.MinValue && ! vAxisMin.Equals(double.NaN)) - { - max = vAxisMax; - min = vAxisMin; - return; - } - - // OK We have to work for it; Calculate min/max of data - GetMaxMinDataValue(rpt, out max, out min, xyb,1); // 20022008 AJM GJL - - if (vAxisMax != int.MinValue && ! vAxisMax.Equals(double.NaN)) - max = vAxisMax; - else - { - // - //int gridIncrs=10; // assume 10 grid increments for now + if (ax != null) + { + vAxisMax = await ax.MaxEval(rpt, _row); + vAxisMin = await ax.MinEval(rpt, _row); + } + else + { + vAxisMax = vAxisMin = int.MinValue; + } + + // Check for case where both min and max are provided + if (vAxisMax != int.MinValue && !vAxisMax.Equals(double.NaN) && + vAxisMin != int.MinValue && !vAxisMin.Equals(double.NaN)) + { + max = vAxisMax; + min = vAxisMin; + return (max, min); + } + + // OK We have to work for it; Calculate min/max of data + (max, min) = await GetMaxMinDataValue(rpt, xyb, 1); // 20022008 AJM GJL + + if (vAxisMax != int.MinValue && !vAxisMax.Equals(double.NaN)) + max = vAxisMax; + else + { + // + //int gridIncrs=10; // assume 10 grid increments for now _gridIncrs = 10; //PJR 20071113 - grid incrs set & adjusted in here now - double incr = max / _gridIncrs; // should be range between max and min? - double log = Math.Floor(Math.Log10(Math.Abs(incr))); + double incr = max / _gridIncrs; // should be range between max and min? + double log = Math.Floor(Math.Log10(Math.Abs(incr))); - double logPow = Math.Pow(10, log) * Math.Sign(max); - double logDig = (int) ((incr / logPow) + .5); + double logPow = Math.Pow(10, log) * Math.Sign(max); + double logDig = (int)((incr / logPow) + .5); - // promote the MSD to either 1, 2, or 5 + // promote the MSD to either 1, 2, or 5 if (logDig > 5.0) logDig = 10.0; else if (logDig > 2.0) @@ -1420,97 +1438,98 @@ protected void GetValueMaxMin(Report rpt, ref double max, ref double min, int xy { _gridIncrs++; } -// 20022008 AJM GJL + // 20022008 AJM GJL double tmpMax = max; // 04032008 AJM - Fixing Strange Number Choice with small numbers max = /*(int)*/ (logDig * logPow * _gridIncrs /*+ 0.5*/); - + if (tmpMax > max - ((max / _gridIncrs) * .5)) { max += (max / _gridIncrs); _gridIncrs++; } - } - - if (vAxisMin != int.MinValue && ! vAxisMin.Equals(double.NaN)) - min = vAxisMin; - else if (min > 0) - min = 0; - else - { - min = Math.Floor(min); - } - - return; - } - - protected void AdjustMargins(Drawing.Rectangle legendRect, Report rpt, Drawing.Graphics g) - { - // //110208AJM GJL Making room for second y axis - - // if (ShowRightYAxis(rpt) && !(IsLegendRight())) - //{ - // Layout.RightMargin = (int)(Layout.LeftMargin * 1.5); - //} - - - // Adjust the margins based on the legend - if (!IsLegendInsidePlotArea()) // When inside plot area we don't adjust plot margins - { - if (IsLegendLeft()) - Layout.LeftMargin += legendRect.Width; - else if (IsLegendRight()) - Layout.RightMargin += legendRect.Width; - if (IsLegendTop()) - Layout.TopMargin += legendRect.Height; - else if (IsLegendBottom()) - Layout.BottomMargin += legendRect.Height; - } - // Force some margins; if any are too small - int min = new RSize(ChartDefn.OwnerReport, ".2 in").PixelsX; - - if (Layout.RightMargin < min + (this._LastCategoryWidth/2)) - Layout.RightMargin = min + (this._LastCategoryWidth/2); - if (Layout.LeftMargin < min) - Layout.LeftMargin = min; - if (Layout.TopMargin < min) - Layout.TopMargin = min; - if (Layout.BottomMargin < min) - Layout.BottomMargin = min; - } - - protected bool IsLegendLeft() - { - Legend l = _ChartDefn.Legend; - if (l == null || !l.Visible) - return false; - - bool rc; - switch (l.Position) - { - case LegendPositionEnum.BottomLeft: - case LegendPositionEnum.LeftBottom: - case LegendPositionEnum.LeftCenter: - case LegendPositionEnum.LeftTop: - case LegendPositionEnum.TopLeft: - rc=true; - break; - default: - rc=false; - break; - } - - return rc; - } - - protected void SetIncrementAndInterval(Report rpt, Axis a, double min, double max, out double incr, out int interval) + } + + if (vAxisMin != int.MinValue && !vAxisMin.Equals(double.NaN)) + min = vAxisMin; + else if (min > 0) + min = 0; + else + { + min = Math.Floor(min); + } + + return (max, min); + } + + protected void AdjustMargins(Drawing.Rectangle legendRect, Report rpt, Drawing.Graphics g) { - interval = _gridIncrs; //PJR 20071113 - gridincrements set by Max value now // assume an interval count of 10 to start + // //110208AJM GJL Making room for second y axis + + // if (ShowRightYAxis(rpt) && !(IsLegendRight())) + //{ + // Layout.RightMargin = (int)(Layout.LeftMargin * 1.5); + //} + + + // Adjust the margins based on the legend + if (!IsLegendInsidePlotArea()) // When inside plot area we don't adjust plot margins + { + if (IsLegendLeft()) + Layout.LeftMargin += legendRect.Width; + else if (IsLegendRight()) + Layout.RightMargin += legendRect.Width; + if (IsLegendTop()) + Layout.TopMargin += legendRect.Height; + else if (IsLegendBottom()) + Layout.BottomMargin += legendRect.Height; + } + // Force some margins; if any are too small + int min = new RSize(ChartDefn.OwnerReport, ".2 in").PixelsX; + + if (Layout.RightMargin < min + (this._LastCategoryWidth / 2)) + Layout.RightMargin = min + (this._LastCategoryWidth / 2); + if (Layout.LeftMargin < min) + Layout.LeftMargin = min; + if (Layout.TopMargin < min) + Layout.TopMargin = min; + if (Layout.BottomMargin < min) + Layout.BottomMargin = min; + } + + protected bool IsLegendLeft() + { + Legend l = _ChartDefn.Legend; + if (l == null || !l.Visible) + return false; + + bool rc; + switch (l.Position) + { + case LegendPositionEnum.BottomLeft: + case LegendPositionEnum.LeftBottom: + case LegendPositionEnum.LeftCenter: + case LegendPositionEnum.LeftTop: + case LegendPositionEnum.TopLeft: + rc = true; + break; + default: + rc = false; + break; + } + + return rc; + } + + protected async Task<(double incr, int interval)> SetIncrementAndInterval(Report rpt, Axis a, double min, double max) + { + int interval = _gridIncrs; //PJR 20071113 - gridincrements set by Max value now // assume an interval count of 10 to start + double incr; if (a.MajorInterval != null) { - incr = a.MajorInterval.EvaluateDouble(rpt, this.ChartRow); + incr = await a.MajorInterval.EvaluateDouble(rpt, this.ChartRow); if (incr.CompareTo(double.MinValue) == 0) incr = (max - min) / interval; else @@ -1521,105 +1540,105 @@ protected void SetIncrementAndInterval(Report rpt, Axis a, double min, double ma else incr = (max - min) / interval; - return; + return (incr, interval); + } + + protected bool IsLegendInsidePlotArea() + { + Legend l = _ChartDefn.Legend; + if (l == null || !l.Visible) + return false; // doesn't really matter + else + return l.InsidePlotArea; + } + + protected bool IsLegendRight() + { + Legend l = _ChartDefn.Legend; + if (l == null || !l.Visible) + return false; + + bool rc; + switch (l.Position) + { + case LegendPositionEnum.BottomRight: + case LegendPositionEnum.RightBottom: + case LegendPositionEnum.RightCenter: + case LegendPositionEnum.TopRight: + case LegendPositionEnum.RightTop: + rc = true; + break; + default: + rc = false; + break; + } + return rc; + } + + protected bool IsLegendTop() + { + Legend l = _ChartDefn.Legend; + if (l == null || !l.Visible) + return false; + + bool rc; + switch (l.Position) + { + case LegendPositionEnum.LeftTop: + case LegendPositionEnum.TopLeft: + case LegendPositionEnum.TopCenter: + case LegendPositionEnum.TopRight: + case LegendPositionEnum.RightTop: + rc = true; + break; + default: + rc = false; + break; + } + return rc; + } + + protected bool IsLegendBottom() + { + Legend l = _ChartDefn.Legend; + if (l == null || !l.Visible) + return false; + + bool rc; + switch (l.Position) + { + case LegendPositionEnum.BottomCenter: + case LegendPositionEnum.BottomLeft: + case LegendPositionEnum.LeftBottom: + case LegendPositionEnum.BottomRight: + case LegendPositionEnum.RightBottom: + rc = true; + break; + default: + rc = false; + break; + } + return rc; + } + + private Row FirstChartRow(Report rpt) + { + Rows _Data = _ChartDefn.ChartMatrix.GetMyData(rpt); + if (_Data != null && + _Data.Data.Count > 0) + return _Data.Data[0]; + else + return null; + + } + #region IDisposable Members + + public void Dispose() + { + if (_bm != null) + _bm.Dispose(); } - protected bool IsLegendInsidePlotArea() - { - Legend l = _ChartDefn.Legend; - if (l == null || !l.Visible) - return false; // doesn't really matter - else - return l.InsidePlotArea; - } - - protected bool IsLegendRight() - { - Legend l = _ChartDefn.Legend; - if (l == null || !l.Visible) - return false; - - bool rc; - switch (l.Position) - { - case LegendPositionEnum.BottomRight: - case LegendPositionEnum.RightBottom: - case LegendPositionEnum.RightCenter: - case LegendPositionEnum.TopRight: - case LegendPositionEnum.RightTop: - rc=true; - break; - default: - rc=false; - break; - } - return rc; - } - - protected bool IsLegendTop() - { - Legend l = _ChartDefn.Legend; - if (l == null || !l.Visible) - return false; - - bool rc; - switch (l.Position) - { - case LegendPositionEnum.LeftTop: - case LegendPositionEnum.TopLeft: - case LegendPositionEnum.TopCenter: - case LegendPositionEnum.TopRight: - case LegendPositionEnum.RightTop: - rc=true; - break; - default: - rc=false; - break; - } - return rc; - } - - protected bool IsLegendBottom() - { - Legend l = _ChartDefn.Legend; - if (l == null || !l.Visible) - return false; - - bool rc; - switch (l.Position) - { - case LegendPositionEnum.BottomCenter: - case LegendPositionEnum.BottomLeft: - case LegendPositionEnum.LeftBottom: - case LegendPositionEnum.BottomRight: - case LegendPositionEnum.RightBottom: - rc=true; - break; - default: - rc=false; - break; - } - return rc; - } - - private Row FirstChartRow(Report rpt) - { - Rows _Data = _ChartDefn.ChartMatrix.GetMyData(rpt); - if (_Data != null && - _Data.Data.Count > 0) - return _Data.Data[0]; - else - return null; - - } - #region IDisposable Members - - public void Dispose() - { - if (_bm != null) - _bm.Dispose(); - } - - #endregion - } + #endregion + } } diff --git a/RdlEngine/Definition/ChartBubble.cs b/RdlEngine/Definition/ChartBubble.cs index cebb72cb..3bb1443c 100644 --- a/RdlEngine/Definition/ChartBubble.cs +++ b/RdlEngine/Definition/ChartBubble.cs @@ -23,6 +23,8 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Runtime.InteropServices; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; #else @@ -32,21 +34,21 @@ the website www.fyiReporting.com. namespace fyiReporting.RDL { - /// - /// Line chart definition and processing. - /// - [Serializable] - internal class ChartBubble: ChartBase - { - - internal ChartBubble(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX,Expression _ToolTipYFormat, Expression _ToolTipXFormat) - : base(r, row, c, m,showTooltips,showTooltipsX,_ToolTipYFormat, _ToolTipXFormat) - { - } - - override internal void Draw(Report rpt) - { - CreateSizedBitmap(); + /// + /// Line chart definition and processing. + /// + [Serializable] + internal class ChartBubble : ChartBase + { + + internal ChartBubble(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX, Expression _ToolTipYFormat, Expression _ToolTipXFormat) + : base(r, row, c, m, showTooltips, showTooltipsX, _ToolTipYFormat, _ToolTipXFormat) + { + } + + override internal async Task Draw(Report rpt) + { + CreateSizedBitmap(); #if !DRAWINGCOMPAT if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -61,7 +63,7 @@ override internal void Draw(Report rpt) } } - using(Drawing.Graphics g = Drawing.Graphics.FromImage(_mf != null ? _mf : _bm)) + using (Drawing.Graphics g = Drawing.Graphics.FromImage(_mf != null ? _mf : _bm)) #else using (Drawing.Graphics g = Drawing.Graphics.FromImage(_bm)) #endif @@ -73,67 +75,67 @@ override internal void Draw(Report rpt) g.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality; g.PageUnit = Drawing.GraphicsUnit.Pixel; - // Adjust the top margin to depend on the title height - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, ChartDefn.Title); - Layout.TopMargin = titleSize.Height; + // Adjust the top margin to depend on the title height + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, ChartDefn.Title); + Layout.TopMargin = titleSize.Height; - // 20022008 AJM GJL - Added new required info - double ymax=0,ymin=0; // Get the max and min values for the y axis - GetValueMaxMin(rpt, ref ymax, ref ymin, 1,1); + // 20022008 AJM GJL - Added new required info + double ymax = 0, ymin = 0; // Get the max and min values for the y axis + (ymax, ymin) = await GetValueMaxMin(rpt, ymax, ymin, 1, 1); double xmax = 0, xmin = 0; // Get the max and min values for the x axis - GetValueMaxMin(rpt, ref xmax, ref xmin, 0,1); + (xmax, xmin) = await GetValueMaxMin(rpt, xmax, xmin, 0, 1); double bmax = 0, bmin = 0; // Get the max and min values for the bubble size if (ChartDefn.Type == ChartTypeEnum.Bubble) // only applies to bubble (not scatter) - GetValueMaxMin(rpt, ref bmax, ref bmin, 2,1); + (bmax, bmin) = await GetValueMaxMin(rpt, bmax, bmin, 2, 1); + + await DrawChartStyle(rpt, g); - DrawChartStyle(rpt, g); - - // Draw title; routine determines if necessary - DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, Layout.Width, Layout.TopMargin)); + // Draw title; routine determines if necessary + await DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, Layout.Width, Layout.TopMargin)); - // Adjust the left margin to depend on the Value Axis - Drawing.Size vaSize = ValueAxisSize(rpt, g, ymin, ymax); - Layout.LeftMargin = vaSize.Width; + // Adjust the left margin to depend on the Value Axis + Drawing.Size vaSize = await ValueAxisSize(rpt, g, ymin, ymax); + Layout.LeftMargin = vaSize.Width; - // Draw legend - Drawing.Rectangle lRect = DrawLegend(rpt,g, false, true); + // Draw legend + Drawing.Rectangle lRect = await DrawLegend(rpt, g, false, true); - // Adjust the bottom margin to depend on the Category Axis - Drawing.Size caSize = CategoryAxisSize(rpt, g, xmin, xmax); - Layout.BottomMargin = caSize.Height; + // Adjust the bottom margin to depend on the Category Axis + Drawing.Size caSize = await CategoryAxisSize(rpt, g, xmin, xmax); + Layout.BottomMargin = caSize.Height; - AdjustMargins(lRect,rpt,g); // Adjust margins based on legend. + AdjustMargins(lRect, rpt, g); // Adjust margins based on legend. - // Draw Plot area - DrawPlotAreaStyle(rpt, g, lRect); + // Draw Plot area + await DrawPlotAreaStyle(rpt, g, lRect); - // Draw Value Axis - if (vaSize.Width > 0) // If we made room for the axis - we need to draw it - DrawValueAxis(rpt, g, ymin, ymax, - new Drawing.Rectangle(Layout.LeftMargin - vaSize.Width, Layout.TopMargin, vaSize.Width, Layout.PlotArea.Height), Layout.LeftMargin, _bm.Width - Layout.RightMargin); + // Draw Value Axis + if (vaSize.Width > 0) // If we made room for the axis - we need to draw it + await DrawValueAxis(rpt, g, ymin, ymax, + new Drawing.Rectangle(Layout.LeftMargin - vaSize.Width, Layout.TopMargin, vaSize.Width, Layout.PlotArea.Height), Layout.LeftMargin, _bm.Width - Layout.RightMargin); // Draw Category Axis if (caSize.Height > 0) - DrawCategoryAxis(rpt, g, xmin, xmax, - new Drawing.Rectangle(Layout.LeftMargin, _bm.Height - Layout.BottomMargin, _bm.Width - Layout.LeftMargin - Layout.RightMargin, vaSize.Height), + await DrawCategoryAxis(rpt, g, xmin, xmax, + new Drawing.Rectangle(Layout.LeftMargin, _bm.Height - Layout.BottomMargin, _bm.Width - Layout.LeftMargin - Layout.RightMargin, vaSize.Height), Layout.TopMargin, _bm.Height - Layout.BottomMargin); - // Draw Plot area data - DrawPlot(rpt, g, xmin, xmax, ymin, ymax, bmin, bmax); - DrawLegend(rpt, g, false, false); - } - - } + // Draw Plot area data + await DrawPlot(rpt, g, xmin, xmax, ymin, ymax, bmin, bmax); + await DrawLegend(rpt, g, false, false); + } - void DrawPlot(Report rpt, Drawing.Graphics g, double xmin, double xmax, double ymin, double ymax, double bmin, double bmax) + } + + async Task DrawPlot(Report rpt, Drawing.Graphics g, double xmin, double xmax, double ymin, double ymax, double bmin, double bmax) { // Draw Plot area data int maxPointHeight = (int)Layout.PlotArea.Height; int maxPointWidth = (int)Layout.PlotArea.Width; - + for (int iCol = 1; iCol <= SeriesCount; iCol++) { @@ -143,65 +145,70 @@ void DrawPlot(Report rpt, Drawing.Graphics g, double xmin, double xmax, double y bool isLine = GetPlotType(rpt, iCol, 1).ToUpper() == "LINE"; for (int iRow = 1; iRow <= CategoryCount; iRow++) { - double xv = this.GetDataValue(rpt, iRow, iCol, 0); - double yv = this.GetDataValue(rpt, iRow, iCol, 1); + double xv = await this.GetDataValue(rpt, iRow, iCol, 0); + double yv = await this.GetDataValue(rpt, iRow, iCol, 1); double bv = this.ChartDefn.Type == ChartTypeEnum.Bubble ? - this.GetDataValue(rpt, iRow, iCol, 2) : 0; - if (xv < xmin || yv < ymin || xv > xmax || yv > ymax) + await this.GetDataValue(rpt, iRow, iCol, 2) : 0; + if (xv < xmin || yv < ymin || xv > xmax || yv > ymax) continue; int x = (int)(((Math.Min(xv, xmax) - xmin) / (xmax - xmin)) * maxPointWidth); int y = (int)(((Math.Min(yv, ymax) - ymin) / (ymax - ymin)) * maxPointHeight); if (y != int.MinValue && x != int.MinValue) - { + { Drawing.Point p = new Drawing.Point(Layout.PlotArea.Left + x, Layout.PlotArea.Top + (maxPointHeight - y)); //GJL 010308 Line subtype scatter plot - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Line || (ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.SmoothLine || isLine) + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Line || (ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.SmoothLine || isLine) { if (!(lastPoint.IsEmpty)) { - Points[0] = lastPoint; - Points[1] = p; - String LineSize = getLineSize(rpt, iCol, 1); - int intLineSize = 2; - switch (LineSize) - { - case "Small": intLineSize = 1; - break; - case "Regular": intLineSize = 2; - break; - case "Large": intLineSize = 3; - break; - case "Extra Large": intLineSize = 4; - break; - case "Super Size": intLineSize = 5; - break; - } - DrawLineBetweenPoints(g, rpt, GetSeriesBrush(rpt, iRow, iCol), Points, intLineSize); - //Add a metafilecomment to use as a tooltip GJL 26092008 + Points[0] = lastPoint; + Points[1] = p; + String LineSize = getLineSize(rpt, iCol, 1); + int intLineSize = 2; + switch (LineSize) + { + case "Small": + intLineSize = 1; + break; + case "Regular": + intLineSize = 2; + break; + case "Large": + intLineSize = 3; + break; + case "Extra Large": + intLineSize = 4; + break; + case "Super Size": + intLineSize = 5; + break; + } + await DrawLineBetweenPoints(g, rpt, await GetSeriesBrush(rpt, iRow, iCol), Points, intLineSize); + //Add a metafilecomment to use as a tooltip GJL 26092008 - if (_showToolTips || _showToolTipsX) - { - string display = ""; - if (_showToolTipsX) display = xv.ToString(_tooltipXFormat); - if (_showToolTips) + if (_showToolTips || _showToolTipsX) { - if (display.Length > 0) display += " , "; - display += yv.ToString(_tooltipYFormat); + string display = ""; + if (_showToolTipsX) display = xv.ToString(_tooltipXFormat); + if (_showToolTips) + { + if (display.Length > 0) display += " , "; + display += yv.ToString(_tooltipYFormat); + } + String val = "ToolTip:" + display + "|X:" + (int)(p.X - 3) + "|Y:" + (int)(p.Y - 3) + "|W:" + 6 + "|H:" + 6; + g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - String val = "ToolTip:" + display + "|X:" + (int)(p.X - 3) + "|Y:" + (int)(p.Y - 3) + "|W:" + 6 + "|H:" + 6; - g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); - } } } else - { - DrawBubble(rpt, g, GetSeriesBrush(rpt, iRow, iCol), p, iRow, iCol, bmin, bmax, bv,xv,yv); + { + await DrawBubble(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), p, iRow, iCol, bmin, bmax, bv, xv, yv); } - lastPoint = p; - } + lastPoint = p; + } } } return; @@ -209,12 +216,12 @@ void DrawPlot(Report rpt, Drawing.Graphics g, double xmin, double xmax, double y /* This code was copied from the Line drawing class. * 010308 GJL */ - void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points) + async Task DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points) { - DrawLineBetweenPoints(g, rpt, brush, points, 2); + await DrawLineBetweenPoints(g, rpt, brush, points, 2); } - void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points,int intLineSize) + async Task DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points, int intLineSize) { if (points.Length <= 1) // Need at least 2 points return; @@ -232,7 +239,7 @@ void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, p = new Drawing.Pen(brush, intLineSize); } - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Smooth && points.Length > 2) + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Smooth && points.Length > 2) g.DrawCurve(p, points, 0.5F); else g.DrawLines(p, points); @@ -245,30 +252,30 @@ void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, return; } - void DrawBubble(Report rpt, Drawing.Graphics g, Drawing.Brush brush, Drawing.Point p, int iRow, int iCol, double bmin, double bmax, double bv,double xv,double yv) - { - Drawing.Pen pen=null; + async Task DrawBubble(Report rpt, Drawing.Graphics g, Drawing.Brush brush, Drawing.Point p, int iRow, int iCol, double bmin, double bmax, double bv, double xv, double yv) + { + Drawing.Pen pen = null; int diameter = BubbleSize(rpt, iRow, iCol, bmin, bmax, bv); // set diameter of bubble - - int radius= diameter /2; - try - { + + int radius = diameter / 2; + try + { if (this.ChartDefn.Type == ChartTypeEnum.Scatter && brush.GetType() == typeof(Drawing.Drawing2D.HatchBrush)) { Drawing.Drawing2D.HatchBrush tmpBrush = (Drawing.Drawing2D.HatchBrush)brush; Drawing.SolidBrush br = new Drawing.SolidBrush(tmpBrush.ForegroundColor); pen = new Drawing.Pen(new Drawing.SolidBrush(tmpBrush.ForegroundColor)); - DrawLegendMarker(g, br, pen, SeriesMarker[iCol - 1], p.X - radius, p.Y - radius, diameter); - DrawDataPoint(rpt, g, new Drawing.Point(p.X - 3, p.Y + 3), iRow, iCol); + DrawLegendMarker(g, br, pen, SeriesMarker[iCol - 1], p.X - radius, p.Y - radius, diameter); + await DrawDataPoint(rpt, g, new Drawing.Point(p.X - 3, p.Y + 3), iRow, iCol); } else { - pen = new Drawing.Pen(brush); + pen = new Drawing.Pen(brush); DrawLegendMarker(g, brush, pen, ChartMarkerEnum.Bubble, p.X - radius, p.Y - radius, diameter); - DrawDataPoint(rpt, g, new Drawing.Point(p.X - 3, p.Y + 3), iRow, iCol); - } + await DrawDataPoint(rpt, g, new Drawing.Point(p.X - 3, p.Y + 3), iRow, iCol); + } //Add a metafilecomment to use as a tooltip GJL 26092008 if (_showToolTips || _showToolTipsX) @@ -280,18 +287,18 @@ void DrawBubble(Report rpt, Drawing.Graphics g, Drawing.Brush brush, Drawing.Poi if (display.Length > 0) display += " , "; display += yv.ToString(_tooltipYFormat); } - String val = "ToolTip:" + display + "|X:" + (int)(p.X - 3) + "|Y:" + (int)(p.Y - 3) + "|W:" + 6 + "|H:" + 6; + String val = "ToolTip:" + display + "|X:" + (int)(p.X - 3) + "|Y:" + (int)(p.Y - 3) + "|W:" + 6 + "|H:" + 6; g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - } - finally - { - if (pen != null) - pen.Dispose(); - } + } + finally + { + if (pen != null) + pen.Dispose(); + } - return; - } + return; + } private int BubbleSize(Report rpt, int iRow, int iCol, double minB, double maxB, double bv) { @@ -308,14 +315,14 @@ private int BubbleSize(Report rpt, int iRow, int iCol, double minB, double maxB, if (Math.Abs(diff) < 1e-9d) // very small difference between max and min? return diameter; // just use the smallest - diameter = (int) (((vdiff / diff) * (bubbleMax - bubbleMin)) + bubbleMin); + diameter = (int)(((vdiff / diff) * (bubbleMax - bubbleMin)) + bubbleMin); return diameter; } // Calculate the size of the value axis; width is max value width + title width // height is max value height - protected Drawing.Size ValueAxisSize(Report rpt, Drawing.Graphics g, double min, double max) + protected async Task ValueAxisSize(Report rpt, Drawing.Graphics g, double min, double max) { Drawing.Size size = Drawing.Size.Empty; if (ChartDefn.ValueAxis == null) @@ -332,26 +339,26 @@ protected Drawing.Size ValueAxisSize(Report rpt, Drawing.Graphics g, double min, } else if (a.Style != null) { - minSize = a.Style.MeasureString(rpt, g, min, TypeCode.Double, null, int.MaxValue); - maxSize = a.Style.MeasureString(rpt, g, max, TypeCode.Double, null, int.MaxValue); + minSize = await a.Style.MeasureString(rpt, g, min, TypeCode.Double, null, int.MaxValue); + maxSize = await a.Style.MeasureString(rpt, g, max, TypeCode.Double, null, int.MaxValue); } else { - minSize = Style.MeasureStringDefaults(rpt, g, min, TypeCode.Double, null, int.MaxValue); - maxSize = Style.MeasureStringDefaults(rpt, g, max, TypeCode.Double, null, int.MaxValue); + minSize = await Style.MeasureStringDefaults(rpt, g, min, TypeCode.Double, null, int.MaxValue); + maxSize = await Style.MeasureStringDefaults(rpt, g, max, TypeCode.Double, null, int.MaxValue); } // Choose the largest size.Width = Math.Max(minSize.Width, maxSize.Width); size.Height = Math.Max(minSize.Height, maxSize.Height); // Now we need to add in the width of the title (if any) - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, a.Title); + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, a.Title); size.Width += titleSize.Width; return size; } - protected void DrawValueAxis(Report rpt, Drawing.Graphics g, double min, double max, + protected async Task DrawValueAxis(Report rpt, Drawing.Graphics g, double min, double max, Drawing.Rectangle rect, int plotLeft, int plotRight) { if (this.ChartDefn.ValueAxis == null) @@ -363,10 +370,10 @@ protected void DrawValueAxis(Report rpt, Drawing.Graphics g, double min, double int intervalCount; double incr; - SetIncrementAndInterval(rpt, a, min, max, out incr, out intervalCount); // Calculate the interval count + (incr, intervalCount) = await SetIncrementAndInterval(rpt, a, min, max); // Calculate the interval count - Drawing.Size tSize = DrawTitleMeasure(rpt, g, a.Title); - DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Top, tSize.Width, rect.Height)); + Drawing.Size tSize = await DrawTitleMeasure(rpt, g, a.Title); + await DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Top, tSize.Width, rect.Height)); double v = min; for (int i = 0; i < intervalCount + 1; i++) @@ -384,48 +391,48 @@ protected void DrawValueAxis(Report rpt, Drawing.Graphics g, double min, double } else if (s != null) { - Drawing.Size size = s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); + Drawing.Size size = await s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); Drawing.Rectangle vRect = new Drawing.Rectangle(rect.Left + tSize.Width, rect.Top + rect.Height - h - (size.Height / 2), rect.Width - tSize.Width, size.Height); - s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); + await s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); } else { - Drawing.Size size = Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); + Drawing.Size size = await Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); Drawing.Rectangle vRect = new Drawing.Rectangle(rect.Left + tSize.Width, rect.Top + rect.Height - h - (size.Height / 2), rect.Width - tSize.Width, size.Height); Style.DrawStringDefaults(g, v, vRect); } - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top + rect.Height - h), new Drawing.Point(plotRight, rect.Top + rect.Height - h)); - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top + rect.Height - h)); + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top + rect.Height - h), new Drawing.Point(plotRight, rect.Top + rect.Height - h)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top + rect.Height - h)); v += incr; } // Draw the end points of the major grid lines - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top), new Drawing.Point(plotLeft, rect.Bottom)); - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top)); - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotRight, rect.Top), new Drawing.Point(plotRight, rect.Bottom)); - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotRight, rect.Bottom)); + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top), new Drawing.Point(plotLeft, rect.Bottom)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top)); + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotRight, rect.Top), new Drawing.Point(plotRight, rect.Bottom)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotRight, rect.Bottom)); return; } - protected void DrawValueAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) + protected async Task DrawValueAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) { if (gl == null || !gl.ShowGridLines) return; if (gl.Style != null) - gl.Style.DrawStyleLine(rpt, g, null, s, e); + await gl.Style.DrawStyleLine(rpt, g, null, s, e); else g.DrawLine(Drawing.Pens.Black, s, e); return; } - protected void DrawValueAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, ChartGridLines gl, Drawing.Point p) + protected async Task DrawValueAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, ChartGridLines gl, Drawing.Point p) { if (tickType == AxisTickMarksEnum.None) return; @@ -451,14 +458,14 @@ protected void DrawValueAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, Ax Style style = gl.Style; if (style != null) - style.DrawStyleLine(rpt, g, null, s, e); + await style.DrawStyleLine(rpt, g, null, s, e); else g.DrawLine(Drawing.Pens.Black, s, e); return; } -///////////////////////// - protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, double min, double max, Drawing.Rectangle rect, int plotTop, int plotBottom) + ///////////////////////// + protected async Task DrawCategoryAxis(Report rpt, Drawing.Graphics g, double min, double max, Drawing.Rectangle rect, int plotTop, int plotBottom) { if (this.ChartDefn.CategoryAxis == null) return; @@ -478,7 +485,7 @@ protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, double min, doub int intervalCount; double incr; - SetIncrementAndInterval(rpt, a, min, max, out incr, out intervalCount); // Calculate the interval count + (incr, intervalCount)= await SetIncrementAndInterval(rpt, a, min, max); // Calculate the interval count int maxValueHeight = 0; double v = min; @@ -494,14 +501,14 @@ protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, double min, doub } else if (s != null) { - size = s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); + size = await s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); Drawing.Rectangle vRect = new Drawing.Rectangle(rect.Left + x - (size.Width / 2), rect.Top + tickSize, size.Width, size.Height); - s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); + await s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); } else { - size = Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); + size = await Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); Drawing.Rectangle vRect = new Drawing.Rectangle(rect.Left + x - (size.Width / 2), rect.Top + tickSize, size.Width, size.Height); Style.DrawStringDefaults(g, v, vRect); @@ -509,39 +516,39 @@ protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, double min, doub if (size.Height > maxValueHeight) // Need to keep track of the maximum height maxValueHeight = size.Height; // this is probably overkill since it should always be the same?? - DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Left + x, plotTop), new Drawing.Point(rect.Left + x, plotBottom)); - DrawCategoryAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Left + x, plotBottom)); + await DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Left + x, plotTop), new Drawing.Point(rect.Left + x, plotBottom)); + await DrawCategoryAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Left + x, plotBottom)); v += incr; } // Draw the end points of the major grid lines - DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Left, plotTop), new Drawing.Point(rect.Left, plotBottom)); - DrawCategoryAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Left, plotBottom)); - DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Right, plotTop), new Drawing.Point(rect.Right, plotBottom)); - DrawCategoryAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Right, plotBottom)); + await DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Left, plotTop), new Drawing.Point(rect.Left, plotBottom)); + await DrawCategoryAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Left, plotBottom)); + await DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(rect.Right, plotTop), new Drawing.Point(rect.Right, plotBottom)); + await DrawCategoryAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(rect.Right, plotBottom)); - Drawing.Size tSize = DrawTitleMeasure(rpt, g, a.Title); - DrawTitle(rpt, g, a.Title, + Drawing.Size tSize = await DrawTitleMeasure(rpt, g, a.Title); + await DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Top + maxValueHeight + tickSize, rect.Width, tSize.Height)); return; } - protected void DrawCategoryAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) + protected async Task DrawCategoryAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) { if (gl == null || !gl.ShowGridLines) return; if (gl.Style != null) - gl.Style.DrawStyleLine(rpt, g, null, s, e); + await gl.Style.DrawStyleLine(rpt, g, null, s, e); else g.DrawLine(Drawing.Pens.Black, s, e); return; } - protected void DrawCategoryAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, ChartGridLines gl, Drawing.Point p) + protected async Task DrawCategoryAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, ChartGridLines gl, Drawing.Point p) { if (tickType == AxisTickMarksEnum.None) return; @@ -567,7 +574,7 @@ protected void DrawCategoryAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, Style style = gl.Style; if (style != null) - style.DrawStyleLine(rpt, g, null, s, e); + await style.DrawStyleLine(rpt, g, null, s, e); else g.DrawLine(Drawing.Pens.Black, s, e); @@ -576,7 +583,7 @@ protected void DrawCategoryAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, // Calculate the size of the value axis; width is max value width + title width // height is max value height - protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g, double min, double max) + protected async Task CategoryAxisSize(Report rpt, Drawing.Graphics g, double min, double max) { Drawing.Size size = Drawing.Size.Empty; if (ChartDefn.CategoryAxis == null) @@ -593,20 +600,20 @@ protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g, double m } else if (a.Style != null) { - minSize = a.Style.MeasureString(rpt, g, min, TypeCode.Double, null, int.MaxValue); - maxSize = a.Style.MeasureString(rpt, g, max, TypeCode.Double, null, int.MaxValue); + minSize = await a.Style.MeasureString(rpt, g, min, TypeCode.Double, null, int.MaxValue); + maxSize = await a.Style.MeasureString(rpt, g, max, TypeCode.Double, null, int.MaxValue); } else { - minSize = Style.MeasureStringDefaults(rpt, g, min, TypeCode.Double, null, int.MaxValue); - maxSize = Style.MeasureStringDefaults(rpt, g, max, TypeCode.Double, null, int.MaxValue); + minSize = await Style.MeasureStringDefaults(rpt, g, min, TypeCode.Double, null, int.MaxValue); + maxSize = await Style.MeasureStringDefaults(rpt, g, max, TypeCode.Double, null, int.MaxValue); } // Choose the largest size.Width = Math.Max(minSize.Width, maxSize.Width); size.Height = Math.Max(minSize.Height, maxSize.Height); // Now we need to add in the height of the title (if any) - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, a.Title); + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, a.Title); size.Height += titleSize.Height; if (a.MajorTickMarks == AxisTickMarksEnum.Cross || @@ -618,5 +625,5 @@ protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g, double m return size; } - } + } } diff --git a/RdlEngine/Definition/ChartColumn.cs b/RdlEngine/Definition/ChartColumn.cs index d3d11d05..2c4f64a4 100644 --- a/RdlEngine/Definition/ChartColumn.cs +++ b/RdlEngine/Definition/ChartColumn.cs @@ -35,41 +35,42 @@ the website www.fyiReporting.com. //using System.Windows.Forms;JD 20080514 - Why? using System.Reflection.Emit; using System.Runtime.InteropServices; +using System.Threading.Tasks; namespace fyiReporting.RDL { - /// - /// Column chart definition and processing - /// - internal class ChartColumn: ChartBase - { - int _GapSize=0; // TODO: hard code for now - 06122007AJM Removed gap so that large category ranges display better - - internal ChartColumn(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX,Expression _ToolTipYFormat, Expression _ToolTipXFormat) - : base(r, row, c, m, showTooltips,showTooltipsX,_ToolTipYFormat,_ToolTipXFormat) - { - } - - override internal void Draw(Report rpt) - { - CreateSizedBitmap(); + /// + /// Column chart definition and processing + /// + internal class ChartColumn : ChartBase + { + int _GapSize = 0; // TODO: hard code for now - 06122007AJM Removed gap so that large category ranges display better + + internal ChartColumn(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX, Expression _ToolTipYFormat, Expression _ToolTipXFormat) + : base(r, row, c, m, showTooltips, showTooltipsX, _ToolTipYFormat, _ToolTipXFormat) + { + } + + override internal async Task Draw(Report rpt) + { + CreateSizedBitmap(); #if !DRAWINGCOMPAT if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - using (Drawing.Graphics g1 = Drawing.Graphics.FromImage(_bm)) - { - _aStream = new System.IO.MemoryStream(); - IntPtr HDC = g1.GetHdc(); - //_mf = new System.Drawing.Imaging.Metafile(_aStream, HDC); - _mf = new Drawing.Imaging.Metafile(_aStream, HDC, - new Drawing.RectangleF(0, 0, _bm.Width, _bm.Height), Drawing.Imaging.MetafileFrameUnit.Pixel); - g1.ReleaseHdc(HDC); - } - } - - using(Drawing.Graphics g = Drawing.Graphics.FromImage(_mf != null ? _mf : _bm)) + { + using (Drawing.Graphics g1 = Drawing.Graphics.FromImage(_bm)) + { + _aStream = new System.IO.MemoryStream(); + IntPtr HDC = g1.GetHdc(); + //_mf = new System.Drawing.Imaging.Metafile(_aStream, HDC); + _mf = new Drawing.Imaging.Metafile(_aStream, HDC, + new Drawing.RectangleF(0, 0, _bm.Width, _bm.Height), Drawing.Imaging.MetafileFrameUnit.Pixel); + g1.ReleaseHdc(HDC); + } + } + + using (Drawing.Graphics g = Drawing.Graphics.FromImage(_mf != null ? _mf : _bm)) #else using (Drawing.Graphics g = Drawing.Graphics.FromImage(_bm)) #endif @@ -80,122 +81,122 @@ override internal void Draw(Report rpt) g.PixelOffsetMode = Drawing.Drawing2D.PixelOffsetMode.None; g.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality; - // Adjust the top margin to depend on the title height - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, ChartDefn.Title); - Layout.TopMargin = titleSize.Height; + // Adjust the top margin to depend on the title height + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, ChartDefn.Title); + Layout.TopMargin = titleSize.Height; + + double max = 0, min = 0; // Get the max and min values + (max, min) = await GetValueMaxMin(rpt, max, min, 0, 1); - double max=0,min=0; // Get the max and min values - GetValueMaxMin(rpt, ref max, ref min,0, 1); + await DrawChartStyle(rpt, g); - DrawChartStyle(rpt, g); - - // Draw title; routine determines if necessary - DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, _bm.Width, Layout.TopMargin)); + // Draw title; routine determines if necessary + await DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, _bm.Width, Layout.TopMargin)); - // Adjust the left margin to depend on the Value Axis - Drawing.Size vaSize = ValueAxisSize(rpt, g, min, max); - Layout.LeftMargin = vaSize.Width; + // Adjust the left margin to depend on the Value Axis + Drawing.Size vaSize = await ValueAxisSize(rpt, g, min, max); + Layout.LeftMargin = vaSize.Width; // Adjust the right margin to depend on the Value Axis bool Show2ndY = ShowRightYAxis(rpt); - Drawing.Size vaSize2= vaSize; + Drawing.Size vaSize2 = vaSize; if (Show2ndY) { double rmax = 0, rmin = 0; - GetMaxMinDataValue(rpt, out rmax, out rmin, 0, 2); - vaSize2 = ValueAxisSize(rpt, g, rmin, rmax); + (rmax, rmin) = await GetMaxMinDataValue(rpt, 0, 2); + vaSize2 = await ValueAxisSize(rpt, g, rmin, rmax); Layout.RightMargin = vaSize2.Width; } - // Draw legend - Drawing.Rectangle lRect = DrawLegend(rpt, g, false, true); + // Draw legend + Drawing.Rectangle lRect = await DrawLegend(rpt, g, false, true); - // Adjust the bottom margin to depend on the Category Axis - Drawing.Size caSize = CategoryAxisSize(rpt, g); - Layout.BottomMargin = caSize.Height; + // Adjust the bottom margin to depend on the Category Axis + Drawing.Size caSize = await CategoryAxisSize(rpt, g); + Layout.BottomMargin = caSize.Height; - AdjustMargins(lRect,rpt, g); // Adjust margins based on legend. + AdjustMargins(lRect, rpt, g); // Adjust margins based on legend. - // Draw Plot area - DrawPlotAreaStyle(rpt, g, lRect); + // Draw Plot area + await DrawPlotAreaStyle(rpt, g, lRect); int intervalCount = 0; //GJL - Used to get the interval count out of DrawValueAxis so that we don't recalculate it again. - double incr = 0.0; //GJL - As above - // Draw Value Axis //GJL now as by ref params to return the values to the above variables - if (vaSize.Width > 0) // If we made room for the axis - we need to draw it - DrawValueAxis(rpt, g, min, max, - new Drawing.Rectangle(Layout.LeftMargin - vaSize.Width, Layout.TopMargin, vaSize.Width, _bm.Height - Layout.TopMargin - Layout.BottomMargin), Layout.LeftMargin, Layout.Width - Layout.RightMargin,out incr,out intervalCount); - - + double incr = 0.0; //GJL - As above + // Draw Value Axis //GJL now as by ref params to return the values to the above variables + if (vaSize.Width > 0) // If we made room for the axis - we need to draw it + (incr, intervalCount) = await DrawValueAxis(rpt, g, min, max, + new Drawing.Rectangle(Layout.LeftMargin - vaSize.Width, Layout.TopMargin, vaSize.Width, _bm.Height - Layout.TopMargin - Layout.BottomMargin), Layout.LeftMargin, Layout.Width - Layout.RightMargin); + + //******************************************************************************************************************************************** //Draw the 2nd value axis - obviously we will only want to do this if we choose a second axis double ScaleFactor = 1.0; //Secong value axis if (Show2ndY) - Draw2ndValueAxis(rpt, g, min, max, new Drawing.Rectangle(Layout.LeftMargin + Layout.PlotArea.Width, Layout.TopMargin, vaSize2.Width, _bm.Height - Layout.TopMargin - Layout.BottomMargin), Layout.LeftMargin, Layout.Width - Layout.RightMargin, incr, intervalCount, ref ScaleFactor); - - // Draw Category Axis - if (caSize.Height > 0) + ScaleFactor = await Draw2ndValueAxis(rpt, g, min, max, new Drawing.Rectangle(Layout.LeftMargin + Layout.PlotArea.Width, Layout.TopMargin, vaSize2.Width, _bm.Height - Layout.TopMargin - Layout.BottomMargin), Layout.LeftMargin, Layout.Width - Layout.RightMargin, incr, intervalCount, ScaleFactor); + + // Draw Category Axis + if (caSize.Height > 0) // 090508ajm passing chart bounds in - DrawCategoryAxis(rpt, g, + await DrawCategoryAxis(rpt, g, new Drawing.Rectangle(Layout.LeftMargin, _bm.Height - Layout.BottomMargin, Layout.PlotArea.Width, caSize.Height), Layout.TopMargin, caSize.Width); - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked) - DrawPlotAreaStacked(rpt, g, max, min); - else if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) - DrawPlotAreaPercentStacked(rpt, g); - else - DrawPlotAreaPlain(rpt, g, max, min,ScaleFactor); - - DrawLegend(rpt, g, false, false); - - } - } - - void DrawPlotAreaPercentStacked(Report rpt, Drawing.Graphics g) - { - int barsNeeded = CategoryCount; - int gapsNeeded = CategoryCount * 2; - - // Draw Plot area data - double max = 1; - - int widthBar = (int) ((Layout.PlotArea.Width - (gapsNeeded*_GapSize)) / barsNeeded); - int maxBarHeight = (int) (Layout.PlotArea.Height); - - // Loop thru calculating all the data points - for (int iRow = 1; iRow <= CategoryCount; iRow++) - { - int barLoc=(int) (Layout.PlotArea.Left + ((iRow-1) * ((double) (Layout.PlotArea.Width) / CategoryCount))); - barLoc += _GapSize; // space before series - - double sum=0; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - double t = GetDataValue(rpt, iRow, iCol); - if (t.CompareTo(double.NaN) == 0) - t = 0; - sum += t; - } - double v=0; - Drawing.Point saveP=Drawing.Point.Empty; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - double t = GetDataValue(rpt, iRow, iCol); - if (t.CompareTo(double.NaN)==0) - t = 0; - v += t; - - int h = (int) ((Math.Min(v/sum,max) / max) * maxBarHeight); - Drawing.Point p = new Drawing.Point(barLoc, Layout.PlotArea.Top + (maxBarHeight - h)); - - Drawing.Rectangle rect; - if (saveP == Drawing.Point.Empty) - rect = new Drawing.Rectangle(p, new Drawing.Size(widthBar,h)); - else - rect = new Drawing.Rectangle(p, new Drawing.Size(widthBar, saveP.Y - p.Y)); - DrawColumnBar(rpt, g, GetSeriesBrush(rpt, iRow, iCol), rect, iRow, iCol); + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked) + await DrawPlotAreaStacked(rpt, g, max, min); + else if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) + await DrawPlotAreaPercentStacked(rpt, g); + else + await DrawPlotAreaPlain(rpt, g, max, min, ScaleFactor); + + await DrawLegend(rpt, g, false, false); + + } + } + + async Task DrawPlotAreaPercentStacked(Report rpt, Drawing.Graphics g) + { + int barsNeeded = CategoryCount; + int gapsNeeded = CategoryCount * 2; + + // Draw Plot area data + double max = 1; + + int widthBar = (int)((Layout.PlotArea.Width - (gapsNeeded * _GapSize)) / barsNeeded); + int maxBarHeight = (int)(Layout.PlotArea.Height); + + // Loop thru calculating all the data points + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + int barLoc = (int)(Layout.PlotArea.Left + ((iRow - 1) * ((double)(Layout.PlotArea.Width) / CategoryCount))); + barLoc += _GapSize; // space before series + + double sum = 0; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + double t = await GetDataValue(rpt, iRow, iCol); + if (t.CompareTo(double.NaN) == 0) + t = 0; + sum += t; + } + double v = 0; + Drawing.Point saveP = Drawing.Point.Empty; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + double t = await GetDataValue(rpt, iRow, iCol); + if (t.CompareTo(double.NaN) == 0) + t = 0; + v += t; + + int h = (int)((Math.Min(v / sum, max) / max) * maxBarHeight); + Drawing.Point p = new Drawing.Point(barLoc, Layout.PlotArea.Top + (maxBarHeight - h)); + + Drawing.Rectangle rect; + if (saveP == Drawing.Point.Empty) + rect = new Drawing.Rectangle(p, new Drawing.Size(widthBar, h)); + else + rect = new Drawing.Rectangle(p, new Drawing.Size(widthBar, saveP.Y - p.Y)); + await DrawColumnBar(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), rect, iRow, iCol); //Add a metafilecomment to use as a tooltip GJL 26092008 //if (_showToolTips) @@ -206,26 +207,26 @@ void DrawPlotAreaPercentStacked(Report rpt, Drawing.Graphics g) if (_showToolTips) { - string display = ""; + string display = ""; if (display.Length > 0) display += " , "; display += t.ToString(_tooltipYFormat); - + String val = "ToolTip:" + display + "|X:" + (int)rect.X + "|Y:" + (int)rect.Y + "|W:" + rect.Width + "|H:" + rect.Height; g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - saveP = p; - } - } + saveP = p; + } + } - return; - } + return; + } /* This method has been modified to allow for a Line plot type and to draw the chart correctly * with selected plot type. * 06122007AJM */ - void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, double ScaleFactor) - { + async Task DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, double ScaleFactor) + { /* Need to adjust bar count to allow for Line plot types * 06122007AJM */ int ColumnCount = 0; @@ -237,13 +238,13 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d } } if (ColumnCount == 0) { ColumnCount = 1; } //Handle no bars (All lines) - int barsNeeded = ColumnCount * CategoryCount; - - int gapsNeeded = CategoryCount * 2; + int barsNeeded = ColumnCount * CategoryCount; + + int gapsNeeded = CategoryCount * 2; - // Draw Plot area data - int widthBar = (int) ((Layout.PlotArea.Width - (gapsNeeded*_GapSize)) / barsNeeded); - int maxBarHeight = (int) (Layout.PlotArea.Height); + // Draw Plot area data + int widthBar = (int)((Layout.PlotArea.Width - (gapsNeeded * _GapSize)) / barsNeeded); + int maxBarHeight = (int)(Layout.PlotArea.Height); /* The following list has been added to keep track of the * previous point for drawing a line intead of a column * when the plottype is Line @@ -251,13 +252,13 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d bool DrawPoint; SortedList LastPoints = new SortedList(); int lineLoc; - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - int barLoc=(int) (Layout.PlotArea.Left + ((iRow-1) * ((double) (Layout.PlotArea.Width) / CategoryCount))); + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + int barLoc = (int)(Layout.PlotArea.Left + ((iRow - 1) * ((double)(Layout.PlotArea.Width) / CategoryCount))); - barLoc += _GapSize; // space before series + barLoc += _GapSize; // space before series lineLoc = barLoc + (widthBar * ColumnCount / 2); - for (int z = 0; z < 2; z++) + for (int z = 0; z < 2; z++) { for (int iCol = 1; iCol <= SeriesCount; iCol++) { @@ -268,7 +269,7 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d { if (z == 0) { - double v = this.GetDataValue(rpt, iRow, iCol); + double v = await this.GetDataValue(rpt, iRow, iCol); double tooltipVal = v; if (GetYAxis(rpt, iCol, iRow).ToUpper() != "LEFT") { @@ -280,7 +281,7 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d v = min; int h = (int)(((Math.Min(v, max) - min) / (max - min)) * maxBarHeight); - DrawColumnBar(rpt, g, GetSeriesBrush(rpt, iRow, iCol), + await DrawColumnBar(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), new Drawing.Rectangle(barLoc, Layout.PlotArea.Top + (maxBarHeight - h), widthBar, h), iRow, iCol); //Add a metafilecomment to use as a tooltip GJL 26092008 @@ -290,7 +291,7 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - + barLoc += widthBar; } @@ -299,7 +300,7 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d { if (z == 1) { - double v = this.GetDataValue(rpt, iRow, iCol); + double v = await this.GetDataValue(rpt, iRow, iCol); double tooltipVal = v; if (GetYAxis(rpt, iCol, iRow).ToUpper() != "LEFT") { @@ -312,10 +313,10 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d if (v.CompareTo(double.NaN) == 0) { //don't draw null - DrawPoint = false; + DrawPoint = false; //insert empty point - LastPoints[iCol] = null; - } + LastPoints[iCol] = null; + } if (DrawPoint) { int h = (int)(((Math.Min(v, max) - min) / (max - min)) * maxBarHeight); @@ -326,35 +327,41 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d if (LastPoints[iCol - 1] == null) LastPoints[iCol - 1] = p; bool DrawMarker = getNoMarkerVal(rpt, iCol, 1) == false; - DrawDataPoint(rpt, g, new Drawing.Point(p.X, p.Y - 14), iRow, iCol); // todo: 14 is arbitrary - if (DrawMarker) { DrawLegendLineMarker(g, GetSeriesBrush(rpt, iRow, iCol), new Drawing.Pen(GetSeriesBrush(rpt, iRow, iCol)), SeriesMarker[iCol - 1], p.X - 5, p.Y - 5, 10);} - + await DrawDataPoint(rpt, g, new Drawing.Point(p.X, p.Y - 14), iRow, iCol); // todo: 14 is arbitrary + if (DrawMarker) { DrawLegendLineMarker(g, await GetSeriesBrush(rpt, iRow, iCol), new Drawing.Pen(await GetSeriesBrush(rpt, iRow, iCol)), SeriesMarker[iCol - 1], p.X - 5, p.Y - 5, 10); } + - if (LastPoints.ContainsKey(iCol) ) + if (LastPoints.ContainsKey(iCol)) { - Drawing.Point[] Points = new Drawing.Point[2]; + Drawing.Point[] Points = new Drawing.Point[2]; Points[0] = p; Drawing.Point pt = (Drawing.Point)LastPoints[iCol]; Points[1] = new Drawing.Point(pt.X - 1, pt.Y); // 05052008AJM - Allowing for breaking lines in chart - if (Points[1] != null) { + if (Points[1] != null) + { String LineSize = getLineSize(rpt, iCol, 1); int intLineSize = 1; switch (LineSize) { - case "Small": intLineSize = 1; + case "Small": + intLineSize = 1; break; - case "Regular": intLineSize = 2; + case "Regular": + intLineSize = 2; break; - case "Large": intLineSize = 3; + case "Large": + intLineSize = 3; break; - case "Extra Large": intLineSize = 4; + case "Extra Large": + intLineSize = 4; break; - case "Super Size": intLineSize = 5; + case "Super Size": + intLineSize = 5; break; } - DrawLineBetweenPoints(g, rpt, GetSeriesBrush(rpt, iRow, iCol), Points,intLineSize); + await DrawLineBetweenPoints(g, rpt, await GetSeriesBrush(rpt, iRow, iCol), Points, intLineSize); } } @@ -365,27 +372,27 @@ void DrawPlotAreaPlain(Report rpt, Drawing.Graphics g, double max, double min, d g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - + LastPoints[iCol] = p; } } } } - } - } - } + } + } + } internal void DrawLegendLineMarker(Drawing.Graphics g, Drawing.Brush b, Drawing.Pen p, ChartMarkerEnum marker, int x, int y, int mSize) { - if (b.GetType() == typeof(Drawing.Drawing2D.HatchBrush)) - { - Drawing.Drawing2D.HatchBrush hb = ( Drawing.Drawing2D.HatchBrush) b; + if (b.GetType() == typeof(Drawing.Drawing2D.HatchBrush)) + { + Drawing.Drawing2D.HatchBrush hb = (Drawing.Drawing2D.HatchBrush)b; b = new Drawing.SolidBrush(hb.ForegroundColor); - } + } - Drawing.Pen p2; - Drawing.PointF[] points; + Drawing.Pen p2; + Drawing.PointF[] points; switch (marker) { case ChartMarkerEnum.Bubble: @@ -395,8 +402,8 @@ internal void DrawLegendLineMarker(Drawing.Graphics g, Drawing.Brush b, Drawing. case ChartMarkerEnum.Square: g.FillRectangle(b, x, y, mSize, mSize); break; - case ChartMarkerEnum.Plus: - + case ChartMarkerEnum.Plus: + p2 = new Drawing.Pen(b, 2.0f); g.DrawLine(p2, new Drawing.Point(x + ((mSize + 1) / 2), y), new Drawing.Point(x + ((mSize + 1) / 2), y + mSize)); //g.DrawLine(p2, new Point(x + (mSize + 1) / 2, y + (mSize + 1) / 2), new Point(x + mSize, y + (mSize + 1) / 2)); @@ -430,13 +437,13 @@ internal void DrawLegendLineMarker(Drawing.Graphics g, Drawing.Brush b, Drawing. * will work, the only issue being that if the line drawing is changed then * this function will need to be updated as well * 05122007 AJM */ - void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points) + async Task DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points) { - DrawLineBetweenPoints(g, rpt, brush, points, 2); + await DrawLineBetweenPoints(g, rpt, brush, points, 2); } - void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points,int intLineSize) + async Task DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points, int intLineSize) { if (points.Length <= 1) // Need at least 2 points return; @@ -454,7 +461,7 @@ void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, p = new Drawing.Pen(brush, intLineSize); } - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Smooth && points.Length > 2) + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Smooth && points.Length > 2) g.DrawCurve(p, points, 0.5F); else g.DrawLines(p, points); @@ -467,38 +474,38 @@ void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, return; } - void DrawPlotAreaStacked(Report rpt, Drawing.Graphics g, double max, double min) - { - int barsNeeded = CategoryCount; - int gapsNeeded = CategoryCount * 2; - - int widthBar = (int) ((Layout.PlotArea.Width - (gapsNeeded*_GapSize)) / barsNeeded); - int maxBarHeight = (int) (Layout.PlotArea.Height); - - // Loop thru calculating all the data points - for (int iRow = 1; iRow <= CategoryCount; iRow++) - { - int barLoc=(int) (Layout.PlotArea.Left + ((iRow-1) * ((double) (Layout.PlotArea.Width) / CategoryCount))); - barLoc += _GapSize; // space before series - - double v=0; - Drawing.Point saveP=Drawing.Point.Empty; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - double t = GetDataValue(rpt, iRow, iCol); - if (t.CompareTo(double.NaN) == 0) - t = 0; - v += t; - - int h = (int) (((Math.Min(v,max)-min) / (max-min)) * maxBarHeight); - Drawing.Point p = new Drawing.Point(barLoc, Layout.PlotArea.Top + (maxBarHeight - h)); - - Drawing.Rectangle rect; - if (saveP == Drawing.Point.Empty) - rect = new Drawing.Rectangle(p, new Drawing.Size(widthBar,h)); - else - rect = new Drawing.Rectangle(p, new Drawing.Size(widthBar, saveP.Y - p.Y)); - DrawColumnBar(rpt, g, GetSeriesBrush(rpt, iRow, iCol), rect, iRow, iCol); + async Task DrawPlotAreaStacked(Report rpt, Drawing.Graphics g, double max, double min) + { + int barsNeeded = CategoryCount; + int gapsNeeded = CategoryCount * 2; + + int widthBar = (int)((Layout.PlotArea.Width - (gapsNeeded * _GapSize)) / barsNeeded); + int maxBarHeight = (int)(Layout.PlotArea.Height); + + // Loop thru calculating all the data points + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + int barLoc = (int)(Layout.PlotArea.Left + ((iRow - 1) * ((double)(Layout.PlotArea.Width) / CategoryCount))); + barLoc += _GapSize; // space before series + + double v = 0; + Drawing.Point saveP = Drawing.Point.Empty; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + double t = await GetDataValue(rpt, iRow, iCol); + if (t.CompareTo(double.NaN) == 0) + t = 0; + v += t; + + int h = (int)(((Math.Min(v, max) - min) / (max - min)) * maxBarHeight); + Drawing.Point p = new Drawing.Point(barLoc, Layout.PlotArea.Top + (maxBarHeight - h)); + + Drawing.Rectangle rect; + if (saveP == Drawing.Point.Empty) + rect = new Drawing.Rectangle(p, new Drawing.Size(widthBar, h)); + else + rect = new Drawing.Rectangle(p, new Drawing.Size(widthBar, saveP.Y - p.Y)); + await DrawColumnBar(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), rect, iRow, iCol); //Add a metafilecomment to use as a tooltip GJL 26092008 if (_showToolTips) @@ -507,69 +514,69 @@ void DrawPlotAreaStacked(Report rpt, Drawing.Graphics g, double max, double min) g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - saveP = p; - } - } + saveP = p; + } + } - return; - } + return; + } - // Calculate the size of the category axis - protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g) - { - _LastCategoryWidth = 0; + // Calculate the size of the category axis + protected async Task CategoryAxisSize(Report rpt, Drawing.Graphics g) + { + _LastCategoryWidth = 0; - Drawing.Size size=Drawing.Size.Empty; - if (this.ChartDefn.CategoryAxis == null) - return size; - Axis a = this.ChartDefn.CategoryAxis.Axis; - if (a == null) - return size; - Style s = a.Style; + Drawing.Size size = Drawing.Size.Empty; + if (this.ChartDefn.CategoryAxis == null) + return size; + Axis a = this.ChartDefn.CategoryAxis.Axis; + if (a == null) + return size; + Style s = a.Style; - // Measure the title - size = DrawTitleMeasure(rpt, g, a.Title); + // Measure the title + size = await DrawTitleMeasure(rpt, g, a.Title); - if (!a.Visible) // don't need to calculate the height - return size; + if (!a.Visible) // don't need to calculate the height + return size; - // Calculate the tallest category name - TypeCode tc; - int maxHeight=0; + // Calculate the tallest category name + TypeCode tc; + int maxHeight = 0; int maxWidth = 0; - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - object v = this.GetCategoryValue(rpt, iRow, out tc); - Drawing.Size tSize; - if (s == null) - tSize = Style.MeasureStringDefaults(rpt, g, v, tc, null, int.MaxValue); - else - tSize =s.MeasureString(rpt, g, v, tc, null, int.MaxValue); - - if (tSize.Height > maxHeight) - maxHeight = tSize.Height; + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + object v = this.GetCategoryValue(rpt, iRow, out tc); + Drawing.Size tSize; + if (s == null) + tSize = await Style.MeasureStringDefaults(rpt, g, v, tc, null, int.MaxValue); + else + tSize = await s.MeasureString(rpt, g, v, tc, null, int.MaxValue); + + if (tSize.Height > maxHeight) + maxHeight = tSize.Height; if (tSize.Width > maxWidth) maxWidth = tSize.Width; - if (iRow == CategoryCount) - _LastCategoryWidth = tSize.Width; - } + if (iRow == CategoryCount) + _LastCategoryWidth = tSize.Width; + } size.Width = maxWidth; // set the widest entry - // Add on the tallest category name - size.Height += maxHeight; + // Add on the tallest category name + size.Height += maxHeight; - // Account for tick marks - int tickSize=0; - if (a.MajorTickMarks == AxisTickMarksEnum.Cross || - a.MajorTickMarks == AxisTickMarksEnum.Outside) - tickSize = this.AxisTickMarkMajorLen; - else if (a.MinorTickMarks == AxisTickMarksEnum.Cross || - a.MinorTickMarks == AxisTickMarksEnum.Outside) - tickSize = this.AxisTickMarkMinorLen; + // Account for tick marks + int tickSize = 0; + if (a.MajorTickMarks == AxisTickMarksEnum.Cross || + a.MajorTickMarks == AxisTickMarksEnum.Outside) + tickSize = this.AxisTickMarkMajorLen; + else if (a.MinorTickMarks == AxisTickMarksEnum.Cross || + a.MinorTickMarks == AxisTickMarksEnum.Outside) + tickSize = this.AxisTickMarkMinorLen; - size.Height += tickSize; + size.Height += tickSize; /* This swap is done so that the size will work correctly with rotated * (vertical) category names * 06122007AJM */ @@ -579,40 +586,41 @@ protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g) size.Height = size.Width; size.Width = tmp; } - return size; - } + return size; + } - // DrawCategoryAxis + // DrawCategoryAxis //09052008ajm added plottop variable to collect the top of the chart - protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangle rect, int plotTop, int maxWidth) - { - if (this.ChartDefn.CategoryAxis == null) - return; - Axis a = this.ChartDefn.CategoryAxis.Axis; - if (a == null) - return; - Style s = a.Style; - Drawing.Size tSize = DrawTitleMeasure(rpt, g, a.Title); - DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Bottom-tSize.Height, rect.Width, tSize.Height)); - - // Account for tick marks - int tickSize=0; - if (a.MajorTickMarks == AxisTickMarksEnum.Cross || - a.MajorTickMarks == AxisTickMarksEnum.Outside) - tickSize = this.AxisTickMarkMajorLen; - else if (a.MinorTickMarks == AxisTickMarksEnum.Cross || - a.MinorTickMarks == AxisTickMarksEnum.Outside) - tickSize = this.AxisTickMarkMinorLen; - - int drawWidth; - int catCount = ChartDefn.Type == ChartTypeEnum.Area? CategoryCount-1: CategoryCount; - drawWidth = rect.Width / catCount; + protected async Task DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangle rect, int plotTop, int maxWidth) + { + if (this.ChartDefn.CategoryAxis == null) + return; + Axis a = this.ChartDefn.CategoryAxis.Axis; + if (a == null) + return; + Style s = a.Style; + Drawing.Size tSize = await DrawTitleMeasure(rpt, g, a.Title); + await DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Bottom - tSize.Height, rect.Width, tSize.Height)); + + // Account for tick marks + int tickSize = 0; + if (a.MajorTickMarks == AxisTickMarksEnum.Cross || + a.MajorTickMarks == AxisTickMarksEnum.Outside) + tickSize = this.AxisTickMarkMajorLen; + else if (a.MinorTickMarks == AxisTickMarksEnum.Cross || + a.MinorTickMarks == AxisTickMarksEnum.Outside) + tickSize = this.AxisTickMarkMinorLen; + + int drawWidth; + int catCount = ChartDefn.Type == ChartTypeEnum.Area ? CategoryCount - 1 : CategoryCount; + drawWidth = rect.Width / catCount; bool mustSize = a.CanOmit && (drawWidth < maxWidth || ChartDefn.Type == ChartTypeEnum.Area); int MajorGrid = 0; // 15052008AJM Fixed for charts without a set major interval - if (a.MajorInterval != null) { + if (a.MajorInterval != null) + { // 09052008WRP get major interval value - MajorGrid = (int)a.MajorInterval.EvaluateDouble(rpt,this._row); + MajorGrid = (int)await a.MajorInterval.EvaluateDouble(rpt, this._row); } // 12052008WRP // setup month scale gridline plot - must check dealing with date data type @@ -621,14 +629,14 @@ protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangl DateTime TempDate = DateTime.Now;//working variable bool date = false; //used for confirming dealing with date data int PreviousLocation = rect.Left; //used to keep track of previous gridline location on x axis - set to x position of category axis at start - TypeCode tc; - object first = this.GetCategoryValue(rpt, 1, out tc); + TypeCode tc; + object first = this.GetCategoryValue(rpt, 1, out tc); if (first != null) { switch (tc) { case TypeCode.DateTime: - date = true; + date = true; break; default: break; @@ -640,55 +648,55 @@ protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangl OldDate = CurrentDate; TempDate = CurrentDate; } - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - object v = this.GetCategoryValue(rpt, iRow, out tc); + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + object v = this.GetCategoryValue(rpt, iRow, out tc); //make sure we are dealing with datetime type if (date) { CurrentDate = (DateTime)v; - + } - int drawLoc=(int) (rect.Left + ((iRow-1) * ((double) rect.Width / catCount))); - - // Draw the category text + int drawLoc = (int)(rect.Left + ((iRow - 1) * ((double)rect.Width / catCount))); + + // Draw the category text int skip = 0; - if (a.Visible && !a.Month) //18052008WRP only show category labels if not month scale - { - Drawing.Rectangle drawRect; - Drawing.Size size = Drawing.Size.Empty; + if (a.Visible && !a.Month) //18052008WRP only show category labels if not month scale + { + Drawing.Rectangle drawRect; + Drawing.Size size = Drawing.Size.Empty; if (mustSize) { // Area chart - value is centered under the tick mark if (s != null) { - size = s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); + size = await s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); } else { - size = Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); + size = await Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); } } - if (ChartDefn.Type == ChartTypeEnum.Area) - { // Area chart - value is centered under the tick mark - drawRect = - new Drawing.Rectangle(drawLoc - (size.Width/2), rect.Top+tickSize, size.Width, size.Height); - } - else // Column/Line charts are just centered in the region. - drawRect = new Drawing.Rectangle(drawLoc, rect.Top+tickSize, drawWidth, rect.Height-tSize.Height); + if (ChartDefn.Type == ChartTypeEnum.Area) + { // Area chart - value is centered under the tick mark + drawRect = + new Drawing.Rectangle(drawLoc - (size.Width / 2), rect.Top + tickSize, size.Width, size.Height); + } + else // Column/Line charts are just centered in the region. + drawRect = new Drawing.Rectangle(drawLoc, rect.Top + tickSize, drawWidth, rect.Height - tSize.Height); if (mustSize && drawRect.Width < size.Width) { - skip = (int) (size.Width / drawWidth); + skip = (int)(size.Width / drawWidth); drawRect.Width = size.Width; } - if (s == null) - Style.DrawStringDefaults(g, v, drawRect); - else - s.DrawString(rpt, g, v, tc, null, drawRect); - } + if (s == null) + Style.DrawStringDefaults(g, v, drawRect); + else + await s.DrawString(rpt, g, v, tc, null, drawRect); + } //09052008WRP Draw major gridlines and place category labels for months scale if (a.Month && date && a.Visible) @@ -697,185 +705,199 @@ protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangl if (CurrentDate.Month != OldDate.Month) { TempDate = CurrentDate; - DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(drawLoc, rect.Top), new Drawing.Point(drawLoc, plotTop)); //Don't overdraw the Y axis on the first gridline + await DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(drawLoc, rect.Top), new Drawing.Point(drawLoc, plotTop)); //Don't overdraw the Y axis on the first gridline CurrentDate = CurrentDate.AddMonths(OldDate.Month - CurrentDate.Month); // get previous category month value string MonthString = CurrentDate.ToString("MMMM"); - Drawing.Size lSize = DrawCategoryTitleMeasure(rpt, g, MonthString,s); + Drawing.Size lSize = await DrawCategoryTitleMeasure(rpt, g, MonthString, s); int catlabelLoc = (int)((drawLoc - PreviousLocation) / 2) + PreviousLocation - (lSize.Width / 2); - DrawCategoryLabel(rpt, g, MonthString, a.Style, new Drawing.Rectangle(catlabelLoc, rect.Top - (lSize.Height - 25), lSize.Width, lSize.Height)); + await DrawCategoryLabel(rpt, g, MonthString, a.Style, new Drawing.Rectangle(catlabelLoc, rect.Top - (lSize.Height - 25), lSize.Width, lSize.Height)); PreviousLocation = drawLoc; OldDate = TempDate; - + } } - if ((MajorGrid != 0) && ((iRow-1) % MajorGrid == 0) && !(a.Month)) + if ((MajorGrid != 0) && ((iRow - 1) % MajorGrid == 0) && !(a.Month)) //if (((iRow - 1) % ((int)a.MajorInterval.EvaluateDouble(rpt, this.ChartRow.RowNumber)) == 0) && !(a.Month)) { - DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(drawLoc, rect.Top), new Drawing.Point(drawLoc, plotTop)); + await DrawCategoryAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(drawLoc, rect.Top), new Drawing.Point(drawLoc, plotTop)); } - // Draw the Major Tick Marks (if necessary) - DrawCategoryAxisTick(g, true, a.MajorTickMarks, new Drawing.Point(drawLoc, rect.Top)); + // Draw the Major Tick Marks (if necessary) + DrawCategoryAxisTick(g, true, a.MajorTickMarks, new Drawing.Point(drawLoc, rect.Top)); iRow += skip; - }//exit from for loop - no more category data + }//exit from for loop - no more category data if (a.Month && date && a.Visible)// 16052008WRP draw last category label for months scale { string MonthString = OldDate.ToString("MMMM"); - Drawing.Size lSize = DrawCategoryTitleMeasure(rpt, g, MonthString,s); + Drawing.Size lSize = await DrawCategoryTitleMeasure(rpt, g, MonthString, s); int catlabelLoc = (int)((rect.Right - PreviousLocation) / 2) + PreviousLocation - (lSize.Width / 2); - DrawCategoryLabel(rpt, g, MonthString, a.Style, new Drawing.Rectangle(catlabelLoc, rect.Top - (lSize.Height - 25), lSize.Width, lSize.Height)); + await DrawCategoryLabel(rpt, g, MonthString, a.Style, new Drawing.Rectangle(catlabelLoc, rect.Top - (lSize.Height - 25), lSize.Width, lSize.Height)); + } + + + // Draw the end on (if necessary) + DrawCategoryAxisTick(g, true, a.MajorTickMarks, new Drawing.Point(rect.Right, rect.Top)); + + return; + } + + + + protected void DrawCategoryAxisTick(Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, Drawing.Point p) + { + int len = bMajor ? AxisTickMarkMajorLen : AxisTickMarkMinorLen; + switch (tickType) + { + case AxisTickMarksEnum.Outside: + g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y), new Drawing.Point(p.X, p.Y + len)); + break; + case AxisTickMarksEnum.Inside: + g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y), new Drawing.Point(p.X, p.Y - len)); + break; + case AxisTickMarksEnum.Cross: + g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y - len), new Drawing.Point(p.X, p.Y + len)); + break; + case AxisTickMarksEnum.None: + default: + break; } - - - // Draw the end on (if necessary) - DrawCategoryAxisTick(g, true, a.MajorTickMarks, new Drawing.Point(rect.Right, rect.Top)); - - return; - } - - - - protected void DrawCategoryAxisTick(Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, Drawing.Point p) - { - int len = bMajor? AxisTickMarkMajorLen: AxisTickMarkMinorLen; - switch (tickType) - { - case AxisTickMarksEnum.Outside: - g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y), new Drawing.Point(p.X, p.Y+len)); - break; - case AxisTickMarksEnum.Inside: - g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y), new Drawing.Point(p.X, p.Y-len)); - break; - case AxisTickMarksEnum.Cross: - g.DrawLine(Drawing.Pens.Black, new Drawing.Point(p.X, p.Y-len), new Drawing.Point(p.X, p.Y+len)); - break; - case AxisTickMarksEnum.None: - default: - break; - } - return; - } - - protected void DrawCategoryAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) + return; + } + + protected async Task DrawCategoryAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) { if (gl == null || !gl.ShowGridLines) return; if (gl.Style != null) - gl.Style.DrawStyleLine(rpt, g, null, s, e); + await gl.Style.DrawStyleLine(rpt, g, null, s, e); else g.DrawLine(Drawing.Pens.Black, s, e); return; } - void DrawColumnBar(Report rpt, Drawing.Graphics g, Drawing.Brush brush, Drawing.Rectangle rect, int iRow, int iCol) - { - if (rect.Height <= 0) - return; + async Task DrawColumnBar(Report rpt, Drawing.Graphics g, Drawing.Brush brush, Drawing.Rectangle rect, int iRow, int iCol) + { + if (rect.Height <= 0) + return; //we want to separate the bars with some whitespace.. GJL 080208 - rect = new Drawing.Rectangle(rect.Left + 2, rect.Top, rect.Width -3, rect.Height); - g.FillRectangle(brush, rect); + rect = new Drawing.Rectangle(rect.Left + 2, rect.Top, rect.Width - 3, rect.Height); + g.FillRectangle(brush, rect); g.DrawRectangle(Drawing.Pens.Black, rect); - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked || - (ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) - { - DrawDataPoint(rpt, g, rect, iRow, iCol); - } - else - { - Drawing.Point p; - p = new Drawing.Point(rect.Left, rect.Top - 14); // todo: 14 is arbitrary - DrawDataPoint(rpt, g, p, iRow, iCol); - } - - return; - } - - protected void DrawValueAxis(Report rpt, Drawing.Graphics g, double min, double max, - Drawing.Rectangle rect, int plotLeft, int plotRight, out double incr,out int intervalCount) - { - incr = 0; - intervalCount = 0; - if (this.ChartDefn.ValueAxis == null) - return; - Axis a = this.ChartDefn.ValueAxis.Axis; - if (a == null) - return; - Style s = a.Style; - - //int intervalCount; + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked || + (ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) + { + await DrawDataPoint(rpt, g, rect, iRow, iCol); + } + else + { + Drawing.Point p; + p = new Drawing.Point(rect.Left, rect.Top - 14); // todo: 14 is arbitrary + await DrawDataPoint(rpt, g, p, iRow, iCol); + } + + return; + } + + protected async Task<(double incr, int intervalCount)> DrawValueAxis(Report rpt, Drawing.Graphics g, double min, double max, + Drawing.Rectangle rect, int plotLeft, int plotRight) + { + double incr = 0; + int intervalCount = 0; + if (this.ChartDefn.ValueAxis == null) + return (incr, intervalCount); + Axis a = this.ChartDefn.ValueAxis.Axis; + if (a == null) + return (incr, intervalCount); + Style s = a.Style; + + //int intervalCount; //double incr; - SetIncrementAndInterval(rpt, a, min, max, out incr, out intervalCount); // Calculate the interval count - - Drawing.Size tSize = DrawTitleMeasure(rpt, g, a.Title); - DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Top, tSize.Width, rect.Height)); - - double v = min; - for (int i=0; i < intervalCount+1; i++) - { - int h = (int) (((Math.Min(v,max)-min) / (max-min)) * rect.Height); - if (h < 0) // this is really some form of error - { - v += incr; - continue; - } - - if (!a.Visible) - { - // nothing to do - } - else if (s != null) - { - Drawing.Size size = s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); - Drawing.Rectangle vRect = - new Drawing.Rectangle(rect.Left+tSize.Width, rect.Top + rect.Height - h - (size.Height/2), rect.Width-tSize.Width, size.Height); - s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); - } - else - { - Drawing.Size size = Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); - Drawing.Rectangle vRect = - new Drawing.Rectangle(rect.Left+tSize.Width, rect.Top + rect.Height - h - (size.Height/2), rect.Width-tSize.Width, size.Height); - Style.DrawStringDefaults(g, v, vRect); - } - - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top + rect.Height - h), new Drawing.Point(plotRight, rect.Top + rect.Height - h)); - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top + rect.Height - h)); - - v += incr; - } - - // Draw the end points of the major grid lines - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top), new Drawing.Point(plotLeft, rect.Bottom)); - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top)); - DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotRight, rect.Top), new Drawing.Point(plotRight, rect.Bottom)); - + (incr, intervalCount) = await SetIncrementAndInterval(rpt, a, min, max); // Calculate the interval count + + Drawing.Size tSize = await DrawTitleMeasure(rpt, g, a.Title); + await DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Top, tSize.Width, rect.Height)); + + double v = min; + for (int i = 0; i < intervalCount + 1; i++) + { + int h = (int)(((Math.Min(v, max) - min) / (max - min)) * rect.Height); + if (h < 0) // this is really some form of error + { + v += incr; + continue; + } + + if (!a.Visible) + { + // nothing to do + } + else if (s != null) + { + Drawing.Size size = await s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); + Drawing.Rectangle vRect = + new Drawing.Rectangle(rect.Left + tSize.Width, rect.Top + rect.Height - h - (size.Height / 2), rect.Width - tSize.Width, size.Height); + await s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); + } + else + { + Drawing.Size size = await Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); + Drawing.Rectangle vRect = + new Drawing.Rectangle(rect.Left + tSize.Width, rect.Top + rect.Height - h - (size.Height / 2), rect.Width - tSize.Width, size.Height); + Style.DrawStringDefaults(g, v, vRect); + } + + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top + rect.Height - h), new Drawing.Point(plotRight, rect.Top + rect.Height - h)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top + rect.Height - h)); + + v += incr; + } + + // Draw the end points of the major grid lines + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top), new Drawing.Point(plotLeft, rect.Bottom)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotLeft, rect.Top)); + await DrawValueAxisGrid(rpt, g, a.MajorGridLines, new Drawing.Point(plotRight, rect.Top), new Drawing.Point(plotRight, rect.Bottom)); + //12052008WRP this line not required adds tick at bottom end of right y axis. //DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Point(plotRight, rect.Bottom)); - return; - } + return (incr, intervalCount); + } //******************************************************************************************************************************* //Draws the second value axis - protected void Draw2ndValueAxis(Report rpt, Drawing.Graphics g, double min, double max, - Drawing.Rectangle rect, int plotLeft, int plotRight,double incr,int intervalCount,ref double ScaleFactor) - { + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// ScaleFactor + protected async Task Draw2ndValueAxis(Report rpt, Drawing.Graphics g, double min, double max, + Drawing.Rectangle rect, int plotLeft, int plotRight, double incr, int intervalCount, double ScaleFactor) + { if (this.ChartDefn.ValueAxis == null) - return; + return ScaleFactor; Axis a = this.ChartDefn.ValueAxis.Axis; if (a == null) - return; + return ScaleFactor; Style s = a.Style; double thisMin = 0; double thisMax = 0; - GetMaxMinDataValue(rpt, out thisMax, out thisMin, 0, 2); + (thisMax, thisMin) = await GetMaxMinDataValue(rpt, 0, 2); thisMin = 0; //Stop rescaling the min on autoscale @@ -932,7 +954,7 @@ protected void Draw2ndValueAxis(Report rpt, Drawing.Graphics g, double min, doub //{ // rIncr = thisMax / rInt; // log = Math.Floor(Math.Log10(Math.Abs(rIncr))); - + // logPow = Math.Pow(10, log) * Math.Sign(thisMax); // logDig = (int)(rIncr / logPow + .5); @@ -956,7 +978,7 @@ protected void Draw2ndValueAxis(Report rpt, Drawing.Graphics g, double min, doub //OK... thisMax needs to be rounded up to the next interval... //Scale based on thisMax and Max... - + //ScaleFactor = thisMax / (max - (max / intervalCount)) ; //if (thisMax < max) //{ @@ -966,7 +988,7 @@ protected void Draw2ndValueAxis(Report rpt, Drawing.Graphics g, double min, doub //double factor = System.Math.Pow(10, System.Math.Floor(System.Math.Log10(ScaleFactor))); - + //ScaleFactor = System.Math.Round(ScaleFactor / factor,1) * factor; // if( ScaleFactor < 1) // { @@ -997,12 +1019,12 @@ protected void Draw2ndValueAxis(Report rpt, Drawing.Graphics g, double min, doub // ScaleFactor = Math.Round(ScaleFactor, (int)System.Math.Floor(System.Math.Log10(factor))); //} - - Drawing.Size tSize = DrawTitleMeasure(rpt, g, a.Title2); - // rect.Width = (int)g.VisibleClipBounds.Width - rect.Left + 20; + Drawing.Size tSize = await DrawTitleMeasure(rpt, g, a.Title2); - DrawTitle(rpt, g, a.Title2, new Drawing.Rectangle((int)rect.Right - tSize.Width, rect.Top, tSize.Width, rect.Height)); + // rect.Width = (int)g.VisibleClipBounds.Width - rect.Left + 20; + + await DrawTitle(rpt, g, a.Title2, new Drawing.Rectangle((int)rect.Right - tSize.Width, rect.Top, tSize.Width, rect.Height)); double v = min; for (int i = 0; i < _gridIncrs + 1; i++) @@ -1019,116 +1041,116 @@ protected void Draw2ndValueAxis(Report rpt, Drawing.Graphics g, double min, doub } else if (s != null) { - Drawing.Size size = s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); + Drawing.Size size = await s.MeasureString(rpt, g, v, TypeCode.Double, null, int.MaxValue); Drawing.Rectangle vRect = new Drawing.Rectangle(rect.Left - (int)(tSize.Width * .5), rect.Top + rect.Height - h - (size.Height / 2), rect.Width - tSize.Width, size.Height); - s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); + await s.DrawString(rpt, g, v, TypeCode.Double, null, vRect); } else { - Drawing.Size size = Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); + Drawing.Size size = await Style.MeasureStringDefaults(rpt, g, v, TypeCode.Double, null, int.MaxValue); Drawing.Rectangle vRect = new Drawing.Rectangle(rect.Left - (int)(tSize.Width * .5), rect.Top + rect.Height - h - (size.Height / 2), rect.Width - (tSize.Width * 2), size.Height); Style.DrawStringDefaults(g, v, vRect); - } + } v += incr; - DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotRight - (AxisTickMarkMajorLen / 2), rect.Top + rect.Height - h)); + await DrawValueAxisTick(rpt, g, true, a.MajorTickMarks, a.MajorGridLines, new Drawing.Point(plotRight - (AxisTickMarkMajorLen / 2), rect.Top + rect.Height - h)); } - return; + return ScaleFactor; } //******************************************************************************************************************************* - protected void DrawValueAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) - { - if (gl == null || !gl.ShowGridLines) - return; - - if (gl.Style != null) - gl.Style.DrawStyleLine(rpt, g, null, s, e); - else - g.DrawLine(Drawing.Pens.Black, s, e); - - return; - } - - protected void DrawValueAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, ChartGridLines gl, Drawing.Point p) - { - if (tickType == AxisTickMarksEnum.None) - return; - - int len = bMajor? AxisTickMarkMajorLen: AxisTickMarkMinorLen; - Drawing.Point s, e; - switch (tickType) - { - case AxisTickMarksEnum.Inside: - s = new Drawing.Point(p.X, p.Y); - e = new Drawing.Point(p.X+len, p.Y); - break; - case AxisTickMarksEnum.Cross: - s = new Drawing.Point(p.X-len, p.Y); - e = new Drawing.Point(p.X+len, p.Y); - break; - case AxisTickMarksEnum.Outside: - default: - s = new Drawing.Point(p.X-len, p.Y); - e = new Drawing.Point(p.X, p.Y); - break; - } - Style style = gl.Style; - - if (style != null) - style.DrawStyleLine(rpt, g, null, s, e); - else - g.DrawLine(Drawing.Pens.Black, s, e); - - return; - } - - // Calculate the size of the value axis; width is max value width + title width - // height is max value height + protected async Task DrawValueAxisGrid(Report rpt, Drawing.Graphics g, ChartGridLines gl, Drawing.Point s, Drawing.Point e) + { + if (gl == null || !gl.ShowGridLines) + return; + + if (gl.Style != null) + await gl.Style.DrawStyleLine(rpt, g, null, s, e); + else + g.DrawLine(Drawing.Pens.Black, s, e); + + return; + } + + protected async Task DrawValueAxisTick(Report rpt, Drawing.Graphics g, bool bMajor, AxisTickMarksEnum tickType, ChartGridLines gl, Drawing.Point p) + { + if (tickType == AxisTickMarksEnum.None) + return; + + int len = bMajor ? AxisTickMarkMajorLen : AxisTickMarkMinorLen; + Drawing.Point s, e; + switch (tickType) + { + case AxisTickMarksEnum.Inside: + s = new Drawing.Point(p.X, p.Y); + e = new Drawing.Point(p.X + len, p.Y); + break; + case AxisTickMarksEnum.Cross: + s = new Drawing.Point(p.X - len, p.Y); + e = new Drawing.Point(p.X + len, p.Y); + break; + case AxisTickMarksEnum.Outside: + default: + s = new Drawing.Point(p.X - len, p.Y); + e = new Drawing.Point(p.X, p.Y); + break; + } + Style style = gl.Style; + + if (style != null) + await style.DrawStyleLine(rpt, g, null, s, e); + else + g.DrawLine(Drawing.Pens.Black, s, e); + + return; + } + + // Calculate the size of the value axis; width is max value width + title width + // height is max value height //WhichAxis.... 1 = Left, 2 = Right GJL 140208 - protected Drawing.Size ValueAxisSize(Report rpt, Drawing.Graphics g, double min, double max) - { - Drawing.Size size=Drawing.Size.Empty; - - if (ChartDefn.ValueAxis == null) - return size; - - Axis a = ChartDefn.ValueAxis.Axis; - - if (a == null) - return size; - - Drawing.Size minSize; - Drawing.Size maxSize; - if (!a.Visible) - { - minSize = maxSize = Drawing.Size.Empty; - } - else if (a.Style != null) - { - minSize = a.Style.MeasureString(rpt, g, min, TypeCode.Double, null, int.MaxValue); - maxSize = a.Style.MeasureString(rpt, g, max, TypeCode.Double, null, int.MaxValue); - } - else - { - minSize = Style.MeasureStringDefaults(rpt, g, min, TypeCode.Double, null, int.MaxValue); - maxSize = Style.MeasureStringDefaults(rpt, g, max, TypeCode.Double, null, int.MaxValue); - } - // Choose the largest - size.Width = Math.Max(minSize.Width, maxSize.Width); - size.Height = Math.Max(minSize.Height, maxSize.Height); - - // Now we need to add in the width of the title (if any) - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, a.Title); - size.Width += titleSize.Width; - - return size; - } - } + protected async Task ValueAxisSize(Report rpt, Drawing.Graphics g, double min, double max) + { + Drawing.Size size = Drawing.Size.Empty; + + if (ChartDefn.ValueAxis == null) + return size; + + Axis a = ChartDefn.ValueAxis.Axis; + + if (a == null) + return size; + + Drawing.Size minSize; + Drawing.Size maxSize; + if (!a.Visible) + { + minSize = maxSize = Drawing.Size.Empty; + } + else if (a.Style != null) + { + minSize = await a.Style.MeasureString(rpt, g, min, TypeCode.Double, null, int.MaxValue); + maxSize = await a.Style.MeasureString(rpt, g, max, TypeCode.Double, null, int.MaxValue); + } + else + { + minSize = await Style.MeasureStringDefaults(rpt, g, min, TypeCode.Double, null, int.MaxValue); + maxSize = await Style.MeasureStringDefaults(rpt, g, max, TypeCode.Double, null, int.MaxValue); + } + // Choose the largest + size.Width = Math.Max(minSize.Width, maxSize.Width); + size.Height = Math.Max(minSize.Height, maxSize.Height); + + // Now we need to add in the width of the title (if any) + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, a.Title); + size.Width += titleSize.Width; + + return size; + } + } } diff --git a/RdlEngine/Definition/ChartData.cs b/RdlEngine/Definition/ChartData.cs index 3065dfbb..52117920 100644 --- a/RdlEngine/Definition/ChartData.cs +++ b/RdlEngine/Definition/ChartData.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal ChartData(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (ChartSeries cs in _Items) { - cs.FinalPass(); + await cs.FinalPass(); } return; } diff --git a/RdlEngine/Definition/ChartExpression.cs b/RdlEngine/Definition/ChartExpression.cs index cfa39622..3d68a498 100644 --- a/RdlEngine/Definition/ChartExpression.cs +++ b/RdlEngine/Definition/ChartExpression.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -100,31 +101,31 @@ internal ChartExpression(ReportDefn r, ReportLink p, XmlNode xNode):base(r,p,xNo } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { - base.FinalPass(); + await base.FinalPass(); if (_Values != null) - _Values.FinalPass(); + await _Values.FinalPass(); if (_DataPoint != null) - _DataPoint.FinalPass(); + await _DataPoint.FinalPass(); if (_ChartLabel != null) - _ChartLabel.FinalPass(); + await _ChartLabel.FinalPass(); if (_PlotType != null) - _PlotType.FinalPass(); + await _PlotType.FinalPass(); if (_YAxis != null) - _YAxis.FinalPass(); + await _YAxis.FinalPass(); if (_NoMarker != null) - _NoMarker.FinalPass(); + await _NoMarker.FinalPass(); if (_LineSize != null) - _LineSize.FinalPass(); + await _LineSize.FinalPass(); if (_Colour != null) - _Colour.FinalPass(); + await _Colour.FinalPass(); return; } - override internal void Run(IPresent ip, Row row) + override internal Task Run(IPresent ip, Row row) { - return; + return Task.CompletedTask; } internal Expression Value diff --git a/RdlEngine/Definition/ChartGridLines.cs b/RdlEngine/Definition/ChartGridLines.cs index 24dc9182..c1c7d1fa 100644 --- a/RdlEngine/Definition/ChartGridLines.cs +++ b/RdlEngine/Definition/ChartGridLines.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -63,10 +64,10 @@ internal ChartGridLines(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } diff --git a/RdlEngine/Definition/ChartLine.cs b/RdlEngine/Definition/ChartLine.cs index 35471370..a2afc72a 100644 --- a/RdlEngine/Definition/ChartLine.cs +++ b/RdlEngine/Definition/ChartLine.cs @@ -23,6 +23,8 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Runtime.InteropServices; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; #else @@ -32,37 +34,37 @@ the website www.fyiReporting.com. namespace fyiReporting.RDL { - /// - /// Line chart definition and processing. - /// - [Serializable] - internal class ChartLine: ChartColumn - { - - internal ChartLine(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX,Expression _ToolTipYFormat, Expression _ToolTipXFormat) + /// + /// Line chart definition and processing. + /// + [Serializable] + internal class ChartLine : ChartColumn + { + + internal ChartLine(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression showTooltips, Expression showTooltipsX, Expression _ToolTipYFormat, Expression _ToolTipXFormat) : base(r, row, c, m, showTooltips, showTooltipsX, _ToolTipYFormat, _ToolTipXFormat) - { - } + { + } - override internal void Draw(Report rpt) - { - CreateSizedBitmap(); + override internal async Task Draw(Report rpt) + { + CreateSizedBitmap(); #if !DRAWINGCOMPAT - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - using (Drawing.Graphics g1 = Drawing.Graphics.FromImage(_bm)) - { - _aStream = new System.IO.MemoryStream(); - IntPtr HDC = g1.GetHdc(); - _mf = new Drawing.Imaging.Metafile(_aStream, HDC, - new Drawing.RectangleF(0, 0, _bm.Width, _bm.Height), Drawing.Imaging.MetafileFrameUnit.Pixel); - g1.ReleaseHdc(HDC); - } - } - - - using(Drawing.Graphics g = Drawing.Graphics.FromImage(_mf != null ? _mf : _bm)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + using (Drawing.Graphics g1 = Drawing.Graphics.FromImage(_bm)) + { + _aStream = new System.IO.MemoryStream(); + IntPtr HDC = g1.GetHdc(); + _mf = new Drawing.Imaging.Metafile(_aStream, HDC, + new Drawing.RectangleF(0, 0, _bm.Width, _bm.Height), Drawing.Imaging.MetafileFrameUnit.Pixel); + g1.ReleaseHdc(HDC); + } + } + + + using (Drawing.Graphics g = Drawing.Graphics.FromImage(_mf != null ? _mf : _bm)) #else using (Drawing.Graphics g = Drawing.Graphics.FromImage(_bm)) #endif @@ -73,83 +75,83 @@ override internal void Draw(Report rpt) g.PixelOffsetMode = Drawing.Drawing2D.PixelOffsetMode.None; g.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality; - // Adjust the top margin to depend on the title height - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, ChartDefn.Title); - Layout.TopMargin = titleSize.Height; + // Adjust the top margin to depend on the title height + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, ChartDefn.Title); + Layout.TopMargin = titleSize.Height; + + // 20022008 AJM GJL - Added new required info + double max = 0, min = 0; // Get the max and min values + (max, min) = await GetValueMaxMin(rpt, max, min, 0, 1); - // 20022008 AJM GJL - Added new required info - double max=0,min=0; // Get the max and min values - GetValueMaxMin(rpt, ref max, ref min, 0,1); + await DrawChartStyle(rpt, g); - DrawChartStyle(rpt, g); - - // Draw title; routine determines if necessary - DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, Layout.Width, Layout.TopMargin)); + // Draw title; routine determines if necessary + await DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, Layout.Width, Layout.TopMargin)); - // Adjust the left margin to depend on the Value Axis - Drawing.Size vaSize = ValueAxisSize(rpt, g, min, max); - Layout.LeftMargin = vaSize.Width; + // Adjust the left margin to depend on the Value Axis + Drawing.Size vaSize = await ValueAxisSize(rpt, g, min, max); + Layout.LeftMargin = vaSize.Width; - // Draw legend - Drawing.Rectangle lRect = DrawLegend(rpt,g, ChartDefn.Type == ChartTypeEnum.Area? false: true, true); + // Draw legend + Drawing.Rectangle lRect = await DrawLegend(rpt, g, ChartDefn.Type == ChartTypeEnum.Area ? false : true, true); - // Adjust the bottom margin to depend on the Category Axis - Drawing.Size caSize = CategoryAxisSize(rpt, g); - Layout.BottomMargin = caSize.Height; + // Adjust the bottom margin to depend on the Category Axis + Drawing.Size caSize = await CategoryAxisSize(rpt, g); + Layout.BottomMargin = caSize.Height; - AdjustMargins(lRect,rpt,g); // Adjust margins based on legend. + AdjustMargins(lRect, rpt, g); // Adjust margins based on legend. - // Draw Plot area - DrawPlotAreaStyle(rpt, g, lRect); + // Draw Plot area + await DrawPlotAreaStyle(rpt, g, lRect); int intervalCount = 0; double incr = 0; - // Draw Value Axis - if (vaSize.Width > 0) // If we made room for the axis - we need to draw it - DrawValueAxis(rpt, g, min, max, - new Drawing.Rectangle(Layout.LeftMargin - vaSize.Width, Layout.TopMargin, vaSize.Width, Layout.PlotArea.Height), Layout.LeftMargin, _bm.Width - Layout.RightMargin,out incr,out intervalCount); + // Draw Value Axis + if (vaSize.Width > 0) // If we made room for the axis - we need to draw it + (incr, intervalCount) = await DrawValueAxis(rpt, g, min, max, + new Drawing.Rectangle(Layout.LeftMargin - vaSize.Width, Layout.TopMargin, vaSize.Width, Layout.PlotArea.Height), Layout.LeftMargin, _bm.Width - Layout.RightMargin); - // Draw Category Axis - if (caSize.Height > 0) + // Draw Category Axis + if (caSize.Height > 0) //09052008ajm passing chart bounds int - DrawCategoryAxis(rpt, g, + await DrawCategoryAxis(rpt, g, new Drawing.Rectangle(Layout.LeftMargin, _bm.Height - Layout.BottomMargin, Layout.PlotArea.Width, caSize.Height), Layout.TopMargin, caSize.Width); - // Draw Plot area data - if (ChartDefn.Type == ChartTypeEnum.Area) - { - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked) - DrawPlotAreaAreaStacked(rpt, g, min, max); - else if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) - DrawPlotAreaAreaPercentStacked(rpt, g); - else - DrawPlotAreaArea(rpt, g, min, max); - } - else - { - DrawPlotAreaLine(rpt, g, min, max); - } - DrawLegend(rpt, g, ChartDefn.Type == ChartTypeEnum.Area? false: true, false); - } - } - - void DrawPlotAreaArea(Report rpt, Drawing.Graphics g, double min, double max) - { - // Draw Plot area data - int maxPointHeight = (int) Layout.PlotArea.Height; - double widthCat = ((double) (Layout.PlotArea.Width) / (CategoryCount-1)); - Drawing.Point[] saveP = new Drawing.Point[CategoryCount]; // used for drawing lines between points - for (int iCol=1; iCol <= SeriesCount; iCol++) - { - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - double v = this.GetDataValue(rpt, iRow, iCol); - - int x = (int) (Layout.PlotArea.Left + ((iRow-1) * widthCat)); - int y = (int) (((Math.Min(v,max)-min) / (max-min)) * maxPointHeight); - Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); - saveP[iRow-1] = p; - DrawLinePoint(rpt, g, GetSeriesBrush(rpt, iRow, iCol), ChartMarkerEnum.None, p, iRow, iCol); + // Draw Plot area data + if (ChartDefn.Type == ChartTypeEnum.Area) + { + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Stacked) + await DrawPlotAreaAreaStacked(rpt, g, min, max); + else if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.PercentStacked) + await DrawPlotAreaAreaPercentStacked(rpt, g); + else + await DrawPlotAreaArea(rpt, g, min, max); + } + else + { + await DrawPlotAreaLine(rpt, g, min, max); + } + await DrawLegend(rpt, g, ChartDefn.Type == ChartTypeEnum.Area ? false : true, false); + } + } + + async Task DrawPlotAreaArea(Report rpt, Drawing.Graphics g, double min, double max) + { + // Draw Plot area data + int maxPointHeight = (int)Layout.PlotArea.Height; + double widthCat = ((double)(Layout.PlotArea.Width) / (CategoryCount - 1)); + Drawing.Point[] saveP = new Drawing.Point[CategoryCount]; // used for drawing lines between points + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + double v = await this.GetDataValue(rpt, iRow, iCol); + + int x = (int)(Layout.PlotArea.Left + ((iRow - 1) * widthCat)); + int y = (int)(((Math.Min(v, max) - min) / (max - min)) * maxPointHeight); + Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); + saveP[iRow - 1] = p; + await DrawLinePoint(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), ChartMarkerEnum.None, p, iRow, iCol); //Add a metafilecomment to use as a tooltip GJL 26092008 if (_showToolTips) @@ -157,54 +159,54 @@ void DrawPlotAreaArea(Report rpt, Drawing.Graphics g, double min, double max) String val = "ToolTip:" + v.ToString(_tooltipYFormat) + "|X:" + (int)(p.X - 5) + "|Y:" + (int)(p.Y - 5) + "|W:" + 10 + "|H:" + 10; g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - } - DrawAreaBetweenPoints(g, GetSeriesBrush(rpt, 1, iCol), saveP, null); - } - return; - } - - void DrawPlotAreaAreaPercentStacked(Report rpt, Drawing.Graphics g) - { - double max = 1; // 100% is the max - // Draw Plot area data - int maxPointHeight = (int) Layout.PlotArea.Height; - double widthCat = ((double) (Layout.PlotArea.Width) / (CategoryCount-1)); - Drawing.Point[,] saveAllP = new Drawing.Point[CategoryCount,SeriesCount]; // used to collect all data points - - // Loop thru calculating all the data points - for (int iRow = 1; iRow <= CategoryCount; iRow++) - { - int x = (int) (Layout.PlotArea.Left + ((iRow-1) * widthCat)); - double sum=0; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - sum += GetDataValue(rpt, iRow, iCol); - } - double v=0; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - v += GetDataValue(rpt, iRow, iCol); - - int y = (int) ((Math.Min(v/sum,max) / max) * maxPointHeight); - Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); - saveAllP[iRow-1, iCol-1] = p; - } - } - - // Now loop thru and plot all the points - Drawing.Point[] saveP = new Drawing.Point[CategoryCount]; // used for drawing lines between points - Drawing.Point[] priorSaveP= new Drawing.Point[CategoryCount]; - for (int iCol=1; iCol <= SeriesCount; iCol++) - { - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - double v = this.GetDataValue(rpt, iRow, iCol); - - int x = (int) (Layout.PlotArea.Left + ((iRow-1) * widthCat)); - int y = (int) ((Math.Min(v,max) / max) * maxPointHeight); - Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); - saveP[iRow-1] = saveAllP[iRow-1, iCol-1]; - DrawLinePoint(rpt, g, GetSeriesBrush(rpt, iRow, iCol), ChartMarkerEnum.None, p, iRow, iCol); + } + DrawAreaBetweenPoints(g, await GetSeriesBrush(rpt, 1, iCol), saveP, null); + } + return; + } + + async Task DrawPlotAreaAreaPercentStacked(Report rpt, Drawing.Graphics g) + { + double max = 1; // 100% is the max + // Draw Plot area data + int maxPointHeight = (int)Layout.PlotArea.Height; + double widthCat = ((double)(Layout.PlotArea.Width) / (CategoryCount - 1)); + Drawing.Point[,] saveAllP = new Drawing.Point[CategoryCount, SeriesCount]; // used to collect all data points + + // Loop thru calculating all the data points + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + int x = (int)(Layout.PlotArea.Left + ((iRow - 1) * widthCat)); + double sum = 0; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + sum += await GetDataValue(rpt, iRow, iCol); + } + double v = 0; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + v += await GetDataValue(rpt, iRow, iCol); + + int y = (int)((Math.Min(v / sum, max) / max) * maxPointHeight); + Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); + saveAllP[iRow - 1, iCol - 1] = p; + } + } + + // Now loop thru and plot all the points + Drawing.Point[] saveP = new Drawing.Point[CategoryCount]; // used for drawing lines between points + Drawing.Point[] priorSaveP = new Drawing.Point[CategoryCount]; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + double v = await this.GetDataValue(rpt, iRow, iCol); + + int x = (int)(Layout.PlotArea.Left + ((iRow - 1) * widthCat)); + int y = (int)((Math.Min(v, max) / max) * maxPointHeight); + Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); + saveP[iRow - 1] = saveAllP[iRow - 1, iCol - 1]; + await DrawLinePoint(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), ChartMarkerEnum.None, p, iRow, iCol); //Add a metafilecomment to use as a tooltip GJL 26092008 if (_showToolTips) @@ -212,50 +214,50 @@ void DrawPlotAreaAreaPercentStacked(Report rpt, Drawing.Graphics g) String val = "ToolTip:" + v.ToString(_tooltipYFormat) + "|X:" + (int)(p.X - 5) + "|Y:" + (int)(p.Y - 5) + "|W:" + 10 + "|H:" + 10; g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - } - DrawAreaBetweenPoints(g, GetSeriesBrush(rpt, 1, iCol), saveP, iCol == 1 ? null : priorSaveP); - // Save prior point values - for (int i=0; i < CategoryCount; i++) - priorSaveP[i] = saveP[i]; - } - return; - } - - void DrawPlotAreaAreaStacked(Report rpt, Drawing.Graphics g, double min, double max) - { - // Draw Plot area data - int maxPointHeight = (int) Layout.PlotArea.Height; - double widthCat = ((double) (Layout.PlotArea.Width) / (CategoryCount-1)); - Drawing.Point[,] saveAllP = new Drawing.Point[CategoryCount,SeriesCount]; // used to collect all data points - - // Loop thru calculating all the data points - for (int iRow = 1; iRow <= CategoryCount; iRow++) - { - int x = (int) (Layout.PlotArea.Left + ((iRow-1) * widthCat)); - double v=0; - for (int iCol = 1; iCol <= SeriesCount; iCol++) - { - v += GetDataValue(rpt, iRow, iCol); - int y = (int) (((Math.Min(v,max)-min) / (max-min)) * maxPointHeight); - Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); - saveAllP[iRow-1, iCol-1] = p; - } - } - - // Now loop thru and plot all the points - Drawing.Point[] saveP = new Drawing.Point[CategoryCount]; // used for drawing lines between points - Drawing.Point[] priorSaveP= new Drawing.Point[CategoryCount]; - for (int iCol=1; iCol <= SeriesCount; iCol++) - { - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - double v = this.GetDataValue(rpt, iRow, iCol); - - int x = (int) (Layout.PlotArea.Left + ((iRow-1) * widthCat)); - int y = (int) (((Math.Min(v,max)-min) / (max-min)) * maxPointHeight); - Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); - saveP[iRow-1] = saveAllP[iRow-1, iCol-1]; - DrawLinePoint(rpt, g, GetSeriesBrush(rpt, iRow, iCol), ChartMarkerEnum.None, p, iRow, iCol); + } + DrawAreaBetweenPoints(g, await GetSeriesBrush(rpt, 1, iCol), saveP, iCol == 1 ? null : priorSaveP); + // Save prior point values + for (int i = 0; i < CategoryCount; i++) + priorSaveP[i] = saveP[i]; + } + return; + } + + async Task DrawPlotAreaAreaStacked(Report rpt, Drawing.Graphics g, double min, double max) + { + // Draw Plot area data + int maxPointHeight = (int)Layout.PlotArea.Height; + double widthCat = ((double)(Layout.PlotArea.Width) / (CategoryCount - 1)); + Drawing.Point[,] saveAllP = new Drawing.Point[CategoryCount, SeriesCount]; // used to collect all data points + + // Loop thru calculating all the data points + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + int x = (int)(Layout.PlotArea.Left + ((iRow - 1) * widthCat)); + double v = 0; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + v += await GetDataValue(rpt, iRow, iCol); + int y = (int)(((Math.Min(v, max) - min) / (max - min)) * maxPointHeight); + Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); + saveAllP[iRow - 1, iCol - 1] = p; + } + } + + // Now loop thru and plot all the points + Drawing.Point[] saveP = new Drawing.Point[CategoryCount]; // used for drawing lines between points + Drawing.Point[] priorSaveP = new Drawing.Point[CategoryCount]; + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + double v = await this.GetDataValue(rpt, iRow, iCol); + + int x = (int)(Layout.PlotArea.Left + ((iRow - 1) * widthCat)); + int y = (int)(((Math.Min(v, max) - min) / (max - min)) * maxPointHeight); + Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); + saveP[iRow - 1] = saveAllP[iRow - 1, iCol - 1]; + await DrawLinePoint(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), ChartMarkerEnum.None, p, iRow, iCol); //Add a metafilecomment to use as a tooltip GJL 26092008 if (_showToolTips) { @@ -263,115 +265,120 @@ void DrawPlotAreaAreaStacked(Report rpt, Drawing.Graphics g, double min, double g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); } - - } - DrawAreaBetweenPoints(g, GetSeriesBrush(rpt, 1, iCol), saveP, iCol == 1 ? null : priorSaveP); - // Save prior point values - for (int i=0; i < CategoryCount; i++) - priorSaveP[i] = saveP[i]; - } - return; - } - - void DrawPlotAreaLine(Report rpt, Drawing.Graphics g, double min, double max) - { - // Draw Plot area data - int maxPointHeight = (int) Layout.PlotArea.Height; - double widthCat = ((double) (Layout.PlotArea.Width) / CategoryCount); - Drawing.Point[] saveP = new Drawing.Point[CategoryCount]; // used for drawing lines between points - for (int iCol=1; iCol <= SeriesCount; iCol++) - { - for (int iRow=1; iRow <= CategoryCount; iRow++) - { - double v = this.GetDataValue(rpt, iRow, iCol); - - int x = (int) (Layout.PlotArea.Left + ((iRow-1) * widthCat) + (widthCat/2) ); - int y = (int) (((Math.Min(v,max)-min) / (max-min)) * maxPointHeight); - Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); - saveP[iRow-1] = p; + + } + DrawAreaBetweenPoints(g, await GetSeriesBrush(rpt, 1, iCol), saveP, iCol == 1 ? null : priorSaveP); + // Save prior point values + for (int i = 0; i < CategoryCount; i++) + priorSaveP[i] = saveP[i]; + } + return; + } + + async Task DrawPlotAreaLine(Report rpt, Drawing.Graphics g, double min, double max) + { + // Draw Plot area data + int maxPointHeight = (int)Layout.PlotArea.Height; + double widthCat = ((double)(Layout.PlotArea.Width) / CategoryCount); + Drawing.Point[] saveP = new Drawing.Point[CategoryCount]; // used for drawing lines between points + for (int iCol = 1; iCol <= SeriesCount; iCol++) + { + for (int iRow = 1; iRow <= CategoryCount; iRow++) + { + double v = await this.GetDataValue(rpt, iRow, iCol); + + int x = (int)(Layout.PlotArea.Left + ((iRow - 1) * widthCat) + (widthCat / 2)); + int y = (int)(((Math.Min(v, max) - min) / (max - min)) * maxPointHeight); + Drawing.Point p = new Drawing.Point(x, Layout.PlotArea.Top + (maxPointHeight - y)); + saveP[iRow - 1] = p; bool DrawPoint = getNoMarkerVal(rpt, iCol, 1) == false; //dont draw the point if I say not to! - if (DrawPoint) { DrawLinePoint(rpt, g, GetSeriesBrush(rpt, iRow, iCol), SeriesMarker[iCol - 1], p, iRow, iCol); } + if (DrawPoint) { await DrawLinePoint(rpt, g, await GetSeriesBrush(rpt, iRow, iCol), SeriesMarker[iCol - 1], p, iRow, iCol); } //Add a metafilecomment to use as a tooltip GJL 26092008 if (_showToolTips) { String val = "ToolTip:" + v.ToString(_tooltipYFormat) + "|X:" + (int)(p.X - 5) + "|Y:" + (int)(p.Y - 5) + "|W:" + 10 + "|H:" + 10; g.AddMetafileComment(new System.Text.ASCIIEncoding().GetBytes(val)); - } - } + } + } String LineSize = getLineSize(rpt, iCol, 1); int intLineSize = 2; switch (LineSize) { - case "Small": intLineSize = 1; + case "Small": + intLineSize = 1; break; - case "Regular": intLineSize = 2; + case "Regular": + intLineSize = 2; break; - case "Large": intLineSize = 3; + case "Large": + intLineSize = 3; break; - case "Extra Large": intLineSize = 4; + case "Extra Large": + intLineSize = 4; break; - case "Super Size": intLineSize = 5; + case "Super Size": + intLineSize = 5; break; } - DrawLineBetweenPoints(g, rpt, GetSeriesBrush(rpt, 1, iCol), saveP, intLineSize); - } - return; - } - - void DrawAreaBetweenPoints(Drawing.Graphics g, Drawing.Brush brush, Drawing.Point[] points, Drawing.Point[] previous) - { - if (points.Length <= 1) // Need at least 2 points - return; - - Drawing.Pen p=null; - try - { - p = new Drawing.Pen(brush, 1); // todo - use line from style ???? - g.DrawLines(p, points); - Drawing.PointF[] poly; - if (previous == null) - { // The bottom is the bottom of the chart - poly = new Drawing.PointF[points.Length + 3]; - int i=0; - foreach (Drawing.Point pt in points) - { - poly[i++] = pt; - } - poly[i++] = new Drawing.PointF(points[points.Length-1].X, Layout.PlotArea.Bottom); - poly[i++] = new Drawing.PointF(points[0].X, Layout.PlotArea.Bottom); - poly[i] = new Drawing.PointF(points[0].X, points[0].Y); - } - else - { // The bottom is the previous line - poly = new Drawing.PointF[(points.Length * 2) + 1]; - int i=0; - foreach (Drawing.Point pt in points) - { - poly[i] = pt; - poly[points.Length+i] = previous[previous.Length - 1 - i]; - i++; - } - poly[poly.Length-1] = poly[0]; - } - g.FillPolygon(brush, poly); - } - finally - { - if (p != null) - p.Dispose(); - } - return; - } - - void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points) - { - DrawLineBetweenPoints(g, rpt, brush, points, 2); - } - - void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points, int intLineSize) + await DrawLineBetweenPoints(g, rpt, await GetSeriesBrush(rpt, 1, iCol), saveP, intLineSize); + } + return; + } + + void DrawAreaBetweenPoints(Drawing.Graphics g, Drawing.Brush brush, Drawing.Point[] points, Drawing.Point[] previous) + { + if (points.Length <= 1) // Need at least 2 points + return; + + Drawing.Pen p = null; + try + { + p = new Drawing.Pen(brush, 1); // todo - use line from style ???? + g.DrawLines(p, points); + Drawing.PointF[] poly; + if (previous == null) + { // The bottom is the bottom of the chart + poly = new Drawing.PointF[points.Length + 3]; + int i = 0; + foreach (Drawing.Point pt in points) + { + poly[i++] = pt; + } + poly[i++] = new Drawing.PointF(points[points.Length - 1].X, Layout.PlotArea.Bottom); + poly[i++] = new Drawing.PointF(points[0].X, Layout.PlotArea.Bottom); + poly[i] = new Drawing.PointF(points[0].X, points[0].Y); + } + else + { // The bottom is the previous line + poly = new Drawing.PointF[(points.Length * 2) + 1]; + int i = 0; + foreach (Drawing.Point pt in points) + { + poly[i] = pt; + poly[points.Length + i] = previous[previous.Length - 1 - i]; + i++; + } + poly[poly.Length - 1] = poly[0]; + } + g.FillPolygon(brush, poly); + } + finally + { + if (p != null) + p.Dispose(); + } + return; + } + + async Task DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points) + { + await DrawLineBetweenPoints(g, rpt, brush, points, 2); + } + + async Task DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Point[] points, int intLineSize) { if (points.Length <= 1) // Need at least 2 points return; @@ -385,7 +392,7 @@ void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, p = new Drawing.Pen(brush, intLineSize); // todo - use line from style ???? - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Smooth && points.Length > 2) + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Smooth && points.Length > 2) g.DrawCurve(p, points, 0.5F); else g.DrawLines(p, points); @@ -398,24 +405,24 @@ void DrawLineBetweenPoints(Drawing.Graphics g, Report rpt, Drawing.Brush brush, return; } - void DrawLinePoint(Report rpt, Drawing.Graphics g, Drawing.Brush brush, ChartMarkerEnum marker, Drawing.Point p, int iRow, int iCol) - { - Drawing.Pen pen=null; - try - { - pen = new Drawing.Pen(brush); - // 20022008 AJM GJL - Added bigger points - DrawLegendMarker(g, brush, pen, marker, p.X-5, p.Y-5, 10); - DrawDataPoint(rpt, g, new Drawing.Point(p.X-5, p.Y+5), iRow, iCol); - } - finally - { - if (pen != null) - pen.Dispose(); - } - - return; - } - - } + async Task DrawLinePoint(Report rpt, Drawing.Graphics g, Drawing.Brush brush, ChartMarkerEnum marker, Drawing.Point p, int iRow, int iCol) + { + Drawing.Pen pen = null; + try + { + pen = new Drawing.Pen(brush); + // 20022008 AJM GJL - Added bigger points + DrawLegendMarker(g, brush, pen, marker, p.X - 5, p.Y - 5, 10); + await DrawDataPoint(rpt, g, new Drawing.Point(p.X - 5, p.Y + 5), iRow, iCol); + } + finally + { + if (pen != null) + pen.Dispose(); + } + + return; + } + + } } diff --git a/RdlEngine/Definition/ChartMap.cs b/RdlEngine/Definition/ChartMap.cs index 620eafdb..020c3274 100644 --- a/RdlEngine/Definition/ChartMap.cs +++ b/RdlEngine/Definition/ChartMap.cs @@ -35,6 +35,7 @@ the website www.fyiReporting.com. using System.Text; using System.Globalization; using System.Runtime.InteropServices; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -50,7 +51,7 @@ internal ChartMap(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression s { } - override internal void Draw(Report rpt) + override internal async Task Draw(Report rpt) { CreateSizedBitmap(); #if !DRAWINGCOMPAT @@ -79,40 +80,40 @@ override internal void Draw(Report rpt) g.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality; // Adjust the top margin to depend on the title height - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, ChartDefn.Title); + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, ChartDefn.Title); Layout.TopMargin = titleSize.Height; - double max=0,min=0; // Get the max and min values - // GetValueMaxMin(rpt, ref max, ref min,0, 1); + double max=0,min=0; // Get the max and min values + // GetValueMaxMin(rpt, ref max, ref min,0, 1); - DrawChartStyle(rpt, g); - - // Draw title; routine determines if necessary - DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, _bm.Width, Layout.TopMargin)); + await DrawChartStyle(rpt, g); + + // Draw title; routine determines if necessary + await DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, _bm.Width, Layout.TopMargin)); Layout.LeftMargin = 0; Layout.RightMargin = 0; // Draw legend - Drawing.Rectangle lRect = DrawLegend(rpt, g, false, true); + Drawing.Rectangle lRect = await DrawLegend(rpt, g, false, true); Layout.BottomMargin = 0; - AdjustMargins(lRect,rpt, g); // Adjust margins based on legend. + AdjustMargins(lRect,rpt, g); // Adjust margins based on legend. + + // Draw Plot area + await DrawPlotAreaStyle(rpt, g, lRect); - // Draw Plot area - DrawPlotAreaStyle(rpt, g, lRect); + string subtype = await _ChartDefn.Subtype.EvaluateString(rpt, _row); - string subtype = _ChartDefn.Subtype.EvaluateString(rpt, _row); - - DrawMap(rpt, g, subtype, max, min); + await DrawMap(rpt, g, subtype, max, min); - DrawLegend(rpt, g, false, false); + await DrawLegend(rpt, g, false, false); } } - private void DrawMap(Report rpt, Drawing.Graphics g, string mapfile, double max, double min) + private async Task DrawMap(Report rpt, Drawing.Graphics g, string mapfile, double max, double min) { string file = XmlUtil.XmlFileExists(mapfile); @@ -130,9 +131,9 @@ private void DrawMap(Report rpt, Drawing.Graphics g, string mapfile, double max, { for (int iCol = 1; iCol <= SeriesCount; iCol++) { - string sv = GetSeriesValue(rpt, iCol); + string sv = await GetSeriesValue(rpt, iCol); - string c = this.GetDataValueString(rpt, iRow, iCol); + string c = await this.GetDataValueString(rpt, iRow, iCol); List pl = mp.GetPolygon(sv); if (pl == null) continue; diff --git a/RdlEngine/Definition/ChartPie.cs b/RdlEngine/Definition/ChartPie.cs index ea5fcd27..12c0e6ce 100644 --- a/RdlEngine/Definition/ChartPie.cs +++ b/RdlEngine/Definition/ChartPie.cs @@ -23,6 +23,8 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Runtime.InteropServices; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; #else @@ -43,7 +45,7 @@ internal ChartPie(Report r, Row row, Chart c, MatrixCellEntry[,] m, Expression s { } - override internal void Draw(Report rpt) + override internal async Task Draw(Report rpt) { CreateSizedBitmap(); @@ -71,42 +73,42 @@ override internal void Draw(Report rpt) g.CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality; // Adjust the top margin to depend on the title height - Drawing.Size titleSize = DrawTitleMeasure(rpt, g, ChartDefn.Title); + Drawing.Size titleSize = await DrawTitleMeasure(rpt, g, ChartDefn.Title); Layout.TopMargin = titleSize.Height; - DrawChartStyle(rpt, g); - - // Draw title; routine determines if necessary - DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, _bm.Width, Layout.TopMargin)); + await DrawChartStyle(rpt, g); + + // Draw title; routine determines if necessary + await DrawTitle(rpt, g, ChartDefn.Title, new Drawing.Rectangle(0, 0, _bm.Width, Layout.TopMargin)); // Draw legend - Drawing.Rectangle lRect = DrawLegend(rpt, g, false, true); + Drawing.Rectangle lRect = await DrawLegend(rpt, g, false, true); // Adjust the bottom margin to depend on the Category Axis - Drawing.Size caSize = CategoryAxisSize(rpt, g); + Drawing.Size caSize = await CategoryAxisSize(rpt, g); Layout.BottomMargin = caSize.Height; // 20022008 AJM GJL - Added required info - AdjustMargins(lRect,rpt,g); // Adjust margins based on legend. + AdjustMargins(lRect,rpt,g); // Adjust margins based on legend. - // Draw Plot area - DrawPlotAreaStyle(rpt, g, lRect); + // Draw Plot area + await DrawPlotAreaStyle(rpt, g, lRect); // Draw Category Axis if (caSize.Height > 0) - DrawCategoryAxis(rpt, g, + await DrawCategoryAxis(rpt, g, new Drawing.Rectangle(Layout.LeftMargin, _bm.Height-Layout.BottomMargin, _bm.Width - Layout.LeftMargin - Layout.RightMargin, caSize.Height)); if (ChartDefn.Type == ChartTypeEnum.Doughnut) - DrawPlotAreaDoughnut(rpt, g); - else - DrawPlotAreaPie(rpt, g); + await DrawPlotAreaDoughnut(rpt, g); + else + await DrawPlotAreaPie(rpt, g); - DrawLegend(rpt, g, false, false); + await DrawLegend(rpt, g, false, false); } } - void DrawPlotAreaDoughnut(Report rpt, Drawing.Graphics g) + async Task DrawPlotAreaDoughnut(Report rpt, Drawing.Graphics g) { // Draw Plot area data int widthPie = Layout.PlotArea.Width; @@ -133,7 +135,7 @@ void DrawPlotAreaDoughnut(Report rpt, Drawing.Graphics g) double total=0; // sum up for this category for (int iCol=1; iCol <= SeriesCount; iCol++) { - total += this.GetDataValue(rpt, iRow, iCol); + total += await this.GetDataValue(rpt, iRow, iCol); } // Pie size decreases as we go in @@ -141,10 +143,10 @@ void DrawPlotAreaDoughnut(Report rpt, Drawing.Graphics g) pieSize = maxPieSize - ((iRow - 1) * doughWidth * 2); for (int iCol=1; iCol <= SeriesCount; iCol++) { - double v = this.GetDataValue(rpt, iRow, iCol); + double v = await this.GetDataValue(rpt, iRow, iCol); endAngle = (float) (startAngle + (v / total * 360)); - DrawPie(g, rpt, GetSeriesBrush(rpt, iRow, iCol), + await DrawPie(g, rpt, await GetSeriesBrush(rpt, iRow, iCol), new Drawing.Rectangle(pieLocX, pieLocY, pieSize, pieSize), iRow, iCol, startAngle, endAngle); startAngle = endAngle; @@ -161,10 +163,10 @@ void DrawPlotAreaDoughnut(Report rpt, Drawing.Graphics g) Rows cData = ChartDefn.ChartMatrix.GetMyData(rpt); Row r = cData.Data[0]; - s.DrawBackgroundCircle(rpt, g, r, rect); + await s.DrawBackgroundCircle(rpt, g, r, rect); } - void DrawPlotAreaPie(Report rpt, Drawing.Graphics g) + async Task DrawPlotAreaPie(Report rpt, Drawing.Graphics g) { int piesNeeded = CategoryCount; int gapsNeeded = CategoryCount + 1; @@ -187,7 +189,7 @@ void DrawPlotAreaPie(Report rpt, Drawing.Graphics g) double total=0; for (int iCol=1; iCol <= SeriesCount; iCol++) { - total += this.GetDataValue(rpt, iRow, iCol); + total += await this.GetDataValue(rpt, iRow, iCol); } if (total > maxCategory) maxCategory = total; @@ -202,7 +204,7 @@ void DrawPlotAreaPie(Report rpt, Drawing.Graphics g) double total=0; for (int iCol=1; iCol <= SeriesCount; iCol++) { - total += this.GetDataValue(rpt, iRow, iCol); + total += await this.GetDataValue(rpt, iRow, iCol); } // Pie size is a ratio of the area of the pies (not the diameter) @@ -210,10 +212,10 @@ void DrawPlotAreaPie(Report rpt, Drawing.Graphics g) int pieSize = (int) (2 * Math.Sqrt(Math.PI * ((maxPieSize/2) * (maxPieSize/2) * total/maxCategory) / Math.PI)); for (int iCol=1; iCol <= SeriesCount; iCol++) { - double v = this.GetDataValue(rpt, iRow, iCol); + double v = await this.GetDataValue(rpt, iRow, iCol); endAngle = (float) (startAngle + (v / total * 360)); - DrawPie(g, rpt, GetSeriesBrush(rpt, iRow, iCol), + await DrawPie(g, rpt, await GetSeriesBrush(rpt, iRow, iCol), new Drawing.Rectangle(pieLocX, pieLocY, pieSize, pieSize), iRow, iCol, startAngle, endAngle); startAngle = endAngle; @@ -222,7 +224,7 @@ void DrawPlotAreaPie(Report rpt, Drawing.Graphics g) } // Calculate the size of the category axis - protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g) + protected async Task CategoryAxisSize(Report rpt, Drawing.Graphics g) { Drawing.Size size=Drawing.Size.Empty; if (this.ChartDefn.CategoryAxis == null || @@ -234,7 +236,7 @@ protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g) Style s = a.Style; // Measure the title - size = DrawTitleMeasure(rpt, g, a.Title); + size = await DrawTitleMeasure(rpt, g, a.Title); if (!a.Visible) // don't need to calculate the height return size; @@ -247,10 +249,10 @@ protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g) object v = this.GetCategoryValue(rpt, iRow, out tc); Drawing.Size tSize; if (s == null) - tSize = Style.MeasureStringDefaults(rpt, g, v, tc, null, int.MaxValue); + tSize = await Style.MeasureStringDefaults(rpt, g, v, tc, null, int.MaxValue); else - tSize =s.MeasureString(rpt, g, v, tc, null, int.MaxValue); + tSize = await s.MeasureString(rpt, g, v, tc, null, int.MaxValue); if (tSize.Height > maxHeight) maxHeight = tSize.Height; @@ -262,7 +264,7 @@ protected Drawing.Size CategoryAxisSize(Report rpt, Drawing.Graphics g) } // DrawCategoryAxis - protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangle rect) + protected async Task DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangle rect) { if (this.ChartDefn.CategoryAxis == null) return; @@ -271,8 +273,8 @@ protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangl return; Style s = a.Style; - Drawing.Size tSize = DrawTitleMeasure(rpt, g, a.Title); - DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Bottom-tSize.Height, rect.Width, tSize.Height)); + Drawing.Size tSize = await DrawTitleMeasure(rpt, g, a.Title); + await DrawTitle(rpt, g, a.Title, new Drawing.Rectangle(rect.Left, rect.Bottom-tSize.Height, rect.Width, tSize.Height)); int drawWidth = rect.Width / CategoryCount; TypeCode tc; @@ -289,16 +291,16 @@ protected void DrawCategoryAxis(Report rpt, Drawing.Graphics g, Drawing.Rectangl if (s == null) Style.DrawStringDefaults(g, v, drawRect); else - s.DrawString(rpt, g, v, tc, null, drawRect); + await s.DrawString(rpt, g, v, tc, null, drawRect); } } return; } - void DrawPie(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Rectangle rect, int iRow, int iCol, float startAngle, float endAngle) + async Task DrawPie(Drawing.Graphics g, Report rpt, Drawing.Brush brush, Drawing.Rectangle rect, int iRow, int iCol, float startAngle, float endAngle) { - if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Exploded) + if ((ChartSubTypeEnum)Enum.Parse(typeof(ChartSubTypeEnum), await _ChartDefn.Subtype.EvaluateString(rpt, _row)) == ChartSubTypeEnum.Exploded) { // Need to adjust the rectangle int side = (int) (rect.Width * .75); // side needs to be smaller to account for exploded pies diff --git a/RdlEngine/Definition/ChartSeries.cs b/RdlEngine/Definition/ChartSeries.cs index 6aab820c..aa5694c4 100644 --- a/RdlEngine/Definition/ChartSeries.cs +++ b/RdlEngine/Definition/ChartSeries.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ // 20022008 AJM GJL - Added Second Y axis support using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -90,10 +91,10 @@ internal ChartSeries(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "ChartSeries requires the DataPoints element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Datapoints != null) - _Datapoints.FinalPass(); + await _Datapoints.FinalPass(); return; } diff --git a/RdlEngine/Definition/Classes.cs b/RdlEngine/Definition/Classes.cs index 0b0105d3..b8ea8265 100644 --- a/RdlEngine/Definition/Classes.cs +++ b/RdlEngine/Definition/Classes.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; @@ -71,11 +72,11 @@ internal ReportClass this[string s] } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (ReportClass rc in _Items) { - rc.FinalPass(); + await rc.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Code.cs b/RdlEngine/Definition/Code.cs index cb321004..95384f37 100644 --- a/RdlEngine/Definition/Code.cs +++ b/RdlEngine/Definition/Code.cs @@ -34,6 +34,7 @@ the website www.fyiReporting.com. using System.Threading; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -53,9 +54,9 @@ internal Code(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Assembly = GetAssembly(); } - override internal void FinalPass() + override internal Task FinalPass() { - return; + return Task.CompletedTask; } private Assembly GetAssembly() diff --git a/RdlEngine/Definition/CodeModule.cs b/RdlEngine/Definition/CodeModule.cs index 8f694bbc..88a73472 100644 --- a/RdlEngine/Definition/CodeModule.cs +++ b/RdlEngine/Definition/CodeModule.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.Reflection; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -71,9 +72,9 @@ internal Assembly LoadedAssembly() return _LoadedAssembly; } - override internal void FinalPass() + override internal Task FinalPass() { - return; + return Task.CompletedTask; } internal string CdModule diff --git a/RdlEngine/Definition/CodeModules.cs b/RdlEngine/Definition/CodeModules.cs index ff4c36e6..fc6b0487 100644 --- a/RdlEngine/Definition/CodeModules.cs +++ b/RdlEngine/Definition/CodeModules.cs @@ -26,6 +26,7 @@ the website www.fyiReporting.com. using System.Collections.Generic; using System.Xml; using System.Reflection; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -96,11 +97,11 @@ internal Type this[string s] } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (CodeModule cm in _Items) { - cm.FinalPass(); + await cm.FinalPass(); } return; } diff --git a/RdlEngine/Definition/ColumnGrouping.cs b/RdlEngine/Definition/ColumnGrouping.cs index 703995ed..707520bd 100644 --- a/RdlEngine/Definition/ColumnGrouping.cs +++ b/RdlEngine/Definition/ColumnGrouping.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -70,12 +71,12 @@ internal ColumnGrouping(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "ColumnGrouping requires either the DynamicColumns element or StaticColumns element but not both."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DynamicColumns != null) - _DynamicColumns.FinalPass(); + await _DynamicColumns.FinalPass(); if (_StaticColumns != null) - _StaticColumns.FinalPass(); + await _StaticColumns.FinalPass(); return ; } diff --git a/RdlEngine/Definition/ColumnGroupings.cs b/RdlEngine/Definition/ColumnGroupings.cs index 9f19a184..5978ac5d 100644 --- a/RdlEngine/Definition/ColumnGroupings.cs +++ b/RdlEngine/Definition/ColumnGroupings.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -68,11 +69,11 @@ internal ColumnGroupings(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (ColumnGrouping g in _Items) { - g.FinalPass(); + await g.FinalPass(); } return; } diff --git a/RdlEngine/Definition/ConnectionProperties.cs b/RdlEngine/Definition/ConnectionProperties.cs index ea70c134..e18c8e32 100644 --- a/RdlEngine/Definition/ConnectionProperties.cs +++ b/RdlEngine/Definition/ConnectionProperties.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -81,10 +82,10 @@ internal ConnectionProperties(ReportDefn r, ReportLink p, XmlNode xNode) : base( OwnerReport.rl.LogError(8, "ConnectionProperties ConnectString is required."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ConnectString != null) - _ConnectString.FinalPass(); + await _ConnectString.FinalPass(); return; } @@ -94,9 +95,9 @@ internal string DataProvider set { _DataProvider = value; } } - internal string Connectstring(Report rpt) + internal async Task Connectstring(Report rpt) { - return _ConnectString.EvaluateString(rpt, null); + return await _ConnectString.EvaluateString(rpt, null); } internal string ConnectstringValue diff --git a/RdlEngine/Definition/Corner.cs b/RdlEngine/Definition/Corner.cs index 56e4383a..fa285006 100644 --- a/RdlEngine/Definition/Corner.cs +++ b/RdlEngine/Definition/Corner.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -60,10 +61,10 @@ internal Corner(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); return; } diff --git a/RdlEngine/Definition/Custom.cs b/RdlEngine/Definition/Custom.cs index 8e7666c5..23413e7a 100644 --- a/RdlEngine/Definition/Custom.cs +++ b/RdlEngine/Definition/Custom.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,9 +65,9 @@ internal Custom(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } - override internal void FinalPass() + override internal Task FinalPass() { - return; + return Task.CompletedTask; } internal string XML diff --git a/RdlEngine/Definition/CustomReportItem.cs b/RdlEngine/Definition/CustomReportItem.cs index 351e672a..41dddd20 100644 --- a/RdlEngine/Definition/CustomReportItem.cs +++ b/RdlEngine/Definition/CustomReportItem.cs @@ -33,6 +33,7 @@ the website www.fyiReporting.com. #endif using System.IO; using System.Linq; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -97,17 +98,17 @@ internal CustomReportItem(ReportDefn r, ReportLink p, XmlNode xNode):base(r, p, OwnerReport.rl.LogError(8, "CustomReportItem requires the Type element."); } - override internal void FinalPass() + async override internal Task FinalPass() { - base.FinalPass(); // this handles the finalpass of the AltReportItems + await base.FinalPass(); // this handles the finalpass of the AltReportItems // Handle the final pass for the Custom Properties if (_Properties != null) { foreach (CustomProperty cp in _Properties) { - cp.Name.FinalPass(); - cp.Value.FinalPass(); + await cp.Name.FinalPass(); + await cp.Value.FinalPass(); } } @@ -131,7 +132,7 @@ override internal void FinalPass() return; } - override internal void Run(IPresent ip, Row row) + override internal async Task Run(IPresent ip, Row row) { Report rpt = ip.Report(); @@ -141,13 +142,13 @@ override internal void Run(IPresent ip, Row row) cri = RdlEngineConfig.CreateCustomReportItem(_Type); Type a = cri.GetType(); Drawing.Bitmap bm = null; - SetProperties(rpt, row, cri); + await SetProperties(rpt, row, cri); int width = WidthCalc(rpt, null) - (Style == null ? 0 : - (Style.EvalPaddingLeftPx(rpt, row) + Style.EvalPaddingRightPx(rpt, row))); + (await Style.EvalPaddingLeftPx(rpt, row) + await Style.EvalPaddingRightPx(rpt, row))); int height = RSize.PixelsFromPoints(this.HeightOrOwnerHeight) - (Style == null ? 0 : - (Style.EvalPaddingTopPx(rpt, row) + Style.EvalPaddingBottomPx(rpt, row))); + (await Style.EvalPaddingTopPx(rpt, row) + await Style.EvalPaddingBottomPx(rpt, row))); bm = new Drawing.Bitmap(width, height); cri.DrawImage(ref bm); @@ -169,7 +170,7 @@ override internal void Run(IPresent ip, Row row) } bm.Save(ostrm, codec, encoderParameters); - ip.Image(new Image(rpt.ReportDefinition, this, xNode), row, null, ostrm); + await ip.Image(new Image(rpt.ReportDefinition, this, xNode), row, null, ostrm); ostrm.Close(); } catch (Exception ex) @@ -181,13 +182,15 @@ override internal void Run(IPresent ip, Row row) if (cri != null) cri.Dispose(); } + + return; } - override internal void RunPage(Pages pgs, Row row) + override internal async Task RunPage(Pages pgs, Row row) { Report rpt = pgs.Report; - if (IsHidden(pgs.Report, row)) + if (await IsHidden(pgs.Report, row)) return; SetPagePositionBegin(pgs); @@ -198,7 +201,7 @@ override internal void RunPage(Pages pgs, Row row) try { cri = RdlEngineConfig.CreateCustomReportItem(_Type); - SetProperties(pgs.Report, row, cri); + await SetProperties(pgs.Report, row, cri); Drawing.Imaging.EncoderParameters encoderParameters = new Drawing.Imaging.EncoderParameters(1); // 20022008 AJM GJL - Using centralised image quality @@ -207,7 +210,7 @@ override internal void RunPage(Pages pgs, Row row) PageImage pi = new PageImage(IMAGEFORMAT, ((format, width, height) => GenerateImage(codec, encoderParameters, width, height, cri)), ImageSizingEnum.Clip); // Create an image - SetPagePositionAndStyle(rpt, pi, row); + await SetPagePositionAndStyle(rpt, pi, row); if (pgs.CurrentPage.YOffset + pi.Y + pi.H >= pgs.BottomOfPage && !pgs.CurrentPage.IsEmpty()) { // force page break if it doesn't fit on the page @@ -231,6 +234,7 @@ override internal void RunPage(Pages pgs, Row row) if (cri != null) cri.Dispose(); } + return; } byte[] GenerateImage(ImageCodecInfo codec, Drawing.Imaging.EncoderParameters parameters, int width, int height, ICustomReportItem cri) @@ -245,7 +249,7 @@ byte[] GenerateImage(ImageCodecInfo codec, Drawing.Imaging.EncoderParameters par return ba; } - void SetProperties(Report rpt, Row row, ICustomReportItem cri) + async Task SetProperties(Report rpt, Row row, ICustomReportItem cri) { if (_Properties == null || _Properties.Count == 0) // Any properties specified? return; @@ -254,7 +258,7 @@ void SetProperties(Report rpt, Row row, ICustomReportItem cri) new Dictionary(_Properties.Count); foreach (CustomProperty cp in _Properties) { - string name = cp.Name.EvaluateString(rpt, row); + string name = await cp.Name.EvaluateString(rpt, row); object val = cp.Value.Evaluate(rpt, row); try { dict.Add(name, val); } catch diff --git a/RdlEngine/Definition/DataLabel.cs b/RdlEngine/Definition/DataLabel.cs index 336852e0..a080fba4 100644 --- a/RdlEngine/Definition/DataLabel.cs +++ b/RdlEngine/Definition/DataLabel.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -80,12 +81,12 @@ internal DataLabel(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { - if (_Style != null) - _Style.FinalPass(); - if (_Value != null) - _Value.FinalPass(); + if (_Style != null) + await _Style.FinalPass(); + if (_Value != null) + await _Value.FinalPass(); return; } diff --git a/RdlEngine/Definition/DataPoint.cs b/RdlEngine/Definition/DataPoint.cs index 584b4e89..856bed4d 100644 --- a/RdlEngine/Definition/DataPoint.cs +++ b/RdlEngine/Definition/DataPoint.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -96,18 +97,18 @@ internal DataPoint(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "DataPoint requires the DataValues element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DataValues != null) - _DataValues.FinalPass(); + await _DataValues.FinalPass(); if (_DataLabel != null) - _DataLabel.FinalPass(); + await _DataLabel.FinalPass(); if (_Action != null) - _Action.FinalPass(); + await _Action.FinalPass(); if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); if (_Marker != null) - _Marker.FinalPass(); + await _Marker.FinalPass(); return; } diff --git a/RdlEngine/Definition/DataPoints.cs b/RdlEngine/Definition/DataPoints.cs index d4bf0669..6df26b9b 100644 --- a/RdlEngine/Definition/DataPoints.cs +++ b/RdlEngine/Definition/DataPoints.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal DataPoints(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (DataPoint dp in _Items) { - dp.FinalPass(); + await dp.FinalPass(); } return; } diff --git a/RdlEngine/Definition/DataRegion.cs b/RdlEngine/Definition/DataRegion.cs index 33cabccc..83537f33 100644 --- a/RdlEngine/Definition/DataRegion.cs +++ b/RdlEngine/Definition/DataRegion.cs @@ -26,6 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -112,9 +113,9 @@ internal bool DataRegionElement(XmlNode xNodeLoop) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { - base.FinalPass(); + await base.FinalPass(); if (this is Table) { // Grids don't have any data responsibilities @@ -157,12 +158,12 @@ override internal void FinalPass() OwnerReport.rl.LogError(8, string.Format("{0} must specify a DataSetName.",this.Name == null? "DataRegions": this.Name.Nm)); } - if (_NoRows != null) - _NoRows.FinalPass(); - if (_Filters != null) - _Filters.FinalPass(); + if (_NoRows != null) + await _NoRows.FinalPass(); + if (_Filters != null) + await _Filters.FinalPass(); if (_PageBreakCondition != null) - _PageBreakCondition.FinalPass(); + await _PageBreakCondition.FinalPass(); return; } @@ -182,9 +183,9 @@ void ResolveNestedDataRegions() return; } - override internal void Run(IPresent ip, Row row) + async override internal Task Run(IPresent ip, Row row) { - base.Run(ip, row); + await base.Run(ip, row); } internal void RunPageRegionBegin(Pages pgs) @@ -205,24 +206,24 @@ internal void RunPageRegionEnd(Pages pgs) } } - internal bool AnyRows(IPresent ip, Rows data) + internal async Task AnyRows(IPresent ip, Rows data) { if (data == null || data.Data == null || data.Data.Count <= 0) { string msg; if (this.NoRows != null) - msg = this.NoRows.EvaluateString(ip.Report(), null); + msg = await this.NoRows.EvaluateString(ip.Report(), null); else msg = null; - ip.DataRegionNoRows(this, msg); + await ip.DataRegionNoRows(this, msg); return false; } return true; } - internal bool AnyRowsPage(Pages pgs, Rows data) + internal async Task AnyRowsPage(Pages pgs, Rows data) { if (data != null && data.Data != null && data.Data.Count > 0) @@ -230,7 +231,7 @@ internal bool AnyRowsPage(Pages pgs, Rows data) string msg; if (this.NoRows != null) - msg = this.NoRows.EvaluateString(pgs.Report, null); + msg = await this.NoRows.EvaluateString(pgs.Report, null); else msg = null; @@ -241,7 +242,7 @@ internal bool AnyRowsPage(Pages pgs, Rows data) RunPageRegionBegin(pgs); // still perform page break if needed PageText pt = new PageText(msg); - SetPagePositionAndStyle(pgs.Report, pt, null); + await SetPagePositionAndStyle(pgs.Report, pt, null); if (pt.SI.BackgroundImage != null) pt.SI.BackgroundImage.H = pt.H; // and in the background image @@ -255,7 +256,7 @@ internal bool AnyRowsPage(Pages pgs, Rows data) return false; } - internal Rows GetFilteredData(Report rpt, Row row) + internal async Task GetFilteredData(Report rpt, Row row) { try { @@ -291,7 +292,7 @@ internal Rows GetFilteredData(Report rpt, Row row) } ar.TrimExcess(); data.Data = ar; - _Filters.ApplyFinalFilters(rpt, data, true); + await _Filters.ApplyFinalFilters(rpt, data, true); // Adjust the rowcount int rCount = 0; diff --git a/RdlEngine/Definition/DataSetDefn.cs b/RdlEngine/Definition/DataSetDefn.cs index 6d8c1c51..a1c22f15 100644 --- a/RdlEngine/Definition/DataSetDefn.cs +++ b/RdlEngine/Definition/DataSetDefn.cs @@ -28,6 +28,7 @@ the website www.fyiReporting.com. using System.IO; using System.Data; using System.Data.SqlClient; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -157,14 +158,14 @@ internal DataSetDefn(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } - override internal void FinalPass() + async override internal Task FinalPass() { - if (_Query != null) // query must be resolved before fields - _Query.FinalPass(); + if (_Query != null) // query must be resolved before fields + await _Query.FinalPass(); if (_Fields != null) - _Fields.FinalPass(); + await _Fields.FinalPass(); if (_Filters != null) - _Filters.FinalPass(); + await _Filters.FinalPass(); return; } @@ -175,7 +176,7 @@ internal void AddHideDuplicates(Textbox tb) _HideDuplicates.Add(tb); } - internal bool GetData(Report rpt) + internal async Task GetData(Report rpt) { ResetHideDuplicates(rpt); @@ -188,7 +189,7 @@ internal bool GetData(Report rpt) xdata = _XmlRowData; // didn't find any data } - bRows = _Query.GetData(rpt, xdata, _Fields, _Filters); // get the data (and apply the filters + bRows = await _Query.GetData(rpt, xdata, _Fields, _Filters); // get the data (and apply the filters return bRows; } @@ -197,7 +198,7 @@ internal bool GetData(Report rpt) return bRows; } - bRows = _Query.GetData(rpt, this._Fields, _Filters); // get the data (and apply the filters + bRows = await _Query.GetData(rpt, this._Fields, _Filters); // get the data (and apply the filters return bRows; } @@ -244,24 +245,24 @@ private string GetDataFile(Report rpt, string file) return d; } - internal void SetData(Report rpt, IDataReader dr) + internal async Task SetData(Report rpt, IDataReader dr) { - Query.SetData(rpt, dr, _Fields, _Filters); // get the data (and apply the filters + await Query.SetData(rpt, dr, _Fields, _Filters); // get the data (and apply the filters } - internal void SetData(Report rpt, DataTable dt) + internal async Task SetData(Report rpt, DataTable dt) { - Query.SetData(rpt, dt, _Fields, _Filters); + await Query.SetData(rpt, dt, _Fields, _Filters); } - internal void SetData(Report rpt, XmlDocument xmlDoc) + internal async Task SetData(Report rpt, XmlDocument xmlDoc) { - Query.SetData(rpt, xmlDoc, _Fields, _Filters); + await Query.SetData(rpt, xmlDoc, _Fields, _Filters); } - internal void SetData(Report rpt, IEnumerable ie) + internal async Task SetData(Report rpt, IEnumerable ie) { - Query.SetData(rpt, ie, _Fields, _Filters); + await Query.SetData(rpt, ie, _Fields, _Filters); } internal void ResetHideDuplicates(Report rpt) diff --git a/RdlEngine/Definition/DataSetReference.cs b/RdlEngine/Definition/DataSetReference.cs index 4f57dc99..e36ebd2b 100644 --- a/RdlEngine/Definition/DataSetReference.cs +++ b/RdlEngine/Definition/DataSetReference.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -75,7 +76,7 @@ internal DataSetReference(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p OwnerReport.rl.LogError(8, "DataSetReference ValueField is required but not specified for" + _DataSetName==null? "": _DataSetName); } - override internal void FinalPass() + override internal Task FinalPass() { _ds = OwnerReport.DataSetsDefn[this._DataSetName]; if (_ds == null) @@ -98,7 +99,7 @@ override internal void FinalPass() } } - return; + return Task.CompletedTask; } internal string DataSetName @@ -119,10 +120,8 @@ internal string LabelField set { _LabelField = value; } } - internal void SupplyValues(Report rpt, out string[] displayValues, out object[] dataValues) + internal async Task<(string[] displayValues, object[] dataValues)> SupplyValues(Report rpt) { - displayValues = null; - dataValues = null; Rows rows = _ds.Query.GetMyData(rpt); if (rows == null) // do we already have data? { @@ -130,17 +129,17 @@ internal void SupplyValues(Report rpt, out string[] displayValues, out object[] // should mark a dataset as only having one retrieval??? bool lConnect = _ds.Query.DataSourceDefn.IsConnected(rpt); if (!lConnect) - _ds.Query.DataSourceDefn.ConnectDataSource(rpt); // connect; since not already connected - _ds.GetData(rpt); // get the data + await _ds.Query.DataSourceDefn.ConnectDataSource(rpt); // connect; since not already connected + await _ds.GetData(rpt); // get the data if (!lConnect) // if we connected; then _ds.Query.DataSourceDefn.CleanUp(rpt); // we cleanup rows = _ds.Query.GetMyData(rpt); if (rows == null) // any data now? - return; // no out of luck + return (null, null); // no out of luck } - displayValues = new string[rows.Data.Count]; - dataValues = new object[displayValues.Length]; + var displayValues = new string[rows.Data.Count]; + var dataValues = new object[displayValues.Length]; int index=0; object o; foreach (Row r in rows.Data) @@ -153,6 +152,7 @@ internal void SupplyValues(Report rpt, out string[] displayValues, out object[] displayValues[index] = o.ToString(); index++; } - } + return (displayValues, dataValues); + } } } diff --git a/RdlEngine/Definition/DataSetsDefn.cs b/RdlEngine/Definition/DataSetsDefn.cs index 318c59ed..c0349318 100644 --- a/RdlEngine/Definition/DataSetsDefn.cs +++ b/RdlEngine/Definition/DataSetsDefn.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Specialized; +using System.Threading.Tasks; using System.Xml; @@ -66,21 +67,21 @@ internal DataSetDefn this[string name] } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (DataSetDefn ds in _Items.Values) { - ds.FinalPass(); + await ds.FinalPass(); } return; } - internal bool GetData(Report rpt) + internal async Task GetData(Report rpt) { bool haveRows = false; foreach (DataSetDefn ds in _Items.Values) { - haveRows |= ds.GetData(rpt); + haveRows |= await ds.GetData(rpt); } return haveRows; diff --git a/RdlEngine/Definition/DataSourceDefn.cs b/RdlEngine/Definition/DataSourceDefn.cs index 0e3cf848..f7d5337c 100644 --- a/RdlEngine/Definition/DataSourceDefn.cs +++ b/RdlEngine/Definition/DataSourceDefn.cs @@ -99,12 +99,12 @@ internal DataSourceDefn(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, string.Format("Either ConnectionProperties or DataSourceReference must be specified for DataSource {0} but not both.", this._Name.Nm)); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ConnectionProperties != null) - _ConnectionProperties.FinalPass(); + await _ConnectionProperties.FinalPass(); - ConnectDataSource(null); + await ConnectDataSource(null); return; } @@ -130,7 +130,7 @@ internal bool AreSameDataSource(DataSourceDefn dsd) cp1.IntegratedSecurity == cp2.IntegratedSecurity); } - internal bool ConnectDataSource(Report rpt) + async internal Task ConnectDataSource(Report rpt) { IDbConnection cn = GetConnection(rpt); if (cn != null) @@ -140,7 +140,7 @@ internal bool ConnectDataSource(Report rpt) if (_DataSourceReference != null) { - ConnectDataSourceReference(rpt); // this will create a _ConnectionProperties + await ConnectDataSourceReference(rpt); // this will create a _ConnectionProperties } if (_ConnectionProperties == null || @@ -153,10 +153,17 @@ internal bool ConnectDataSource(Report rpt) try { cn = RdlEngineConfig.GetConnection(_ConnectionProperties.DataProvider, - _ConnectionProperties.Connectstring(rpt)); + await _ConnectionProperties.Connectstring(rpt)); if (cn != null) { - cn.Open(); + if (cn is DbConnection dbConnection) + { + await dbConnection.OpenAsync(); + } + else + { + cn.Open(); + } rc = true; } } @@ -179,7 +186,7 @@ async internal Task ConnectDataSourceAsync(Report rpt) if (_DataSourceReference != null) { - ConnectDataSourceReference(rpt); // this will create a _ConnectionProperties + await ConnectDataSourceReference(rpt); // this will create a _ConnectionProperties } if (_ConnectionProperties == null || @@ -192,7 +199,7 @@ async internal Task ConnectDataSourceAsync(Report rpt) try { cn = RdlEngineConfig.GetConnection(_ConnectionProperties.DataProvider, - _ConnectionProperties.Connectstring(rpt)); + await _ConnectionProperties.Connectstring(rpt)); if (cn != null) { if (cn is DbConnection dbConnection) @@ -246,7 +253,7 @@ private IDbConnection HandleConnectionError(Report rpt, IDbConnection cn, Except return cn; } - void ConnectDataSourceReference(Report rpt) + async Task ConnectDataSourceReference(Report rpt) { if (_ConnectionProperties != null) return; @@ -278,7 +285,7 @@ void ConnectDataSourceReference(Report rpt) XmlNode xNodeLoop = xDoc.FirstChild; _ConnectionProperties = new ConnectionProperties(OwnerReport, this, xNodeLoop); - _ConnectionProperties.FinalPass(); + await _ConnectionProperties.FinalPass(); } catch (Exception e) { diff --git a/RdlEngine/Definition/DataSourcesDefn.cs b/RdlEngine/Definition/DataSourcesDefn.cs index 3e103009..9454e342 100644 --- a/RdlEngine/Definition/DataSourcesDefn.cs +++ b/RdlEngine/Definition/DataSourcesDefn.cs @@ -77,11 +77,11 @@ internal void CleanUp(Report rpt) // closes any connections } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (DataSourceDefn ds in _Items.Values) { - ds.FinalPass(); + await ds.FinalPass(); } return; } diff --git a/RdlEngine/Definition/DataValue.cs b/RdlEngine/Definition/DataValue.cs index 56d7765c..d795ad3f 100644 --- a/RdlEngine/Definition/DataValue.cs +++ b/RdlEngine/Definition/DataValue.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -57,10 +58,10 @@ internal DataValue(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Value != null) - _Value.FinalPass(); + await _Value.FinalPass(); return; } diff --git a/RdlEngine/Definition/DataValues.cs b/RdlEngine/Definition/DataValues.cs index 8471704a..7939720d 100644 --- a/RdlEngine/Definition/DataValues.cs +++ b/RdlEngine/Definition/DataValues.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal DataValues(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (DataValue dv in _Items) { - dv.FinalPass(); + await dv.FinalPass(); } return; } diff --git a/RdlEngine/Definition/DefaultValue.cs b/RdlEngine/Definition/DefaultValue.cs index 2f81e004..376ade3f 100644 --- a/RdlEngine/Definition/DefaultValue.cs +++ b/RdlEngine/Definition/DefaultValue.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -61,12 +62,12 @@ internal DefaultValue(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DataSetReference != null) - _DataSetReference.FinalPass(); + await _DataSetReference.FinalPass(); if (_Values != null) - _Values.FinalPass(); + await _Values.FinalPass(); return; } @@ -76,7 +77,7 @@ internal DataSetReference DataSetReference set { _DataSetReference = value; } } - internal object[] GetValue(Report rpt) + internal async Task GetValue(Report rpt) { if (_Values != null) return ValuesCalc(rpt); @@ -86,7 +87,7 @@ internal object[] GetValue(Report rpt) string[] dsValues; if (_DataSetReference != null) - _DataSetReference.SupplyValues(rpt, out dsValues, out dValues); + (dsValues, dValues) = await _DataSetReference.SupplyValues(rpt); this.SetDataValues(rpt, dValues); return dValues; diff --git a/RdlEngine/Definition/Details.cs b/RdlEngine/Definition/Details.cs index a0ca4557..2a221ad9 100644 --- a/RdlEngine/Definition/Details.cs +++ b/RdlEngine/Definition/Details.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -77,16 +78,16 @@ internal Details(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "Details requires the TableRows element."); } - override internal void FinalPass() + async override internal Task FinalPass() { - _TableRows.FinalPass(); + await _TableRows.FinalPass(); if (_Grouping != null) - _Grouping.FinalPass(); + await _Grouping.FinalPass(); if (_Sorting != null) - _Sorting.FinalPass(); + await _Sorting.FinalPass(); if (_Visibility != null) { - _Visibility.FinalPass(); + await _Visibility.FinalPass(); if (_Visibility.ToggleItem != null) { _ToggleTextbox = (Textbox) (OwnerReport.LUReportItems[_Visibility.ToggleItem]); @@ -97,28 +98,28 @@ override internal void FinalPass() return; } - internal void Run(IPresent ip, Rows rs, int start, int end) + internal async Task Run(IPresent ip, Rows rs, int start, int end) { // if no rows output or rows just leave if (rs == null || rs.Data == null) return; - if (this.Visibility != null && Visibility.IsHidden(ip.Report(), rs.Data[start]) && Visibility.ToggleItem == null) + if (this.Visibility != null && await Visibility.IsHidden(ip.Report(), rs.Data[start]) && Visibility.ToggleItem == null) return; // not visible for (int r=start; r <= end; r++) { - _TableRows.Run(ip, rs.Data[r]); + await _TableRows.Run(ip, rs.Data[r]); } return; } - internal void RunPage(Pages pgs, Rows rs, int start, int end, float footerHeight) + internal async Task RunPage(Pages pgs, Rows rs, int start, int end, float footerHeight) { // if no rows output or rows just leave if (rs == null || rs.Data == null) return; - if (this.Visibility != null && Visibility.IsHidden(pgs.Report, rs.Data[start])) + if (this.Visibility != null && await Visibility.IsHidden(pgs.Report, rs.Data[start])) return; // not visible Page p; @@ -128,23 +129,23 @@ internal void RunPage(Pages pgs, Rows rs, int start, int end, float footerHeight { p = pgs.CurrentPage; // this can change after running a row row = rs.Data[r]; - float hrows = HeightOfRows(pgs, row); // height of all the rows in the details + float hrows = await HeightOfRows(pgs, row); // height of all the rows in the details float height = p.YOffset + hrows; // add the footerheight that must be on every page - height += OwnerTable.GetPageFooterHeight(pgs, row); + height += await OwnerTable.GetPageFooterHeight(pgs, row); if (r == end) height += footerHeight; // on last row; may need additional room for footer if (height > pgs.BottomOfPage) { - OwnerTable.RunPageFooter(pgs, row, false); + await OwnerTable.RunPageFooter(pgs, row, false); p = OwnerTable.RunPageNew(pgs, p); - OwnerTable.RunPageHeader(pgs, row, false, null); - _TableRows.RunPage(pgs, row, true); // force checking since header + hrows might be > BottomOfPage + await OwnerTable.RunPageHeader(pgs, row, false, null); + await _TableRows.RunPage(pgs, row, true); // force checking since header + hrows might be > BottomOfPage } - else - _TableRows.RunPage(pgs, row, hrows > pgs.BottomOfPage); + else + await _TableRows.RunPage(pgs, row, hrows > pgs.BottomOfPage); } return; } @@ -155,14 +156,14 @@ internal TableRows TableRows set { _TableRows = value; } } - internal float HeightOfRows(Pages pgs, Row r) + internal async Task HeightOfRows(Pages pgs, Row r) { - if (this.Visibility != null && Visibility.IsHidden(pgs.Report, r)) + if (this.Visibility != null && await Visibility.IsHidden(pgs.Report, r)) { return 0; } - return _TableRows.HeightOfRows(pgs, r); + return await _TableRows.HeightOfRows(pgs, r); } internal Grouping Grouping diff --git a/RdlEngine/Definition/Drillthrough.cs b/RdlEngine/Definition/Drillthrough.cs index dc84190f..edf6e361 100644 --- a/RdlEngine/Definition/Drillthrough.cs +++ b/RdlEngine/Definition/Drillthrough.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -62,10 +63,10 @@ internal Drillthrough(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "Drillthrough requires the ReportName element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DrillthroughParameters != null) - _DrillthroughParameters.FinalPass(); + await _DrillthroughParameters.FinalPass(); return; } diff --git a/RdlEngine/Definition/DrillthroughParameter.cs b/RdlEngine/Definition/DrillthroughParameter.cs index e8a47a17..a8fa9c17 100644 --- a/RdlEngine/Definition/DrillthroughParameter.cs +++ b/RdlEngine/Definition/DrillthroughParameter.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -80,12 +81,12 @@ internal DrillthroughParameter(ReportDefn r, ReportLink p, XmlNode xNode) : base } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Value != null) - _Value.FinalPass(); + await _Value.FinalPass(); if (_Omit != null) - _Omit.FinalPass(); + await _Omit.FinalPass(); return; } @@ -101,12 +102,12 @@ internal Expression Value set { _Value = value; } } - internal string ValueValue(Report rpt, Row r) + internal async Task ValueValue(Report rpt, Row r) { if (_Value == null) return ""; - return _Value.EvaluateString(rpt, r); + return await _Value.EvaluateString(rpt, r); } internal Expression Omit @@ -115,12 +116,12 @@ internal Expression Omit set { _Omit = value; } } - internal bool OmitValue(Report rpt, Row r) + internal async Task OmitValue(Report rpt, Row r) { if (_Omit == null) return false; - return _Omit.EvaluateBoolean(rpt, r); + return await _Omit.EvaluateBoolean(rpt, r); } } } diff --git a/RdlEngine/Definition/DrillthroughParameters.cs b/RdlEngine/Definition/DrillthroughParameters.cs index 8d16bd33..dd116d16 100644 --- a/RdlEngine/Definition/DrillthroughParameters.cs +++ b/RdlEngine/Definition/DrillthroughParameters.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -62,11 +63,11 @@ internal DrillthroughParameters(ReportDefn r, ReportLink p, XmlNode xNode) : bas _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (DrillthroughParameter r in _Items) { - r.FinalPass(); + await r.FinalPass(); } return; } diff --git a/RdlEngine/Definition/DynamicCategories.cs b/RdlEngine/Definition/DynamicCategories.cs index 16f5bba4..80c819d8 100644 --- a/RdlEngine/Definition/DynamicCategories.cs +++ b/RdlEngine/Definition/DynamicCategories.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -68,14 +69,14 @@ internal DynamicCategories(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Grouping != null) - _Grouping.FinalPass(); + await _Grouping.FinalPass(); if (_Sorting != null) - _Sorting.FinalPass(); + await _Sorting.FinalPass(); if (_Label != null) - _Label.FinalPass(); + await _Label.FinalPass(); return; } diff --git a/RdlEngine/Definition/DynamicColumns.cs b/RdlEngine/Definition/DynamicColumns.cs index 28ec5512..4b5b21f1 100644 --- a/RdlEngine/Definition/DynamicColumns.cs +++ b/RdlEngine/Definition/DynamicColumns.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.Collections; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -87,18 +88,18 @@ internal DynamicColumns(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "DynamicColumns requires the ReportItems element defined with exactly one report item."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Grouping != null) - _Grouping.FinalPass(); + await _Grouping.FinalPass(); if (_Sorting != null) - _Sorting.FinalPass(); + await _Sorting.FinalPass(); if (_Subtotal != null) - _Subtotal.FinalPass(); + await _Subtotal.FinalPass(); if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); if (_Visibility != null) - _Visibility.FinalPass(); + await _Visibility.FinalPass(); return; } diff --git a/RdlEngine/Definition/DynamicExpression.cs b/RdlEngine/Definition/DynamicExpression.cs index 3da7579b..b8713885 100644 --- a/RdlEngine/Definition/DynamicExpression.cs +++ b/RdlEngine/Definition/DynamicExpression.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Collections.Specialized; using System.Threading; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -46,10 +47,11 @@ internal DynamicExpression(Report rpt, ReportLink p, string expr, Row row) _Source=expr; _Expr = null; _rl = p; - _Type = DoParse(rpt); + // HACK: async + _Type = Task.Run(async ()=> await DoParse(rpt)).GetAwaiter().GetResult(); } - internal TypeCode DoParse(Report rpt) + internal async Task DoParse(Report rpt) { // optimization: avoid expression overhead if this isn't really an expression if (_Source == null) @@ -121,7 +123,7 @@ internal TypeCode DoParse(Report rpt) try { - _Expr = p.Parse(lu, _Source); + _Expr = await p.Parse(lu, _Source); } catch (Exception e) { @@ -133,7 +135,7 @@ internal TypeCode DoParse(Report rpt) // Optimize removing any expression that always result in a constant try { - _Expr = _Expr.ConstantOptimization(); + _Expr = await _Expr.ConstantOptimization(); } catch(Exception ex) { @@ -187,21 +189,21 @@ public System.TypeCode GetTypeCode() return _Expr.GetTypeCode(); } - public bool IsConstant() + public async Task IsConstant() { - return _Expr.IsConstant(); + return await _Expr.IsConstant(); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { try { - return _Expr.Evaluate(rpt, row); + return await _Expr.Evaluate(rpt, row); } catch (Exception e) { @@ -216,11 +218,11 @@ public object Evaluate(Report rpt, Row row) } } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { try { - return _Expr.EvaluateString(rpt, row); + return await _Expr.EvaluateString(rpt, row); } catch (Exception e) { @@ -230,11 +232,11 @@ public string EvaluateString(Report rpt, Row row) } } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { try { - return _Expr.EvaluateDouble(rpt, row); + return await _Expr.EvaluateDouble(rpt, row); } catch (Exception e) { @@ -244,11 +246,11 @@ public double EvaluateDouble(Report rpt, Row row) } } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { try { - return _Expr.EvaluateDecimal(rpt, row); + return await _Expr.EvaluateDecimal(rpt, row); } catch (Exception e) { @@ -258,11 +260,11 @@ public decimal EvaluateDecimal(Report rpt, Row row) } } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { try { - return _Expr.EvaluateInt32(rpt, row); + return await _Expr.EvaluateInt32(rpt, row); } catch (Exception e) { @@ -272,11 +274,11 @@ public int EvaluateInt32(Report rpt, Row row) } } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { try { - return _Expr.EvaluateDateTime(rpt, row); + return await _Expr.EvaluateDateTime(rpt, row); } catch (Exception e) { @@ -286,11 +288,11 @@ public DateTime EvaluateDateTime(Report rpt, Row row) } } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { try { - return _Expr.EvaluateBoolean(rpt, row); + return await _Expr.EvaluateBoolean(rpt, row); } catch (Exception e) { diff --git a/RdlEngine/Definition/DynamicRows.cs b/RdlEngine/Definition/DynamicRows.cs index 0a809e1b..bf69a41c 100644 --- a/RdlEngine/Definition/DynamicRows.cs +++ b/RdlEngine/Definition/DynamicRows.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.Collections; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -91,18 +92,18 @@ internal DynamicRows(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "DynamicRows requires the ReportItems element defined with exactly one report item."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Grouping != null) - _Grouping.FinalPass(); + await _Grouping.FinalPass(); if (_Sorting != null) - _Sorting.FinalPass(); + await _Sorting.FinalPass(); if (_Subtotal != null) - _Subtotal.FinalPass(); + await _Subtotal.FinalPass(); if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); if (_Visibility != null) - _Visibility.FinalPass(); + await _Visibility.FinalPass(); return; } diff --git a/RdlEngine/Definition/DynamicSeries.cs b/RdlEngine/Definition/DynamicSeries.cs index 60db8efb..c9ce508d 100644 --- a/RdlEngine/Definition/DynamicSeries.cs +++ b/RdlEngine/Definition/DynamicSeries.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -70,14 +71,14 @@ internal DynamicSeries(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Grouping != null) - _Grouping.FinalPass(); + await _Grouping.FinalPass(); if (_Sorting != null) - _Sorting.FinalPass(); + await _Sorting.FinalPass(); if (_Label != null) - _Label.FinalPass(); + await _Label.FinalPass(); return; } diff --git a/RdlEngine/Definition/EmbeddedImage.cs b/RdlEngine/Definition/EmbeddedImage.cs index 2fc236ec..b74d6095 100644 --- a/RdlEngine/Definition/EmbeddedImage.cs +++ b/RdlEngine/Definition/EmbeddedImage.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -93,9 +94,9 @@ internal EmbeddedImage(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "EmbeddedImage ImageData is required but not specified for " + (this.Name == null? "'name not specified'": this.Name.Nm)); } - override internal void FinalPass() + override internal Task FinalPass() { - return; + return Task.CompletedTask; } internal Name Name diff --git a/RdlEngine/Definition/EmbeddedImages.cs b/RdlEngine/Definition/EmbeddedImages.cs index e895884f..882ec2b9 100644 --- a/RdlEngine/Definition/EmbeddedImages.cs +++ b/RdlEngine/Definition/EmbeddedImages.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; @@ -59,11 +60,11 @@ internal EmbeddedImages(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (EmbeddedImage ei in _Items) { - ei.FinalPass(); + await ei.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Expression.cs b/RdlEngine/Definition/Expression.cs index 19e30960..6126c410 100644 --- a/RdlEngine/Definition/Expression.cs +++ b/RdlEngine/Definition/Expression.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Collections.Specialized; using System.Threading; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -58,7 +59,7 @@ internal string UniqueName get {return _UniqueName;} } - override internal void FinalPass() + override internal async Task FinalPass() { // optimization: avoid expression overhead if this isn't really an expression if (_Source == null) @@ -142,7 +143,7 @@ override internal void FinalPass() try { - _Expr = p.Parse(lu, _Source); + _Expr = await p.Parse(lu, _Source); } catch (Exception e) { @@ -154,7 +155,7 @@ override internal void FinalPass() // Optimize removing any expression that always result in a constant try { - _Expr = _Expr.ConstantOptimization(); + _Expr = await _Expr.ConstantOptimization(); } catch(Exception ex) { @@ -218,23 +219,23 @@ public System.TypeCode GetTypeCode() return _Expr.GetTypeCode(); } - public bool IsConstant() + public async Task IsConstant() { if (_Expr == null) { - this.FinalPass(); // expression hasn't been parsed yet -- let try to parse it. + await this.FinalPass(); // expression hasn't been parsed yet -- let try to parse it. if (_Expr == null) return false; // no luck; then don't treat as constant } - return _Expr.IsConstant(); + return await _Expr.IsConstant(); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { try { @@ -247,7 +248,7 @@ public object Evaluate(Report rpt, Row row) row = rows.Data[0]; } - return _Expr.Evaluate(rpt, row); + return await _Expr.Evaluate(rpt, row); } catch (Exception e) { @@ -262,11 +263,11 @@ public object Evaluate(Report rpt, Row row) } } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { try { - return _Expr.EvaluateString(rpt, row); + return await _Expr.EvaluateString(rpt, row); } catch (Exception e) { @@ -276,11 +277,11 @@ public string EvaluateString(Report rpt, Row row) } } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { try { - return _Expr.EvaluateDouble(rpt, row); + return await _Expr.EvaluateDouble(rpt, row); } catch (Exception e) { @@ -290,11 +291,11 @@ public double EvaluateDouble(Report rpt, Row row) } } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { try { - return _Expr.EvaluateDecimal(rpt, row); + return await _Expr.EvaluateDecimal(rpt, row); } catch (Exception e) { @@ -304,11 +305,11 @@ public decimal EvaluateDecimal(Report rpt, Row row) } } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { try { - return _Expr.EvaluateInt32(rpt, row); + return await _Expr.EvaluateInt32(rpt, row); } catch (Exception e) { @@ -318,11 +319,11 @@ public int EvaluateInt32(Report rpt, Row row) } } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { try { - return _Expr.EvaluateDateTime(rpt, row); + return await _Expr.EvaluateDateTime(rpt, row); } catch (Exception e) { @@ -332,11 +333,11 @@ public DateTime EvaluateDateTime(Report rpt, Row row) } } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { try { - return _Expr.EvaluateBoolean(rpt, row); + return await _Expr.EvaluateBoolean(rpt, row); } catch (Exception e) { @@ -348,10 +349,10 @@ public bool EvaluateBoolean(Report rpt, Row row) #endregion - public void SetSource(string sql) + public async Task SetSource(string sql) { this._Source = sql; - FinalPass(); + await FinalPass(); } } diff --git a/RdlEngine/Definition/Field.cs b/RdlEngine/Definition/Field.cs index bbd2f7da..1bd97fa4 100644 --- a/RdlEngine/Definition/Field.cs +++ b/RdlEngine/Definition/Field.cs @@ -21,6 +21,7 @@ limitations under the License. the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -93,10 +94,10 @@ internal Field(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Value != null) - _Value.FinalPass(); + await _Value.FinalPass(); // Resolve the field if specified if (_DataField != null) diff --git a/RdlEngine/Definition/Fields.cs b/RdlEngine/Definition/Fields.cs index 1917c60e..3e172a84 100644 --- a/RdlEngine/Definition/Fields.cs +++ b/RdlEngine/Definition/Fields.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Specialized; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -80,11 +81,11 @@ internal Field this[string s] } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (Field f in _Items.Values) { - f.FinalPass(); + await f.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Filter.cs b/RdlEngine/Definition/Filter.cs index a983ae29..2c62c520 100644 --- a/RdlEngine/Definition/Filter.cs +++ b/RdlEngine/Definition/Filter.cs @@ -28,6 +28,7 @@ the website www.fyiReporting.com. using System.Collections.Generic; using System.Globalization; using RdlEngine.Resources; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -148,10 +149,10 @@ internal Filter(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { - _FilterExpression.FinalPass(); - _FilterValues.FinalPass(); + await _FilterExpression.FinalPass(); + await _FilterValues.FinalPass(); return; } @@ -212,12 +213,12 @@ internal bool Apply(Report rpt, Row datarow) } } - internal void Apply(Report rpt, Rows data) + internal async Task Apply(Report rpt, Rows data) { if (this._FilterOperatorSingleRow) ApplySingleRowFilter(rpt, data); else - ApplyTopBottomFilter(rpt, data); + await ApplyTopBottomFilter(rpt, data); } private void ApplySingleRowFilter(Report rpt, Rows data) @@ -237,14 +238,14 @@ private void ApplySingleRowFilter(Report rpt, Rows data) return; } - private void ApplyTopBottomFilter(Report rpt, Rows data) + private async Task ApplyTopBottomFilter(Report rpt, Rows data) { if (data.Data.Count <= 0) // No data; nothing to do return; // Get the filter value and validate it FilterValue fv = this._FilterValues.Items[0]; - double val = fv.Expression.EvaluateDouble(rpt, data.Data[0]); + double val = await fv.Expression.EvaluateDouble(rpt, data.Data[0]); if (val <= 0) // if less than equal 0; then request results in no data { data.Data.Clear(); diff --git a/RdlEngine/Definition/FilterValue.cs b/RdlEngine/Definition/FilterValue.cs index be5f6bae..3566e9a5 100644 --- a/RdlEngine/Definition/FilterValue.cs +++ b/RdlEngine/Definition/FilterValue.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -40,10 +41,10 @@ internal FilterValue(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Expression != null) - _Expression.FinalPass(); + await _Expression.FinalPass(); return; } diff --git a/RdlEngine/Definition/FilterValues.cs b/RdlEngine/Definition/FilterValues.cs index 8a0b669c..2701b0ab 100644 --- a/RdlEngine/Definition/FilterValues.cs +++ b/RdlEngine/Definition/FilterValues.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -65,11 +66,11 @@ internal FilterValues(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (FilterValue f in _Items) { - f.FinalPass(); + await f.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Filters.cs b/RdlEngine/Definition/Filters.cs index a1193648..2362a6e3 100644 --- a/RdlEngine/Definition/Filters.cs +++ b/RdlEngine/Definition/Filters.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal Filters(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (Filter f in _Items) { - f.FinalPass(); + await f.FinalPass(); } return; } @@ -85,7 +86,7 @@ internal bool Apply(Report rpt, Row datarow) return true; } - internal void ApplyFinalFilters(Report rpt, Rows data, bool makeCopy) + internal async Task ApplyFinalFilters(Report rpt, Rows data, bool makeCopy) { // Need to apply the Top/Bottom and then the rest of the data @@ -112,7 +113,7 @@ internal void ApplyFinalFilters(Report rpt, Rows data, bool makeCopy) for (; iFilter < _Items.Count && data.Data.Count > 0; iFilter++) { Filter f = (Filter) _Items[iFilter]; - f.Apply(rpt, data); + await f.Apply(rpt, data); } // trim the space diff --git a/RdlEngine/Definition/Footer.cs b/RdlEngine/Definition/Footer.cs index 1d4fb67d..4d66efd5 100644 --- a/RdlEngine/Definition/Footer.cs +++ b/RdlEngine/Definition/Footer.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -65,28 +66,28 @@ internal Footer(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "TableRows element is required with a Footer but not specified."); } - override internal void FinalPass() + async override internal Task FinalPass() { - _TableRows.FinalPass(); + await _TableRows.FinalPass(); return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { - _TableRows.Run(ip, row); + await _TableRows.Run(ip, row); return; } - internal void RunPage(Pages pgs, Row row) + internal async Task RunPage(Pages pgs, Row row) { Page p = pgs.CurrentPage; - if (p.YOffset + HeightOfRows(pgs, row) > pgs.BottomOfPage) + if (p.YOffset + await HeightOfRows(pgs, row) > pgs.BottomOfPage) { p = OwnerTable.RunPageNew(pgs, p); - OwnerTable.RunPageHeader(pgs, row, false, null); + await OwnerTable.RunPageHeader(pgs, row, false, null); } - _TableRows.RunPage(pgs, row); + await _TableRows.RunPage(pgs, row); return; } @@ -97,9 +98,9 @@ internal TableRows TableRows set { _TableRows = value; } } - internal float HeightOfRows(Pages pgs, Row r) + internal async Task HeightOfRows(Pages pgs, Row r) { - return _TableRows.HeightOfRows(pgs, r); + return await _TableRows.HeightOfRows(pgs, r); } internal bool RepeatOnNewPage diff --git a/RdlEngine/Definition/GroupExpression.cs b/RdlEngine/Definition/GroupExpression.cs index ab6e0484..e536aaae 100644 --- a/RdlEngine/Definition/GroupExpression.cs +++ b/RdlEngine/Definition/GroupExpression.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -40,10 +41,10 @@ internal GroupExpression(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Expression != null) - _Expression.FinalPass(); + await _Expression.FinalPass(); return; } diff --git a/RdlEngine/Definition/GroupExpressions.cs b/RdlEngine/Definition/GroupExpressions.cs index 8b6301ba..6f71ce18 100644 --- a/RdlEngine/Definition/GroupExpressions.cs +++ b/RdlEngine/Definition/GroupExpressions.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal GroupExpressions(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (GroupExpression g in _Items) { - g.FinalPass(); + await g.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Grouping.cs b/RdlEngine/Definition/Grouping.cs index 56b31ec3..76bc6412 100644 --- a/RdlEngine/Definition/Grouping.cs +++ b/RdlEngine/Definition/Grouping.cs @@ -25,6 +25,7 @@ the website www.fyiReporting.com. using System.Xml; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -172,20 +173,20 @@ internal Grouping(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Label != null) - _Label.FinalPass(); + await _Label.FinalPass(); if (_GroupExpressions != null) - _GroupExpressions.FinalPass(); + await _GroupExpressions.FinalPass(); if (_Custom != null) - _Custom.FinalPass(); + await _Custom.FinalPass(); if (_Filters != null) - _Filters.FinalPass(); + await _Filters.FinalPass(); if (_ParentGroup != null) - _ParentGroup.FinalPass(); + await _ParentGroup.FinalPass(); if (_PageBreakCondition != null) - _PageBreakCondition.FinalPass(); + await _PageBreakCondition.FinalPass(); // Determine if group is defined inside of a Matrix; these get // different runtime expression handling in FunctionAggr @@ -255,11 +256,11 @@ internal bool PageBreakAtEnd set { _PageBreakAtEnd = value; } } - internal bool PageBreakCondition(Report r, Row row, bool SeMancaDefinizione) + internal async Task PageBreakCondition(Report r, Row row, bool SeMancaDefinizione) { bool result; if (_PageBreakCondition != null) - result = _PageBreakCondition.EvaluateBoolean(r, row); + result = await _PageBreakCondition.EvaluateBoolean(r, row); else result = SeMancaDefinizione; return result; diff --git a/RdlEngine/Definition/Header.cs b/RdlEngine/Definition/Header.cs index 9b7f875a..a1c49535 100644 --- a/RdlEngine/Definition/Header.cs +++ b/RdlEngine/Definition/Header.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -63,21 +64,21 @@ internal Header(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "Header requires the TableRows element."); } - override internal void FinalPass() + async override internal Task FinalPass() { - _TableRows.FinalPass(); + await _TableRows.FinalPass(); OwnerReport.DataCache.Add(this); return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { - _TableRows.Run(ip, row); + await _TableRows.Run(ip, row); return; } - internal void RunPage(Pages pgs, Row row) + internal async Task RunPage(Pages pgs, Row row) { WorkClass wc = this.GetValue(pgs.Report); @@ -86,19 +87,19 @@ internal void RunPage(Pages pgs, Row row) Page p = pgs.CurrentPage; - float height = p.YOffset + HeightOfRows(pgs, row); - height += OwnerTable.GetPageFooterHeight(pgs, row); + float height = p.YOffset + await HeightOfRows(pgs, row); + height += await OwnerTable.GetPageFooterHeight(pgs, row); if (height > pgs.BottomOfPage) { Table t = OwnerTable; - t.RunPageFooter(pgs, row, false); + await t.RunPageFooter(pgs, row, false); p = t.RunPageNew(pgs, p); - t.RunPageHeader(pgs, row, false, null); + await t.RunPageHeader(pgs, row, false, null); if (this.RepeatOnNewPage) return; // should already be on the page } - _TableRows.RunPage(pgs, row); + await _TableRows.RunPage(pgs, row); wc.OutputRow = row; wc.OutputPage = pgs.CurrentPage; return; @@ -124,9 +125,9 @@ internal TableRows TableRows set { _TableRows = value; } } - internal float HeightOfRows(Pages pgs, Row r) + internal async Task HeightOfRows(Pages pgs, Row r) { - return _TableRows.HeightOfRows(pgs, r); + return await _TableRows.HeightOfRows(pgs, r); } internal bool RepeatOnNewPage diff --git a/RdlEngine/Definition/Image.cs b/RdlEngine/Definition/Image.cs index 747e9983..d929b167 100644 --- a/RdlEngine/Definition/Image.cs +++ b/RdlEngine/Definition/Image.cs @@ -35,6 +35,7 @@ the website www.fyiReporting.com. using System.Collections.Specialized; using System.Threading; using System.Net; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -43,35 +44,36 @@ namespace fyiReporting.RDL /// Represents an image. Source of image can from database, external or embedded. /// [Serializable] - internal class Image : ReportItem - { - ImageSourceEnum _ImageSource; // Identifies the source of the image: - Expression _Value; // See Source. Expected datatype is string or - // binary, depending on Source. If the Value is - // null, no image is displayed. - Expression _MIMEType; // (string) An expression, the value of which is the - // MIMEType for the image. - // Valid values are: image/bmp, image/jpeg, - // image/gif, image/png, image/x-png - // Required if Source = Database. Ignored otherwise. - ImageSizingEnum _Sizing; // Defines the behavior if the image does not fit within the specified size. - - bool _ConstantImage; // true if Image is a constant at runtime + internal class Image : ReportItem + { + ImageSourceEnum _ImageSource; // Identifies the source of the image: + Expression _Value; // See Source. Expected datatype is string or + // binary, depending on Source. If the Value is + // null, no image is displayed. + Expression _MIMEType; // (string) An expression, the value of which is the + // MIMEType for the image. + // Valid values are: image/bmp, image/jpeg, + // image/gif, image/png, image/x-png + // Required if Source = Database. Ignored otherwise. + ImageSizingEnum _Sizing; // Defines the behavior if the image does not fit within the specified size. + + bool _ConstantImage; // true if Image is a constant at runtime string _EmbeddedImageData; // only for RenderHtml and embeddedImage. we need the embedded image code for html. private string imageUrl; //Added from forum, User: solidstate http://www.fyireporting.com/forum/viewtopic.php?t=905 - private static void CopyStream(Stream src, Stream dst) - { - byte[] buffer = new byte[16 * 1024]; + private static void CopyStream(Stream src, Stream dst) + { + byte[] buffer = new byte[16 * 1024]; int bytesRead; - while ((bytesRead = src.Read(buffer, 0, buffer.Length)) > 0) { + while ((bytesRead = src.Read(buffer, 0, buffer.Length)) > 0) + { dst.Write(buffer, 0, bytesRead); } - } - + } + /// /// Only gets set for Images which contain urls rather than coming from the database etc.. /// @@ -79,292 +81,292 @@ public string ImageUrl { get { return imageUrl; } private set { imageUrl = value; } - } - - internal Image(ReportDefn r, ReportLink p, XmlNode xNode):base(r,p,xNode) - { - _ImageSource=ImageSourceEnum.Unknown; - _Value=null; - _MIMEType=null; - _Sizing=ImageSizingEnum.AutoSize; - _ConstantImage = false; - - // Loop thru all the child nodes - foreach(XmlNode xNodeLoop in xNode.ChildNodes) - { - if (xNodeLoop.NodeType != XmlNodeType.Element) - continue; - switch (xNodeLoop.Name) - { - case "Source": - _ImageSource = fyiReporting.RDL.ImageSource.GetStyle(xNodeLoop.InnerText); - break; - case "Value": - _Value = new Expression(r, this, xNodeLoop, ExpressionType.Variant); - break; - case "MIMEType": - _MIMEType = new Expression(r, this, xNodeLoop, ExpressionType.String); - break; - case "Sizing": - _Sizing = ImageSizing.GetStyle(xNodeLoop.InnerText, OwnerReport.rl); - break; - default: - if (ReportItemElement(xNodeLoop)) // try at ReportItem level - break; - // don't know this element - log it - OwnerReport.rl.LogError(4, "Unknown Image element " + xNodeLoop.Name + " ignored."); - break; - } - } - if (_ImageSource==ImageSourceEnum.Unknown) - OwnerReport.rl.LogError(8, "Image requires a Source element."); - if (_Value == null) - OwnerReport.rl.LogError(8, "Image requires the Value element."); - } - - // Handle parsing of function in final pass - override internal void FinalPass() - { - base.FinalPass(); - - _Value.FinalPass(); - if (_MIMEType != null) - _MIMEType.FinalPass(); - - _ConstantImage = this.IsConstant(); - - return; - } - - // Returns true if the image and style remain constant at runtime - bool IsConstant() - { - - if (_Value.IsConstant()) - { - if (_MIMEType == null || _MIMEType.IsConstant()) - { -// if (this.Style == null || this.Style.ConstantStyle) -// return true; - return true; // ok if style changes - } - } - return false; - } - - override internal void Run(IPresent ip, Row row) - { - base.Run(ip, row); - - string mtype=null; - Stream strm=null; - try - { - strm = GetImageStream(ip.Report(), row, out mtype); - - ip.Image(this, row, mtype, strm); - } - catch - { - // image failed to load; continue processing - } - finally - { - if (strm != null) - strm.Close(); - } - return; - } - - override internal void RunPage(Pages pgs, Row row) - { - Report r = pgs.Report; - bool bHidden = IsHidden(r, row); - - WorkClass wc = GetWC(r); - string mtype=null; - Stream strm=null; - Drawing.Image im=null; - - SetPagePositionBegin(pgs); + } + + internal Image(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p, xNode) + { + _ImageSource = ImageSourceEnum.Unknown; + _Value = null; + _MIMEType = null; + _Sizing = ImageSizingEnum.AutoSize; + _ConstantImage = false; + + // Loop thru all the child nodes + foreach (XmlNode xNodeLoop in xNode.ChildNodes) + { + if (xNodeLoop.NodeType != XmlNodeType.Element) + continue; + switch (xNodeLoop.Name) + { + case "Source": + _ImageSource = fyiReporting.RDL.ImageSource.GetStyle(xNodeLoop.InnerText); + break; + case "Value": + _Value = new Expression(r, this, xNodeLoop, ExpressionType.Variant); + break; + case "MIMEType": + _MIMEType = new Expression(r, this, xNodeLoop, ExpressionType.String); + break; + case "Sizing": + _Sizing = ImageSizing.GetStyle(xNodeLoop.InnerText, OwnerReport.rl); + break; + default: + if (ReportItemElement(xNodeLoop)) // try at ReportItem level + break; + // don't know this element - log it + OwnerReport.rl.LogError(4, "Unknown Image element " + xNodeLoop.Name + " ignored."); + break; + } + } + if (_ImageSource == ImageSourceEnum.Unknown) + OwnerReport.rl.LogError(8, "Image requires a Source element."); + if (_Value == null) + OwnerReport.rl.LogError(8, "Image requires the Value element."); + } + + // Handle parsing of function in final pass + async override internal Task FinalPass() + { + await base.FinalPass(); + + await _Value.FinalPass(); + if (_MIMEType != null) + await _MIMEType.FinalPass(); + + _ConstantImage = await this.IsConstant(); + + return; + } + + // Returns true if the image and style remain constant at runtime + async Task IsConstant() + { + + if (await _Value.IsConstant()) + { + if (_MIMEType == null || await _MIMEType.IsConstant()) + { + // if (this.Style == null || this.Style.ConstantStyle) + // return true; + return true; // ok if style changes + } + } + return false; + } + + async override internal Task Run(IPresent ip, Row row) + { + await base.Run(ip, row); + + string mtype = null; + Stream strm = null; + try + { + (strm, mtype) = await GetImageStream(ip.Report(), row); + + await ip.Image(this, row, mtype, strm); + } + catch + { + // image failed to load; continue processing + } + finally + { + if (strm != null) + strm.Close(); + } + return; + } + + override internal async Task RunPage(Pages pgs, Row row) + { + Report r = pgs.Report; + bool bHidden = await IsHidden(r, row); + + WorkClass wc = GetWC(r); + string mtype = null; + Stream strm = null; + Drawing.Image im = null; + + SetPagePositionBegin(pgs); if (bHidden) { PageImage pi = new PageImage(ImageFormat.Jpeg, (byte[])null, 0, 0); - this.SetPagePositionAndStyle(r, pi, row); + await this.SetPagePositionAndStyle(r, pi, row); SetPagePositionEnd(pgs, pi.Y + pi.H); return; } - if (wc.PgImage != null) - { // have we already generated this one - // reuse most of the work; only position will likely change - PageImage pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.GetImageData(), wc.PgImage.SamplesW, wc.PgImage.SamplesH); - pi.Name = wc.PgImage.Name; // this is name it will be shared under - pi.Sizing = this._Sizing; - this.SetPagePositionAndStyle(r, pi, row); - pgs.CurrentPage.AddObject(pi); + if (wc.PgImage != null) + { // have we already generated this one + // reuse most of the work; only position will likely change + PageImage pi = new PageImage(wc.PgImage.ImgFormat, wc.PgImage.GetImageData(), wc.PgImage.SamplesW, wc.PgImage.SamplesH); + pi.Name = wc.PgImage.Name; // this is name it will be shared under + pi.Sizing = this._Sizing; + await this.SetPagePositionAndStyle(r, pi, row); + pgs.CurrentPage.AddObject(pi); SetPagePositionEnd(pgs, pi.Y + pi.H); - return; - } + return; + } - try - { - strm = GetImageStream(r, row, out mtype); + try + { + (strm, mtype) = await GetImageStream(r, row); if (strm == null) { r.rl.LogError(4, string.Format("Unable to load image {0}.", this.Name.Nm)); return; } - im = Drawing.Image.FromStream(strm); - int height = im.Height; - int width = im.Width; - MemoryStream ostrm = new MemoryStream(); - strm.Position = 0; - ImageFormat imf; - switch(mtype.ToLower()) - { - case "image/jpeg" : - imf = ImageFormat.Jpeg; - CopyStream(strm, ostrm); - break; - case "image/png": - imf = ImageFormat.Png; - CopyStream(strm, ostrm); - break; - default: // from old code where all images convert to jpeg, i don't know why. May be need delete it and add all support formats. - imf = ImageFormat.Jpeg; - ImageCodecInfo[] info; - info = ImageCodecInfo.GetImageEncoders(); - Drawing.Imaging.EncoderParameters encoderParameters; - encoderParameters = new Drawing.Imaging.EncoderParameters(1); - encoderParameters.Param[0] = new Drawing.Imaging.EncoderParameter(Drawing.Imaging.Encoder.Quality, ImageQualityManager.EmbeddedImageQuality); - ImageCodecInfo codec = null; - for (int i = 0; i < info.Length; i++) - { - if (info[i].FormatDescription == "JPEG") - { - codec = info[i]; - break; - } - } - im.Save(ostrm, codec, encoderParameters); - break; - } - - byte[] ba = ostrm.ToArray(); - ostrm.Close(); - PageImage pi = new PageImage(imf, ba, width, height); - pi.Sizing = this._Sizing; - this.SetPagePositionAndStyle(r, pi, row); - - pgs.CurrentPage.AddObject(pi); - if (_ConstantImage) - { - wc.PgImage = pi; - // create unique name; PDF generation uses this to optimize the saving of the image only once - pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString(); // create unique name - } + im = Drawing.Image.FromStream(strm); + int height = im.Height; + int width = im.Width; + MemoryStream ostrm = new MemoryStream(); + strm.Position = 0; + ImageFormat imf; + switch (mtype.ToLower()) + { + case "image/jpeg": + imf = ImageFormat.Jpeg; + CopyStream(strm, ostrm); + break; + case "image/png": + imf = ImageFormat.Png; + CopyStream(strm, ostrm); + break; + default: // from old code where all images convert to jpeg, i don't know why. May be need delete it and add all support formats. + imf = ImageFormat.Jpeg; + ImageCodecInfo[] info; + info = ImageCodecInfo.GetImageEncoders(); + Drawing.Imaging.EncoderParameters encoderParameters; + encoderParameters = new Drawing.Imaging.EncoderParameters(1); + encoderParameters.Param[0] = new Drawing.Imaging.EncoderParameter(Drawing.Imaging.Encoder.Quality, ImageQualityManager.EmbeddedImageQuality); + ImageCodecInfo codec = null; + for (int i = 0; i < info.Length; i++) + { + if (info[i].FormatDescription == "JPEG") + { + codec = info[i]; + break; + } + } + im.Save(ostrm, codec, encoderParameters); + break; + } + + byte[] ba = ostrm.ToArray(); + ostrm.Close(); + PageImage pi = new PageImage(imf, ba, width, height); + pi.Sizing = this._Sizing; + await this.SetPagePositionAndStyle(r, pi, row); + + pgs.CurrentPage.AddObject(pi); + if (_ConstantImage) + { + wc.PgImage = pi; + // create unique name; PDF generation uses this to optimize the saving of the image only once + pi.Name = "pi" + Interlocked.Increment(ref Parser.Counter).ToString(); // create unique name + } SetPagePositionEnd(pgs, pi.Y + pi.H); } - catch (Exception e) - { - // image failed to load, continue processing - r.rl.LogError(4, "Image load failed. " + e.Message); - } - finally - { - if (strm != null) - strm.Close(); - if (im != null) - im.Dispose(); - } - return; - } - - Stream GetImageStream(Report rpt, Row row, out string mtype) - { - mtype=null; - Stream strm=null; - try - { - switch (this.ImageSource) - { - case ImageSourceEnum.Database: - if (_MIMEType == null) - return null; - mtype = _MIMEType.EvaluateString(rpt, row); - object o = _Value.Evaluate(rpt, row); - strm = new MemoryStream((byte[]) o); - break; - case ImageSourceEnum.Embedded: - string name = _Value.EvaluateString(rpt, row); - EmbeddedImage ei = (EmbeddedImage) OwnerReport.LUEmbeddedImages[name]; - mtype = ei.MIMEType; - byte[] ba = Convert.FromBase64String(ei.ImageData); + catch (Exception e) + { + // image failed to load, continue processing + r.rl.LogError(4, "Image load failed. " + e.Message); + } + finally + { + if (strm != null) + strm.Close(); + if (im != null) + im.Dispose(); + } + return; + } + + async Task<(Stream stream, string mtype)> GetImageStream(Report rpt, Row row) + { + string mtype = null; + Stream strm = null; + try + { + switch (this.ImageSource) + { + case ImageSourceEnum.Database: + if (_MIMEType == null) + return (null, mtype); + mtype = await _MIMEType.EvaluateString(rpt, row); + object o = _Value.Evaluate(rpt, row); + strm = new MemoryStream((byte[])o); + break; + case ImageSourceEnum.Embedded: + string name = await _Value.EvaluateString(rpt, row); + EmbeddedImage ei = (EmbeddedImage)OwnerReport.LUEmbeddedImages[name]; + mtype = ei.MIMEType; + byte[] ba = Convert.FromBase64String(ei.ImageData); _EmbeddedImageData = ei.ImageData; // we need this for html embedded image strm = new MemoryStream(ba); - break; - case ImageSourceEnum.External: - //Added Image URL from forum, User: solidstate http://www.fyireporting.com/forum/viewtopic.php?t=905 - string fname = this.ImageUrl = _Value.EvaluateString(rpt, row); - mtype = GetMimeType(fname); - if (fname.StartsWith("http:") || - fname.StartsWith("file:") || - fname.StartsWith("https:")) - { - WebRequest wreq = WebRequest.Create(fname); - WebResponse wres = wreq.GetResponse(); - strm = wres.GetResponseStream(); - } - else - strm = new FileStream(fname, System.IO.FileMode.Open, FileAccess.Read); - break; - default: - return null; - } - } - catch (Exception e) - { - if (strm != null) - { - strm.Close(); - strm = null; - } - rpt.rl.LogError(4, string.Format("Unable to load image. {0}", e.Message)); - } - - return strm; - } - - internal ImageSourceEnum ImageSource - { - get { return _ImageSource; } - set { _ImageSource = value; } - } - - internal Expression Value - { - get { return _Value; } - set { _Value = value; } - } - - internal Expression MIMEType - { - get { return _MIMEType; } - set { _MIMEType = value; } - } - - internal ImageSizingEnum Sizing - { - get { return _Sizing; } - set { _Sizing = value; } - } - - internal bool ConstantImage - { - get { return _ConstantImage; } - } + break; + case ImageSourceEnum.External: + //Added Image URL from forum, User: solidstate http://www.fyireporting.com/forum/viewtopic.php?t=905 + string fname = this.ImageUrl = await _Value.EvaluateString(rpt, row); + mtype = GetMimeType(fname); + if (fname.StartsWith("http:") || + fname.StartsWith("file:") || + fname.StartsWith("https:")) + { + WebRequest wreq = WebRequest.Create(fname); + WebResponse wres = wreq.GetResponse(); + strm = wres.GetResponseStream(); + } + else + strm = new FileStream(fname, System.IO.FileMode.Open, FileAccess.Read); + break; + default: + return (null, mtype); + } + } + catch (Exception e) + { + if (strm != null) + { + strm.Close(); + strm = null; + } + rpt.rl.LogError(4, string.Format("Unable to load image. {0}", e.Message)); + } + + return (strm, mtype); + } + + internal ImageSourceEnum ImageSource + { + get { return _ImageSource; } + set { _ImageSource = value; } + } + + internal Expression Value + { + get { return _Value; } + set { _Value = value; } + } + + internal Expression MIMEType + { + get { return _MIMEType; } + set { _MIMEType = value; } + } + + internal ImageSizingEnum Sizing + { + get { return _Sizing; } + set { _Sizing = value; } + } + + internal bool ConstantImage + { + get { return _ConstantImage; } + } internal string EmbeddedImageData { @@ -373,58 +375,58 @@ internal string EmbeddedImageData static internal string GetMimeType(string file) - { - String fileExt; - - int startPos = file.LastIndexOf(".") + 1; - - fileExt = file.Substring(startPos).ToLower(); - - switch (fileExt) - { - case "bmp": - return "image/bmp"; - case "jpeg": - case "jpe": - case "jpg": - case "jfif": - return "image/jpeg"; - case "gif": - return "image/gif"; - case "png": - return "image/png"; - case "tif": - case "tiff": - return "image/tiff"; - default: - return null; - } - } - - private WorkClass GetWC(Report rpt) - { - WorkClass wc = rpt.Cache.Get(this, "wc") as WorkClass; - if (wc == null) - { - wc = new WorkClass(); - rpt.Cache.Add(this, "wc", wc); - } - return wc; - } - - private void RemoveImageWC(Report rpt) - { - rpt.Cache.Remove(this, "wc"); - } - - class WorkClass - { - internal PageImage PgImage; // When ConstantImage is true this will save the PageImage for reuse - internal WorkClass() - { - PgImage=null; - } - } - - } + { + String fileExt; + + int startPos = file.LastIndexOf(".") + 1; + + fileExt = file.Substring(startPos).ToLower(); + + switch (fileExt) + { + case "bmp": + return "image/bmp"; + case "jpeg": + case "jpe": + case "jpg": + case "jfif": + return "image/jpeg"; + case "gif": + return "image/gif"; + case "png": + return "image/png"; + case "tif": + case "tiff": + return "image/tiff"; + default: + return null; + } + } + + private WorkClass GetWC(Report rpt) + { + WorkClass wc = rpt.Cache.Get(this, "wc") as WorkClass; + if (wc == null) + { + wc = new WorkClass(); + rpt.Cache.Add(this, "wc", wc); + } + return wc; + } + + private void RemoveImageWC(Report rpt) + { + rpt.Cache.Remove(this, "wc"); + } + + class WorkClass + { + internal PageImage PgImage; // When ConstantImage is true this will save the PageImage for reuse + internal WorkClass() + { + PgImage = null; + } + } + + } } diff --git a/RdlEngine/Definition/Legend.cs b/RdlEngine/Definition/Legend.cs index d7f39365..0841a855 100644 --- a/RdlEngine/Definition/Legend.cs +++ b/RdlEngine/Definition/Legend.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -81,10 +82,10 @@ internal Legend(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } diff --git a/RdlEngine/Definition/Line.cs b/RdlEngine/Definition/Line.cs index 75378b87..ae75fcba 100644 --- a/RdlEngine/Definition/Line.cs +++ b/RdlEngine/Definition/Line.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -48,19 +49,20 @@ internal Line(ReportDefn r, ReportLink p, XmlNode xNode) : base(r,p,xNode) } } } - override internal void Run(IPresent ip, Row row) + override internal Task Run(IPresent ip, Row row) { ip.Line(this, row); + return Task.CompletedTask; } - override internal void RunPage(Pages pgs, Row row) + override internal async Task RunPage(Pages pgs, Row row) { Report r = pgs.Report; - bool bHidden = IsHidden(r, row); + bool bHidden = await IsHidden(r, row); SetPagePositionBegin(pgs); PageLine pl = new PageLine(); - SetPagePositionAndStyle(r, pl, row); + await SetPagePositionAndStyle(r, pl, row); if (!bHidden) pgs.CurrentPage.AddObject(pl); SetPagePositionEnd(pgs, pl.Y); diff --git a/RdlEngine/Definition/List.cs b/RdlEngine/Definition/List.cs index eeed2e6b..941e7407 100644 --- a/RdlEngine/Definition/List.cs +++ b/RdlEngine/Definition/List.cs @@ -24,6 +24,8 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.Collections.Generic; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Majorsilence.Drawing; #else @@ -95,16 +97,16 @@ internal List(ReportDefn r, ReportLink p, XmlNode xNode):base(r,p,xNode) DataRegionFinish(); // Tidy up the DataRegion } - override internal void FinalPass() + async override internal Task FinalPass() { - base.FinalPass(); + await base.FinalPass(); if (_Grouping != null) - _Grouping.FinalPass(); + await _Grouping.FinalPass(); if (_Sorting != null) - _Sorting.FinalPass(); + await _Sorting.FinalPass(); if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); // determine if the size is dynamic depending on any of its // contained textbox have cangrow true @@ -131,52 +133,54 @@ override internal void FinalPass() return; } - override internal void Run(IPresent ip, Row row) + async override internal Task Run(IPresent ip, Row row) { Report r = ip.Report(); WorkClass wc = GetValue(r); - wc.Data = GetFilteredData(r, row); + wc.Data = await GetFilteredData(r, row); - if (!AnyRows(ip, wc.Data)) // if no rows return + if (!await AnyRows(ip, wc.Data)) // if no rows return return; // nothing left to do RunSetGrouping(r, wc); - base.Run(ip, row); + await base.Run(ip, row); + + if (!await ip.ListStart(this, row)) + return; // renderer doesn't want to continue - if (!ip.ListStart(this, row)) - return; // renderer doesn't want to continue - - RunGroups(ip, wc, wc.Groups); + await RunGroups(ip, wc, wc.Groups); - ip.ListEnd(this, row); + await ip.ListEnd(this, row); RemoveValue(r); } - override internal void RunPage(Pages pgs, Row row) + async override internal Task RunPage(Pages pgs, Row row) { Report r = pgs.Report; - if (IsHidden(r, row)) + if (await IsHidden(r, row)) return; WorkClass wc = GetValue(r); - wc.Data = GetFilteredData(r, row); + wc.Data = await GetFilteredData(r, row); SetPagePositionBegin(pgs); - if (!AnyRowsPage(pgs, wc.Data)) // if no rows return + if (!await AnyRowsPage(pgs, wc.Data)) // if no rows return return; // nothing left to do RunPageRegionBegin(pgs); RunSetGrouping(pgs.Report, wc); - RunPageGroups(pgs, wc, wc.Groups); + await RunPageGroups(pgs, wc, wc.Groups); RunPageRegionEnd(pgs); SetPagePositionEnd(pgs, pgs.CurrentPage.YOffset); RemoveValue(r); + + return; } private void RunSetGrouping(Report rpt, WorkClass wc) @@ -302,7 +306,7 @@ private void PrepGroups(Report rpt, WorkClass wc) return; } - private void RunGroups(IPresent ip, WorkClass wc, List groupEntries) + private async Task RunGroups(IPresent ip, WorkClass wc, List groupEntries) { foreach (GroupEntry ge in groupEntries) { @@ -325,7 +329,7 @@ private void RunGroups(IPresent ip, WorkClass wc, List groupEntries) { ip.ListEntryBegin(this, wc.Data.Data[r]); if (_ReportItems != null) - _ReportItems.Run(ip, wc.Data.Data[r]); + await _ReportItems.Run(ip, wc.Data.Data[r]); ip.ListEntryEnd(this, wc.Data.Data[r]); } } @@ -335,14 +339,14 @@ private void RunGroups(IPresent ip, WorkClass wc, List groupEntries) // pass the first row of the group if (_ReportItems != null) - _ReportItems.Run(ip, wc.Data.Data[ge.StartRow]); + await _ReportItems.Run(ip, wc.Data.Data[ge.StartRow]); ip.ListEntryEnd(this, wc.Data.Data[ge.StartRow]); } } } - private void RunPageGroups(Pages pgs, WorkClass wc, List groupEntries) + private async Task RunPageGroups(Pages pgs, WorkClass wc, List groupEntries) { Report rpt = pgs.Report; Page p = pgs.CurrentPage; @@ -374,7 +378,7 @@ private void RunPageGroups(Pages pgs, WorkClass wc, List groupEntrie for (int r=ge.StartRow; r <= ge.EndRow; r++) { row = wc.Data.Data[r]; - height = HeightOfList(rpt, pgs.G, row); + height = await HeightOfList(rpt, pgs.G, row); if (p.YOffset + height > pagebottom && !p.IsEmpty()) // need another page for this row? p = RunPageNew(pgs, p); // yes; if at end this page is empty @@ -382,12 +386,12 @@ private void RunPageGroups(Pages pgs, WorkClass wc, List groupEntrie float saveYoffset = p.YOffset; // this can be affected by other page items if (Style != null) { var border = new PageRectangle(); - SetPagePositionAndStyle(rpt, border, row); + await SetPagePositionAndStyle(rpt, border, row); p.AddObject(border); } if (_ReportItems != null) - _ReportItems.RunPage(pgs, row, listoffset); + await _ReportItems.RunPage(pgs, row, listoffset); if (p == pgs.CurrentPage) // did subitems force new page? { // no use the height of the list @@ -398,7 +402,7 @@ private void RunPageGroups(Pages pgs, WorkClass wc, List groupEntrie p = pgs.CurrentPage; // set to new page if (this.Style != null) { - p.YOffset += this.Style.EvalPaddingBottom(rpt, row); + p.YOffset += await this.Style.EvalPaddingBottom(rpt, row); } } } @@ -410,14 +414,14 @@ private void RunPageGroups(Pages pgs, WorkClass wc, List groupEntrie // pass the first row of the group row = wc.Data.Data[ge.StartRow]; - height = HeightOfList(rpt, pgs.G, row); + height = await HeightOfList(rpt, pgs.G, row); if (p.YOffset + height > pagebottom && !p.IsEmpty()) // need another page for this row? p = RunPageNew(pgs, p); // yes; if at end this page is empty float saveYoffset = p.YOffset; // this can be affected by other page items if (_ReportItems != null) - _ReportItems.RunPage(pgs, row, listoffset); + await _ReportItems.RunPage(pgs, row, listoffset); if (p == pgs.CurrentPage) // did subitems force new page? @@ -429,7 +433,7 @@ private void RunPageGroups(Pages pgs, WorkClass wc, List groupEntrie p = pgs.CurrentPage; // set to new page if (this.Style != null) { - p.YOffset += this.Style.EvalPaddingBottom(rpt, row); + p.YOffset += await this.Style.EvalPaddingBottom(rpt, row); } } @@ -472,7 +476,7 @@ internal Grouping Grouping set { _Grouping = value; } } - internal float HeightOfList(Report rpt, Graphics g, Row r) + internal async Task HeightOfList(Report rpt, Graphics g, Row r) { WorkClass wc = GetValue(rpt); @@ -484,9 +488,9 @@ internal float HeightOfList(Report rpt, Graphics g, Row r) foreach (Textbox tb in this._GrowList) { float top = (float) (tb.Top == null? 0.0 : tb.Top.Points); - height = top + tb.RunTextCalcHeight(rpt, g, r); + height = top + await tb.RunTextCalcHeight(rpt, g, r); if (tb.Style != null) - height += (tb.Style.EvalPaddingBottom(rpt, r) + tb.Style.EvalPaddingTop(rpt, r)); + height += (await tb.Style.EvalPaddingBottom(rpt, r) + await tb.Style.EvalPaddingTop(rpt, r)); defnHeight = Math.Max(height, defnHeight); } wc.CalcHeight = defnHeight; diff --git a/RdlEngine/Definition/Marker.cs b/RdlEngine/Definition/Marker.cs index 8dc7efca..0a27feaf 100644 --- a/RdlEngine/Definition/Marker.cs +++ b/RdlEngine/Definition/Marker.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -66,10 +67,10 @@ internal Marker(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } diff --git a/RdlEngine/Definition/Matrix.cs b/RdlEngine/Definition/Matrix.cs index 74844939..5bcb455b 100644 --- a/RdlEngine/Definition/Matrix.cs +++ b/RdlEngine/Definition/Matrix.cs @@ -26,359 +26,365 @@ the website www.fyiReporting.com. using System.Collections; using System.Globalization; using System.Text; +using System.Threading.Tasks; namespace fyiReporting.RDL { - /// - /// Represents the report item (and Data region) for a matrix (cross-tabulation) - /// - [Serializable] - internal class Matrix : DataRegion - { - Corner _Corner; // The region that contains the elements of - // the upper left corner area of the matrix. - // If omitted, no report items are output in - // the corner. - ColumnGroupings _ColumnGroupings; // The set of column groupings for the matrix - RowGroupings _RowGroupings; // The set of row groupings for the matrix - MatrixRows _MatrixRows; // The rows contained in each detail cell - // of the matrix layout - MatrixColumns _MatrixColumns; // The columns contained in each detail - // cell of the matrix layout - MatrixLayoutDirectionEnum _LayoutDirection; // Indicates whether the matrix columns - // grow left-to-right (with headers on the - // left) or right-to-left (with headers on the - // right). - int _GroupsBeforeRowHeaders; // The number of instances of the - // outermost column group that should - // appear to the left of the row headers - // (right of the row headers for RTL - // matrixes). Default is 0. - string _CellDataElementName; // The name to use for the cell element. Default: �Cell� - MatrixCellDataElementOutputEnum _CellDataElementOutput; // Indicates whether the cell contents - //should appear in a data rendering. Default is Output. - static string nullterminal = '\ufffe'.ToString(); - static string terminal = '\uffff'.ToString(); - - internal Matrix(ReportDefn r, ReportLink p, XmlNode xNode):base(r,p,xNode) - { - _Corner=null; - _ColumnGroupings=null; - _RowGroupings=null; - _MatrixRows=null; - _MatrixColumns=null; - _LayoutDirection=MatrixLayoutDirectionEnum.LTR; - _GroupsBeforeRowHeaders=0; - _CellDataElementName=null; - _CellDataElementOutput=MatrixCellDataElementOutputEnum.Output; - - // Loop thru all the child nodes - foreach(XmlNode xNodeLoop in xNode.ChildNodes) - { - if (xNodeLoop.NodeType != XmlNodeType.Element) - continue; - switch (xNodeLoop.Name) - { - case "Corner": - _Corner = new Corner(r, this, xNodeLoop); - break; - case "ColumnGroupings": - _ColumnGroupings = new ColumnGroupings(r, this, xNodeLoop); - break; - case "RowGroupings": - _RowGroupings = new RowGroupings(r, this, xNodeLoop); - break; - case "MatrixRows": - _MatrixRows = new MatrixRows(r, this, xNodeLoop); - break; - case "MatrixColumns": - _MatrixColumns = new MatrixColumns(r, this, xNodeLoop); - break; - case "LayoutDirection": - _LayoutDirection = MatrixLayoutDirection.GetStyle(xNodeLoop.InnerText, OwnerReport.rl); - break; - case "GroupsBeforeRowHeaders": - _GroupsBeforeRowHeaders = XmlUtil.Integer(xNodeLoop.InnerText); - break; - case "CellDataElementName": - _CellDataElementName = xNodeLoop.InnerText; - break; - case "CellDataElementOutput": - _CellDataElementOutput = MatrixCellDataElementOutput.GetStyle(xNodeLoop.InnerText, OwnerReport.rl); - break; - default: - if (DataRegionElement(xNodeLoop)) // try at DataRegion level - break; - // don't know this element - log it - OwnerReport.rl.LogError(4, "Unknown Matrix element '" + xNodeLoop.Name + "' ignored."); - break; - } - } - DataRegionFinish(); // Tidy up the DataRegion - - if (_ColumnGroupings == null) - OwnerReport.rl.LogError(8, "Matrix element ColumnGroupings not specified for " + (this.Name == null? "'name not specified'": this.Name.Nm)); - if (_RowGroupings == null) - OwnerReport.rl.LogError(8, "Matrix element RowGroupings not specified for " + (this.Name == null? "'name not specified'": this.Name.Nm)); - if (_MatrixRows == null) - OwnerReport.rl.LogError(8, "Matrix element MatrixRows not specified for " + (this.Name == null? "'name not specified'": this.Name.Nm)); - if (_MatrixColumns == null) - OwnerReport.rl.LogError(8, "Matrix element MatrixColumns not specified for " + (this.Name == null? "'name not specified'": this.Name.Nm)); - - // MatrixCells count must be the same as the number of StaticColumns. - // If there are no StaticColumns it must be 1 - if (OwnerReport.rl.MaxSeverity > 4) - return; // don't perform this check if we've already go errors - int mc = _MatrixRows.CellCount; // MatrixCells - int sc = Math.Max(1, _ColumnGroupings.StaticCount); - if (mc != sc) - { - OwnerReport.rl.LogError(8, "The count of MatrixCells must be 1 or equal to the number of StaticColumns if there are any. Matrix " + (this.Name == null? "unknown.": this.Name.Nm)); - } - // matrix columns must also equal the static count (or 1 if no static columns) - mc = this.CountMatrixColumns; - if (mc != sc) - { - OwnerReport.rl.LogError(8, "The count of MatrixColumns must be 1 or equal to the number of StaticColumns if there are any. Matrix " + (this.Name == null? "unknown.": this.Name.Nm)); - } - // matrix rows must also equal the static count (or 1 if no static rows) - int mr = this.CountMatrixRows; - int sr = Math.Max(1, _RowGroupings.StaticCount); - if (mr != sr) - { - OwnerReport.rl.LogError(8, "The count of MatrixRows must be 1 or equal to the number of StaticRows if there are any. Matrix " + (this.Name == null? "unknown.": this.Name.Nm)); - } - } - - override internal void FinalPass() - { - base.FinalPass(); - - float totalHeight=0; - if (_Corner != null) - _Corner.FinalPass(); - if (_ColumnGroupings != null) - { - _ColumnGroupings.FinalPass(); - totalHeight += _ColumnGroupings.DefnHeight(); - } - if (_RowGroupings != null) - _RowGroupings.FinalPass(); - if (_MatrixRows != null) - { - _MatrixRows.FinalPass(); - totalHeight += _MatrixRows.DefnHeight(); - } - if (_MatrixColumns != null) - _MatrixColumns.FinalPass(); - - if (this.Height == null) - { // Calculate a height based on the sum of the TableRows - this.Height = new RSize(this.OwnerReport, string.Format(NumberFormatInfo.InvariantInfo, "{0:0.00}pt", totalHeight)); - } - - return; - } - - override internal void Run(IPresent ip, Row row) - { - Report rpt = ip.Report(); - WorkClass wc = GetValue(rpt); - wc.FullData = wc.Data = GetFilteredData(rpt, row); - - if (!AnyRows(ip, wc.Data)) // if no rows return - return; // nothing left to do - - int maxColumns; - int maxRows; - MatrixCellEntry[,] matrix = RunBuild(rpt, out maxRows, out maxColumns); - - // Now run thru the rows and columns of the matrix passing the information - // on to the rendering engine + /// + /// Represents the report item (and Data region) for a matrix (cross-tabulation) + /// + [Serializable] + internal class Matrix : DataRegion + { + Corner _Corner; // The region that contains the elements of + // the upper left corner area of the matrix. + // If omitted, no report items are output in + // the corner. + ColumnGroupings _ColumnGroupings; // The set of column groupings for the matrix + RowGroupings _RowGroupings; // The set of row groupings for the matrix + MatrixRows _MatrixRows; // The rows contained in each detail cell + // of the matrix layout + MatrixColumns _MatrixColumns; // The columns contained in each detail + // cell of the matrix layout + MatrixLayoutDirectionEnum _LayoutDirection; // Indicates whether the matrix columns + // grow left-to-right (with headers on the + // left) or right-to-left (with headers on the + // right). + int _GroupsBeforeRowHeaders; // The number of instances of the + // outermost column group that should + // appear to the left of the row headers + // (right of the row headers for RTL + // matrixes). Default is 0. + string _CellDataElementName; // The name to use for the cell element. Default: �Cell� + MatrixCellDataElementOutputEnum _CellDataElementOutput; // Indicates whether the cell contents + //should appear in a data rendering. Default is Output. + static string nullterminal = '\ufffe'.ToString(); + static string terminal = '\uffff'.ToString(); + + internal Matrix(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p, xNode) + { + _Corner = null; + _ColumnGroupings = null; + _RowGroupings = null; + _MatrixRows = null; + _MatrixColumns = null; + _LayoutDirection = MatrixLayoutDirectionEnum.LTR; + _GroupsBeforeRowHeaders = 0; + _CellDataElementName = null; + _CellDataElementOutput = MatrixCellDataElementOutputEnum.Output; + + // Loop thru all the child nodes + foreach (XmlNode xNodeLoop in xNode.ChildNodes) + { + if (xNodeLoop.NodeType != XmlNodeType.Element) + continue; + switch (xNodeLoop.Name) + { + case "Corner": + _Corner = new Corner(r, this, xNodeLoop); + break; + case "ColumnGroupings": + _ColumnGroupings = new ColumnGroupings(r, this, xNodeLoop); + break; + case "RowGroupings": + _RowGroupings = new RowGroupings(r, this, xNodeLoop); + break; + case "MatrixRows": + _MatrixRows = new MatrixRows(r, this, xNodeLoop); + break; + case "MatrixColumns": + _MatrixColumns = new MatrixColumns(r, this, xNodeLoop); + break; + case "LayoutDirection": + _LayoutDirection = MatrixLayoutDirection.GetStyle(xNodeLoop.InnerText, OwnerReport.rl); + break; + case "GroupsBeforeRowHeaders": + _GroupsBeforeRowHeaders = XmlUtil.Integer(xNodeLoop.InnerText); + break; + case "CellDataElementName": + _CellDataElementName = xNodeLoop.InnerText; + break; + case "CellDataElementOutput": + _CellDataElementOutput = MatrixCellDataElementOutput.GetStyle(xNodeLoop.InnerText, OwnerReport.rl); + break; + default: + if (DataRegionElement(xNodeLoop)) // try at DataRegion level + break; + // don't know this element - log it + OwnerReport.rl.LogError(4, "Unknown Matrix element '" + xNodeLoop.Name + "' ignored."); + break; + } + } + DataRegionFinish(); // Tidy up the DataRegion + + if (_ColumnGroupings == null) + OwnerReport.rl.LogError(8, "Matrix element ColumnGroupings not specified for " + (this.Name == null ? "'name not specified'" : this.Name.Nm)); + if (_RowGroupings == null) + OwnerReport.rl.LogError(8, "Matrix element RowGroupings not specified for " + (this.Name == null ? "'name not specified'" : this.Name.Nm)); + if (_MatrixRows == null) + OwnerReport.rl.LogError(8, "Matrix element MatrixRows not specified for " + (this.Name == null ? "'name not specified'" : this.Name.Nm)); + if (_MatrixColumns == null) + OwnerReport.rl.LogError(8, "Matrix element MatrixColumns not specified for " + (this.Name == null ? "'name not specified'" : this.Name.Nm)); + + // MatrixCells count must be the same as the number of StaticColumns. + // If there are no StaticColumns it must be 1 + if (OwnerReport.rl.MaxSeverity > 4) + return; // don't perform this check if we've already go errors + int mc = _MatrixRows.CellCount; // MatrixCells + int sc = Math.Max(1, _ColumnGroupings.StaticCount); + if (mc != sc) + { + OwnerReport.rl.LogError(8, "The count of MatrixCells must be 1 or equal to the number of StaticColumns if there are any. Matrix " + (this.Name == null ? "unknown." : this.Name.Nm)); + } + // matrix columns must also equal the static count (or 1 if no static columns) + mc = this.CountMatrixColumns; + if (mc != sc) + { + OwnerReport.rl.LogError(8, "The count of MatrixColumns must be 1 or equal to the number of StaticColumns if there are any. Matrix " + (this.Name == null ? "unknown." : this.Name.Nm)); + } + // matrix rows must also equal the static count (or 1 if no static rows) + int mr = this.CountMatrixRows; + int sr = Math.Max(1, _RowGroupings.StaticCount); + if (mr != sr) + { + OwnerReport.rl.LogError(8, "The count of MatrixRows must be 1 or equal to the number of StaticRows if there are any. Matrix " + (this.Name == null ? "unknown." : this.Name.Nm)); + } + } + + async override internal Task FinalPass() + { + await base.FinalPass(); + + float totalHeight = 0; + if (_Corner != null) + await _Corner.FinalPass(); + if (_ColumnGroupings != null) + { + await _ColumnGroupings.FinalPass(); + totalHeight += _ColumnGroupings.DefnHeight(); + } + if (_RowGroupings != null) + await _RowGroupings.FinalPass(); + if (_MatrixRows != null) + { + await _MatrixRows.FinalPass(); + totalHeight += _MatrixRows.DefnHeight(); + } + if (_MatrixColumns != null) + await _MatrixColumns.FinalPass(); + + if (this.Height == null) + { // Calculate a height based on the sum of the TableRows + this.Height = new RSize(this.OwnerReport, string.Format(NumberFormatInfo.InvariantInfo, "{0:0.00}pt", totalHeight)); + } + + return; + } + + async override internal Task Run(IPresent ip, Row row) + { + Report rpt = ip.Report(); + WorkClass wc = GetValue(rpt); + wc.FullData = wc.Data = await GetFilteredData(rpt, row); + + if (!await AnyRows(ip, wc.Data)) // if no rows return + return; // nothing left to do + + int maxColumns; + int maxRows; + MatrixCellEntry[,] matrix; + + (matrix, maxRows, maxColumns) = await RunBuild(rpt); + + // Now run thru the rows and columns of the matrix passing the information + // on to the rendering engine int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have - if (!ip.MatrixStart(this, matrix, row, headerRows, maxRows, maxColumns)) - return; - for (int iRow = 0; iRow < maxRows; iRow++) - { - ip.MatrixRowStart(this, iRow, row); - for (int iColumn = 0; iColumn < maxColumns; iColumn++) - { - MatrixCellEntry mce = matrix[iRow, iColumn]; - if (mce == null) - { - ip.MatrixCellStart(this, null, iRow, iColumn, row, float.MinValue, float.MinValue, 1); - ip.MatrixCellEnd(this, null, iRow, iColumn, row); - } - else - { - wc.Data = mce.Data; // Must set this for evaluation - - Row lrow = wc.Data.Data.Count > 0? wc.Data.Data[0]:null; - mce.DisplayItem.SetMC(rpt, mce); // set for use by the display item - SetGroupingValues(rpt, mce); - - ip.MatrixCellStart(this, mce.DisplayItem, iRow, iColumn, lrow, mce.Height, mce.Width, mce.ColSpan); - - mce.DisplayItem.Run(ip, lrow); - ip.MatrixCellEnd(this, mce.DisplayItem, iRow, iColumn, lrow); - } - } - ip.MatrixRowEnd(this, iRow, row); - } - ip.MatrixEnd(this, row); - RemoveValue(rpt); - } - - override internal void RunPage(Pages pgs, Row row) - { - Report r = pgs.Report; - if (IsHidden(r, row)) - return; - - WorkClass wc = GetValue(r); - - wc.FullData = wc.Data = GetFilteredData(r, row); - - SetPagePositionBegin(pgs); - - if (!AnyRowsPage(pgs, wc.Data)) // if no rows return - return; // nothing left to do - - int maxColumns; - int maxRows; - int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have - MatrixCellEntry[,] matrix = RunBuild(r, out maxRows, out maxColumns); - - // Now run thru the rows and columns of the matrix creating the pages - RunPageRegionBegin(pgs); - Page p = pgs.CurrentPage; - p.YOffset += this.RelativeY(r); - - for (int iRow = 0; iRow < maxRows; iRow++) - { - float h = HeightOfRow(pgs, matrix, iRow); - if (h <= 0) // there were no cells in row - continue; // skip the row - - if (p.YOffset + h > pgs.BottomOfPage) - { - p = RunPageNew(pgs, p); - // run thru the headers again - for (int aRow = 0; aRow < headerRows; aRow++) - { - RunPageColumns(pgs, wc, matrix, aRow, maxColumns); - p.YOffset += HeightOfRow(pgs, matrix, aRow); - } - } - RunPageColumns(pgs, wc, matrix, iRow, maxColumns); - p.YOffset += h; - } - - RunPageRegionEnd(pgs); - SetPagePositionEnd(pgs, pgs.CurrentPage.YOffset); - RemoveValue(r); - } - - internal void RunReset(Report rpt) - { - RemoveValue(rpt); - } - - float HeightOfRow(Pages pgs, MatrixCellEntry[,] matrix, int iRow) - { - Report rpt = pgs.Report; - WorkClass wc = GetValue(rpt); - - int maxColumns = matrix.GetLength(1); - float height=0; - bool bResetAllHeights=false; - - // Handle the corner; it might span rows & columns - bool bCorner = false; - float cornerHeight=0; - if (iRow == 0 && matrix[0, 0] != null && - (this.ColumnGroupings.Items.Count > 1 || - this.RowGroupings.Items.Count > 1)) - { - bCorner = true; - } - - for (int iCol=0; iCol < maxColumns; iCol++) - { - MatrixCellEntry mce = matrix[iRow, iCol]; - if (mce == null) - continue; - if (mce.DisplayItem is Textbox) - { - Textbox tb = mce.DisplayItem as Textbox; - if (tb.CanGrow) - { - wc.Data = mce.Data; // Must set this for evaluation - - Row lrow = wc.Data.Data.Count > 0? wc.Data.Data[0]:null; - mce.DisplayItem.SetMC(rpt, mce); // set for use by the display item - SetGroupingValues(rpt, mce); - - float tbh = tb.RunTextCalcHeight(rpt, pgs.G, lrow); - if (height < tbh) - { - if (bCorner && iCol == 0) - { - cornerHeight = tbh; - } - else - { - bResetAllHeights = true; - height = tbh; - } - } - } - } - - if (bCorner && iCol == 0) - continue; - if (height < mce.Height) - height = mce.Height; - } - - if (bResetAllHeights) // If any text forces the row to grow; all heights must be fixed - { - for (int iCol=0; iCol < maxColumns; iCol++) - { - if (bCorner && iCol == 0) - continue; - MatrixCellEntry mce = matrix[iRow, iCol]; - if (mce != null) - mce.Height = height; - } - } - - // Even with expansion room; we might need more space for the corner - if (bCorner && cornerHeight > matrix[0,0].Height) - { // add the additional space needed to the first row's height - float newRow0Height; - if (ColumnGroupings.Items.Count == 1) - newRow0Height = cornerHeight; - else if (matrix[0,1] != null) - newRow0Height = matrix[0,1].Height + (cornerHeight - matrix[0,0].Height); - else - newRow0Height = (cornerHeight - matrix[0,0].Height); - height = newRow0Height; - matrix[0,0].Height = cornerHeight; - for (int iCol=1; iCol < maxColumns; iCol++) - { - MatrixCellEntry mce = matrix[0, iCol]; - if (mce != null) - mce.Height = newRow0Height; - } - } - - return height; - } + if (!await ip.MatrixStart(this, matrix, row, headerRows, maxRows, maxColumns)) + return; + for (int iRow = 0; iRow < maxRows; iRow++) + { + ip.MatrixRowStart(this, iRow, row); + for (int iColumn = 0; iColumn < maxColumns; iColumn++) + { + MatrixCellEntry mce = matrix[iRow, iColumn]; + if (mce == null) + { + await ip.MatrixCellStart(this, null, iRow, iColumn, row, float.MinValue, float.MinValue, 1); + await ip.MatrixCellEnd(this, null, iRow, iColumn, row); + } + else + { + wc.Data = mce.Data; // Must set this for evaluation + + Row lrow = wc.Data.Data.Count > 0 ? wc.Data.Data[0] : null; + mce.DisplayItem.SetMC(rpt, mce); // set for use by the display item + SetGroupingValues(rpt, mce); + + await ip.MatrixCellStart(this, mce.DisplayItem, iRow, iColumn, lrow, mce.Height, mce.Width, mce.ColSpan); + + await mce.DisplayItem.Run(ip, lrow); + await ip.MatrixCellEnd(this, mce.DisplayItem, iRow, iColumn, lrow); + } + } + ip.MatrixRowEnd(this, iRow, row); + } + await ip.MatrixEnd(this, row); + RemoveValue(rpt); + } + + async override internal Task RunPage(Pages pgs, Row row) + { + Report r = pgs.Report; + if (await IsHidden(r, row)) + return; + + WorkClass wc = GetValue(r); + + wc.FullData = wc.Data = await GetFilteredData(r, row); + + SetPagePositionBegin(pgs); + + if (!await AnyRowsPage(pgs, wc.Data)) // if no rows return + return; // nothing left to do + + int maxColumns; + int maxRows; + int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have + MatrixCellEntry[,] matrix; + + (matrix, maxRows, maxColumns) = await RunBuild(r); + + // Now run thru the rows and columns of the matrix creating the pages + RunPageRegionBegin(pgs); + Page p = pgs.CurrentPage; + p.YOffset += this.RelativeY(r); + + for (int iRow = 0; iRow < maxRows; iRow++) + { + float h = await HeightOfRow(pgs, matrix, iRow); + if (h <= 0) // there were no cells in row + continue; // skip the row + + if (p.YOffset + h > pgs.BottomOfPage) + { + p = RunPageNew(pgs, p); + // run thru the headers again + for (int aRow = 0; aRow < headerRows; aRow++) + { + await RunPageColumns(pgs, wc, matrix, aRow, maxColumns); + p.YOffset += await HeightOfRow(pgs, matrix, aRow); + } + } + await RunPageColumns(pgs, wc, matrix, iRow, maxColumns); + p.YOffset += h; + } + + RunPageRegionEnd(pgs); + SetPagePositionEnd(pgs, pgs.CurrentPage.YOffset); + RemoveValue(r); + return; + } + + internal void RunReset(Report rpt) + { + RemoveValue(rpt); + } + + async Task HeightOfRow(Pages pgs, MatrixCellEntry[,] matrix, int iRow) + { + Report rpt = pgs.Report; + WorkClass wc = GetValue(rpt); + + int maxColumns = matrix.GetLength(1); + float height = 0; + bool bResetAllHeights = false; + + // Handle the corner; it might span rows & columns + bool bCorner = false; + float cornerHeight = 0; + if (iRow == 0 && matrix[0, 0] != null && + (this.ColumnGroupings.Items.Count > 1 || + this.RowGroupings.Items.Count > 1)) + { + bCorner = true; + } + + for (int iCol = 0; iCol < maxColumns; iCol++) + { + MatrixCellEntry mce = matrix[iRow, iCol]; + if (mce == null) + continue; + if (mce.DisplayItem is Textbox) + { + Textbox tb = mce.DisplayItem as Textbox; + if (tb.CanGrow) + { + wc.Data = mce.Data; // Must set this for evaluation + + Row lrow = wc.Data.Data.Count > 0 ? wc.Data.Data[0] : null; + mce.DisplayItem.SetMC(rpt, mce); // set for use by the display item + SetGroupingValues(rpt, mce); + + float tbh = await tb.RunTextCalcHeight(rpt, pgs.G, lrow); + if (height < tbh) + { + if (bCorner && iCol == 0) + { + cornerHeight = tbh; + } + else + { + bResetAllHeights = true; + height = tbh; + } + } + } + } + + if (bCorner && iCol == 0) + continue; + if (height < mce.Height) + height = mce.Height; + } + + if (bResetAllHeights) // If any text forces the row to grow; all heights must be fixed + { + for (int iCol = 0; iCol < maxColumns; iCol++) + { + if (bCorner && iCol == 0) + continue; + MatrixCellEntry mce = matrix[iRow, iCol]; + if (mce != null) + mce.Height = height; + } + } + + // Even with expansion room; we might need more space for the corner + if (bCorner && cornerHeight > matrix[0, 0].Height) + { // add the additional space needed to the first row's height + float newRow0Height; + if (ColumnGroupings.Items.Count == 1) + newRow0Height = cornerHeight; + else if (matrix[0, 1] != null) + newRow0Height = matrix[0, 1].Height + (cornerHeight - matrix[0, 0].Height); + else + newRow0Height = (cornerHeight - matrix[0, 0].Height); + height = newRow0Height; + matrix[0, 0].Height = cornerHeight; + for (int iCol = 1; iCol < maxColumns; iCol++) + { + MatrixCellEntry mce = matrix[0, iCol]; + if (mce != null) + mce.Height = newRow0Height; + } + } + + return height; + } internal float[] ColumnWidths(MatrixCellEntry[,] matrix, int maxColumns) { - float[] widths= new float[maxColumns]; + float[] widths = new float[maxColumns]; for (int iColumn = 0; iColumn < maxColumns; iColumn++) { @@ -387,873 +393,881 @@ internal float[] ColumnWidths(MatrixCellEntry[,] matrix, int maxColumns) return widths; } - float WidthOfColumn(MatrixCellEntry[,] matrix, int iCol) - { - int maxRows = matrix.GetLength(0); - for (int iRow=0; iRow < maxRows; iRow++) - { - if (matrix[iRow, iCol] != null && matrix[iRow, iCol].ColSpan == 1) - return matrix[iRow, iCol].Width; - } - return 0; - } - - void RunPageColumns(Pages pgs, WorkClass wc, MatrixCellEntry[,] matrix, int iRow, int maxColumns) - { - Report rpt = pgs.Report; - - float xpos = GetOffsetCalc(pgs.Report) + LeftCalc(rpt); - for (int iColumn = 0; iColumn < maxColumns; iColumn++) - { - MatrixCellEntry mce = matrix[iRow, iColumn]; - - if (mce == null) - { // have a null column but we need to fill column space - xpos += WidthOfColumn(matrix, iColumn); - continue; - } - wc.Data = mce.Data; // Must set this for evaluation - - Row lrow = wc.Data.Data.Count > 0? wc.Data.Data[0]:null; - SetGroupingValues(rpt, mce); - mce.DisplayItem.SetMC(rpt, mce); // set for use by the display item - mce.XPosition = xpos; - mce.DisplayItem.RunPage(pgs, lrow); - xpos += mce.Width; - iColumn += (mce.ColSpan-1); // skip columns already accounted for - } - } - - // RunBuild is used by both Matrix.Run and Chart.Run to obtain the necessary data - // used by their respective rendering interfaces - internal MatrixCellEntry[,] RunBuild(Report rpt, out int numRows, out int numCols) - { - WorkClass wc = GetValue(rpt); - Rows _Data = wc.Data; - - // loop thru all the data; - // form bitmap arrays for each unique data value of each grouping (row and column) value - int maxColumns = _RowGroupings.Items.Count; // maximum # of columns in matrix - // at top we need a row per column grouping - int maxRows = _ColumnGroupings.Items.Count; // maximum # of rows in matrix - // at left we need a column per row grouping - - MatrixEntry mcg = new MatrixEntry(null, "", null, _Data.Data.Count); - _ColumnGroupings.SetME(rpt, mcg); - mcg.FirstRow=0; - mcg.LastRow=_Data.Data.Count-1; - mcg.Rows = new BitArray(_Data.Data.Count, true); // all data - - MatrixEntry mrg = new MatrixEntry(null, "", null, _Data.Data.Count); - _RowGroupings.SetME(rpt, mrg); - mrg.FirstRow=0; - mrg.LastRow=_Data.Data.Count-1; - mrg.Rows = new BitArray(_Data.Data.Count, true); // all data - - int iRow=0; // row counter - foreach (Row r in _Data.Data) - { - // Handle the column values - HandleColumnGrouping(rpt, wc, _Data, r, mcg, 0, iRow, ref maxColumns); - - // Handle the row values - HandleRowGrouping(rpt, wc, _Data, r, mrg, 0, iRow, ref maxRows); - - iRow++; - } - - // Determine how many subtotal columns are needed - maxColumns += RunCountSubtotalColumns(rpt, wc, mcg, 0); - - // Determine how many subtotal rows are needed - maxRows += RunCountSubtotalRows(rpt, wc, mrg, 0); - - ///// - // Build and populate the 2 dimensional table of MatrixCellEntry - // that constitute the matrix - ///// - MatrixCellEntry[,] matrix = new MatrixCellEntry[maxRows, maxColumns]; - - // Do the column headings - int iColumn = _RowGroupings.Items.Count; - RunColumnHeaders(rpt, wc, mcg, matrix, _Data, 0, ref iColumn, 0); - - // Do the row headings - iRow = _ColumnGroupings.Items.Count; - RunRowHeaders(rpt, wc, mrg, matrix, _Data, ref iRow, 0, 0); - - // Do the row/column data - iRow = _ColumnGroupings.Items.Count; - RunDataRow(rpt, wc, mrg, mcg, matrix, _Data, ref iRow, _RowGroupings.Items.Count, 0); - - // Do the corner - matrix[0, 0] = RunCorner(_Data); - - // now return the matrix data - numRows = maxRows; - numCols = maxColumns; - return matrix; - } - - int CountMatrixCells - { - get - { - MatrixRow mr = this.MatrixRows.Items[0] as MatrixRow; - return mr.MatrixCells.Items.Count; - } - } - - int CountMatrixColumns - { - get - { - return this.MatrixColumns.Items.Count; - } - } - - int CountMatrixRows - { - get - { - return this.MatrixRows.Items.Count; - } - } - - ColumnGrouping LastCg - { - get { return (ColumnGrouping) (_ColumnGroupings.Items[_ColumnGroupings.Items.Count-1]); } - } - - RowGrouping LastRg - { - get { return (RowGrouping) (_RowGroupings.Items[_RowGroupings.Items.Count-1]); } - } - - /// - /// Get the last (dynamic) ColumnGrouping - /// - /// - ColumnGrouping LastDynColumnGrouping - { - get - { - for (int i=_ColumnGroupings.Items.Count-1; i >= 0; i--) - { - ColumnGrouping cg = (ColumnGrouping) (_ColumnGroupings.Items[i]); - if (cg.StaticColumns == null) - return cg; - } - return (ColumnGrouping) (_ColumnGroupings.Items[_ColumnGroupings.Items.Count-1]); - } - } - - /// - /// Get the last (dynamic) RowGrouping - /// - /// - RowGrouping LastDynRowGrouping - { - get - { - for (int i=_RowGroupings.Items.Count-1; i >= 0; i--) - { - RowGrouping rg = (RowGrouping) (_RowGroupings.Items[i]); - if (rg.StaticRows == null) - return rg; - } - return (RowGrouping) (_RowGroupings.Items[_RowGroupings.Items.Count-1]); - } - } - - void HandleRowGrouping(Report rpt, WorkClass wc, Rows rows, Row r, MatrixEntry m, int rgi, int iRow, ref int maxRows) - { - while (rgi < _RowGroupings.Items.Count) - { - RowGrouping rg = _RowGroupings.Items[rgi] as RowGrouping; - Grouping grp=null; - string result; - - if (rg.StaticRows != null) // handle static rows - { - for (int sri=0; sri < rg.StaticRows.Items.Count; sri++) - { - result = Convert.ToChar(Convert.ToInt32('a')+sri).ToString() + terminal; // static row; put all data in it - StaticRow sr = rg.StaticRows.Items[sri] as StaticRow; - MatrixEntry ame; + float WidthOfColumn(MatrixCellEntry[,] matrix, int iCol) + { + int maxRows = matrix.GetLength(0); + for (int iRow = 0; iRow < maxRows; iRow++) + { + if (matrix[iRow, iCol] != null && matrix[iRow, iCol].ColSpan == 1) + return matrix[iRow, iCol].Width; + } + return 0; + } + + async Task RunPageColumns(Pages pgs, WorkClass wc, MatrixCellEntry[,] matrix, int iRow, int maxColumns) + { + Report rpt = pgs.Report; + + float xpos = GetOffsetCalc(pgs.Report) + LeftCalc(rpt); + for (int iColumn = 0; iColumn < maxColumns; iColumn++) + { + MatrixCellEntry mce = matrix[iRow, iColumn]; + + if (mce == null) + { // have a null column but we need to fill column space + xpos += WidthOfColumn(matrix, iColumn); + continue; + } + wc.Data = mce.Data; // Must set this for evaluation + + Row lrow = wc.Data.Data.Count > 0 ? wc.Data.Data[0] : null; + SetGroupingValues(rpt, mce); + mce.DisplayItem.SetMC(rpt, mce); // set for use by the display item + mce.XPosition = xpos; + await mce.DisplayItem.RunPage(pgs, lrow); + xpos += mce.Width; + iColumn += (mce.ColSpan - 1); // skip columns already accounted for + } + } + + // RunBuild is used by both Matrix.Run and Chart.Run to obtain the necessary data + // used by their respective rendering interfaces + internal async Task<(MatrixCellEntry[,], int numRows, int numCols)> RunBuild(Report rpt) + { + int numRows; + int numCols; + + WorkClass wc = GetValue(rpt); + Rows _Data = wc.Data; + + // loop thru all the data; + // form bitmap arrays for each unique data value of each grouping (row and column) value + int maxColumns = _RowGroupings.Items.Count; // maximum # of columns in matrix + // at top we need a row per column grouping + int maxRows = _ColumnGroupings.Items.Count; // maximum # of rows in matrix + // at left we need a column per row grouping + + MatrixEntry mcg = new MatrixEntry(null, "", null, _Data.Data.Count); + _ColumnGroupings.SetME(rpt, mcg); + mcg.FirstRow = 0; + mcg.LastRow = _Data.Data.Count - 1; + mcg.Rows = new BitArray(_Data.Data.Count, true); // all data + + MatrixEntry mrg = new MatrixEntry(null, "", null, _Data.Data.Count); + _RowGroupings.SetME(rpt, mrg); + mrg.FirstRow = 0; + mrg.LastRow = _Data.Data.Count - 1; + mrg.Rows = new BitArray(_Data.Data.Count, true); // all data + + int iRow = 0; // row counter + foreach (Row r in _Data.Data) + { + // Handle the column values + maxColumns = await HandleColumnGrouping(rpt, wc, _Data, r, mcg, 0, iRow, maxColumns); + + // Handle the row values + maxRows = await HandleRowGrouping(rpt, wc, _Data, r, mrg, 0, iRow, maxRows); + + iRow++; + } + + // Determine how many subtotal columns are needed + maxColumns += RunCountSubtotalColumns(rpt, wc, mcg, 0); + + // Determine how many subtotal rows are needed + maxRows += RunCountSubtotalRows(rpt, wc, mrg, 0); + + ///// + // Build and populate the 2 dimensional table of MatrixCellEntry + // that constitute the matrix + ///// + MatrixCellEntry[,] matrix = new MatrixCellEntry[maxRows, maxColumns]; + + // Do the column headings + int iColumn = _RowGroupings.Items.Count; + RunColumnHeaders(rpt, wc, mcg, matrix, _Data, 0, ref iColumn, 0); + + // Do the row headings + iRow = _ColumnGroupings.Items.Count; + RunRowHeaders(rpt, wc, mrg, matrix, _Data, ref iRow, 0, 0); + + // Do the row/column data + iRow = _ColumnGroupings.Items.Count; + RunDataRow(rpt, wc, mrg, mcg, matrix, _Data, ref iRow, _RowGroupings.Items.Count, 0); + + // Do the corner + matrix[0, 0] = RunCorner(_Data); + + // now return the matrix data + numRows = maxRows; + numCols = maxColumns; + return (matrix, numRows, numCols); + } + + int CountMatrixCells + { + get + { + MatrixRow mr = this.MatrixRows.Items[0] as MatrixRow; + return mr.MatrixCells.Items.Count; + } + } + + int CountMatrixColumns + { + get + { + return this.MatrixColumns.Items.Count; + } + } + + int CountMatrixRows + { + get + { + return this.MatrixRows.Items.Count; + } + } + + ColumnGrouping LastCg + { + get { return (ColumnGrouping)(_ColumnGroupings.Items[_ColumnGroupings.Items.Count - 1]); } + } + + RowGrouping LastRg + { + get { return (RowGrouping)(_RowGroupings.Items[_RowGroupings.Items.Count - 1]); } + } + + /// + /// Get the last (dynamic) ColumnGrouping + /// + /// + ColumnGrouping LastDynColumnGrouping + { + get + { + for (int i = _ColumnGroupings.Items.Count - 1; i >= 0; i--) + { + ColumnGrouping cg = (ColumnGrouping)(_ColumnGroupings.Items[i]); + if (cg.StaticColumns == null) + return cg; + } + return (ColumnGrouping)(_ColumnGroupings.Items[_ColumnGroupings.Items.Count - 1]); + } + } + + /// + /// Get the last (dynamic) RowGrouping + /// + /// + RowGrouping LastDynRowGrouping + { + get + { + for (int i = _RowGroupings.Items.Count - 1; i >= 0; i--) + { + RowGrouping rg = (RowGrouping)(_RowGroupings.Items[i]); + if (rg.StaticRows == null) + return rg; + } + return (RowGrouping)(_RowGroupings.Items[_RowGroupings.Items.Count - 1]); + } + } + + async Task HandleRowGrouping(Report rpt, WorkClass wc, Rows rows, Row r, MatrixEntry m, int rgi, int iRow, int maxRows) + { + while (rgi < _RowGroupings.Items.Count) + { + RowGrouping rg = _RowGroupings.Items[rgi] as RowGrouping; + Grouping grp = null; + string result; + + if (rg.StaticRows != null) // handle static rows + { + for (int sri = 0; sri < rg.StaticRows.Items.Count; sri++) + { + result = Convert.ToChar(Convert.ToInt32('a') + sri).ToString() + terminal; // static row; put all data in it + StaticRow sr = rg.StaticRows.Items[sri] as StaticRow; + MatrixEntry ame; m.HashData.TryGetValue(result, out ame); if (ame == null) - { - ame = new MatrixEntry(r, result, m, rows.Data.Count); - ame.RowGroup = rg; - ame.StaticRow = sri; - m.HashData.Add(result, ame); - if (rg == LastRg) // Add a row when we add data at lowest level - maxRows++; - } - ame.Rows.Set(iRow, true); - // Logic in FirstRow and Last row determine whether value gets set - ame.FirstRow = iRow; - ame.LastRow = iRow; - HandleRowGrouping(rpt, wc, rows, r, ame, rgi+1, iRow, ref maxRows); - } - break; // handled ones below it recursively - } - else // handle dynamic columns - { - grp = rg.DynamicRows.Grouping; - - StringBuilder sb = new StringBuilder(); - foreach (GroupExpression ge in grp.GroupExpressions.Items) - { - string temp = ge.Expression.EvaluateString(rpt, r); - if (temp == null || temp == "") - sb.Append(nullterminal); - else - sb.Append(temp); - sb.Append(terminal); // mark end of group - } - result = sb.ToString(); - - MatrixEntry ame; + { + ame = new MatrixEntry(r, result, m, rows.Data.Count); + ame.RowGroup = rg; + ame.StaticRow = sri; + m.HashData.Add(result, ame); + if (rg == LastRg) // Add a row when we add data at lowest level + maxRows++; + } + ame.Rows.Set(iRow, true); + // Logic in FirstRow and Last row determine whether value gets set + ame.FirstRow = iRow; + ame.LastRow = iRow; + maxRows = await HandleRowGrouping(rpt, wc, rows, r, ame, rgi + 1, iRow, maxRows); + } + break; // handled ones below it recursively + } + else // handle dynamic columns + { + grp = rg.DynamicRows.Grouping; + + StringBuilder sb = new StringBuilder(); + foreach (GroupExpression ge in grp.GroupExpressions.Items) + { + string temp = await ge.Expression.EvaluateString(rpt, r); + if (temp == null || temp == "") + sb.Append(nullterminal); + else + sb.Append(temp); + sb.Append(terminal); // mark end of group + } + result = sb.ToString(); + + MatrixEntry ame; m.HashData.TryGetValue(result, out ame); if (ame == null) - { - ame = new MatrixEntry(r, result, m, rows.Data.Count); - ame.RowGroup = rg; - m.HashData.Add(result, ame); - if (rg == LastRg) // Add a row when we add data at lowest level - maxRows++; - } - ame.Rows.Set(iRow, true); - // Logic in FirstRow and Last row determine whether value gets set - ame.FirstRow = iRow; - ame.LastRow = iRow; - m = ame; // now go down a level - rgi++; - } - } - } - - void HandleColumnGrouping(Report rpt, WorkClass wc, Rows rows, Row r, MatrixEntry m, int cgi, int iRow, ref int maxColumns) - { - while (cgi < _ColumnGroupings.Items.Count) - { - ColumnGrouping cg = _ColumnGroupings.Items[cgi] as ColumnGrouping; - Grouping grp=null; - string result; - - if (cg.StaticColumns != null) // handle static columns - { - for (int sci=0; sci < cg.StaticColumns.Items.Count; sci++) - { - result = Convert.ToChar(Convert.ToInt32('a')+sci).ToString() + terminal; // static column; put all data in it - StaticColumn sc = cg.StaticColumns.Items[sci] as StaticColumn; - MatrixEntry ame; + { + ame = new MatrixEntry(r, result, m, rows.Data.Count); + ame.RowGroup = rg; + m.HashData.Add(result, ame); + if (rg == LastRg) // Add a row when we add data at lowest level + maxRows++; + } + ame.Rows.Set(iRow, true); + // Logic in FirstRow and Last row determine whether value gets set + ame.FirstRow = iRow; + ame.LastRow = iRow; + m = ame; // now go down a level + rgi++; + } + } + + return maxRows; + } + + async Task HandleColumnGrouping(Report rpt, WorkClass wc, Rows rows, Row r, MatrixEntry m, int cgi, int iRow, int maxColumns) + { + while (cgi < _ColumnGroupings.Items.Count) + { + ColumnGrouping cg = _ColumnGroupings.Items[cgi] as ColumnGrouping; + Grouping grp = null; + string result; + + if (cg.StaticColumns != null) // handle static columns + { + for (int sci = 0; sci < cg.StaticColumns.Items.Count; sci++) + { + result = Convert.ToChar(Convert.ToInt32('a') + sci).ToString() + terminal; // static column; put all data in it + StaticColumn sc = cg.StaticColumns.Items[sci] as StaticColumn; + MatrixEntry ame; m.HashData.TryGetValue(result, out ame); if (ame == null) - { - ame = new MatrixEntry(r, result, m, rows.Data.Count); - ame.ColumnGroup = cg; - ame.StaticColumn = sci; - m.HashData.Add(result, ame); - if (cg == LastCg) // Add a column when we add data at lowest level - maxColumns++; - } - ame.Rows.Set(iRow, true); - // Logic in FirstRow and Last row determine whether value gets set - ame.FirstRow = iRow; - ame.LastRow = iRow; - HandleColumnGrouping(rpt, wc, rows, r, ame, cgi+1, iRow, ref maxColumns); - } - break; // handled ones below it recursively - } - else // handle dynamic columns - { - grp = cg.DynamicColumns.Grouping; - - StringBuilder sb = new StringBuilder(); - foreach (GroupExpression ge in grp.GroupExpressions.Items) - { - string temp = ge.Expression.EvaluateString(rpt, r); - if (temp == null || temp == "") - sb.Append(nullterminal); - else - sb.Append(temp); - sb.Append(terminal); // mark end of group - } - result = sb.ToString(); - - MatrixEntry ame; + { + ame = new MatrixEntry(r, result, m, rows.Data.Count); + ame.ColumnGroup = cg; + ame.StaticColumn = sci; + m.HashData.Add(result, ame); + if (cg == LastCg) // Add a column when we add data at lowest level + maxColumns++; + } + ame.Rows.Set(iRow, true); + // Logic in FirstRow and Last row determine whether value gets set + ame.FirstRow = iRow; + ame.LastRow = iRow; + maxColumns = await HandleColumnGrouping(rpt, wc, rows, r, ame, cgi + 1, iRow, maxColumns); + } + break; // handled ones below it recursively + } + else // handle dynamic columns + { + grp = cg.DynamicColumns.Grouping; + + StringBuilder sb = new StringBuilder(); + foreach (GroupExpression ge in grp.GroupExpressions.Items) + { + string temp = await ge.Expression.EvaluateString(rpt, r); + if (temp == null || temp == "") + sb.Append(nullterminal); + else + sb.Append(temp); + sb.Append(terminal); // mark end of group + } + result = sb.ToString(); + + MatrixEntry ame; m.HashData.TryGetValue(result, out ame); - if (ame == null) - { - ame = new MatrixEntry(r, result, m, rows.Data.Count); - ame.ColumnGroup = cg; - m.HashData.Add(result, ame); - if (cg == LastCg) // Add a column when we add data at lowest level - maxColumns++; - } - ame.Rows.Set(iRow, true); - // Logic in FirstRow and Last row determine whether value gets set - ame.FirstRow = iRow; - ame.LastRow = iRow; - m = ame; // now go down a level - cgi++; - } - } - } - - int RunCountSubtotalColumns(Report rpt, WorkClass wc, MatrixEntry m, int level) - { - // Get the number of static columns - int scCount = Math.Max(1, this._ColumnGroupings.StaticCount); - - int count = 0; - // Increase the column count when subtotal is requested at this level - ColumnGrouping cg = (ColumnGrouping) (_ColumnGroupings.Items[level]); - if (cg.DynamicColumns != null && - cg.DynamicColumns.Subtotal != null) - count = scCount; - - if (m.GetSortedData(rpt) == null || level+1 >= _ColumnGroupings.Items.Count) - return count; - - // Now dive into the data - foreach (MatrixEntry ame in m.GetSortedData(rpt)) - { - count += RunCountSubtotalColumns(rpt, wc, ame, level+1); - } - - return count; - } - - int RunCountSubtotalRows(Report rpt, WorkClass wc, MatrixEntry m, int level) - { - // Get the number of static columns - int srCount = Math.Max(1, this._RowGroupings.StaticCount); - - int count = 0; - // Increase the row count when subtotal is requested at this level - RowGrouping rg = (RowGrouping) (_RowGroupings.Items[level]); - if (rg.DynamicRows != null && - rg.DynamicRows.Subtotal != null) - count = srCount; - - if (m.GetSortedData(rpt) == null || level+1 >= _RowGroupings.Items.Count) - return count; - - // Now dive into the data - foreach (MatrixEntry ame in m.GetSortedData(rpt)) - { - count += RunCountSubtotalRows(rpt, wc, ame, level+1); - } - - return count; - } - - void RunColumnHeaders(Report rpt, WorkClass wc, MatrixEntry m, MatrixCellEntry[,] matrix, Rows _Data, int iRow, ref int iColumn, int level) - { - foreach (MatrixEntry ame in m.GetSortedData(rpt)) - { - matrix[iRow, iColumn] = RunGetColumnHeader(rpt, ame, _Data); - matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); - matrix[iRow, iColumn].Height = ame.ColumnGroup.Height == null? 0: ame.ColumnGroup.Height.Points; - if (ame.GetSortedData(rpt) != null) - { - RunColumnHeaders(rpt, wc, ame, matrix, _Data, iRow+1, ref iColumn, level+1); - } - else - iColumn++; - } - - ColumnGrouping cg = (ColumnGrouping) (_ColumnGroupings.Items[level]); - - // if we need subtotal on the group - if (cg.DynamicColumns != null && - cg.DynamicColumns.Subtotal != null) - { - ReportItem ri = cg.DynamicColumns.Subtotal.ReportItems.Items[0]; - matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri); - matrix[iRow, iColumn].Height = cg.Height.Points; - matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); - RunColumnStaticHeaders(rpt, wc, matrix, _Data, iRow, iColumn, level); - iColumn += this.CountMatrixCells; - } - } - - void RunColumnStaticHeaders(Report rpt, WorkClass wc, MatrixCellEntry[,] matrix, Rows _Data, int iRow, int iColumn, int level) - { - ColumnGrouping cg=null; - for (int i=level+1; i < _ColumnGroupings.Items.Count; i++) - { - iRow++; // the row will below the headers - cg = (ColumnGrouping) (_ColumnGroupings.Items[i]); - if (cg.StaticColumns != null) - break; - } - if (cg == null || cg.StaticColumns == null) - return; - - foreach (StaticColumn sc in cg.StaticColumns.Items) - { - ReportItem ri = sc.ReportItems.Items[0]; - matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri); - matrix[iRow, iColumn].Height = cg.Height.Points; - matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); - - iColumn++; - } - return; - } - - float RunGetColumnWidth(MatrixCellEntry mce) - { - if (this.MatrixColumns == null) - return 0; // We use this routine for chart(s) and they don't build the matrix columns - - MatrixColumn mcol; // work variable to hold a MatrixColumn - - mcol = this.MatrixColumns.Items[0] as MatrixColumn; - float defWidth = mcol.Width.Points; - - if (CountMatrixColumns == 1) // if only one column width is easy - return defWidth; - - // find out which static column it is. - ColumnGrouping cg=null; - MatrixCells mcells=null; - ReportItem ri = mce.DisplayItem; - for (ReportLink rl= ri.Parent; rl != null; rl = rl.Parent) - { - if (rl is ColumnGrouping) - { - cg = rl as ColumnGrouping; - break; - } - if (rl is MatrixCells) - { - mcells = rl as MatrixCells; - break; - } - if (rl is Matrix) - break; - } - - int offset = 0; - - // If the item is one of the MatrixCell; then use same offset - if (mcells != null) - { - foreach (MatrixCell mcell in mcells.Items) - { - ReportItem ric = mcell.ReportItems.Items[0] as ReportItem; - if (ric == ri) - { - mcol = this.MatrixColumns.Items[offset] as MatrixColumn; - return mcol.Width.Points; - } - offset++; - } - return defWidth; - } - - if (cg == null || cg.StaticColumns == null) - return defWidth; - - // Otherwise find the same relative Matrix Column from the static columns - mcol=null; - foreach (StaticColumn sc in cg.StaticColumns.Items) - { - ReportItem cri = sc.ReportItems.Items[0] as ReportItem; - if (ri == cri) - { - mcol = this.MatrixColumns.Items[offset] as MatrixColumn; - break; - } - offset++; - } - - return mcol == null? defWidth: mcol.Width.Points; - } - - MatrixCellEntry RunGetColumnHeader(Report rpt, MatrixEntry me, Rows _Data) - { - ReportItem ri; - if (me.ColumnGroup.StaticColumns != null) - { // Handle static column reference - StaticColumn sc = me.ColumnGroup.StaticColumns.Items[me.StaticColumn] as StaticColumn; - ri = sc.ReportItems.Items[0]; - } - else - ri = me.ColumnGroup.DynamicColumns.ReportItems.Items[0]; // dynamic column - Rows subData = new Rows(rpt, _Data, me.FirstRow, me.LastRow, me.Rows); - MatrixCellEntry mce = new MatrixCellEntry(subData, ri); - - return mce; - } - - MatrixCellEntry RunCorner(Rows d) - { - if (_Corner == null) - return null; - - ReportItem ri = _Corner.ReportItems.Items[0]; - MatrixCellEntry mce = new MatrixCellEntry(d, ri); - - float height=0; - foreach (ColumnGrouping cg in this.ColumnGroupings.Items) - { - height += cg.Height.Points; - } - mce.Height = height; - - float width=0; - foreach (RowGrouping rg in this.RowGroupings.Items) - { - width += rg.Width.Points; - } - mce.Width = width; - - mce.ColSpan = RowGroupings.Items.Count; - return mce; - } - - void RunDataColumn(Report rpt, WorkClass wc, MatrixEntry rm, MatrixEntry cm, MatrixCellEntry[,] matrix, Rows _Data, int iRow, ref int iColumn, int level, int rowcell) - { - BitArray andData; - MatrixRow mr = this.MatrixRows.Items[rowcell] as MatrixRow; - float height = mr.Height == null? 0: mr.Height.Points; - - foreach (MatrixEntry ame in cm.GetSortedData(rpt)) - { - if (ame.ColumnGroup != LastCg) - { - RunDataColumn(rpt, wc, rm, ame, matrix, _Data, iRow, ref iColumn, level+1, rowcell); - continue; - } - andData = new BitArray(ame.Rows); // copy the data - andData.And(rm.Rows); // because And is destructive - matrix[iRow, iColumn] = RunGetMatrixCell(rpt, ame, iRow, _Data, andData, - Math.Max(rm.FirstRow, ame.FirstRow), - Math.Min(rm.LastRow, ame.LastRow)); - matrix[iRow, iColumn].Height = height; - matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); - matrix[iRow, iColumn].ColumnME = ame; - matrix[iRow, iColumn].RowME = rm; - - iColumn++; - } - // do we need to subtotal this? - ColumnGrouping cg = (ColumnGrouping) (_ColumnGroupings.Items[level]); - if (cg.DynamicColumns != null && - cg.DynamicColumns.Subtotal != null) - { - andData = new BitArray(cm.Rows); // copy the data - andData.And(rm.Rows); // because And is destructive - for (int i=0; i < this.CountMatrixCells; i++) - { - matrix[iRow, iColumn] = RunGetMatrixCell(rpt, cm, rowcell, i, _Data, andData, - Math.Max(rm.FirstRow, cm.FirstRow), - Math.Min(rm.LastRow, cm.LastRow)); - matrix[iRow, iColumn].Height = height; - matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); - matrix[iRow, iColumn].ColumnME = cm; - matrix[iRow, iColumn].RowME = rm; - iColumn++; - } - } - } - - void RunDataRow(Report rpt, WorkClass wc, MatrixEntry rm, MatrixEntry cm, MatrixCellEntry[,] matrix, Rows _Data, ref int iRow, int iColumn, int level) - { - int saveColumn; - int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have - int rgsCount = this.RowGroupings.StaticCount; // count of static row groups - foreach (MatrixEntry ame in rm.GetSortedData(rpt)) - { - if (ame.RowGroup != LastRg) - { - RunDataRow(rpt, wc, ame, cm, matrix, _Data, ref iRow, iColumn, level+1); - continue; - } - saveColumn = iColumn; - int rowcell = rgsCount == 0? 0: (iRow - headerRows) % rgsCount; - RunDataColumn(rpt, wc, ame, cm, matrix, _Data, iRow, ref saveColumn, 0, rowcell); - iRow++; - } - // do we need to subtotal this? - RowGrouping rg = (RowGrouping) (_RowGroupings.Items[level]); - if (rg.DynamicRows != null && - rg.DynamicRows.Subtotal != null) - { - for (int i=0; i < this.CountMatrixRows; i++) - { - saveColumn = iColumn; - RunDataColumn(rpt, wc, rm, cm, matrix, _Data, iRow, ref saveColumn, 0, i); - iRow++; - } - } - } - - void RunRowHeaders(Report rpt, WorkClass wc, MatrixEntry m, MatrixCellEntry[,] matrix, Rows _Data, ref int iRow, int iColumn, int level) - { - foreach (MatrixEntry ame in m.GetSortedData(rpt)) - { - matrix[iRow, iColumn] = RunGetRowHeader(rpt, ame, _Data); - matrix[iRow, iColumn].Height = RunRowHeight(iRow); - matrix[iRow, iColumn].Width = ame.RowGroup.Width == null? 0: ame.RowGroup.Width.Points; - if (ame.GetSortedData(rpt) != null) - { - RunRowHeaders(rpt, wc, ame, matrix, _Data, ref iRow, iColumn+1, level+1); - } - else - iRow++; - } - - RowGrouping rg = (RowGrouping) (_RowGroupings.Items[level]); - // do we need to subtotal this - if (rg.DynamicRows != null && - rg.DynamicRows.Subtotal != null) - { // TODO need to loop thru static?? - ReportItem ri = rg.DynamicRows.Subtotal.ReportItems.Items[0]; - matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri); - matrix[iRow, iColumn].Width = rg.Width.Points; - matrix[iRow, iColumn].Height = RunRowHeight(iRow); - RunRowStaticHeaders(rpt, wc, matrix, _Data, iRow, level); - iRow += Math.Max(1,this.RowGroupings.StaticCount); - } - } - - float RunRowHeight(int iRow) - { - // calculate the height of this row - int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have - int rgsCount = this.RowGroupings.StaticCount; // count of static row groups - int rowcell = rgsCount == 0? 0: (iRow - headerRows) % rgsCount; - MatrixRow mr = this.MatrixRows.Items[rowcell] as MatrixRow; // get height - float height = mr.Height == null? 0: mr.Height.Points; - return height; - } - - void RunRowStaticHeaders(Report rpt, WorkClass wc, MatrixCellEntry[,] matrix, Rows _Data, int iRow, int level) - { - RowGrouping rg=null; - int i; - int iColumn=0; - for (i=level+1; i < _RowGroupings.Items.Count; i++) - { - iColumn++; // Column for the row static headers - rg = (RowGrouping) (_RowGroupings.Items[i]); - if (rg.StaticRows != null) - break; - } - if (rg == null || rg.StaticRows == null) - return; - - i=0; - foreach (StaticRow sr in rg.StaticRows.Items) - { - ReportItem ri = sr.ReportItems.Items[0]; - matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri); - matrix[iRow, iColumn].Width = rg.Width.Points; - MatrixRow mr = this.MatrixRows.Items[i++] as MatrixRow; - float height = mr.Height == null? 0: mr.Height.Points; - matrix[iRow, iColumn].Height = height; - - iRow++; - } - return; - } - - MatrixCellEntry RunGetRowHeader(Report rpt, MatrixEntry me, Rows _Data) - { - ReportItem ri; - if (me.RowGroup.StaticRows != null) - { // Handle static row reference - StaticRow sr = me.RowGroup.StaticRows.Items[me.StaticRow] as StaticRow; - ri = sr.ReportItems.Items[0]; - } - else // handle dynamic row reference - ri = me.RowGroup.DynamicRows.ReportItems.Items[0]; - Rows subData = new Rows(rpt, _Data, me.FirstRow, me.LastRow, me.Rows); - MatrixCellEntry mce = new MatrixCellEntry(subData, ri); - - return mce; - - } - - MatrixCellEntry RunGetMatrixCell(Report rpt, MatrixEntry me, int iRow, Rows _Data, BitArray rows, int firstRow, int lastRow) - { - int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have - int rgsCount = this.RowGroupings.StaticCount; // count of static row groups - int rowcell = rgsCount == 0? 0: (iRow - headerRows) % rgsCount; - - return RunGetMatrixCell(rpt, me, rowcell, me.StaticColumn, _Data, rows, firstRow, lastRow); - } - - MatrixCellEntry RunGetMatrixCell(Report rpt, MatrixEntry me, int rcell, int ccell, Rows _Data, BitArray rows, int firstRow, int lastRow) - { - MatrixRow mr = this._MatrixRows.Items[rcell]; - MatrixCell mc = mr.MatrixCells.Items[ccell]; - ReportItem ri = mc.ReportItems.Items[0]; - Rows subData = new Rows(rpt, _Data, firstRow, lastRow, rows); - MatrixCellEntry mce = new MatrixCellEntry(subData, ri); - - return mce; - } - - internal Corner Corner - { - get { return _Corner; } - set { _Corner = value; } - } - - internal ColumnGroupings ColumnGroupings - { - get { return _ColumnGroupings; } - set { _ColumnGroupings = value; } - } - - internal Rows GetMyData(Report rpt) - { - WorkClass wc = GetValue(rpt); - return wc.Data; - } - - internal void SetMyData(Report rpt, Rows data) - { - WorkClass wc = GetValue(rpt); - wc.Data = data; - } - - internal RowGroupings RowGroupings - { - get { return _RowGroupings; } - set { _RowGroupings = value; } - } - - internal MatrixRows MatrixRows - { - get { return _MatrixRows; } - set { _MatrixRows = value; } - } - - internal MatrixColumns MatrixColumns - { - get { return _MatrixColumns; } - set { _MatrixColumns = value; } - } - - internal MatrixLayoutDirectionEnum LayoutDirection - { - get { return _LayoutDirection; } - set { _LayoutDirection = value; } - } - - internal int GroupsBeforeRowHeaders - { - get { return _GroupsBeforeRowHeaders; } - set { _GroupsBeforeRowHeaders = value; } - } - - internal string CellDataElementName - { - get { return _CellDataElementName; } - set { _CellDataElementName = value; } - } - - private void SetGroupingValues(Report rpt, MatrixCellEntry mce) - { - WorkClass wc = GetValue(rpt); - Rows data = wc.FullData; - - SetGroupingValuesInit(rpt, data, mce.RowME, mce.ColumnME); - SetGroupingValuesMe(rpt, data, mce.RowME); - SetGroupingValuesMe(rpt, data, mce.ColumnME); - - return; - } - - private void SetGroupingValuesInit(Report rpt, Rows data, MatrixEntry rme, MatrixEntry cme) - { - // handle the column grouping - if (cme != null) - { - foreach (ColumnGrouping cg in this.ColumnGroupings.Items) - { - if (cg.DynamicColumns != null) - SetGrouping(rpt, cg.DynamicColumns.Grouping, cme, data); - } - } - // handle the row grouping - if (rme != null) - { - foreach (RowGrouping rg in this.RowGroupings.Items) - { - if (rg.DynamicRows != null) - SetGrouping(rpt, rg.DynamicRows.Grouping, rme, data); - } - } - } - - private void SetGroupingValuesMe(Report rpt, Rows data, MatrixEntry me) - { - if (me == null) - return; - // handle the column grouping - if (me.ColumnGroup != null && me.ColumnGroup.DynamicColumns != null) - SetGrouping(rpt, me.ColumnGroup.DynamicColumns.Grouping, me, data); - - // handle the row grouping - if (me.RowGroup != null && me.RowGroup.DynamicRows != null) - SetGrouping(rpt, me.RowGroup.DynamicRows.Grouping, me, data); - - if (me.Parent != null) // go up the tree?? - SetGroupingValuesMe(rpt, data, me.Parent); - } - - private void SetGrouping(Report rpt, Grouping g, MatrixEntry me, Rows data) - { - if (g == null) - return; - - if (me.Data == null) - me.Data = new Rows(rpt, data, me.FirstRow, me.LastRow, me.Rows); - g.SetRows(rpt, me.Data); - } - - internal MatrixCellDataElementOutputEnum CellDataElementOutput - { - get { return _CellDataElementOutput; } - set { _CellDataElementOutput = value; } - } - - private WorkClass GetValue(Report rpt) - { - WorkClass wc = rpt.Cache.Get(this, "wc") as WorkClass; - if (wc == null) - { - wc = new WorkClass(); - rpt.Cache.Add(this, "wc", wc); - } - return wc; - } - - private void RemoveValue(Report rpt) - { - rpt.Cache.Remove(this, "wc"); - } - - class WorkClass - { - internal Rows Data; - internal Rows FullData; - internal WorkClass() - { - Data=null; - FullData=null; - } - } - } + if (ame == null) + { + ame = new MatrixEntry(r, result, m, rows.Data.Count); + ame.ColumnGroup = cg; + m.HashData.Add(result, ame); + if (cg == LastCg) // Add a column when we add data at lowest level + maxColumns++; + } + ame.Rows.Set(iRow, true); + // Logic in FirstRow and Last row determine whether value gets set + ame.FirstRow = iRow; + ame.LastRow = iRow; + m = ame; // now go down a level + cgi++; + } + } + + return maxColumns; + + } + + int RunCountSubtotalColumns(Report rpt, WorkClass wc, MatrixEntry m, int level) + { + // Get the number of static columns + int scCount = Math.Max(1, this._ColumnGroupings.StaticCount); + + int count = 0; + // Increase the column count when subtotal is requested at this level + ColumnGrouping cg = (ColumnGrouping)(_ColumnGroupings.Items[level]); + if (cg.DynamicColumns != null && + cg.DynamicColumns.Subtotal != null) + count = scCount; + + if (m.GetSortedData(rpt) == null || level + 1 >= _ColumnGroupings.Items.Count) + return count; + + // Now dive into the data + foreach (MatrixEntry ame in m.GetSortedData(rpt)) + { + count += RunCountSubtotalColumns(rpt, wc, ame, level + 1); + } + + return count; + } + + int RunCountSubtotalRows(Report rpt, WorkClass wc, MatrixEntry m, int level) + { + // Get the number of static columns + int srCount = Math.Max(1, this._RowGroupings.StaticCount); + + int count = 0; + // Increase the row count when subtotal is requested at this level + RowGrouping rg = (RowGrouping)(_RowGroupings.Items[level]); + if (rg.DynamicRows != null && + rg.DynamicRows.Subtotal != null) + count = srCount; + + if (m.GetSortedData(rpt) == null || level + 1 >= _RowGroupings.Items.Count) + return count; + + // Now dive into the data + foreach (MatrixEntry ame in m.GetSortedData(rpt)) + { + count += RunCountSubtotalRows(rpt, wc, ame, level + 1); + } + + return count; + } + + void RunColumnHeaders(Report rpt, WorkClass wc, MatrixEntry m, MatrixCellEntry[,] matrix, Rows _Data, int iRow, ref int iColumn, int level) + { + foreach (MatrixEntry ame in m.GetSortedData(rpt)) + { + matrix[iRow, iColumn] = RunGetColumnHeader(rpt, ame, _Data); + matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); + matrix[iRow, iColumn].Height = ame.ColumnGroup.Height == null ? 0 : ame.ColumnGroup.Height.Points; + if (ame.GetSortedData(rpt) != null) + { + RunColumnHeaders(rpt, wc, ame, matrix, _Data, iRow + 1, ref iColumn, level + 1); + } + else + iColumn++; + } + + ColumnGrouping cg = (ColumnGrouping)(_ColumnGroupings.Items[level]); + + // if we need subtotal on the group + if (cg.DynamicColumns != null && + cg.DynamicColumns.Subtotal != null) + { + ReportItem ri = cg.DynamicColumns.Subtotal.ReportItems.Items[0]; + matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri); + matrix[iRow, iColumn].Height = cg.Height.Points; + matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); + RunColumnStaticHeaders(rpt, wc, matrix, _Data, iRow, iColumn, level); + iColumn += this.CountMatrixCells; + } + } + + void RunColumnStaticHeaders(Report rpt, WorkClass wc, MatrixCellEntry[,] matrix, Rows _Data, int iRow, int iColumn, int level) + { + ColumnGrouping cg = null; + for (int i = level + 1; i < _ColumnGroupings.Items.Count; i++) + { + iRow++; // the row will below the headers + cg = (ColumnGrouping)(_ColumnGroupings.Items[i]); + if (cg.StaticColumns != null) + break; + } + if (cg == null || cg.StaticColumns == null) + return; + + foreach (StaticColumn sc in cg.StaticColumns.Items) + { + ReportItem ri = sc.ReportItems.Items[0]; + matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri); + matrix[iRow, iColumn].Height = cg.Height.Points; + matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); + + iColumn++; + } + return; + } + + float RunGetColumnWidth(MatrixCellEntry mce) + { + if (this.MatrixColumns == null) + return 0; // We use this routine for chart(s) and they don't build the matrix columns + + MatrixColumn mcol; // work variable to hold a MatrixColumn + + mcol = this.MatrixColumns.Items[0] as MatrixColumn; + float defWidth = mcol.Width.Points; + + if (CountMatrixColumns == 1) // if only one column width is easy + return defWidth; + + // find out which static column it is. + ColumnGrouping cg = null; + MatrixCells mcells = null; + ReportItem ri = mce.DisplayItem; + for (ReportLink rl = ri.Parent; rl != null; rl = rl.Parent) + { + if (rl is ColumnGrouping) + { + cg = rl as ColumnGrouping; + break; + } + if (rl is MatrixCells) + { + mcells = rl as MatrixCells; + break; + } + if (rl is Matrix) + break; + } + + int offset = 0; + + // If the item is one of the MatrixCell; then use same offset + if (mcells != null) + { + foreach (MatrixCell mcell in mcells.Items) + { + ReportItem ric = mcell.ReportItems.Items[0] as ReportItem; + if (ric == ri) + { + mcol = this.MatrixColumns.Items[offset] as MatrixColumn; + return mcol.Width.Points; + } + offset++; + } + return defWidth; + } + + if (cg == null || cg.StaticColumns == null) + return defWidth; + + // Otherwise find the same relative Matrix Column from the static columns + mcol = null; + foreach (StaticColumn sc in cg.StaticColumns.Items) + { + ReportItem cri = sc.ReportItems.Items[0] as ReportItem; + if (ri == cri) + { + mcol = this.MatrixColumns.Items[offset] as MatrixColumn; + break; + } + offset++; + } + + return mcol == null ? defWidth : mcol.Width.Points; + } + + MatrixCellEntry RunGetColumnHeader(Report rpt, MatrixEntry me, Rows _Data) + { + ReportItem ri; + if (me.ColumnGroup.StaticColumns != null) + { // Handle static column reference + StaticColumn sc = me.ColumnGroup.StaticColumns.Items[me.StaticColumn] as StaticColumn; + ri = sc.ReportItems.Items[0]; + } + else + ri = me.ColumnGroup.DynamicColumns.ReportItems.Items[0]; // dynamic column + Rows subData = new Rows(rpt, _Data, me.FirstRow, me.LastRow, me.Rows); + MatrixCellEntry mce = new MatrixCellEntry(subData, ri); + + return mce; + } + + MatrixCellEntry RunCorner(Rows d) + { + if (_Corner == null) + return null; + + ReportItem ri = _Corner.ReportItems.Items[0]; + MatrixCellEntry mce = new MatrixCellEntry(d, ri); + + float height = 0; + foreach (ColumnGrouping cg in this.ColumnGroupings.Items) + { + height += cg.Height.Points; + } + mce.Height = height; + + float width = 0; + foreach (RowGrouping rg in this.RowGroupings.Items) + { + width += rg.Width.Points; + } + mce.Width = width; + + mce.ColSpan = RowGroupings.Items.Count; + return mce; + } + + void RunDataColumn(Report rpt, WorkClass wc, MatrixEntry rm, MatrixEntry cm, MatrixCellEntry[,] matrix, Rows _Data, int iRow, ref int iColumn, int level, int rowcell) + { + BitArray andData; + MatrixRow mr = this.MatrixRows.Items[rowcell] as MatrixRow; + float height = mr.Height == null ? 0 : mr.Height.Points; + + foreach (MatrixEntry ame in cm.GetSortedData(rpt)) + { + if (ame.ColumnGroup != LastCg) + { + RunDataColumn(rpt, wc, rm, ame, matrix, _Data, iRow, ref iColumn, level + 1, rowcell); + continue; + } + andData = new BitArray(ame.Rows); // copy the data + andData.And(rm.Rows); // because And is destructive + matrix[iRow, iColumn] = RunGetMatrixCell(rpt, ame, iRow, _Data, andData, + Math.Max(rm.FirstRow, ame.FirstRow), + Math.Min(rm.LastRow, ame.LastRow)); + matrix[iRow, iColumn].Height = height; + matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); + matrix[iRow, iColumn].ColumnME = ame; + matrix[iRow, iColumn].RowME = rm; + + iColumn++; + } + // do we need to subtotal this? + ColumnGrouping cg = (ColumnGrouping)(_ColumnGroupings.Items[level]); + if (cg.DynamicColumns != null && + cg.DynamicColumns.Subtotal != null) + { + andData = new BitArray(cm.Rows); // copy the data + andData.And(rm.Rows); // because And is destructive + for (int i = 0; i < this.CountMatrixCells; i++) + { + matrix[iRow, iColumn] = RunGetMatrixCell(rpt, cm, rowcell, i, _Data, andData, + Math.Max(rm.FirstRow, cm.FirstRow), + Math.Min(rm.LastRow, cm.LastRow)); + matrix[iRow, iColumn].Height = height; + matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]); + matrix[iRow, iColumn].ColumnME = cm; + matrix[iRow, iColumn].RowME = rm; + iColumn++; + } + } + } + + void RunDataRow(Report rpt, WorkClass wc, MatrixEntry rm, MatrixEntry cm, MatrixCellEntry[,] matrix, Rows _Data, ref int iRow, int iColumn, int level) + { + int saveColumn; + int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have + int rgsCount = this.RowGroupings.StaticCount; // count of static row groups + foreach (MatrixEntry ame in rm.GetSortedData(rpt)) + { + if (ame.RowGroup != LastRg) + { + RunDataRow(rpt, wc, ame, cm, matrix, _Data, ref iRow, iColumn, level + 1); + continue; + } + saveColumn = iColumn; + int rowcell = rgsCount == 0 ? 0 : (iRow - headerRows) % rgsCount; + RunDataColumn(rpt, wc, ame, cm, matrix, _Data, iRow, ref saveColumn, 0, rowcell); + iRow++; + } + // do we need to subtotal this? + RowGrouping rg = (RowGrouping)(_RowGroupings.Items[level]); + if (rg.DynamicRows != null && + rg.DynamicRows.Subtotal != null) + { + for (int i = 0; i < this.CountMatrixRows; i++) + { + saveColumn = iColumn; + RunDataColumn(rpt, wc, rm, cm, matrix, _Data, iRow, ref saveColumn, 0, i); + iRow++; + } + } + } + + void RunRowHeaders(Report rpt, WorkClass wc, MatrixEntry m, MatrixCellEntry[,] matrix, Rows _Data, ref int iRow, int iColumn, int level) + { + foreach (MatrixEntry ame in m.GetSortedData(rpt)) + { + matrix[iRow, iColumn] = RunGetRowHeader(rpt, ame, _Data); + matrix[iRow, iColumn].Height = RunRowHeight(iRow); + matrix[iRow, iColumn].Width = ame.RowGroup.Width == null ? 0 : ame.RowGroup.Width.Points; + if (ame.GetSortedData(rpt) != null) + { + RunRowHeaders(rpt, wc, ame, matrix, _Data, ref iRow, iColumn + 1, level + 1); + } + else + iRow++; + } + + RowGrouping rg = (RowGrouping)(_RowGroupings.Items[level]); + // do we need to subtotal this + if (rg.DynamicRows != null && + rg.DynamicRows.Subtotal != null) + { // TODO need to loop thru static?? + ReportItem ri = rg.DynamicRows.Subtotal.ReportItems.Items[0]; + matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri); + matrix[iRow, iColumn].Width = rg.Width.Points; + matrix[iRow, iColumn].Height = RunRowHeight(iRow); + RunRowStaticHeaders(rpt, wc, matrix, _Data, iRow, level); + iRow += Math.Max(1, this.RowGroupings.StaticCount); + } + } + + float RunRowHeight(int iRow) + { + // calculate the height of this row + int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have + int rgsCount = this.RowGroupings.StaticCount; // count of static row groups + int rowcell = rgsCount == 0 ? 0 : (iRow - headerRows) % rgsCount; + MatrixRow mr = this.MatrixRows.Items[rowcell] as MatrixRow; // get height + float height = mr.Height == null ? 0 : mr.Height.Points; + return height; + } + + void RunRowStaticHeaders(Report rpt, WorkClass wc, MatrixCellEntry[,] matrix, Rows _Data, int iRow, int level) + { + RowGrouping rg = null; + int i; + int iColumn = 0; + for (i = level + 1; i < _RowGroupings.Items.Count; i++) + { + iColumn++; // Column for the row static headers + rg = (RowGrouping)(_RowGroupings.Items[i]); + if (rg.StaticRows != null) + break; + } + if (rg == null || rg.StaticRows == null) + return; + + i = 0; + foreach (StaticRow sr in rg.StaticRows.Items) + { + ReportItem ri = sr.ReportItems.Items[0]; + matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri); + matrix[iRow, iColumn].Width = rg.Width.Points; + MatrixRow mr = this.MatrixRows.Items[i++] as MatrixRow; + float height = mr.Height == null ? 0 : mr.Height.Points; + matrix[iRow, iColumn].Height = height; + + iRow++; + } + return; + } + + MatrixCellEntry RunGetRowHeader(Report rpt, MatrixEntry me, Rows _Data) + { + ReportItem ri; + if (me.RowGroup.StaticRows != null) + { // Handle static row reference + StaticRow sr = me.RowGroup.StaticRows.Items[me.StaticRow] as StaticRow; + ri = sr.ReportItems.Items[0]; + } + else // handle dynamic row reference + ri = me.RowGroup.DynamicRows.ReportItems.Items[0]; + Rows subData = new Rows(rpt, _Data, me.FirstRow, me.LastRow, me.Rows); + MatrixCellEntry mce = new MatrixCellEntry(subData, ri); + + return mce; + + } + + MatrixCellEntry RunGetMatrixCell(Report rpt, MatrixEntry me, int iRow, Rows _Data, BitArray rows, int firstRow, int lastRow) + { + int headerRows = _ColumnGroupings.Items.Count; // number of column headers we have + int rgsCount = this.RowGroupings.StaticCount; // count of static row groups + int rowcell = rgsCount == 0 ? 0 : (iRow - headerRows) % rgsCount; + + return RunGetMatrixCell(rpt, me, rowcell, me.StaticColumn, _Data, rows, firstRow, lastRow); + } + + MatrixCellEntry RunGetMatrixCell(Report rpt, MatrixEntry me, int rcell, int ccell, Rows _Data, BitArray rows, int firstRow, int lastRow) + { + MatrixRow mr = this._MatrixRows.Items[rcell]; + MatrixCell mc = mr.MatrixCells.Items[ccell]; + ReportItem ri = mc.ReportItems.Items[0]; + Rows subData = new Rows(rpt, _Data, firstRow, lastRow, rows); + MatrixCellEntry mce = new MatrixCellEntry(subData, ri); + + return mce; + } + + internal Corner Corner + { + get { return _Corner; } + set { _Corner = value; } + } + + internal ColumnGroupings ColumnGroupings + { + get { return _ColumnGroupings; } + set { _ColumnGroupings = value; } + } + + internal Rows GetMyData(Report rpt) + { + WorkClass wc = GetValue(rpt); + return wc.Data; + } + + internal void SetMyData(Report rpt, Rows data) + { + WorkClass wc = GetValue(rpt); + wc.Data = data; + } + + internal RowGroupings RowGroupings + { + get { return _RowGroupings; } + set { _RowGroupings = value; } + } + + internal MatrixRows MatrixRows + { + get { return _MatrixRows; } + set { _MatrixRows = value; } + } + + internal MatrixColumns MatrixColumns + { + get { return _MatrixColumns; } + set { _MatrixColumns = value; } + } + + internal MatrixLayoutDirectionEnum LayoutDirection + { + get { return _LayoutDirection; } + set { _LayoutDirection = value; } + } + + internal int GroupsBeforeRowHeaders + { + get { return _GroupsBeforeRowHeaders; } + set { _GroupsBeforeRowHeaders = value; } + } + + internal string CellDataElementName + { + get { return _CellDataElementName; } + set { _CellDataElementName = value; } + } + + private void SetGroupingValues(Report rpt, MatrixCellEntry mce) + { + WorkClass wc = GetValue(rpt); + Rows data = wc.FullData; + + SetGroupingValuesInit(rpt, data, mce.RowME, mce.ColumnME); + SetGroupingValuesMe(rpt, data, mce.RowME); + SetGroupingValuesMe(rpt, data, mce.ColumnME); + + return; + } + + private void SetGroupingValuesInit(Report rpt, Rows data, MatrixEntry rme, MatrixEntry cme) + { + // handle the column grouping + if (cme != null) + { + foreach (ColumnGrouping cg in this.ColumnGroupings.Items) + { + if (cg.DynamicColumns != null) + SetGrouping(rpt, cg.DynamicColumns.Grouping, cme, data); + } + } + // handle the row grouping + if (rme != null) + { + foreach (RowGrouping rg in this.RowGroupings.Items) + { + if (rg.DynamicRows != null) + SetGrouping(rpt, rg.DynamicRows.Grouping, rme, data); + } + } + } + + private void SetGroupingValuesMe(Report rpt, Rows data, MatrixEntry me) + { + if (me == null) + return; + // handle the column grouping + if (me.ColumnGroup != null && me.ColumnGroup.DynamicColumns != null) + SetGrouping(rpt, me.ColumnGroup.DynamicColumns.Grouping, me, data); + + // handle the row grouping + if (me.RowGroup != null && me.RowGroup.DynamicRows != null) + SetGrouping(rpt, me.RowGroup.DynamicRows.Grouping, me, data); + + if (me.Parent != null) // go up the tree?? + SetGroupingValuesMe(rpt, data, me.Parent); + } + + private void SetGrouping(Report rpt, Grouping g, MatrixEntry me, Rows data) + { + if (g == null) + return; + + if (me.Data == null) + me.Data = new Rows(rpt, data, me.FirstRow, me.LastRow, me.Rows); + g.SetRows(rpt, me.Data); + } + + internal MatrixCellDataElementOutputEnum CellDataElementOutput + { + get { return _CellDataElementOutput; } + set { _CellDataElementOutput = value; } + } + + private WorkClass GetValue(Report rpt) + { + WorkClass wc = rpt.Cache.Get(this, "wc") as WorkClass; + if (wc == null) + { + wc = new WorkClass(); + rpt.Cache.Add(this, "wc", wc); + } + return wc; + } + + private void RemoveValue(Report rpt) + { + rpt.Cache.Remove(this, "wc"); + } + + class WorkClass + { + internal Rows Data; + internal Rows FullData; + internal WorkClass() + { + Data = null; + FullData = null; + } + } + } } diff --git a/RdlEngine/Definition/MatrixCell.cs b/RdlEngine/Definition/MatrixCell.cs index bd91e3f9..6aefe378 100644 --- a/RdlEngine/Definition/MatrixCell.cs +++ b/RdlEngine/Definition/MatrixCell.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -60,10 +61,10 @@ internal MatrixCell(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "MatrixCell requires the ReportItems element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); return; } diff --git a/RdlEngine/Definition/MatrixCells.cs b/RdlEngine/Definition/MatrixCells.cs index ead3e046..652a13ad 100644 --- a/RdlEngine/Definition/MatrixCells.cs +++ b/RdlEngine/Definition/MatrixCells.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal MatrixCells(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (MatrixCell m in _Items) { - m.FinalPass(); + await m.FinalPass(); } return; } diff --git a/RdlEngine/Definition/MatrixColumn.cs b/RdlEngine/Definition/MatrixColumn.cs index 61fa8e26..b4550aba 100644 --- a/RdlEngine/Definition/MatrixColumn.cs +++ b/RdlEngine/Definition/MatrixColumn.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -56,9 +57,9 @@ internal MatrixColumn(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + override internal Task FinalPass() { - return; + return Task.CompletedTask; } internal RSize Width diff --git a/RdlEngine/Definition/MatrixColumns.cs b/RdlEngine/Definition/MatrixColumns.cs index 6c878694..b8f10b0a 100644 --- a/RdlEngine/Definition/MatrixColumns.cs +++ b/RdlEngine/Definition/MatrixColumns.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal MatrixColumns(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (MatrixColumn m in _Items) { - m.FinalPass(); + await m.FinalPass(); } return; } diff --git a/RdlEngine/Definition/MatrixRow.cs b/RdlEngine/Definition/MatrixRow.cs index 6c0ef094..aa852e2d 100644 --- a/RdlEngine/Definition/MatrixRow.cs +++ b/RdlEngine/Definition/MatrixRow.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -61,10 +62,10 @@ internal MatrixRow(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "MatrixRow requires the MatrixCells element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_MatrixCells != null) - _MatrixCells.FinalPass(); + await _MatrixCells.FinalPass(); return; } diff --git a/RdlEngine/Definition/MatrixRows.cs b/RdlEngine/Definition/MatrixRows.cs index ce7e180b..b83bfe34 100644 --- a/RdlEngine/Definition/MatrixRows.cs +++ b/RdlEngine/Definition/MatrixRows.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal MatrixRows(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (MatrixRow m in _Items) { - m.FinalPass(); + await m.FinalPass(); } return; } diff --git a/RdlEngine/Definition/PageFooter.cs b/RdlEngine/Definition/PageFooter.cs index 3e3ee60c..59973b19 100644 --- a/RdlEngine/Definition/PageFooter.cs +++ b/RdlEngine/Definition/PageFooter.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -82,16 +83,16 @@ internal PageFooter(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "PageFooter Height is required."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { if (OwnerReport.Subreport != null) return; // don't process page footers for sub-reports @@ -99,11 +100,11 @@ internal void Run(IPresent ip, Row row) rpt.TotalPages = rpt.PageNumber = 1; ip.PageFooterStart(this); if (_ReportItems != null) - _ReportItems.Run(ip, row); + await _ReportItems.Run(ip, row); ip.PageFooterEnd(this); } - internal void RunPage(Pages pgs) + internal async Task RunPage(Pages pgs) { if (OwnerReport.Subreport != null) return; // don't process page footers for sub-reports @@ -125,8 +126,8 @@ internal void RunPage(Pages pgs) if (pgs[i].PageNumber == 1 && pgs.Count > 1 && !_PrintOnFirstPage) continue; // Don't put footer on the first page if (pgs[i].PageNumber == pgs.Count && !_PrintOnLastPage) - continue; // Don't put footer on the last page - _ReportItems.RunPage(pgs, null, OwnerReport.LeftMargin.Points); + continue; // Don't put footer on the last page + await _ReportItems.RunPage(pgs, null, OwnerReport.LeftMargin.Points); } } diff --git a/RdlEngine/Definition/PageHeader.cs b/RdlEngine/Definition/PageHeader.cs index 9c27f6be..478b2fa8 100644 --- a/RdlEngine/Definition/PageHeader.cs +++ b/RdlEngine/Definition/PageHeader.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -82,16 +83,16 @@ internal PageHeader(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "PageHeader Height is required."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { if (OwnerReport.Subreport != null) return; // don't process page headers for sub-reports @@ -99,11 +100,11 @@ internal void Run(IPresent ip, Row row) rpt.TotalPages = rpt.PageNumber = 1; ip.PageHeaderStart(this); if (_ReportItems != null) - _ReportItems.Run(ip, row); + await _ReportItems.Run(ip, row); ip.PageHeaderEnd(this); } - internal void RunPage(Pages pgs) + async internal Task RunPage(Pages pgs) { if (OwnerReport.Subreport != null) return; // don't process page headers for sub-reports @@ -122,8 +123,8 @@ internal void RunPage(Pages pgs) if (p.PageNumber == 1 && pgs.Count > 1 && !_PrintOnFirstPage) continue; // Don't put header on the first page if (p.PageNumber == pgs.Count && !_PrintOnLastPage) - continue; // Don't put header on the last page - _ReportItems.RunPage(pgs, null, OwnerReport.LeftMargin.Points); + continue; // Don't put header on the last page + await _ReportItems.RunPage(pgs, null, OwnerReport.LeftMargin.Points); } } diff --git a/RdlEngine/Definition/ParameterValue.cs b/RdlEngine/Definition/ParameterValue.cs index adf36753..35353465 100644 --- a/RdlEngine/Definition/ParameterValue.cs +++ b/RdlEngine/Definition/ParameterValue.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -67,12 +68,12 @@ internal ParameterValue(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Value != null) - _Value.FinalPass(); + await _Value.FinalPass(); if (_Label != null) - _Label.FinalPass(); + await _Label.FinalPass(); return; } diff --git a/RdlEngine/Definition/ParameterValues.cs b/RdlEngine/Definition/ParameterValues.cs index 760218a3..fd75079f 100644 --- a/RdlEngine/Definition/ParameterValues.cs +++ b/RdlEngine/Definition/ParameterValues.cs @@ -23,90 +23,91 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL { - /// - /// Collection of parameter values. - /// - [Serializable] - internal class ParameterValues : ReportLink - { - List _Items; // list of ParameterValue + /// + /// Collection of parameter values. + /// + [Serializable] + internal class ParameterValues : ReportLink + { + List _Items; // list of ParameterValue - internal ParameterValues(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) - { - ParameterValue pv; + internal ParameterValues(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) + { + ParameterValue pv; _Items = new List(); - // Loop thru all the child nodes - foreach(XmlNode xNodeLoop in xNode.ChildNodes) - { - if (xNodeLoop.NodeType != XmlNodeType.Element) - continue; - switch (xNodeLoop.Name) - { - case "ParameterValue": - pv = new ParameterValue(r, this, xNodeLoop); - break; - default: - pv=null; // don't know what this is - // don't know this element - log it - OwnerReport.rl.LogError(4, "Unknown ParameterValues element '" + xNodeLoop.Name + "' ignored."); - break; - } - if (pv != null) - _Items.Add(pv); - } + // Loop thru all the child nodes + foreach (XmlNode xNodeLoop in xNode.ChildNodes) + { + if (xNodeLoop.NodeType != XmlNodeType.Element) + continue; + switch (xNodeLoop.Name) + { + case "ParameterValue": + pv = new ParameterValue(r, this, xNodeLoop); + break; + default: + pv = null; // don't know what this is + // don't know this element - log it + OwnerReport.rl.LogError(4, "Unknown ParameterValues element '" + xNodeLoop.Name + "' ignored."); + break; + } + if (pv != null) + _Items.Add(pv); + } - if (_Items.Count == 0) - OwnerReport.rl.LogError(8, "For ParameterValues at least one ParameterValue is required."); - else + if (_Items.Count == 0) + OwnerReport.rl.LogError(8, "For ParameterValues at least one ParameterValue is required."); + else _Items.TrimExcess(); - } - - override internal void FinalPass() - { - foreach (ParameterValue pv in _Items) - { - pv.FinalPass(); - } - return; - } + } + + async override internal Task FinalPass() + { + foreach (ParameterValue pv in _Items) + { + await pv.FinalPass(); + } + return; + } internal List Items - { - get { return _Items; } - } + { + get { return _Items; } + } - internal void SupplyValues(Report rpt, out string[] displayValues, out object[] dataValues) - { - displayValues = new string[_Items.Count]; - dataValues = new object[_Items.Count]; - int index=0; - // go thru the parameters extracting the data values - foreach (ParameterValue pv in _Items) - { - if (pv.Value == null) - dataValues[index] = null; - else - dataValues[index] = pv.Value.Evaluate(rpt, null); - if (pv.Label == null) - { // if label is null use the data value; if not provided use "" - if (dataValues[index] == null) - displayValues[index] = ""; - else - displayValues[index] = dataValues[index].ToString(); - } - else - { - displayValues[index] = pv.Label.EvaluateString(rpt, null); - if (displayValues[index] == null) - displayValues[index] = ""; - } - index++; - } - return; - } - } + internal async Task<(string[] displayValues, object[] dataValues)> SupplyValues(Report rpt) + { + string[] displayValues = new string[_Items.Count]; + object[] dataValues = new object[_Items.Count]; + int index = 0; + // go thru the parameters extracting the data values + foreach (ParameterValue pv in _Items) + { + if (pv.Value == null) + dataValues[index] = null; + else + dataValues[index] = await pv.Value.Evaluate(rpt, null); + if (pv.Label == null) + { // if label is null use the data value; if not provided use "" + if (dataValues[index] == null) + displayValues[index] = ""; + else + displayValues[index] = dataValues[index].ToString(); + } + else + { + displayValues[index] = await pv.Label.EvaluateString(rpt, null); + if (displayValues[index] == null) + displayValues[index] = ""; + } + index++; + } + return (displayValues, dataValues); + } + } } diff --git a/RdlEngine/Definition/PlotArea.cs b/RdlEngine/Definition/PlotArea.cs index c2abb68f..71e20fef 100644 --- a/RdlEngine/Definition/PlotArea.cs +++ b/RdlEngine/Definition/PlotArea.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -56,10 +57,10 @@ internal PlotArea(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } diff --git a/RdlEngine/Definition/Query.cs b/RdlEngine/Definition/Query.cs index acbe0f43..a9faa9f6 100644 --- a/RdlEngine/Definition/Query.cs +++ b/RdlEngine/Definition/Query.cs @@ -105,19 +105,13 @@ internal Query(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - internal override void FinalPass() - { - // HACK: - Task.Run(async ()=> await FinalPassAsync()).GetAwaiter().GetResult(); - } - // Handle parsing of function in final pass - internal override async Task FinalPassAsync() + internal override async Task FinalPass() { if (_CommandText != null) - _CommandText.FinalPass(); + await _CommandText.FinalPass(); if (_QueryParameters != null) - _QueryParameters.FinalPass(); + await _QueryParameters.FinalPass(); // verify the data source DataSourceDefn ds = null; @@ -138,13 +132,13 @@ internal override async Task FinalPassAsync() return; // Treat this as a SQL statement - String sql = _CommandText.EvaluateString(null, null); + String sql = await _CommandText.EvaluateString(null, null); IDbCommand cmSQL = null; IDataReader dr = null; try { cmSQL = cnSQL.CreateCommand(); - cmSQL.CommandText = AddParametersAsLiterals(null, cnSQL, sql, false); + cmSQL.CommandText = await AddParametersAsLiterals(null, cnSQL, sql, false); if (this._QueryCommandType == QueryCommandTypeEnum.StoredProcedure) cmSQL.CommandType = CommandType.StoredProcedure; @@ -194,7 +188,7 @@ internal override async Task FinalPassAsync() } } - internal bool GetData(Report rpt, Fields flds, Filters f) + internal async Task GetData(Report rpt, Fields flds, Filters f) { Rows uData = this.GetMyUserData(rpt); if (uData != null) @@ -219,13 +213,13 @@ internal bool GetData(Report rpt, Fields flds, Filters f) } Rows _Data = new Rows(rpt, null,null,null); // no sorting and grouping at base data - String sql = _CommandText.EvaluateString(rpt, null); + String sql = await _CommandText.EvaluateString(rpt, null); IDbCommand cmSQL=null; IDataReader dr=null; try { cmSQL = cnSQL.CreateCommand(); - cmSQL.CommandText = AddParametersAsLiterals(rpt, cnSQL, sql, true); + cmSQL.CommandText = await AddParametersAsLiterals(rpt, cnSQL, sql, true); if (this._QueryCommandType == QueryCommandTypeEnum.StoredProcedure) cmSQL.CommandType = CommandType.StoredProcedure; if (this._Timeout > 0) @@ -281,7 +275,7 @@ internal bool GetData(Report rpt, Fields flds, Filters f) } ar.TrimExcess(); // free up any extraneous space; can be sizeable for large # rows if (f != null) - f.ApplyFinalFilters(rpt, _Data, false); + await f.ApplyFinalFilters(rpt, _Data, false); //#if DEBUG // rpt.rl.LogError(4, "Rows Read:" + ar.Count.ToString() + " SQL:" + sql ); //#endif @@ -306,7 +300,7 @@ internal bool GetData(Report rpt, Fields flds, Filters f) } // Obtain the data from the XML - internal bool GetData(Report rpt, string xmlData, Fields flds, Filters f) + internal async Task GetData(Report rpt, string xmlData, Fields flds, Filters f) { Rows uData = this.GetMyUserData(rpt); if (uData != null) @@ -399,7 +393,7 @@ internal bool GetData(Report rpt, string xmlData, Fields flds, Filters f) ar.TrimExcess(); // free up any extraneous space; can be sizeable for large # rows if (f != null) { - f.ApplyFinalFilters(rpt, _Data, false); + await f.ApplyFinalFilters(rpt, _Data, false); } SetMyData(rpt, _Data); @@ -407,7 +401,7 @@ internal bool GetData(Report rpt, string xmlData, Fields flds, Filters f) } - internal void SetData(Report rpt, IEnumerable ie, Fields flds, Filters f, bool collection = false) + internal async Task SetData(Report rpt, IEnumerable ie, Fields flds, Filters f, bool collection = false) { if (ie == null) // Does user want to remove user data? { @@ -485,12 +479,12 @@ internal void SetData(Report rpt, IEnumerable ie, Fields flds, Filters f, bool c } ar.TrimExcess(); // free up any extraneous space; can be sizeable for large # rows if (f != null) - f.ApplyFinalFilters(rpt, rows, false); + await f.ApplyFinalFilters(rpt, rows, false); SetMyUserData(rpt, rows); } - internal void SetData(Report rpt, IDataReader dr, Fields flds, Filters f) + internal async Task SetData(Report rpt, IDataReader dr, Fields flds, Filters f) { if (dr == null) // Does user want to remove user data? { @@ -520,12 +514,12 @@ internal void SetData(Report rpt, IDataReader dr, Fields flds, Filters f) } ar.TrimExcess(); // free up any extraneous space; can be sizeable for large # rows if (f != null) - f.ApplyFinalFilters(rpt, rows, false); + await f.ApplyFinalFilters(rpt, rows, false); SetMyUserData(rpt, rows); } - internal void SetData(Report rpt, DataTable dt, Fields flds, Filters f) + internal async Task SetData(Report rpt, DataTable dt, Fields flds, Filters f) { if (dt == null) // Does user want to remove user data? { @@ -561,12 +555,12 @@ internal void SetData(Report rpt, DataTable dt, Fields flds, Filters f) } ar.TrimExcess(); // free up any extraneous space; can be sizeable for large # rows if (f != null) - f.ApplyFinalFilters(rpt, rows, false); + await f.ApplyFinalFilters(rpt, rows, false); SetMyUserData(rpt, rows); } - internal void SetData(Report rpt, XmlDocument xmlDoc, Fields flds, Filters f) + internal async Task SetData(Report rpt, XmlDocument xmlDoc, Fields flds, Filters f) { if (xmlDoc == null) // Does user want to remove user data? { @@ -628,7 +622,7 @@ internal void SetData(Report rpt, XmlDocument xmlDoc, Fields flds, Filters f) ar.TrimExcess(); // free up any extraneous space; can be sizeable for large # rows if (f != null) - f.ApplyFinalFilters(rpt, rows, false); + await f.ApplyFinalFilters(rpt, rows, false); SetMyUserData(rpt, rows); } @@ -670,7 +664,7 @@ private void AddParameters(Report rpt, IDbConnection cn, IDbCommand cmSQL, bool } } - private string AddParametersAsLiterals(Report rpt, IDbConnection cn, string sql, bool bValue) + private async Task AddParametersAsLiterals(Report rpt, IDbConnection cn, string sql, bool bValue) { // No parameters means nothing to do if (this._QueryParameters == null || @@ -710,7 +704,7 @@ private string AddParametersAsLiterals(Report rpt, IDbConnection cn, string sql, string svalue; if (bValue) { // use the value provided - svalue = this.ParameterValue(rpt, qp); + svalue = await this.ParameterValue(rpt, qp); } else { // just need a place holder value that will pass parsing @@ -742,12 +736,12 @@ private string AddParametersAsLiterals(Report rpt, IDbConnection cn, string sql, return sb.ToString(); } - private string ParameterValue(Report rpt, QueryParameter qp) + private async Task ParameterValue(Report rpt, QueryParameter qp) { if (!qp.IsArray) { // handle non-array - string svalue = qp.Value.EvaluateString(rpt, null); + string svalue = await qp.Value.EvaluateString(rpt, null); if (svalue == null) svalue = "null"; else switch (qp.Value.Expr.GetTypeCode()) @@ -764,7 +758,7 @@ private string ParameterValue(Report rpt, QueryParameter qp) } StringBuilder sb = new StringBuilder(); - ArrayList ar = qp.Value.Evaluate(rpt, null) as ArrayList; + ArrayList ar = await qp.Value.Evaluate(rpt, null) as ArrayList; if (ar == null) return null; diff --git a/RdlEngine/Definition/QueryParameter.cs b/RdlEngine/Definition/QueryParameter.cs index cb3599bf..f4f37faa 100644 --- a/RdlEngine/Definition/QueryParameter.cs +++ b/RdlEngine/Definition/QueryParameter.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -84,10 +85,10 @@ internal QueryParameter(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Value != null) - _Value.FinalPass(); + await _Value.FinalPass(); return; } diff --git a/RdlEngine/Definition/QueryParameters.cs b/RdlEngine/Definition/QueryParameters.cs index c288b29d..e1312bcf 100644 --- a/RdlEngine/Definition/QueryParameters.cs +++ b/RdlEngine/Definition/QueryParameters.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -66,11 +67,11 @@ internal QueryParameters(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (QueryParameter q in _Items) { - q.FinalPass(); + await q.FinalPass(); if (q.IsArray) _ContainsArray = true; } diff --git a/RdlEngine/Definition/RDLParser.cs b/RdlEngine/Definition/RDLParser.cs index d3b5b7a1..3c6c15a7 100644 --- a/RdlEngine/Definition/RDLParser.cs +++ b/RdlEngine/Definition/RDLParser.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Xml; using fyiReporting.RDL; using RdlEngine.Resources; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -114,12 +115,12 @@ public Report Report /// /// /// A Report instance. - public Report Parse() + public async Task Parse() { - return Parse(0); + return await Parse(0); } - internal Report Parse(int oc) + internal async Task Parse(int oc) { if (_RdlDocument == null) // no document? return null; // nothing to do @@ -136,6 +137,7 @@ internal Report Parse(int oc) ReportLog rl = new ReportLog(); // create a report log ReportDefn rd = new ReportDefn(xNode, rl, this._Folder, this._DataSourceReferencePassword, oc, OnSubReportGetContent, OverwriteConnectionString, OverwriteInSubreport); + await rd.InitializeAsync(); _Report = new Report(rd); bPassed = true; diff --git a/RdlEngine/Definition/Rectangle.cs b/RdlEngine/Definition/Rectangle.cs index 0ec75cb2..55d53d3b 100644 --- a/RdlEngine/Definition/Rectangle.cs +++ b/RdlEngine/Definition/Rectangle.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -76,34 +77,34 @@ internal Rectangle(ReportDefn r, ReportLink p, XmlNode xNode):base(r,p,xNode) } } - override internal void FinalPass() + async override internal Task FinalPass() { - base.FinalPass(); + await base.FinalPass(); if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); return; } - override internal void Run(IPresent ip, Row row) + async override internal Task Run(IPresent ip, Row row) { - base.Run(ip, row); + await base.Run(ip, row); if (_ReportItems == null) return; - if (ip.RectangleStart(this, row)) + if (await ip.RectangleStart(this, row)) { - _ReportItems.Run(ip, row); - ip.RectangleEnd(this, row); + await _ReportItems.Run(ip, row); + await ip.RectangleEnd(this, row); } } - override internal void RunPage(Pages pgs, Row row) + async override internal Task RunPage(Pages pgs, Row row) { Report r = pgs.Report; - bool bHidden = IsHidden(r, row); + bool bHidden = await IsHidden(r, row); SetPagePositionBegin(pgs); @@ -115,7 +116,7 @@ override internal void RunPage(Pages pgs, Row row) } PageRectangle pr = new PageRectangle(); - SetPagePositionAndStyle(r, pr, row); + await SetPagePositionAndStyle(r, pr, row); if (pr.SI.BackgroundImage != null) pr.SI.BackgroundImage.H = pr.H; // and in the background image @@ -129,7 +130,7 @@ override internal void RunPage(Pages pgs, Row row) float saveY = p.YOffset; // p.YOffset += (Top == null ? 0 : this.Top.Points); p.YOffset = pr.Y; // top of rectangle is base for contained report items - _ReportItems.RunPage(pgs, row, GetOffsetCalc(pgs.Report) + LeftCalc(r)); + await _ReportItems.RunPage(pgs, row, GetOffsetCalc(pgs.Report) + LeftCalc(r)); p.YOffset = saveY; } @@ -142,6 +143,8 @@ override internal void RunPage(Pages pgs, Row row) } // SetPagePositionEnd(pgs, pgs.CurrentPage.YOffset); SetPagePositionEnd(pgs, pr.Y + pr.H); + + return; } internal override void RemoveWC(Report rpt) diff --git a/RdlEngine/Definition/ReportClass.cs b/RdlEngine/Definition/ReportClass.cs index 3dce8b98..cf84ec6b 100644 --- a/RdlEngine/Definition/ReportClass.cs +++ b/RdlEngine/Definition/ReportClass.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.Reflection; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -67,9 +68,9 @@ internal ReportClass(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "Class InstanceName is required but not specified or invalid for " + _ClassName==null? "": _ClassName); } - override internal void FinalPass() + override internal Task FinalPass() { - return; + return Task.CompletedTask; } internal object Load(Report rpt) diff --git a/RdlEngine/Definition/ReportDefn.cs b/RdlEngine/Definition/ReportDefn.cs index 0c897fcc..e76e4d6c 100644 --- a/RdlEngine/Definition/ReportDefn.cs +++ b/RdlEngine/Definition/ReportDefn.cs @@ -98,11 +98,12 @@ public class ReportDefn IDictionary _LUDynamicNames; // for dynamic names IDictionary _LUAggrScope; // Datasets, Dataregions, grouping names IDictionary _LUEmbeddedImages; // Embedded images - string _ParseFolder; // temporary folder for looking up things during parse/finalpass + readonly string _ParseFolder; // temporary folder for looking up things during parse/finalpass Type _CodeType; // used for parsing of expressions; DONT USE AT RUNTIME string _OverwriteConnectionString; // To overwrite ConnectionString bool _OverwriteInSubreport; // Overwrite ConnectionString in subreport too + readonly XmlNode _xNode; /// /// EBN 31/03/2014 @@ -116,50 +117,54 @@ public CrossDelegate SubReportGetContent } // Constructor - internal ReportDefn(XmlNode xNode, ReportLog replog, string folder, NeedPassword getpswd, int objcount, CrossDelegate crossdel, string overwriteConnectionString, bool overwriteInSubreport) // report has no parents + internal ReportDefn(XmlNode xNode, ReportLog replog, string folder, NeedPassword getpswd, int objcount, CrossDelegate crossdel, + string overwriteConnectionString, bool overwriteInSubreport) // report has no parents { - rl = replog; // used for error reporting - _ObjectCount = objcount; // starting number for objects in this report; 0 other than for subreports + _xNode = xNode; + rl = replog; // used for error reporting + _ObjectCount = objcount; // starting number for objects in this report; 0 other than for subreports GetDataSourceReferencePassword = getpswd; _ParseFolder = folder; _Description = null; - _Author = null; + _Author = null; _AutoRefresh = -1; _DataSourcesDefn = null; - _DataSetsDefn = null; - _Body = null; - _Width = null; - _PageHeader = null; - _PageFooter = null; - _PageHeight = null; - _PageWidth = null; - _LeftMargin = null; + _DataSetsDefn = null; + _Body = null; + _Width = null; + _PageHeader = null; + _PageFooter = null; + _PageHeight = null; + _PageWidth = null; + _LeftMargin = null; _RightMargin = null; - _TopMargin = null; + _TopMargin = null; _BottomMargin = null; _EmbeddedImages = null; - _Language = null; - _CodeModules = null; + _Language = null; + _CodeModules = null; _Code = null; - _Classes = null; - _DataTransform = null; - _DataSchema = null; + _Classes = null; + _DataTransform = null; + _DataSchema = null; _DataElementName = null; _DataElementStyle = DataElementStyleEnum.AttributeNormal; - _LUReportItems = new Hashtable(); // to hold all the textBoxes - _LUAggrScope = new ListDictionary(); // to hold all dataset, dataregion, grouping names - _LUEmbeddedImages = new ListDictionary(); // probably not very many + _LUReportItems = new Hashtable(); // to hold all the textBoxes + _LUAggrScope = new ListDictionary(); // to hold all dataset, dataregion, grouping names + _LUEmbeddedImages = new ListDictionary(); // probably not very many _LUDynamicNames = new Hashtable(); - _DataCache = new List(); - - // EBN 30/03/2014 - SubReportGetContent = crossdel; + _DataCache = new List(); + + // EBN 30/03/2014 + SubReportGetContent = crossdel; _OverwriteConnectionString = overwriteConnectionString; _OverwriteInSubreport = overwriteInSubreport; + } + public async Task InitializeAsync() { // Run thru the attributes - foreach(XmlAttribute xAttr in xNode.Attributes) + foreach(XmlAttribute xAttr in _xNode.Attributes) { switch (xAttr.Name) { @@ -170,7 +175,7 @@ internal ReportDefn(XmlNode xNode, ReportLog replog, string folder, NeedPassword } // Loop thru all the child nodes - foreach(XmlNode xNodeLoop in xNode.ChildNodes) + foreach(XmlNode xNodeLoop in _xNode.ChildNodes) { if (xNodeLoop.NodeType != XmlNodeType.Element) continue; @@ -266,7 +271,7 @@ internal ReportDefn(XmlNode xNode, ReportLog replog, string folder, NeedPassword if (rl.MaxSeverity <= 4) // don't do final pass if already have serious errors { - FinalPass(folder); // call final parser pass for expression resolution + await FinalPass(_ParseFolder); // call final parser pass for expression resolution } // Cleanup any dangling resources @@ -275,7 +280,7 @@ internal ReportDefn(XmlNode xNode, ReportLog replog, string folder, NeedPassword } // - void FinalPass(string folder) + async Task FinalPass(string folder) { // Now do some addition validation and final preparation @@ -291,35 +296,35 @@ void FinalPass(string folder) _LUUser.Add("Language", new FunctionUserLanguage()); if (_CodeModules != null) { - _CodeModules.FinalPass(); + await _CodeModules.FinalPass(); _CodeModules.LoadModules(); } if (_Classes != null) { - _Classes.FinalPass(); + await _Classes.FinalPass(); // _Classes.Load(); } if (_Code != null) { - _Code.FinalPass(); + await _Code.FinalPass(); _CodeType = _Code.CodeType(); } - if (_ReportParameters != null) // report parameters might be used in data source connection strings - _ReportParameters.FinalPass(); + if (_ReportParameters != null) // report parameters might be used in data source connection strings + await _ReportParameters.FinalPass(); if (_DataSourcesDefn != null) - _DataSourcesDefn.FinalPass(); + await _DataSourcesDefn.FinalPass(); if (_DataSetsDefn != null) - _DataSetsDefn.FinalPass(); - _Body.FinalPass(); + await _DataSetsDefn.FinalPass(); + await _Body.FinalPass(); if (_PageHeader != null) - _PageHeader.FinalPass(); + await _PageHeader.FinalPass(); if (_PageFooter != null) - _PageFooter.FinalPass(); + await _PageFooter.FinalPass(); if (_EmbeddedImages != null) - _EmbeddedImages.FinalPass(); + await _EmbeddedImages.FinalPass(); if (_Language != null) - _Language.FinalPass(); + await _Language.FinalPass(); _DataCache.TrimExcess(); // reduce size of array of expressions that cache data return; @@ -353,7 +358,7 @@ async internal Task RunGetData(Report rpt, IDictionary parms) // Step 1- set the parameter values for the runtime if (parms != null && ReportParameters != null) { - ReportParameters.SetRuntimeValues(rpt, parms); // set the parameters + await ReportParameters.SetRuntimeValues(rpt, parms); // set the parameters } // Step 2- prep the datasources (ie connect and execute the queries) @@ -366,7 +371,7 @@ async internal Task RunGetData(Report rpt, IDictionary parms) if (_DataSetsDefn != null) { ResetCachedData(rpt); - bRows = _DataSetsDefn.GetData(rpt); + bRows = await _DataSetsDefn.GetData(rpt); } // Step 4- cleanup any DB connections @@ -402,7 +407,7 @@ private void ResetCachedData(Report rpt) } } - internal void Run(IPresent ip) + internal async Task Run(IPresent ip) { if (_Subreport == null) { // do true intialization @@ -411,15 +416,15 @@ internal void Run(IPresent ip) if (ip.IsPagingNeeded()) { - RunPage(ip); + await RunPage(ip); } else { if (_PageHeader != null && !(ip is RenderXml)) - _PageHeader.Run(ip, null); - _Body.Run(ip, null); + await _PageHeader.Run(ip, null); + await _Body.Run(ip, null); if (_PageFooter != null && !(ip is RenderXml)) - _PageFooter.Run(ip, null); + await _PageFooter.Run(ip, null); } if (_Subreport == null) @@ -429,7 +434,7 @@ internal void Run(IPresent ip) _DataSourcesDefn.CleanUp(ip.Report()); // datasets may not have been cleaned up } - internal void RunPage(IPresent ip) + internal async Task RunPage(IPresent ip) { Pages pgs = new Pages(ip.Report()); try @@ -437,17 +442,17 @@ internal void RunPage(IPresent ip) Page p = new Page(1); // kick it off with a new page pgs.AddPage(p); - // Create all the pages - _Body.RunPage(pgs); + // Create all the pages + await _Body.RunPage(pgs); if (pgs.LastPage.IsEmpty()&& pgs.PageCount > 1) // get rid of extraneous pages which pgs.RemoveLastPage(); // can be caused by region page break at end // Now create the headers and footers for all the pages (as needed) if (_PageHeader != null) - _PageHeader.RunPage(pgs); + await _PageHeader.RunPage(pgs); if (_PageFooter != null) - _PageFooter.RunPage(pgs); + await _PageFooter.RunPage(pgs); pgs.SortPageItems(); // Handle ZIndex ordering of pages @@ -698,7 +703,7 @@ internal Expression Language set { _Language = value; } } - internal string EvalLanguage(Report rpt, Row r) + internal async Task EvalLanguage(Report rpt, Row r) { if (_Language == null) { @@ -706,7 +711,7 @@ internal string EvalLanguage(Report rpt, Row r) return ci.Name; } - return _Language.EvaluateString(rpt, r); + return await _Language.EvaluateString(rpt, r); } internal CodeModules CodeModules diff --git a/RdlEngine/Definition/ReportItem.cs b/RdlEngine/Definition/ReportItem.cs index 5c88dcc4..b29640ce 100644 --- a/RdlEngine/Definition/ReportItem.cs +++ b/RdlEngine/Definition/ReportItem.cs @@ -203,22 +203,22 @@ internal bool ReportItemElement(XmlNode xNodeLoop) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); if (_Action != null) - _Action.FinalPass(); + await _Action.FinalPass(); if (_Visibility != null) - _Visibility.FinalPass(); + await _Visibility.FinalPass(); if (_ToolTip != null) - _ToolTip.FinalPass(); + await _ToolTip.FinalPass(); if (_Label != null) - _Label.FinalPass(); + await _Label.FinalPass(); if (_Bookmark != null) - _Bookmark.FinalPass(); + await _Bookmark.FinalPass(); if (_Custom != null) - _Custom.FinalPass(); + await _Custom.FinalPass(); if (Parent.Parent is TableCell) // This is part of a table { @@ -342,25 +342,13 @@ int PositioningWidth(ReportItem ri) return w; } - internal virtual void Run(IPresent ip, Row row) - { - return; - } - - internal virtual Task RunAsync(IPresent ip, Row row) + internal virtual Task Run(IPresent ip, Row row) { - Run(ip, row); return Task.CompletedTask; } - internal virtual void RunPage(Pages pgs, Row row) - { - return; - } - - virtual internal Task RunPageAsync(Pages pgs, Row row) + virtual internal Task RunPage(Pages pgs, Row row) { - RunPage(pgs, row); return Task.CompletedTask; } @@ -501,11 +489,11 @@ internal float HeightOrOwnerHeight } } - internal bool IsHidden(Report rpt, Row r) + internal async Task IsHidden(Report rpt, Row r) { if (this._Visibility == null) return false; - return _Visibility.IsHidden(rpt, r); + return await _Visibility.IsHidden(rpt, r); } internal void SetPageLeft(Report rpt) @@ -521,7 +509,7 @@ internal void SetPageLeft(Report rpt) Left = new RSize(OwnerReport, "0pt"); } - internal void SetPagePositionAndStyle(Report rpt, PageItem pi, Row row) + internal async Task SetPagePositionAndStyle(Report rpt, PageItem pi, Row row) { WorkClass wc = GetWC(rpt); pi.X = GetOffsetCalc(rpt) + LeftCalc(rpt); @@ -577,7 +565,7 @@ internal void SetPagePositionAndStyle(Report rpt, PageItem pi, Row row) pi.W = this.WidthOrOwnerWidth(rpt); } if (Style != null) - pi.SI = Style.GetStyleInfo(rpt, row); + pi.SI = await Style.GetStyleInfo(rpt, row); else pi.SI = new StyleInfo(); // this will just default everything @@ -586,15 +574,15 @@ internal void SetPagePositionAndStyle(Report rpt, PageItem pi, Row row) // Catch any action needed if (this._Action != null) { - pi.BookmarkLink = _Action.BookmarkLinkValue(rpt, row); - pi.HyperLink = _Action.HyperLinkValue(rpt, row); + pi.BookmarkLink = await _Action.BookmarkLinkValue(rpt, row); + pi.HyperLink = await _Action.HyperLinkValue(rpt, row); } if (this._Bookmark != null) - pi.Bookmark = _Bookmark.EvaluateString(rpt, row); + pi.Bookmark = await _Bookmark.EvaluateString(rpt, row); if (this._ToolTip != null) - pi.Tooltip = _ToolTip.EvaluateString(rpt, row); + pi.Tooltip = await _ToolTip.EvaluateString(rpt, row); } internal MatrixCellEntry GetMC(Report rpt) @@ -848,12 +836,12 @@ internal Expression ToolTip set { _ToolTip = value; } } - internal string ToolTipValue(Report rpt, Row r) + internal async Task ToolTipValue(Report rpt, Row r) { if (_ToolTip == null) return null; - return _ToolTip.EvaluateString(rpt, r); + return await _ToolTip.EvaluateString(rpt, r); } internal Expression Label @@ -874,12 +862,12 @@ internal Expression Bookmark set { _Bookmark = value; } } - internal string BookmarkValue(Report rpt, Row r) + internal async Task BookmarkValue(Report rpt, Row r) { if (_Bookmark == null) return null; - return _Bookmark.EvaluateString(rpt, r); + return await _Bookmark.EvaluateString(rpt, r); } internal TableCell TC @@ -927,7 +915,9 @@ virtual internal DataElementOutputEnum DataElementOutput if (this is Textbox) { Textbox tb = this as Textbox; - if (tb.Value.IsConstant()) + // HACK: async + bool isConstant = Task.Run(async () => await tb.Value.IsConstant()).GetAwaiter().GetResult(); + if (isConstant) return DataElementOutputEnum.NoOutput; else return DataElementOutputEnum.Output; diff --git a/RdlEngine/Definition/ReportItems.cs b/RdlEngine/Definition/ReportItems.cs index 3a110582..8c737c4a 100644 --- a/RdlEngine/Definition/ReportItems.cs +++ b/RdlEngine/Definition/ReportItems.cs @@ -25,6 +25,7 @@ the website www.fyiReporting.com. using System.Collections.Generic; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -109,11 +110,11 @@ internal ReportItem this[int i] } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (ReportItem ri in _Items) - { - ri.FinalPass(); + { + await ri.FinalPass(); } _Items.Sort(); // sort on ZIndex; y, x (see ReportItem compare routine) @@ -128,21 +129,21 @@ override internal void FinalPass() return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { foreach (ReportItem ri in _Items) { - ri.Run(ip, row); + await ri.Run(ip, row); } return; } - internal void RunPage(Pages pgs, Row row, float xOffset) + internal async Task RunPage(Pages pgs, Row row, float xOffset) { SetXOffset(pgs.Report, xOffset); foreach (ReportItem ri in _Items) { - ri.RunPage(pgs, row); + await ri.RunPage(pgs, row); } return; } diff --git a/RdlEngine/Definition/ReportLink.cs b/RdlEngine/Definition/ReportLink.cs index 9ceab211..a2306107 100644 --- a/RdlEngine/Definition/ReportLink.cs +++ b/RdlEngine/Definition/ReportLink.cs @@ -46,11 +46,9 @@ internal ReportLink(ReportDefn r, ReportLink p) // Give opportunity for report elements to do additional work // e.g. expressions should be parsed at this point - abstract internal void FinalPass(); - virtual internal Task FinalPassAsync() + virtual internal Task FinalPass() { - FinalPass(); return Task.CompletedTask; } diff --git a/RdlEngine/Definition/ReportParameter.cs b/RdlEngine/Definition/ReportParameter.cs index 4352986e..ca9921ae 100644 --- a/RdlEngine/Definition/ReportParameter.cs +++ b/RdlEngine/Definition/ReportParameter.cs @@ -25,6 +25,7 @@ the website www.fyiReporting.com. using System.Xml; using System.Collections; using System.Globalization; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -138,12 +139,12 @@ internal ReportParameter(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, string.Format("ReportParameter DataType is required but not specified or invalid for {0}.", _Name==null? "": _Name.Nm)); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DefaultValue != null) - _DefaultValue.FinalPass(); + await _DefaultValue.FinalPass(); if (_ValidValues != null) - _ValidValues.FinalPass(); + await _ValidValues.FinalPass(); return; } @@ -153,7 +154,7 @@ internal Name Name set { _Name = value; } } - internal object GetRuntimeValue(Report rpt) + internal async Task GetRuntimeValue(Report rpt) { object rtv = rpt == null? null: rpt.Cache.Get(this, "runtimevalue"); @@ -163,7 +164,7 @@ internal object GetRuntimeValue(Report rpt) if (_DefaultValue == null) return null; - object[] result = _DefaultValue.GetValue(rpt); + object[] result = await _DefaultValue.GetValue(rpt); if (result == null) return null; object v = result[0]; @@ -177,7 +178,7 @@ internal object GetRuntimeValue(Report rpt) return rtv; } - internal ArrayList GetRuntimeValues(Report rpt) + internal async Task GetRuntimeValues(Report rpt) { ArrayList rtv = rpt == null ? null : (ArrayList) rpt.Cache.Get(this, "rtvs"); @@ -188,7 +189,7 @@ internal ArrayList GetRuntimeValues(Report rpt) if (_DefaultValue == null) return null; - object[] result = _DefaultValue.GetValue(rpt); + object[] result = await _DefaultValue.GetValue(rpt); if (result == null) return null; @@ -453,7 +454,10 @@ public string[] DisplayValues if (_DisplayValues == null) { if (_rp.ValidValues != null) - _DisplayValues = _rp.ValidValues.DisplayValues(_rpt); + { + // HACK: async + _DisplayValues = Task.Run(async () => await _rp.ValidValues.DisplayValues(_rpt)).GetAwaiter().GetResult(); + } } return _DisplayValues; } @@ -469,7 +473,10 @@ public object[] DataValues if (_DataValues == null) { if (_rp.ValidValues != null) - _DataValues = _rp.ValidValues.DataValues(this._rpt); + { + // HACK: async + _DataValues = Task.Run(async () => await _rp.ValidValues.DataValues(this._rpt)).GetAwaiter().GetResult(); + } } return _DataValues; } @@ -540,7 +547,10 @@ private ArrayList ParseValue(string v) /// public ArrayList Values { - get { return _rp.GetRuntimeValues(this._rpt); } + get { + // HACK: async + return Task.Run(async () => await _rp.GetRuntimeValues(this._rpt)).GetAwaiter().GetResult(); + } set { ArrayList ar = new ArrayList(value.Count); diff --git a/RdlEngine/Definition/ReportParameters.cs b/RdlEngine/Definition/ReportParameters.cs index 623edcb4..3e7cf886 100644 --- a/RdlEngine/Definition/ReportParameters.cs +++ b/RdlEngine/Definition/ReportParameters.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Specialized; +using System.Threading.Tasks; using System.Xml; @@ -60,7 +61,7 @@ internal ReportParameters(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p } } - internal void SetRuntimeValues(Report rpt, IDictionary parms) + internal async Task SetRuntimeValues(Report rpt, IDictionary parms) { // Fill the values to use in the report parameters foreach (string pname in parms.Keys) // Loop thru the passed parameters @@ -77,14 +78,14 @@ internal void SetRuntimeValues(Report rpt, IDictionary parms) object parmValue = parms[pname]; if (parmValue is string && rp.ValidValues != null) { - string[] dvs = rp.ValidValues.DisplayValues(rpt); + string[] dvs = await rp.ValidValues.DisplayValues(rpt); if (dvs != null && dvs.Length > 0) { for (int i = 0; i < dvs.Length; i++) { if (dvs[i] == (string) parmValue) { - object[] dv = rp.ValidValues.DataValues(rpt); + object[] dv = await rp.ValidValues.DataValues(rpt); parmValue = dv[i]; break; } @@ -97,11 +98,11 @@ internal void SetRuntimeValues(Report rpt, IDictionary parms) return; } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (ReportParameter rp in _Items.Values) { - rp.FinalPass(); + await rp.FinalPass(); } return; } diff --git a/RdlEngine/Definition/RowGrouping.cs b/RdlEngine/Definition/RowGrouping.cs index 8f6205eb..ffda1dd7 100644 --- a/RdlEngine/Definition/RowGrouping.cs +++ b/RdlEngine/Definition/RowGrouping.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -68,12 +69,12 @@ internal RowGrouping(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "RowGrouping requires the Width element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DynamicRows != null) - _DynamicRows.FinalPass(); + await _DynamicRows.FinalPass(); if (_StaticRows != null) - _StaticRows.FinalPass(); + await _StaticRows.FinalPass(); return; } diff --git a/RdlEngine/Definition/RowGroupings.cs b/RdlEngine/Definition/RowGroupings.cs index 3e66cd9f..eae4b5a9 100644 --- a/RdlEngine/Definition/RowGroupings.cs +++ b/RdlEngine/Definition/RowGroupings.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -68,11 +69,11 @@ internal RowGroupings(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (RowGrouping g in _Items) { - g.FinalPass(); + await g.FinalPass(); } return; } diff --git a/RdlEngine/Definition/SeriesGrouping.cs b/RdlEngine/Definition/SeriesGrouping.cs index 6ae726b3..e16675ba 100644 --- a/RdlEngine/Definition/SeriesGrouping.cs +++ b/RdlEngine/Definition/SeriesGrouping.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -68,14 +69,14 @@ internal SeriesGrouping(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DynamicSeries != null) - _DynamicSeries.FinalPass(); + await _DynamicSeries.FinalPass(); if (_StaticSeries != null) - _StaticSeries.FinalPass(); + await _StaticSeries.FinalPass(); if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } diff --git a/RdlEngine/Definition/SeriesGroupings.cs b/RdlEngine/Definition/SeriesGroupings.cs index 68d728ea..fa706735 100644 --- a/RdlEngine/Definition/SeriesGroupings.cs +++ b/RdlEngine/Definition/SeriesGroupings.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -62,11 +63,11 @@ internal SeriesGroupings(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (SeriesGrouping sg in _Items) { - sg.FinalPass(); + await sg.FinalPass(); } return; } diff --git a/RdlEngine/Definition/SortBy.cs b/RdlEngine/Definition/SortBy.cs index bb569d68..74a326c7 100644 --- a/RdlEngine/Definition/SortBy.cs +++ b/RdlEngine/Definition/SortBy.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -68,10 +69,10 @@ internal SortBy(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_SortExpression != null) - _SortExpression.FinalPass(); + await _SortExpression.FinalPass(); return; } diff --git a/RdlEngine/Definition/Sorting.cs b/RdlEngine/Definition/Sorting.cs index 1693c2ed..5638ebf0 100644 --- a/RdlEngine/Definition/Sorting.cs +++ b/RdlEngine/Definition/Sorting.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -65,11 +66,11 @@ internal Sorting(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (SortBy s in _Items) { - s.FinalPass(); + await s.FinalPass(); } return; } diff --git a/RdlEngine/Definition/StaticCategories.cs b/RdlEngine/Definition/StaticCategories.cs index cb98e798..b85199ad 100644 --- a/RdlEngine/Definition/StaticCategories.cs +++ b/RdlEngine/Definition/StaticCategories.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal StaticCategories(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (StaticMember sm in _Items) { - sm.FinalPass(); + await sm.FinalPass(); } return; } diff --git a/RdlEngine/Definition/StaticColumn.cs b/RdlEngine/Definition/StaticColumn.cs index 4936c50e..e6083b7d 100644 --- a/RdlEngine/Definition/StaticColumn.cs +++ b/RdlEngine/Definition/StaticColumn.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -60,10 +61,10 @@ internal StaticColumn(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "StaticColumn requires the ReportItems element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); return; } diff --git a/RdlEngine/Definition/StaticColumns.cs b/RdlEngine/Definition/StaticColumns.cs index a83e662d..476aab41 100644 --- a/RdlEngine/Definition/StaticColumns.cs +++ b/RdlEngine/Definition/StaticColumns.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal StaticColumns(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (StaticColumn sc in _Items) { - sc.FinalPass(); + await sc.FinalPass(); } return; } diff --git a/RdlEngine/Definition/StaticMember.cs b/RdlEngine/Definition/StaticMember.cs index ae11573a..501476b0 100644 --- a/RdlEngine/Definition/StaticMember.cs +++ b/RdlEngine/Definition/StaticMember.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -58,10 +59,10 @@ internal StaticMember(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Label != null) - _Label.FinalPass(); + await _Label.FinalPass(); return; } diff --git a/RdlEngine/Definition/StaticRow.cs b/RdlEngine/Definition/StaticRow.cs index 814e5d0a..cbb8f1e0 100644 --- a/RdlEngine/Definition/StaticRow.cs +++ b/RdlEngine/Definition/StaticRow.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -60,10 +61,10 @@ internal StaticRow(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "StaticRow requires the ReportItems element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); return; } diff --git a/RdlEngine/Definition/StaticRows.cs b/RdlEngine/Definition/StaticRows.cs index 217c91a8..8b1ce319 100644 --- a/RdlEngine/Definition/StaticRows.cs +++ b/RdlEngine/Definition/StaticRows.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal StaticRows(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (StaticRow r in _Items) { - r.FinalPass(); + await r.FinalPass(); } return; } diff --git a/RdlEngine/Definition/StaticSeries.cs b/RdlEngine/Definition/StaticSeries.cs index 3a2be21e..d829dabd 100644 --- a/RdlEngine/Definition/StaticSeries.cs +++ b/RdlEngine/Definition/StaticSeries.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -65,11 +66,11 @@ internal StaticSeries(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (StaticMember sm in _Items) { - sm.FinalPass(); + await sm.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Style.cs b/RdlEngine/Definition/Style.cs index 3bd49610..579ebf9a 100644 --- a/RdlEngine/Definition/Style.cs +++ b/RdlEngine/Definition/Style.cs @@ -25,6 +25,8 @@ the website www.fyiReporting.com. using System.Xml; using System.IO; using System.Text; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; using Drawing2D = Majorsilence.Drawing.Drawing2D; @@ -251,70 +253,70 @@ internal Style(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_BorderColor != null) - _BorderColor.FinalPass(); + await _BorderColor.FinalPass(); if (_BorderStyle != null) - _BorderStyle.FinalPass(); + await _BorderStyle.FinalPass(); if (_BorderWidth != null) - _BorderWidth.FinalPass(); + await _BorderWidth.FinalPass(); if (_BackgroundColor != null) - _BackgroundColor.FinalPass(); + await _BackgroundColor.FinalPass(); if (_BackgroundGradientType != null) - _BackgroundGradientType.FinalPass(); + await _BackgroundGradientType.FinalPass(); if (_BackgroundGradientEndColor != null) - _BackgroundGradientEndColor.FinalPass(); + await _BackgroundGradientEndColor.FinalPass(); if (_BackgroundImage != null) - _BackgroundImage.FinalPass(); + await _BackgroundImage.FinalPass(); if (_FontStyle != null) - _FontStyle.FinalPass(); + await _FontStyle.FinalPass(); if (_FontFamily != null) - _FontFamily.FinalPass(); + await _FontFamily.FinalPass(); if (_FontSize != null) - _FontSize.FinalPass(); + await _FontSize.FinalPass(); if (_FontWeight != null) - _FontWeight.FinalPass(); + await _FontWeight.FinalPass(); if (_Format != null) - _Format.FinalPass(); + await _Format.FinalPass(); if (_TextDecoration != null) - _TextDecoration.FinalPass(); + await _TextDecoration.FinalPass(); if (_TextAlign != null) - _TextAlign.FinalPass(); + await _TextAlign.FinalPass(); if (_VerticalAlign != null) - _VerticalAlign.FinalPass(); + await _VerticalAlign.FinalPass(); if (_Color != null) - _Color.FinalPass(); + await _Color.FinalPass(); if (_PaddingLeft != null) - _PaddingLeft.FinalPass(); + await _PaddingLeft.FinalPass(); if (_PaddingRight != null) - _PaddingRight.FinalPass(); + await _PaddingRight.FinalPass(); if (_PaddingTop != null) - _PaddingTop.FinalPass(); + await _PaddingTop.FinalPass(); if (_PaddingBottom != null) - _PaddingBottom.FinalPass(); + await _PaddingBottom.FinalPass(); if (_LineHeight != null) - _LineHeight.FinalPass(); + await _LineHeight.FinalPass(); if (_Direction != null) - _Direction.FinalPass(); + await _Direction.FinalPass(); if (_WritingMode != null) - _WritingMode.FinalPass(); + await _WritingMode.FinalPass(); if (_Language != null) - _Language.FinalPass(); + await _Language.FinalPass(); if (_UnicodeBiDirectional != null) - _UnicodeBiDirectional.FinalPass(); + await _UnicodeBiDirectional.FinalPass(); if (_Calendar != null) - _Calendar.FinalPass(); + await _Calendar.FinalPass(); if (_NumeralLanguage != null) - _NumeralLanguage.FinalPass(); + await _NumeralLanguage.FinalPass(); if (_NumeralVariant != null) - _NumeralVariant.FinalPass(); + await _NumeralVariant.FinalPass(); - _ConstantStyle = this.IsConstant(); + _ConstantStyle = await this.IsConstant(); return; } - internal void DrawBackground(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangle rect) + internal async Task DrawBackground(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangle rect) { Drawing2D.LinearGradientBrush linGrBrush = null; @@ -322,12 +324,12 @@ internal void DrawBackground(Report rpt, Drawing.Graphics g, Row r, Drawing.Rect this.BackgroundGradientEndColor != null && this.BackgroundColor != null) { - string bgt = this.BackgroundGradientType.EvaluateString(rpt, r); - string bgc = this.BackgroundColor.EvaluateString(rpt, r); + string bgt = await this.BackgroundGradientType.EvaluateString(rpt, r); + string bgc = await this.BackgroundColor.EvaluateString(rpt, r); Drawing.Color c = XmlUtil.ColorFromHtml(bgc, Drawing.Color.White, rpt); - string bgec = this.BackgroundGradientEndColor.EvaluateString(rpt, r); + string bgec = await this.BackgroundGradientEndColor.EvaluateString(rpt, r); Drawing.Color ec = XmlUtil.ColorFromHtml(bgec, Drawing.Color.White, rpt); switch (bgt) @@ -368,7 +370,7 @@ internal void DrawBackground(Report rpt, Drawing.Graphics g, Row r, Drawing.Rect { if (this.BackgroundColor != null) { - string bgc = this.BackgroundColor.EvaluateString(rpt, r); + string bgc = await this.BackgroundColor.EvaluateString(rpt, r); Drawing.Color c = XmlUtil.ColorFromHtml(bgc, Drawing.Color.White, rpt); using (Drawing.SolidBrush sb = new Drawing.SolidBrush(c)) { @@ -378,13 +380,13 @@ internal void DrawBackground(Report rpt, Drawing.Graphics g, Row r, Drawing.Rect } } - internal void DrawBackgroundCircle(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangle rect) + internal async Task DrawBackgroundCircle(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangle rect) { // Don't use the gradient in this case (since it won't match) the rest of the // background. (Routine is only used by ChartPie in the doughnut case.) if (this.BackgroundColor != null) { - string bgc = this.BackgroundColor.EvaluateString(rpt, r); + string bgc = await this.BackgroundColor.EvaluateString(rpt, r); Drawing.Color c = XmlUtil.ColorFromHtml(bgc, Drawing.Color.White, rpt); using (Drawing.SolidBrush sb = new Drawing.SolidBrush(c)) { @@ -395,7 +397,7 @@ internal void DrawBackgroundCircle(Report rpt, Drawing.Graphics g, Row r, Drawin } // Draw a border using the current style - internal void DrawBorder(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangle rect) + internal async Task DrawBorder(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangle rect) { if (this.BorderStyle == null) return; @@ -415,27 +417,27 @@ internal void DrawBorder(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangl { if (BorderStyle.Default != null) { - v = BorderStyle.Default.EvaluateString(rpt, r); + v = await BorderStyle.Default.EvaluateString(rpt, r); topBS = bottomBS = leftBS = rightBS = StyleBorderStyle.GetBorderStyle(v, BorderStyleEnum.None); } if (BorderStyle.Top != null) { - v = BorderStyle.Top.EvaluateString(rpt, r); + v = await BorderStyle.Top.EvaluateString(rpt, r); topBS = StyleBorderStyle.GetBorderStyle(v, topBS); } if (BorderStyle.Bottom != null) { - v = BorderStyle.Bottom.EvaluateString(rpt, r); + v = await BorderStyle.Bottom.EvaluateString(rpt, r); bottomBS = StyleBorderStyle.GetBorderStyle(v, bottomBS); } if (BorderStyle.Left != null) { - v = BorderStyle.Left.EvaluateString(rpt, r); + v = await BorderStyle.Left.EvaluateString(rpt, r); leftBS = StyleBorderStyle.GetBorderStyle(v, leftBS); } if (BorderStyle.Right != null) { - v = BorderStyle.Right.EvaluateString(rpt, r); + v = await BorderStyle.Right.EvaluateString(rpt, r); rightBS = StyleBorderStyle.GetBorderStyle(v, rightBS); } } @@ -446,28 +448,28 @@ internal void DrawBorder(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangl { if (BorderColor.Default != null) { - v = BorderColor.Default.EvaluateString(rpt, r); + v = await BorderColor.Default.EvaluateString(rpt, r); topColor = bottomColor = leftColor = rightColor = XmlUtil.ColorFromHtml(v, Drawing.Color.Black, rpt); } if (BorderColor.Top != null) { - v = BorderColor.Top.EvaluateString(rpt, r); + v = await BorderColor.Top.EvaluateString(rpt, r); topColor = XmlUtil.ColorFromHtml(v, Drawing.Color.Black, rpt); } if (BorderColor.Bottom != null) { - v = BorderColor.Bottom.EvaluateString(rpt, r); + v = await BorderColor.Bottom.EvaluateString(rpt, r); bottomColor = XmlUtil.ColorFromHtml(v, Drawing.Color.Black, rpt); } if (BorderColor.Left != null) { - v = BorderColor.Left.EvaluateString(rpt, r); + v = await BorderColor.Left.EvaluateString(rpt, r); leftColor = XmlUtil.ColorFromHtml(v, Drawing.Color.Black, rpt); } if (BorderColor.Right != null) { - v = BorderColor.Right.EvaluateString(rpt, r); + v = await BorderColor.Right.EvaluateString(rpt, r); rightColor = XmlUtil.ColorFromHtml(v, Drawing.Color.Black, rpt); } } @@ -478,23 +480,23 @@ internal void DrawBorder(Report rpt, Drawing.Graphics g, Row r, Drawing.Rectangl { if (BorderWidth.Default != null) { - topWidth = bottomWidth = leftWidth = rightWidth = (int) new RSize(this.OwnerReport, BorderWidth.Default.EvaluateString(rpt, r)).PixelsX; + topWidth = bottomWidth = leftWidth = rightWidth = (int) new RSize(this.OwnerReport, await BorderWidth.Default.EvaluateString(rpt, r)).PixelsX; } if (BorderWidth.Top != null) { - topWidth = (int) new RSize(this.OwnerReport, BorderWidth.Top.EvaluateString(rpt, r)).PixelsX; + topWidth = (int) new RSize(this.OwnerReport, await BorderWidth.Top.EvaluateString(rpt, r)).PixelsX; } if (BorderWidth.Bottom != null) { - bottomWidth = (int) new RSize(this.OwnerReport, BorderWidth.Bottom.EvaluateString(rpt, r)).PixelsX; + bottomWidth = (int) new RSize(this.OwnerReport, await BorderWidth.Bottom.EvaluateString(rpt, r)).PixelsX; } if (BorderWidth.Left != null) { - leftWidth = (int) new RSize(this.OwnerReport, BorderWidth.Left.EvaluateString(rpt, r)).PixelsY; + leftWidth = (int) new RSize(this.OwnerReport, await BorderWidth.Left.EvaluateString(rpt, r)).PixelsY; } if (BorderWidth.Right != null) { - rightWidth = (int) new RSize(this.OwnerReport, BorderWidth.Right.EvaluateString(rpt, r)).PixelsY; + rightWidth = (int) new RSize(this.OwnerReport, await BorderWidth.Right.EvaluateString(rpt, r)).PixelsY; } } @@ -581,7 +583,7 @@ private void DrawBorderDashStyle(Drawing.Pen p, BorderStyleEnum bs) } // Draw a line into the specified graphics object using the current style - internal void DrawStyleLine(Report rpt, Drawing.Graphics g, Row r, Drawing.Point s, Drawing.Point e) + internal async Task DrawStyleLine(Report rpt, Drawing.Graphics g, Row r, Drawing.Point s, Drawing.Point e) { int width; Drawing.Color color; @@ -589,14 +591,14 @@ internal void DrawStyleLine(Report rpt, Drawing.Graphics g, Row r, Drawing.Point // Border Width default is used for the line width if (BorderWidth != null && BorderWidth.Default != null) - width = (int) new RSize(this.OwnerReport, BorderWidth.Default.EvaluateString(rpt, r)).PixelsX; + width = (int) new RSize(this.OwnerReport, await BorderWidth.Default.EvaluateString(rpt, r)).PixelsX; else width = 1; // Border Color default is used for the line color if (BorderColor != null && BorderColor.Default != null) { - string v = BorderColor.Default.EvaluateString(rpt, r); + string v = await BorderColor.Default.EvaluateString(rpt, r); color = XmlUtil.ColorFromHtml(v, Drawing.Color.Black, rpt); } else @@ -604,7 +606,7 @@ internal void DrawStyleLine(Report rpt, Drawing.Graphics g, Row r, Drawing.Point if (BorderStyle != null && BorderStyle.Default != null) { - string v = BorderStyle.Default.EvaluateString(rpt, r); + string v = await BorderStyle.Default.EvaluateString(rpt, r); bs = StyleBorderStyle.GetBorderStyle(v, BorderStyleEnum.None); } else @@ -620,14 +622,14 @@ internal void DrawStyleLine(Report rpt, Drawing.Graphics g, Row r, Drawing.Point // Draw a string into the specified graphics object using the current style // information - internal void DrawString(Report rpt, Drawing.Graphics g, object o, TypeCode tc, Row r, Drawing.Rectangle rect) + internal async Task DrawString(Report rpt, Drawing.Graphics g, object o, TypeCode tc, Row r, Drawing.Rectangle rect) { // the string to draw - var s = Style.GetFormatedString(rpt, this, r, o, tc); + var s = await Style.GetFormatedString(rpt, this, r, o, tc); - using (Drawing.Font drawFont = GetFont(rpt, r)) // Font we'll draw with - using (Drawing.Brush drawBrush = GetBrush(rpt, r)) // Brush we'll draw with - using (Drawing.StringFormat drawFormat = GetStringFormat(rpt, r)) // StringFormat we'll draw with + using (Drawing.Font drawFont = await GetFont(rpt, r)) // Font we'll draw with + using (Drawing.Brush drawBrush = await GetBrush(rpt, r)) // Brush we'll draw with + using (Drawing.StringFormat drawFormat = await GetStringFormat(rpt, r)) // StringFormat we'll draw with { // Draw string drawFormat.FormatFlags |= Drawing.StringFormatFlags.NoWrap; @@ -662,12 +664,12 @@ static internal void DrawStringDefaults(Drawing.Graphics g, object o, Drawing.Re // Calc size of a string with the specified graphics object using the current style // information - internal Drawing.Size MeasureString(Report rpt, Drawing.Graphics g, object o, TypeCode tc, Row r, int maxWidth) + internal async Task MeasureString(Report rpt, Drawing.Graphics g, object o, TypeCode tc, Row r, int maxWidth) { - string s = Style.GetFormatedString(rpt, this, r, o, tc); // the string to draw + string s = await Style.GetFormatedString(rpt, this, r, o, tc); // the string to draw - using (Drawing.Font drawFont = GetFont(rpt, r)) // Font we'll draw with - using (Drawing.StringFormat drawFormat = GetStringFormat(rpt, r)) // StringFormat we'll draw with + using (Drawing.Font drawFont = await GetFont(rpt, r)) // Font we'll draw with + using (Drawing.StringFormat drawFormat = await GetStringFormat(rpt, r)) // StringFormat we'll draw with { // Measure string if (maxWidth == int.MaxValue) @@ -681,9 +683,9 @@ internal Drawing.Size MeasureString(Report rpt, Drawing.Graphics g, object o, Ty } // Measure a string using the defaults for a Style font - static internal Drawing.Size MeasureStringDefaults(Report rpt, Drawing.Graphics g, object o, TypeCode tc, Row r, int maxWidth) + static internal async Task MeasureStringDefaults(Report rpt, Drawing.Graphics g, object o, TypeCode tc, Row r, int maxWidth) { - string s = Style.GetFormatedString(rpt, null, r, o, tc); // the string to draw + string s = await Style.GetFormatedString(rpt, null, r, o, tc); // the string to draw Drawing.Size size = Drawing.Size.Empty; using (Drawing.Font drawFont = new Drawing.Font("Arial", 10)) // Font we'll draw with @@ -701,13 +703,13 @@ static internal Drawing.Size MeasureStringDefaults(Report rpt, Drawing.Graphics } } - internal Drawing.Brush GetBrush(Report rpt, Row r) + internal async Task GetBrush(Report rpt, Row r) { Drawing.Brush drawBrush; // Get the brush information if (this.Color != null) { - string c = this.Color.EvaluateString(rpt, r); + string c = await this.Color.EvaluateString(rpt, r); Drawing.Color color = XmlUtil.ColorFromHtml(c, Drawing.Color.Black, rpt); drawBrush = new Drawing.SolidBrush(color); } @@ -716,13 +718,13 @@ internal Drawing.Brush GetBrush(Report rpt, Row r) return drawBrush; } - internal Drawing.Font GetFont(Report rpt, Row r) + internal async Task GetFont(Report rpt, Row r) { // Get the font information // FAMILY string ff; if (this.FontFamily != null) - ff = this.FontFamily.EvaluateString(rpt, r); + ff = await this.FontFamily.EvaluateString(rpt, r); else ff = "Arial"; @@ -730,13 +732,13 @@ internal Drawing.Font GetFont(Report rpt, Row r) Drawing.FontStyle fs = 0; if (this.FontStyle != null) { - string fStyle = this.FontStyle.EvaluateString(rpt, r); + string fStyle = await this.FontStyle.EvaluateString(rpt, r); if (fStyle == "Italic") fs |= Drawing.FontStyle.Italic; } if (this.TextDecoration != null) { - string td = this.TextDecoration.EvaluateString(rpt, r); + string td = await this.TextDecoration.EvaluateString(rpt, r); switch (td) { case "Underline": @@ -756,7 +758,7 @@ internal Drawing.Font GetFont(Report rpt, Row r) // WEIGHT if (this.FontWeight != null) { - string weight = this.FontWeight.EvaluateString(rpt, r); + string weight = await this.FontWeight.EvaluateString(rpt, r); switch(weight.ToLower()) { case "bold": @@ -784,7 +786,7 @@ internal Drawing.Font GetFont(Report rpt, Row r) float size; // Value is in points if (this.FontSize != null) { - string lsize = this.FontSize.EvaluateString(rpt, r); + string lsize = await this.FontSize.EvaluateString(rpt, r); RSize rs = new RSize(this.OwnerReport, lsize); size = rs.Points; } @@ -795,32 +797,32 @@ internal Drawing.Font GetFont(Report rpt, Row r) return new Drawing.Font(fFamily, size, fs); } - internal Drawing.StringFormat GetStringFormat(Report rpt, Row r) + internal async Task GetStringFormat(Report rpt, Row r) { - return GetStringFormat(rpt, r, Drawing.StringAlignment.Center); + return await GetStringFormat(rpt, r, Drawing.StringAlignment.Center); } - internal Drawing.StringFormat GetStringFormat(Report rpt, Row r, Drawing.StringAlignment defTextAlign) + internal async Task GetStringFormat(Report rpt, Row r, Drawing.StringAlignment defTextAlign) { // Set format of string. Drawing.StringFormat drawFormat = new Drawing.StringFormat(); if (this.Direction != null) { - string dir = this.Direction.EvaluateString(rpt, r); + string dir = await this.Direction.EvaluateString(rpt, r); if (dir == "RTL") drawFormat.FormatFlags |= Drawing.StringFormatFlags.DirectionRightToLeft; } if (this.WritingMode != null) { - string wm = this.WritingMode.EvaluateString(rpt, r); + string wm = await this.WritingMode.EvaluateString(rpt, r); if (wm == "tb-rl") drawFormat.FormatFlags |= Drawing.StringFormatFlags.DirectionVertical; } if (this.TextAlign != null) { - string ta = this.TextAlign.EvaluateString(rpt, r); + string ta = await this.TextAlign.EvaluateString(rpt, r); switch (ta.ToLower()) { case "left": @@ -843,7 +845,7 @@ internal Drawing.StringFormat GetStringFormat(Report rpt, Row r, Drawing.StringA if (this.VerticalAlign != null) { - string va = this.VerticalAlign.EvaluateString(rpt, r); + string va = await this.VerticalAlign.EvaluateString(rpt, r); switch (va.ToLower()) { case "top": @@ -977,7 +979,7 @@ internal string GetCSS(Report rpt, Row row, bool bDefaults) } // Generate an evaluated version of all the style parameters; used for page processing - internal StyleInfo GetStyleInfo(Report rpt, Row r) + internal async Task GetStyleInfo(Report rpt, Row r) { WorkClass wc = GetWC(rpt); if (wc != null && wc.StyleInfo != null) // When StyleInfo is available; style is a constant @@ -990,31 +992,31 @@ internal StyleInfo GetStyleInfo(Report rpt, Row r) if (this.BorderColor != null) { StyleBorderColor bc = this.BorderColor; - si.BColorLeft = bc.EvalLeft(rpt, r); - si.BColorRight = bc.EvalRight(rpt, r); - si.BColorTop = bc.EvalTop(rpt, r); - si.BColorBottom = bc.EvalBottom(rpt, r); + si.BColorLeft = await bc.EvalLeft(rpt, r); + si.BColorRight = await bc.EvalRight(rpt, r); + si.BColorTop = await bc.EvalTop(rpt, r); + si.BColorBottom = await bc.EvalBottom(rpt, r); } if (this.BorderStyle != null) { StyleBorderStyle bs = this.BorderStyle; - si.BStyleLeft = bs.EvalLeft(rpt, r); - si.BStyleRight = bs.EvalRight(rpt, r); - si.BStyleTop = bs.EvalTop(rpt, r); - si.BStyleBottom = bs.EvalBottom(rpt, r); + si.BStyleLeft = await bs.EvalLeft(rpt, r); + si.BStyleRight = await bs.EvalRight(rpt, r); + si.BStyleTop = await bs.EvalTop(rpt, r); + si.BStyleBottom = await bs.EvalBottom(rpt, r); } if (this.BorderWidth != null) { StyleBorderWidth bw = this.BorderWidth; - si.BWidthLeft = bw.EvalLeft(rpt, r); - si.BWidthRight = bw.EvalRight(rpt, r); - si.BWidthTop = bw.EvalTop(rpt, r); - si.BWidthBottom = bw.EvalBottom(rpt, r); + si.BWidthLeft = await bw.EvalLeft(rpt, r); + si.BWidthRight = await bw.EvalRight(rpt, r); + si.BWidthTop = await bw.EvalTop(rpt, r); + si.BWidthBottom = await bw.EvalBottom(rpt, r); } - si.BackgroundColor = this.EvalBackgroundColor(rpt, r); + si.BackgroundColor = await this.EvalBackgroundColor(rpt, r); // When background color not specified; and reportitem part of table // use the tables background color if (si.BackgroundColor == Drawing.Color.Empty) @@ -1026,40 +1028,40 @@ internal StyleInfo GetStyleInfo(Report rpt, Row r) { Table t = ri.TC.OwnerTable; if (t.Style != null) - si.BackgroundColor = t.Style.EvalBackgroundColor(rpt, r); + si.BackgroundColor = await t.Style.EvalBackgroundColor(rpt, r); } } } - si.BackgroundGradientType = this.EvalBackgroundGradientType(rpt, r); - si.BackgroundGradientEndColor = this.EvalBackgroundGradientEndColor(rpt, r); + si.BackgroundGradientType = await this.EvalBackgroundGradientType(rpt, r); + si.BackgroundGradientEndColor = await this.EvalBackgroundGradientEndColor(rpt, r); if (this._BackgroundImage != null) { - si.BackgroundImage = _BackgroundImage.GetPageImage(rpt, r); + si.BackgroundImage = await _BackgroundImage.GetPageImage(rpt, r); } else si.BackgroundImage = null; - si.FontStyle = this.EvalFontStyle(rpt, r); - si.FontFamily = this.EvalFontFamily(rpt, r); - si.FontSize = this.EvalFontSize(rpt, r); - si.FontWeight = this.EvalFontWeight(rpt, r); - si._Format = this.EvalFormat(rpt, r); //(string) .NET Framework formatting string1 - si.TextDecoration = this.EvalTextDecoration(rpt, r); - si.TextAlign = this.EvalTextAlign(rpt, r); - si.VerticalAlign = this.EvalVerticalAlign(rpt, r); - si.Color = this.EvalColor(rpt, r); - si.PaddingLeft = this.EvalPaddingLeft(rpt, r); - si.PaddingRight = this.EvalPaddingRight(rpt, r); - si.PaddingTop = this.EvalPaddingTop(rpt, r); - si.PaddingBottom = this.EvalPaddingBottom(rpt, r); - si.LineHeight = this.EvalLineHeight(rpt, r); - si.Direction = this.EvalDirection(rpt, r); - si.WritingMode = this.EvalWritingMode(rpt, r); - si.Language = this.EvalLanguage(rpt, r); - si.UnicodeBiDirectional = this.EvalUnicodeBiDirectional(rpt, r); - si.Calendar = this.EvalCalendar(rpt, r); - si.NumeralLanguage = this.EvalNumeralLanguage(rpt, r); - si.NumeralVariant = this.EvalNumeralVariant(rpt, r); + si.FontStyle = await this.EvalFontStyle(rpt, r); + si.FontFamily = await this.EvalFontFamily(rpt, r); + si.FontSize = await this.EvalFontSize(rpt, r); + si.FontWeight = await this.EvalFontWeight(rpt, r); + si._Format = await this.EvalFormat(rpt, r); //(string) .NET Framework formatting string1 + si.TextDecoration = await this.EvalTextDecoration(rpt, r); + si.TextAlign = await this.EvalTextAlign(rpt, r); + si.VerticalAlign = await this.EvalVerticalAlign(rpt, r); + si.Color = await this.EvalColor(rpt, r); + si.PaddingLeft = await this.EvalPaddingLeft(rpt, r); + si.PaddingRight = await this.EvalPaddingRight(rpt, r); + si.PaddingTop = await this.EvalPaddingTop(rpt, r); + si.PaddingBottom = await this.EvalPaddingBottom(rpt, r); + si.LineHeight = await this.EvalLineHeight(rpt, r); + si.Direction = await this.EvalDirection(rpt, r); + si.WritingMode = await this.EvalWritingMode(rpt, r); + si.Language = await this.EvalLanguage(rpt, r); + si.UnicodeBiDirectional = await this.EvalUnicodeBiDirectional(rpt, r); + si.Calendar = await this.EvalCalendar(rpt, r); + si.NumeralLanguage = await this.EvalNumeralLanguage(rpt, r); + si.NumeralVariant = await this.EvalNumeralVariant(rpt, r); if (this._ConstantStyle) // We'll only do this work once { @@ -1071,7 +1073,7 @@ internal StyleInfo GetStyleInfo(Report rpt, Row r) } // Format a string; passed a style but style may be null; - static internal string GetFormatedString(Report rpt, Style s, Row row, object o, TypeCode tc) + static internal async Task GetFormatedString(Report rpt, Style s, Row row, object o, TypeCode tc) { string t = null; if (o == null) @@ -1082,7 +1084,7 @@ static internal string GetFormatedString(Report rpt, Style s, Row row, object o, { if (s != null && s.Format != null) { - format = s.Format.EvaluateString(rpt, row); + format = await s.Format.EvaluateString(rpt, row); if (format != null && format.Length > 0) { switch (tc) @@ -1146,114 +1148,114 @@ static internal string GetFormatedString(Report rpt, Style s, Row row, object o, return t; } - private bool IsConstant() + private async Task IsConstant() { bool rc = true; if (_BorderColor != null) - rc = _BorderColor.IsConstant(); + rc = await _BorderColor.IsConstant(); if (!rc) return false; if (_BorderStyle != null) - rc = _BorderStyle.IsConstant(); + rc = await _BorderStyle.IsConstant(); if (!rc) return false; if (_BorderWidth != null) - rc = _BorderWidth.IsConstant(); + rc = await _BorderWidth.IsConstant(); if (!rc) return false; if (_BackgroundColor != null) - rc = _BackgroundColor.IsConstant(); + rc = await _BackgroundColor.IsConstant(); if (!rc) return false; if (_BackgroundImage != null) - rc = _BackgroundImage.IsConstant(); + rc = await _BackgroundImage.IsConstant(); if (!rc) return false; if (_FontStyle != null) - rc = _FontStyle.IsConstant(); + rc = await _FontStyle.IsConstant(); if (!rc) return false; if (_FontFamily != null) - rc = _FontFamily.IsConstant(); + rc = await _FontFamily.IsConstant(); if (!rc) return false; if (_FontSize != null) - rc = _FontSize.IsConstant(); + rc = await _FontSize.IsConstant(); if (!rc) return false; if (_FontWeight != null) - rc = _FontWeight.IsConstant(); + rc = await _FontWeight.IsConstant(); if (!rc) return false; if (_TextDecoration != null) - rc = _TextDecoration.IsConstant(); + rc = await _TextDecoration.IsConstant(); if (!rc) return false; if (_TextAlign != null) - rc = _TextAlign.IsConstant(); + rc = await _TextAlign.IsConstant(); if (!rc) return false; if (_VerticalAlign != null) - rc = _VerticalAlign.IsConstant(); + rc = await _VerticalAlign.IsConstant(); if (!rc) return false; if (_Color != null) - rc = _Color.IsConstant(); + rc = await _Color.IsConstant(); if (!rc) return false; if (_PaddingLeft != null) - rc = _PaddingLeft.IsConstant(); + rc = await _PaddingLeft.IsConstant(); if (!rc) return false; if (_PaddingRight != null) - rc = _PaddingRight.IsConstant(); + rc = await _PaddingRight.IsConstant(); if (!rc) return false; if (_PaddingTop != null) - rc = _PaddingTop.IsConstant(); + rc = await _PaddingTop.IsConstant(); if (!rc) return false; if (_PaddingBottom != null) - rc = _PaddingBottom.IsConstant(); + rc = await _PaddingBottom.IsConstant(); if (!rc) return false; if (_LineHeight != null) - rc = _LineHeight.IsConstant(); + rc = await _LineHeight.IsConstant(); if (!rc) return false; @@ -1261,12 +1263,12 @@ private bool IsConstant() return rc; } - internal Drawing.Rectangle PaddingAdjust(Report rpt, Row r, Drawing.Rectangle rect, bool bAddIn) + internal async Task PaddingAdjust(Report rpt, Row r, Drawing.Rectangle rect, bool bAddIn) { - int pbottom = this.EvalPaddingBottomPx(rpt, r); - int ptop = this.EvalPaddingTopPx(rpt, r); - int pleft = this.EvalPaddingLeftPx(rpt, r); - int pright = this.EvalPaddingRightPx(rpt, r); + int pbottom = await this.EvalPaddingBottomPx(rpt, r); + int ptop = await this.EvalPaddingTopPx(rpt, r); + int pleft = await this.EvalPaddingLeftPx(rpt, r); + int pright = await this.EvalPaddingRightPx(rpt, r); Drawing.Rectangle rt; if (bAddIn) // add in when trying to size the object @@ -1302,12 +1304,12 @@ internal Expression BackgroundColor set { _BackgroundColor = value; } } - internal Drawing.Color EvalBackgroundColor(Report rpt, Row row) + internal async Task EvalBackgroundColor(Report rpt, Row row) { if (_BackgroundColor == null) return Drawing.Color.Empty; - string c = _BackgroundColor.EvaluateString(rpt, row); + string c = await _BackgroundColor.EvaluateString(rpt, row); return XmlUtil.ColorFromHtml(c, Drawing.Color.Empty, rpt); } @@ -1317,12 +1319,12 @@ internal Expression BackgroundGradientType set { _BackgroundGradientType = value; } } - internal BackgroundGradientTypeEnum EvalBackgroundGradientType(Report rpt, Row r) + internal async Task EvalBackgroundGradientType(Report rpt, Row r) { if (_BackgroundGradientType == null) return BackgroundGradientTypeEnum.None; - string bgt = _BackgroundGradientType.EvaluateString(rpt, r); + string bgt = await _BackgroundGradientType.EvaluateString(rpt, r); return StyleInfo.GetBackgroundGradientType(bgt, BackgroundGradientTypeEnum.None); } @@ -1332,12 +1334,12 @@ internal Expression BackgroundGradientEndColor set { _BackgroundGradientEndColor = value; } } - internal Drawing.Color EvalBackgroundGradientEndColor(Report rpt, Row r) + internal async Task EvalBackgroundGradientEndColor(Report rpt, Row r) { if (_BackgroundGradientEndColor == null) return Drawing.Color.Empty; - string c = _BackgroundGradientEndColor.EvaluateString(rpt, r); + string c = await _BackgroundGradientEndColor.EvaluateString(rpt, r); return XmlUtil.ColorFromHtml(c, Drawing.Color.Empty, rpt); } @@ -1358,20 +1360,20 @@ internal Expression FontStyle set { _FontStyle = value; } } - internal bool IsFontItalic(Report rpt, Row r) + internal async Task IsFontItalic(Report rpt, Row r) { - if (EvalFontStyle(rpt, r) == FontStyleEnum.Italic) + if (await EvalFontStyle(rpt, r) == FontStyleEnum.Italic) return true; return false; } - internal FontStyleEnum EvalFontStyle(Report rpt, Row row) + internal async Task EvalFontStyle(Report rpt, Row row) { if (_FontStyle == null) return FontStyleEnum.Normal; - string fs = _FontStyle.EvaluateString(rpt, row); + string fs = await _FontStyle.EvaluateString(rpt, row); return StyleInfo.GetFontStyle(fs, FontStyleEnum.Normal); } @@ -1381,12 +1383,12 @@ internal Expression FontFamily set { _FontFamily = value; } } - internal string EvalFontFamily(Report rpt, Row row) + internal async Task EvalFontFamily(Report rpt, Row row) { if (_FontFamily == null) return "Arial"; - return _FontFamily.EvaluateString(rpt, row); + return await _FontFamily.EvaluateString(rpt, row); } internal Expression FontSize @@ -1395,13 +1397,13 @@ internal Expression FontSize set { _FontSize = value; } } - internal float EvalFontSize(Report rpt, Row row) + internal async Task EvalFontSize(Report rpt, Row row) { if (_FontSize == null) return 10; string pts; - pts = _FontSize.EvaluateString(rpt, row); + pts = await _FontSize.EvaluateString(rpt, row); RSize sz = new RSize(this.OwnerReport, pts); return sz.Points; @@ -1413,21 +1415,21 @@ internal Expression FontWeight set { _FontWeight = value; } } - internal FontWeightEnum EvalFontWeight(Report rpt, Row row) + internal async Task EvalFontWeight(Report rpt, Row row) { if (_FontWeight == null) return FontWeightEnum.Normal; - string weight = this.FontWeight.EvaluateString(rpt, row); + string weight = await this.FontWeight.EvaluateString(rpt, row); return StyleInfo.GetFontWeight(weight, FontWeightEnum.Normal); } - internal bool IsFontBold(Report rpt, Row r) + internal async Task IsFontBold(Report rpt, Row r) { if (this.FontWeight == null) return false; - string weight = this.FontWeight.EvaluateString(rpt, r); + string weight = await this.FontWeight.EvaluateString(rpt, r); switch(weight.ToLower()) { case "bold": @@ -1449,12 +1451,12 @@ internal Expression Format set { _Format = value; } } - internal string EvalFormat(Report rpt, Row row) + internal async Task EvalFormat(Report rpt, Row row) { if (_Format == null) return "General"; - string f = _Format.EvaluateString(rpt, row); + string f = await _Format.EvaluateString(rpt, row); if (f == null || f.Length == 0) return "General"; @@ -1469,12 +1471,12 @@ internal Expression TextDecoration set { _TextDecoration = value; } } - internal TextDecorationEnum EvalTextDecoration(Report rpt, Row r) + internal async Task EvalTextDecoration(Report rpt, Row r) { if (_TextDecoration == null) return TextDecorationEnum.None; - string td = _TextDecoration.EvaluateString(rpt, r); + string td = await _TextDecoration.EvaluateString(rpt, r); return StyleInfo.GetTextDecoration(td, TextDecorationEnum.None); } @@ -1484,12 +1486,12 @@ internal Expression TextAlign set { _TextAlign = value; } } - internal TextAlignEnum EvalTextAlign(Report rpt, Row row) + internal async Task EvalTextAlign(Report rpt, Row row) { if (_TextAlign == null) return TextAlignEnum.General; - string a = _TextAlign.EvaluateString(rpt, row); + string a = await _TextAlign.EvaluateString(rpt, row); return StyleInfo.GetTextAlign(a, TextAlignEnum.General); } @@ -1499,12 +1501,12 @@ internal Expression VerticalAlign set { _VerticalAlign = value; } } - internal VerticalAlignEnum EvalVerticalAlign(Report rpt, Row row) + internal async Task EvalVerticalAlign(Report rpt, Row row) { if (_VerticalAlign == null) return VerticalAlignEnum.Top; - string v = _VerticalAlign.EvaluateString(rpt, row); + string v = await _VerticalAlign.EvaluateString(rpt, row); return StyleInfo.GetVerticalAlign(v, VerticalAlignEnum.Top); } @@ -1514,12 +1516,12 @@ internal Expression Color set { _Color = value; } } - internal Drawing.Color EvalColor(Report rpt, Row row) + internal async Task EvalColor(Report rpt, Row row) { if (_Color == null) return Drawing.Color.Black; - string c = _Color.EvaluateString(rpt, row); + string c = await _Color.EvaluateString(rpt, row); return XmlUtil.ColorFromHtml(c, Drawing.Color.Black, rpt); } @@ -1529,22 +1531,22 @@ internal Expression PaddingLeft set { _PaddingLeft = value; } } - internal float EvalPaddingLeft(Report rpt, Row row) + internal async Task EvalPaddingLeft(Report rpt, Row row) { if (_PaddingLeft == null) return 0; - string v = _PaddingLeft.EvaluateString(rpt, row); + string v = await _PaddingLeft.EvaluateString(rpt, row); RSize rz = new RSize(OwnerReport, v); return rz.Points; } - internal int EvalPaddingLeftPx(Report rpt, Row row) + internal async Task EvalPaddingLeftPx(Report rpt, Row row) { if (_PaddingLeft == null) return 0; - string v = _PaddingLeft.EvaluateString(rpt, row); + string v = await _PaddingLeft.EvaluateString(rpt, row); RSize rz = new RSize(OwnerReport, v); return rz.PixelsX; } @@ -1555,22 +1557,22 @@ internal Expression PaddingRight set { _PaddingRight = value; } } - internal float EvalPaddingRight(Report rpt, Row row) + internal async Task EvalPaddingRight(Report rpt, Row row) { if (_PaddingRight == null) return 0; - string v = _PaddingRight.EvaluateString(rpt, row); + string v = await _PaddingRight.EvaluateString(rpt, row); RSize rz = new RSize(OwnerReport, v); return rz.Points; } - internal int EvalPaddingRightPx(Report rpt, Row row) + internal async Task EvalPaddingRightPx(Report rpt, Row row) { if (_PaddingRight == null) return 0; - string v = _PaddingRight.EvaluateString(rpt, row); + string v = await _PaddingRight.EvaluateString(rpt, row); RSize rz = new RSize(OwnerReport, v); return rz.PixelsX; } @@ -1581,22 +1583,22 @@ internal Expression PaddingTop set { _PaddingTop = value; } } - internal float EvalPaddingTop(Report rpt, Row row) + internal async Task EvalPaddingTop(Report rpt, Row row) { if (_PaddingTop == null) return 0; - string v = _PaddingTop.EvaluateString(rpt, row); + string v = await _PaddingTop.EvaluateString(rpt, row); RSize rz = new RSize(OwnerReport, v); return rz.Points; } - internal int EvalPaddingTopPx(Report rpt, Row row) + internal async Task EvalPaddingTopPx(Report rpt, Row row) { if (_PaddingTop == null) return 0; - string v = _PaddingTop.EvaluateString(rpt, row); + string v = await _PaddingTop.EvaluateString(rpt, row); RSize rz = new RSize(OwnerReport, v); return rz.PixelsY; } @@ -1607,22 +1609,22 @@ internal Expression PaddingBottom set { _PaddingBottom = value; } } - internal float EvalPaddingBottom(Report rpt, Row row) + internal async Task EvalPaddingBottom(Report rpt, Row row) { if (_PaddingBottom == null) return 0; - string v = _PaddingBottom.EvaluateString(rpt, row); + string v = await _PaddingBottom.EvaluateString(rpt, row); RSize rz = new RSize(OwnerReport, v); return rz.Points; } - internal int EvalPaddingBottomPx(Report rpt, Row row) + internal async Task EvalPaddingBottomPx(Report rpt, Row row) { if (_PaddingBottom == null) return 0; - string v = _PaddingBottom.EvaluateString(rpt, row); + string v = await _PaddingBottom.EvaluateString(rpt, row); RSize rz = new RSize(OwnerReport, v); return rz.PixelsY; } @@ -1633,12 +1635,12 @@ internal Expression LineHeight set { _LineHeight = value; } } - internal float EvalLineHeight(Report rpt, Row r) + internal async Task EvalLineHeight(Report rpt, Row r) { if (_LineHeight == null) return float.NaN; - string sz = _LineHeight.EvaluateString(rpt, r); + string sz = await _LineHeight.EvaluateString(rpt, r); RSize rz = new RSize(OwnerReport, sz); return rz.Points; } @@ -1649,12 +1651,12 @@ internal Expression Direction set { _Direction = value; } } - internal DirectionEnum EvalDirection(Report rpt, Row r) + internal async Task EvalDirection(Report rpt, Row r) { if (_Direction == null) return DirectionEnum.LTR; - string d = _Direction.EvaluateString(rpt, r); + string d = await _Direction.EvaluateString(rpt, r); return StyleInfo.GetDirection(d, DirectionEnum.LTR); } @@ -1664,12 +1666,12 @@ internal Expression WritingMode set { _WritingMode = value; } } - internal WritingModeEnum EvalWritingMode(Report rpt, Row r) + internal async Task EvalWritingMode(Report rpt, Row r) { if (_WritingMode == null) return WritingModeEnum.lr_tb; - string w = _WritingMode.EvaluateString(rpt, r); + string w = await _WritingMode.EvaluateString(rpt, r); return StyleInfo.GetWritingMode(w, WritingModeEnum.lr_tb ); } @@ -1680,12 +1682,12 @@ internal Expression Language set { _Language = value; } } - internal string EvalLanguage(Report rpt, Row r) + internal async Task EvalLanguage(Report rpt, Row r) { if (_Language == null) - return OwnerReport.EvalLanguage(rpt, r); + return await OwnerReport.EvalLanguage(rpt, r); - return _Language.EvaluateString(rpt, r); + return await _Language.EvaluateString(rpt, r); } internal Expression UnicodeBiDirectional @@ -1694,12 +1696,12 @@ internal Expression UnicodeBiDirectional set { _UnicodeBiDirectional = value; } } - internal UnicodeBiDirectionalEnum EvalUnicodeBiDirectional(Report rpt, Row r) + internal async Task EvalUnicodeBiDirectional(Report rpt, Row r) { if (_UnicodeBiDirectional == null) return UnicodeBiDirectionalEnum.Normal; - string u = _UnicodeBiDirectional.EvaluateString(rpt, r); + string u = await _UnicodeBiDirectional.EvaluateString(rpt, r); return StyleInfo.GetUnicodeBiDirectional(u, UnicodeBiDirectionalEnum.Normal); } @@ -1709,12 +1711,12 @@ internal Expression Calendar set { _Calendar = value; } } - internal CalendarEnum EvalCalendar(Report rpt, Row r) + internal async Task EvalCalendar(Report rpt, Row r) { if (_Calendar == null) return CalendarEnum.Gregorian; - string c = _Calendar.EvaluateString(rpt, r); + string c = await _Calendar.EvaluateString(rpt, r); return StyleInfo.GetCalendar(c, CalendarEnum.Gregorian); } @@ -1724,12 +1726,12 @@ internal Expression NumeralLanguage set { _NumeralLanguage = value; } } - internal string EvalNumeralLanguage(Report rpt, Row r) + internal async Task EvalNumeralLanguage(Report rpt, Row r) { if (_NumeralLanguage == null) - return EvalLanguage(rpt, r); + return await EvalLanguage(rpt, r); - return _NumeralLanguage.EvaluateString(rpt, r); + return await _NumeralLanguage.EvaluateString(rpt, r); } internal Expression NumeralVariant @@ -1738,12 +1740,12 @@ internal Expression NumeralVariant set { _NumeralVariant = value; } } - internal int EvalNumeralVariant(Report rpt, Row r) + internal async Task EvalNumeralVariant(Report rpt, Row r) { if (_NumeralVariant == null) return 1; - int v = (int) _NumeralVariant.EvaluateDouble(rpt, r); + int v = (int)await _NumeralVariant.EvaluateDouble(rpt, r); if (v < 1 || v > 7) // correct for bad data v = 1; return v; diff --git a/RdlEngine/Definition/StyleBackgroundImage.cs b/RdlEngine/Definition/StyleBackgroundImage.cs index 542c9104..768d427f 100644 --- a/RdlEngine/Definition/StyleBackgroundImage.cs +++ b/RdlEngine/Definition/StyleBackgroundImage.cs @@ -34,6 +34,7 @@ the website www.fyiReporting.com. using System.Globalization; using System.Threading; using System.Net; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -97,16 +98,16 @@ internal StyleBackgroundImage(ReportDefn r, ReportLink p, XmlNode xNode) : base( } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Value != null) - _Value.FinalPass(); + await _Value.FinalPass(); if (_MIMEType != null) - _MIMEType.FinalPass(); + await _MIMEType.FinalPass(); if (_BackgroundRepeat != null) - _BackgroundRepeat.FinalPass(); + await _BackgroundRepeat.FinalPass(); - _ConstantImage = this.IsConstant(); + _ConstantImage = await this.IsConstant(); return; } @@ -129,7 +130,7 @@ internal string GetCSS(Report rpt, Row row, bool bDefaults) return sb.ToString(); } - internal bool IsConstant() + internal async Task IsConstant() { if (_Source == StyleBackgroundImageSourceEnum.Database) return false; @@ -137,17 +138,17 @@ internal bool IsConstant() bool rc = true; if (_Value != null) - rc = _Value.IsConstant(); + rc = await _Value.IsConstant(); if (!rc) return false; if (_BackgroundRepeat != null) - rc = _BackgroundRepeat.IsConstant(); + rc = await _BackgroundRepeat.IsConstant(); return rc; } - internal PageImage GetPageImage(Report rpt, Row row) + internal async Task GetPageImage(Report rpt, Row row) { string mtype=null; Stream strm=null; @@ -165,7 +166,7 @@ internal PageImage GetPageImage(Report rpt, Row row) try { - strm = GetImageStream(rpt, row, out mtype); + (strm, mtype) = await GetImageStream(rpt, row); if (strm == null) { rpt.rl.LogError(4, string.Format("Unable to load image {0}.", @@ -204,7 +205,7 @@ internal PageImage GetPageImage(Report rpt, Row row) pi.SI = new StyleInfo(); // this will just default everything if (_BackgroundRepeat != null) { - string r = _BackgroundRepeat.EvaluateString(rpt, row).ToLower(); + string r = (await _BackgroundRepeat.EvaluateString(rpt, row)).ToLower(); switch (r) { case "repeat": @@ -242,9 +243,9 @@ internal PageImage GetPageImage(Report rpt, Row row) return pi; } - Stream GetImageStream(Report rpt, Row row, out string mtype) + async Task<(Stream stream, string mtype)> GetImageStream(Report rpt, Row row) { - mtype=null; + string mtype=null; Stream strm=null; try { @@ -252,20 +253,20 @@ Stream GetImageStream(Report rpt, Row row, out string mtype) { case StyleBackgroundImageSourceEnum.Database: if (_MIMEType == null) - return null; - mtype = _MIMEType.EvaluateString(rpt, row); + return (null, mtype); + mtype = await _MIMEType.EvaluateString(rpt, row); object o = _Value.Evaluate(rpt, row); strm = new MemoryStream((byte[]) o); break; case StyleBackgroundImageSourceEnum.Embedded: - string name = _Value.EvaluateString(rpt, row); + string name = await _Value.EvaluateString(rpt, row); EmbeddedImage ei = (EmbeddedImage) OwnerReport.LUEmbeddedImages[name]; mtype = ei.MIMEType; byte[] ba = Convert.FromBase64String(ei.ImageData); strm = new MemoryStream(ba); break; case StyleBackgroundImageSourceEnum.External: - string fname = _Value.EvaluateString(rpt, row); + string fname = await _Value.EvaluateString(rpt, row); mtype = Image.GetMimeType(fname); if (fname.StartsWith("http:") || fname.StartsWith("file:") || @@ -279,7 +280,7 @@ Stream GetImageStream(Report rpt, Row row, out string mtype) strm = new FileStream(fname, System.IO.FileMode.Open, FileAccess.Read); break; default: - return null; + return (null, mtype); } } catch @@ -291,7 +292,7 @@ Stream GetImageStream(Report rpt, Row row, out string mtype) } } - return strm; + return (strm, mtype); } static internal string GetCSSDefaults() diff --git a/RdlEngine/Definition/StyleBorderColor.cs b/RdlEngine/Definition/StyleBorderColor.cs index 1608c33e..810785b2 100644 --- a/RdlEngine/Definition/StyleBorderColor.cs +++ b/RdlEngine/Definition/StyleBorderColor.cs @@ -24,6 +24,8 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.Text; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; #else @@ -85,18 +87,18 @@ internal StyleBorderColor(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Default != null) - _Default.FinalPass(); + await _Default.FinalPass(); if (_Left != null) - _Left.FinalPass(); + await _Left.FinalPass(); if (_Right != null) - _Right.FinalPass(); + await _Right.FinalPass(); if (_Top != null) - _Top.FinalPass(); + await _Top.FinalPass(); if (_Bottom != null) - _Bottom.FinalPass(); + await _Bottom.FinalPass(); return; } @@ -125,36 +127,36 @@ internal string GetCSS(Report rpt, Row row, bool bDefaults) return sb.ToString(); } - internal bool IsConstant() + internal async Task IsConstant() { bool rc = true; if (_Default != null) - rc = _Default.IsConstant(); + rc = await _Default.IsConstant(); if (!rc) return false; if (_Left != null) - rc = _Left.IsConstant(); + rc = await _Left.IsConstant(); if (!rc) return false; if (_Right != null) - rc = _Right.IsConstant(); + rc = await _Right.IsConstant(); if (!rc) return false; if (_Top != null) - rc = _Top.IsConstant(); + rc = await _Top.IsConstant(); if (!rc) return false; if (_Bottom != null) - rc = _Bottom.IsConstant(); + rc = await _Bottom.IsConstant(); return rc; } @@ -170,12 +172,12 @@ internal Expression Default set { _Default = value; } } - internal Drawing.Color EvalDefault(Report rpt, Row r) + internal async Task EvalDefault(Report rpt, Row r) { if (_Default == null) return Drawing.Color.Black; - string c = _Default.EvaluateString(rpt, r); + string c = await _Default.EvaluateString(rpt, r); return XmlUtil.ColorFromHtml(c, Drawing.Color.Black, rpt); } @@ -185,12 +187,12 @@ internal Expression Left set { _Left = value; } } - internal Drawing.Color EvalLeft(Report rpt, Row r) + internal async Task EvalLeft(Report rpt, Row r) { if (_Left == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string c = _Left.EvaluateString(rpt, r); + string c = await _Left.EvaluateString(rpt, r); return XmlUtil.ColorFromHtml(c, Drawing.Color.Black, rpt); } @@ -200,12 +202,12 @@ internal Expression Right set { _Right = value; } } - internal Drawing.Color EvalRight(Report rpt, Row r) + internal async Task EvalRight(Report rpt, Row r) { if (_Right == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string c = _Right.EvaluateString(rpt, r); + string c = await _Right.EvaluateString(rpt, r); return XmlUtil.ColorFromHtml(c, Drawing.Color.Black, rpt); } @@ -215,12 +217,12 @@ internal Expression Top set { _Top = value; } } - internal Drawing.Color EvalTop(Report rpt, Row r) + internal async Task EvalTop(Report rpt, Row r) { if (_Top == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string c = _Top.EvaluateString(rpt, r); + string c = await _Top.EvaluateString(rpt, r); return XmlUtil.ColorFromHtml(c, Drawing.Color.Black, rpt); } @@ -230,12 +232,12 @@ internal Expression Bottom set { _Bottom = value; } } - internal Drawing.Color EvalBottom(Report rpt, Row r) + internal async Task EvalBottom(Report rpt, Row r) { if (_Bottom == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string c = _Bottom.EvaluateString(rpt, r); + string c = await _Bottom.EvaluateString(rpt, r); return XmlUtil.ColorFromHtml(c, Drawing.Color.Black, rpt); } } diff --git a/RdlEngine/Definition/StyleBorderStyle.cs b/RdlEngine/Definition/StyleBorderStyle.cs index 590ca9d5..2022e62a 100644 --- a/RdlEngine/Definition/StyleBorderStyle.cs +++ b/RdlEngine/Definition/StyleBorderStyle.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.Text; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -79,18 +80,18 @@ internal StyleBorderStyle(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Default != null) - _Default.FinalPass(); + await _Default.FinalPass(); if (_Left != null) - _Left.FinalPass(); + await _Left.FinalPass(); if (_Right != null) - _Right.FinalPass(); + await _Right.FinalPass(); if (_Top != null) - _Top.FinalPass(); + await _Top.FinalPass(); if (_Bottom != null) - _Bottom.FinalPass(); + await _Bottom.FinalPass(); return; } @@ -119,36 +120,36 @@ internal string GetCSS(Report rpt, Row row, bool bDefaults) return sb.ToString(); } - internal bool IsConstant() + internal async Task IsConstant() { bool rc = true; if (_Default != null) - rc = _Default.IsConstant(); + rc = await _Default.IsConstant(); if (!rc) return false; if (_Left != null) - rc = _Left.IsConstant(); + rc = await _Left.IsConstant(); if (!rc) return false; if (_Right != null) - rc = _Right.IsConstant(); + rc = await _Right.IsConstant(); if (!rc) return false; if (_Top != null) - rc = _Top.IsConstant(); + rc = await _Top.IsConstant(); if (!rc) return false; if (_Bottom != null) - rc = _Bottom.IsConstant(); + rc = await _Bottom.IsConstant(); return rc; } @@ -164,12 +165,12 @@ internal Expression Default set { _Default = value; } } - internal BorderStyleEnum EvalDefault(Report rpt, Row r) + internal async Task EvalDefault(Report rpt, Row r) { if (_Default == null) return BorderStyleEnum.None; - string bs = _Default.EvaluateString(rpt, r); + string bs = await _Default.EvaluateString(rpt, r); return GetBorderStyle(bs, BorderStyleEnum.Solid); } @@ -179,12 +180,12 @@ internal Expression Left set { _Left = value; } } - internal BorderStyleEnum EvalLeft(Report rpt, Row r) + internal async Task EvalLeft(Report rpt, Row r) { if (_Left == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string bs = _Left.EvaluateString(rpt, r); + string bs = await _Left.EvaluateString(rpt, r); return GetBorderStyle(bs, BorderStyleEnum.Solid); } @@ -194,12 +195,12 @@ internal Expression Right set { _Right = value; } } - internal BorderStyleEnum EvalRight(Report rpt, Row r) + internal async Task EvalRight(Report rpt, Row r) { if (_Right == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string bs = _Right.EvaluateString(rpt, r); + string bs = await _Right.EvaluateString(rpt, r); return GetBorderStyle(bs, BorderStyleEnum.Solid); } @@ -209,12 +210,12 @@ internal Expression Top set { _Top = value; } } - internal BorderStyleEnum EvalTop(Report rpt, Row r) + internal async Task EvalTop(Report rpt, Row r) { if (_Top == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string bs = _Top.EvaluateString(rpt, r); + string bs = await _Top.EvaluateString(rpt, r); return GetBorderStyle(bs, BorderStyleEnum.Solid); } @@ -224,12 +225,12 @@ internal Expression Bottom set { _Bottom = value; } } - internal BorderStyleEnum EvalBottom(Report rpt, Row r) + internal async Task EvalBottom(Report rpt, Row r) { if (_Bottom == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string bs = _Bottom.EvaluateString(rpt, r); + string bs = await _Bottom.EvaluateString(rpt, r); return GetBorderStyle(bs, BorderStyleEnum.Solid); } diff --git a/RdlEngine/Definition/StyleBorderWidth.cs b/RdlEngine/Definition/StyleBorderWidth.cs index 0799d4dc..4510c9d4 100644 --- a/RdlEngine/Definition/StyleBorderWidth.cs +++ b/RdlEngine/Definition/StyleBorderWidth.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.Text; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -77,18 +78,18 @@ internal StyleBorderWidth(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Default != null) - _Default.FinalPass(); + await _Default.FinalPass(); if (_Left != null) - _Left.FinalPass(); + await _Left.FinalPass(); if (_Right != null) - _Right.FinalPass(); + await _Right.FinalPass(); if (_Top != null) - _Top.FinalPass(); + await _Top.FinalPass(); if (_Bottom != null) - _Bottom.FinalPass(); + await _Bottom.FinalPass(); return; } @@ -117,36 +118,36 @@ internal string GetCSS(Report rpt, Row row, bool bDefaults) return sb.ToString(); } - internal bool IsConstant() + internal async Task IsConstant() { bool rc = true; if (_Default != null) - rc = _Default.IsConstant(); + rc = await _Default.IsConstant(); if (!rc) return false; if (_Left != null) - rc = _Left.IsConstant(); + rc = await _Left.IsConstant(); if (!rc) return false; if (_Right != null) - rc = _Right.IsConstant(); + rc = await _Right.IsConstant(); if (!rc) return false; if (_Top != null) - rc = _Top.IsConstant(); + rc = await _Top.IsConstant(); if (!rc) return false; if (_Bottom != null) - rc = _Bottom.IsConstant(); + rc = await _Bottom.IsConstant(); return rc; } @@ -162,13 +163,13 @@ internal Expression Default set { _Default = value; } } - internal float EvalDefault(Report rpt, Row r) // return points + internal async Task EvalDefault(Report rpt, Row r) // return points { if (_Default == null) return 1; string sw; - sw = _Default.EvaluateString(rpt, r); + sw = await _Default.EvaluateString(rpt, r); RSize rs = new RSize(this.OwnerReport, sw); return rs.Points; @@ -180,12 +181,12 @@ internal Expression Left set { _Left = value; } } - internal float EvalLeft(Report rpt, Row r) // return points + internal async Task EvalLeft(Report rpt, Row r) // return points { if (_Left == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string sw = _Left.EvaluateString(rpt, r); + string sw = await _Left.EvaluateString(rpt, r); RSize rs = new RSize(this.OwnerReport, sw); return rs.Points; } @@ -196,12 +197,12 @@ internal Expression Right set { _Right = value; } } - internal float EvalRight(Report rpt, Row r) // return points + internal async Task EvalRight(Report rpt, Row r) // return points { if (_Right == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string sw = _Right.EvaluateString(rpt, r); + string sw = await _Right.EvaluateString(rpt, r); RSize rs = new RSize(this.OwnerReport, sw); return rs.Points; } @@ -212,12 +213,12 @@ internal Expression Top set { _Top = value; } } - internal float EvalTop(Report rpt, Row r) // return points + internal async Task EvalTop(Report rpt, Row r) // return points { if (_Top == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string sw = _Top.EvaluateString(rpt, r); + string sw = await _Top.EvaluateString(rpt, r); RSize rs = new RSize(this.OwnerReport, sw); return rs.Points; } @@ -228,12 +229,12 @@ internal Expression Bottom set { _Bottom = value; } } - internal float EvalBottom(Report rpt, Row r) // return points + internal async Task EvalBottom(Report rpt, Row r) // return points { if (_Bottom == null) - return EvalDefault(rpt, r); + return await EvalDefault(rpt, r); - string sw = _Bottom.EvaluateString(rpt, r); + string sw = await _Bottom.EvaluateString(rpt, r); RSize rs = new RSize(this.OwnerReport, sw); return rs.Points; } diff --git a/RdlEngine/Definition/Subreport.cs b/RdlEngine/Definition/Subreport.cs index 489455d5..b62ec3b6 100644 --- a/RdlEngine/Definition/Subreport.cs +++ b/RdlEngine/Definition/Subreport.cs @@ -106,29 +106,29 @@ internal Subreport(ReportDefn r, ReportLink p, XmlNode xNode) :base(r, p, xNode) } // Handle parsing of function in final pass - override internal void FinalPass() + override async internal Task FinalPass() { - base.FinalPass(); + await base.FinalPass(); // Subreports aren't allowed in PageHeader or PageFooter; if (this.InPageHeaderOrFooter()) OwnerReport.rl.LogError(8, String.Format("The Subreport '{0}' is not allowed in a PageHeader or PageFooter", this.Name == null? "unknown": Name.Nm) ); if (_Parameters != null) - _Parameters.FinalPass(); + await _Parameters.FinalPass(); if (_NoRows != null) - _NoRows.FinalPass(); + await _NoRows.FinalPass(); - _ReportDefn = GetReport(OwnerReport.ParseFolder); + _ReportDefn = await GetReport(OwnerReport.ParseFolder); if (_ReportDefn != null) // only null in error case (e.g. subreport not found) _ReportDefn.Subreport = this; return; } - async override internal Task RunAsync(IPresent ip, Row row) + async override internal Task Run(IPresent ip, Row row) { Report r = ip.Report(); - base.Run(ip, row); + await base.Run(ip, row); // need to save the owner report and nest in this defintion ReportDefn saveReport = r.ReportDefinition; @@ -160,25 +160,19 @@ async override internal Task RunAsync(IPresent ip, Row row) await r.RunGetData(null); } - ip.Subreport(this, row); + await ip.Subreport(this, row); r.SetReportDefinition(saveReport); // restore the current report r.ParentConnections = saveDS; // restore the data connnections } - internal override void RunPage(Pages pgs, Row row) - { - // HACK: - Task.Run(async () => await RunPageAsync(pgs, row)).GetAwaiter().GetResult(); - } - - async override internal Task RunPageAsync(Pages pgs, Row row) + async override internal Task RunPage(Pages pgs, Row row) { Report r = pgs.Report; - if (IsHidden(r, row)) + if (await IsHidden(r, row)) return; - await base.RunPageAsync(pgs, row); + await base.RunPage(pgs, row); // need to save the owner report and nest in this defintion ReportDefn saveReport = r.ReportDefinition; @@ -227,21 +221,21 @@ async override internal Task RunPageAsync(Pages pgs, Row row) // // Run the subreport -- this is the major effort in creating the display objects in the page // - r.ReportDefinition.Body.RunPage(pgs); // create a the subreport items + await r.ReportDefinition.Body.RunPage(pgs); // create a the subreport items yOffset = pgs.CurrentPage.YOffset; } else { // Handle NoRows message string msg; if (this.NoRows != null) - msg = this.NoRows.EvaluateString(pgs.Report, null); + msg = await this.NoRows.EvaluateString(pgs.Report, null); else msg = null; if (msg != null) { PageText pt = new PageText(msg); - SetPagePositionAndStyle(pgs.Report, pt, null); + await SetPagePositionAndStyle(pgs.Report, pt, null); if (pt.SI.BackgroundImage != null) pt.SI.BackgroundImage.H = pt.H; // and in the background image @@ -270,7 +264,7 @@ internal override void RemoveWC(Report rpt) _ReportDefn.Body.RemoveWC(rpt); } - private ReportDefn GetReport(string folder) + private async Task GetReport(string folder) { string prog; string name; @@ -299,7 +293,7 @@ private ReportDefn GetReport(string folder) rdlp.OverwriteInSubreport = OwnerReport.OverwriteInSubreport; } - r = rdlp.Parse(OwnerReport.GetObjectNumber()); + r = await rdlp.Parse(OwnerReport.GetObjectNumber()); OwnerReport.SetObjectNumber(r.ReportDefinition.GetObjectNumber()); if (r.ErrorMaxSeverity > 0) { diff --git a/RdlEngine/Definition/SubreportParameter.cs b/RdlEngine/Definition/SubreportParameter.cs index e489d355..461855a6 100644 --- a/RdlEngine/Definition/SubreportParameter.cs +++ b/RdlEngine/Definition/SubreportParameter.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -80,10 +81,10 @@ internal SubreportParameter(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Value != null) - _Value.FinalPass(); + await _Value.FinalPass(); return; } @@ -99,12 +100,12 @@ internal Expression Value set { _Value = value; } } - internal string ValueValue(Report rpt, Row r) + internal async Task ValueValue(Report rpt, Row r) { if (_Value == null) return ""; - return _Value.EvaluateString(rpt, r); + return await _Value.EvaluateString(rpt, r); } } } diff --git a/RdlEngine/Definition/SubreportParameters.cs b/RdlEngine/Definition/SubreportParameters.cs index 57f4c61f..4c3b38b1 100644 --- a/RdlEngine/Definition/SubreportParameters.cs +++ b/RdlEngine/Definition/SubreportParameters.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -62,11 +63,11 @@ internal SubReportParameters(ReportDefn r, ReportLink p, XmlNode xNode) : base(r _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (SubreportParameter rp in _Items) { - rp.FinalPass(); + await rp.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Subtotal.cs b/RdlEngine/Definition/Subtotal.cs index 8cf515af..eb72a55f 100644 --- a/RdlEngine/Definition/Subtotal.cs +++ b/RdlEngine/Definition/Subtotal.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -90,12 +91,12 @@ internal Subtotal(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "Subtotal requires the ReportItems element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_ReportItems != null) - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } diff --git a/RdlEngine/Definition/Table.cs b/RdlEngine/Definition/Table.cs index d01aa698..065b452f 100644 --- a/RdlEngine/Definition/Table.cs +++ b/RdlEngine/Definition/Table.cs @@ -28,6 +28,7 @@ the website www.fyiReporting.com. using System.Globalization; using System.Diagnostics; using RdlEngine.Resources; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -170,31 +171,31 @@ private void VerifyCCTableRows(string label, TableRows trs, int colCount) return; } - override internal void FinalPass() + async override internal Task FinalPass() { - base.FinalPass(); + await base.FinalPass(); float totalHeight=0; if (_TableColumns != null) - _TableColumns.FinalPass(); + await _TableColumns.FinalPass(); if (_Header != null) { - _Header.FinalPass(); + await _Header.FinalPass(); totalHeight += _Header.TableRows.DefnHeight(); } if (_TableGroups != null) { - _TableGroups.FinalPass(); + await _TableGroups.FinalPass(); totalHeight += _TableGroups.DefnHeight(); } if (_Details != null) { - _Details.FinalPass(); + await _Details.FinalPass(); totalHeight += _Details.TableRows.DefnHeight(); } if (_Footer != null) { - _Footer.FinalPass(); + await _Footer.FinalPass(); totalHeight += _Footer.TableRows.DefnHeight(); } @@ -206,7 +207,7 @@ override internal void FinalPass() return; } - override internal void Run(IPresent ip, Row row) + async override internal Task Run(IPresent ip, Row row) { Report r = ip.Report(); TableWorkClass wc = GetValue(r); @@ -214,14 +215,14 @@ override internal void Run(IPresent ip, Row row) if (_IsGrid) wc.Data = Rows.CreateOneRow(r); else - wc.Data = GetFilteredData(r, row); + wc.Data = await GetFilteredData(r, row); - if (!AnyRows(ip, wc.Data)) // if no rows return + if (!await AnyRows(ip, wc.Data)) // if no rows return return; // nothing left to do RunPrep(r, row, wc); - if (!ip.TableStart(this, row)) + if (!await ip.TableStart(this, row)) return; // render doesn't want to continue if (_TableColumns != null) @@ -232,16 +233,16 @@ override internal void Run(IPresent ip, Row row) { ip.TableHeaderStart(_Header, row); Row frow = wc.Data.Data.Count > 0? wc.Data.Data[0]: null; - _Header.Run(ip, frow); + await _Header.Run(ip, frow); ip.TableHeaderEnd(_Header, row); } // Body ip.TableBodyStart(this, row); if (wc.RecursiveGroup != null) - RunRecursiveGroups(ip, wc); + await RunRecursiveGroups(ip, wc); else - RunGroups(ip, wc.Groups, wc); + await RunGroups(ip, wc.Groups, wc); ip.TableBodyEnd(this, row); // Footer @@ -249,29 +250,31 @@ override internal void Run(IPresent ip, Row row) { ip.TableFooterStart(_Footer, row); Row lrow = wc.Data.Data.Count > 0? wc.Data.Data[wc.Data.Data.Count-1]: null; - _Footer.Run(ip, lrow); + await _Footer.Run(ip, lrow); ip.TableFooterEnd(_Footer, row); } - ip.TableEnd(this, row); + await ip.TableEnd(this, row); RemoveValue(r); + + return; } - override internal void RunPage(Pages pgs, Row row) + async override internal Task RunPage(Pages pgs, Row row) { Report r = pgs.Report; - if (IsHidden(r, row)) + if (await IsHidden(r, row)) return; TableWorkClass wc = GetValue(r); if (_IsGrid) wc.Data = Rows.CreateOneRow(r); else - wc.Data = GetFilteredData(r, row); + wc.Data = await GetFilteredData(r, row); SetPagePositionBegin(pgs); - if (!AnyRowsPage(pgs, wc.Data)) // if no rows return + if (!await AnyRowsPage(pgs, wc.Data)) // if no rows return return; // nothing left to do RunPrep(r, row, wc); @@ -281,21 +284,21 @@ override internal void RunPage(Pages pgs, Row row) Page p = pgs.CurrentPage; p.YOffset += this.RelativeY(r); - // Calculate the xpositions of the columns - TableColumns.CalculateXPositions(r, GetOffsetCalc(r) + LeftCalc(r), row); + // Calculate the xpositions of the columns + await TableColumns.CalculateXPositions(r, GetOffsetCalc(r) + LeftCalc(r), row); - RunPageHeader(pgs, wc.Data.Data[0], true, null); + await RunPageHeader(pgs, wc.Data.Data[0], true, null); if (wc.RecursiveGroup != null) { - RunRecursiveGroupsPage(pgs, wc); + await RunRecursiveGroupsPage(pgs, wc); } else { float groupHeight = 0; if (wc.Data.Data.Count > 0 && _Footer != null) - groupHeight = _Footer.HeightOfRows(pgs, wc.Data.Data[0]); - RunGroupsPage(pgs, wc, wc.Groups, wc.Data.Data.Count - 1, groupHeight); + groupHeight = await _Footer.HeightOfRows(pgs, wc.Data.Data[0]); + await RunGroupsPage(pgs, wc, wc.Groups, wc.Data.Data.Count - 1, groupHeight); } // Footer @@ -303,7 +306,7 @@ override internal void RunPage(Pages pgs, Row row) { // Row == null means the inital/last page Row lRow = wc.Data.Data.Count > 0 ? wc.Data.Data[wc.Data.Data.Count - 1] : null; - RunPageFooter(pgs, lRow, true); + await RunPageFooter(pgs, lRow, true); } // dst, use the code above @@ -324,44 +327,45 @@ override internal void RunPage(Pages pgs, Row row) SetPagePositionEnd(pgs, pgs.CurrentPage.YOffset); RemoveValue(r); + return; } internal bool IsGrid { get { return _IsGrid; } } - internal void RunPageFooter(Pages pgs, Row row, bool bLast) + internal async Task RunPageFooter(Pages pgs, Row row, bool bLast) { if (_Footer != null && (_Footer.RepeatOnNewPage || bLast)) { Page p = pgs.CurrentPage; - if (p.YOffset + _Footer.HeightOfRows(pgs, row) > pgs.BottomOfPage) + if (p.YOffset + await _Footer.HeightOfRows(pgs, row) > pgs.BottomOfPage) { p = RunPageNew(pgs, p); - RunPageHeader(pgs, row, false, null); + await RunPageHeader(pgs, row, false, null); } - _Footer.RunPage(pgs, row); + await _Footer.RunPage(pgs, row); } } - internal float GetPageFooterHeight(Pages pgs, Row row) + internal async Task GetPageFooterHeight(Pages pgs, Row row) { // Calculate height of footer on every page float FooterHeight = 0; if (Footer != null && Footer.RepeatOnNewPage) - FooterHeight += Footer.HeightOfRows(pgs, row); + FooterHeight += await Footer.HeightOfRows(pgs, row); // Need add calculation for group footer which show on every page return FooterHeight; } - internal void RunPageHeader(Pages pgs, Row frow, bool bFirst, TableGroup stoptg) + internal async Task RunPageHeader(Pages pgs, Row frow, bool bFirst, TableGroup stoptg) { // Do the table headers bool isEmpty = pgs.CurrentPage.IsEmpty(); if (_Header != null && (_Header.RepeatOnNewPage || bFirst)) { - _Header.RunPage(pgs, frow); + await _Header.RunPage(pgs, frow); if (isEmpty) pgs.CurrentPage.SetEmpty(); // Consider this empty of data } @@ -384,7 +388,7 @@ internal void RunPageHeader(Pages pgs, Row frow, bool bFirst, TableGroup stoptg) { if (tg.Header.RepeatOnNewPage) { - tg.Header.RunPage(pgs, frow); + await tg.Header.RunPage(pgs, frow); } } } @@ -722,7 +726,7 @@ private void PrepRecursiveGroup(Report rpt, TableWorkClass wc) return; } - private void RunGroups(IPresent ip, List groupEntries, TableWorkClass wc) + private async Task RunGroups(IPresent ip, List groupEntries, TableWorkClass wc) { Report rpt = ip.Report(); GroupEntry fge = (GroupEntry) (groupEntries[0]); @@ -757,23 +761,23 @@ private void RunGroups(IPresent ip, List groupEntries, TableWorkClas wc.GroupNestCount = RunGroupsCount(ge.NestedGroup, 0); else wc.GroupNestCount = (ge.EndRow - ge.StartRow + 1) * DetailsCount; - tg.Header.Run(ip, wc.Data.Data[ge.StartRow]); + await tg.Header.Run(ip, wc.Data.Data[ge.StartRow]); wc.GroupNestCount = 0; } } // Handle the nested groups if any if (ge.NestedGroup.Count > 0) - RunGroups(ip, ge.NestedGroup, wc); + await RunGroups(ip, ge.NestedGroup, wc); // If no nested groups then handle the detail rows for the group else if (_Details != null) { if (ge.Group != null && ge.Group.Parent as TableGroup == null) - { // Group defined on table; means that Detail rows only put out once per group - _Details.Run(ip, wc.Data, ge.StartRow, ge.StartRow); + { // Group defined on table; means that Detail rows only put out once per group + await _Details.Run(ip, wc.Data, ge.StartRow, ge.StartRow); } else - _Details.Run(ip, wc.Data, ge.StartRow, ge.EndRow); + await _Details.Run(ip, wc.Data, ge.StartRow, ge.EndRow); } // Do the group footer @@ -783,7 +787,7 @@ private void RunGroups(IPresent ip, List groupEntries, TableWorkClas { TableGroup tg = ge.Group.Parent as TableGroup; // detail groups will result in null if (tg != null && tg.Footer != null) - tg.Footer.Run(ip, wc.Data.Data[ge.EndRow]); + await tg.Footer.Run(ip, wc.Data.Data[ge.EndRow]); } ip.GroupingInstanceEnd(ge.Group); } @@ -792,7 +796,7 @@ private void RunGroups(IPresent ip, List groupEntries, TableWorkClas ip.GroupingEnd(fge.Group); } - private void RunGroupsPage(Pages pgs, TableWorkClass wc, List groupEntries, int endRow, float groupHeight) + private async Task RunGroupsPage(Pages pgs, TableWorkClass wc, List groupEntries, int endRow, float groupHeight) { Report rpt = pgs.Report; foreach (GroupEntry ge in groupEntries) @@ -817,10 +821,10 @@ private void RunGroupsPage(Pages pgs, TableWorkClass wc, List groupE TableGroup tg = ge.Group.Parent as TableGroup; // if (ge.Group.PageBreakAtStart && !pgs.CurrentPage.IsEmpty()) // Add check PageBreakCondition not only PageBreakAtStart - if (ge.Group.PageBreakAtStart && ge.Group.PageBreakCondition(rpt, wc.Data.Data[ge.StartRow], ge.Group.PageBreakAtStart) && !pgs.CurrentPage.IsEmpty()) + if (ge.Group.PageBreakAtStart && await ge.Group.PageBreakCondition(rpt, wc.Data.Data[ge.StartRow], ge.Group.PageBreakAtStart) && !pgs.CurrentPage.IsEmpty()) { RunPageNew(pgs, pgs.CurrentPage); - RunPageHeader(pgs, wc.Data.Data[ge.StartRow], false, tg); + await RunPageHeader(pgs, wc.Data.Data[ge.StartRow], false, tg); } if (tg != null && tg.Header != null) @@ -831,11 +835,11 @@ private void RunGroupsPage(Pages pgs, TableWorkClass wc, List groupE else wc.GroupNestCount = (ge.EndRow - ge.StartRow + 1) * DetailsCount; - tg.Header.RunPage(pgs, wc.Data.Data[ge.StartRow]); + await tg.Header.RunPage(pgs, wc.Data.Data[ge.StartRow]); wc.GroupNestCount = 0; } } - float footerHeight = RunGroupsFooterHeight(pgs, wc, ge); + float footerHeight = await RunGroupsFooterHeight(pgs, wc, ge); if (ge.EndRow == endRow && ( Footer != null ? !Footer.RepeatOnNewPage: true)) @@ -845,18 +849,18 @@ private void RunGroupsPage(Pages pgs, TableWorkClass wc, List groupE // Handle the nested groups if any if (ge.NestedGroup.Count > 0) - RunGroupsPage(pgs, wc, ge.NestedGroup, ge.EndRow, footerHeight); + await RunGroupsPage(pgs, wc, ge.NestedGroup, ge.EndRow, footerHeight); // If no nested groups then handle the detail rows for the group else if (_Details != null) { if (ge.Group != null && ge.Group.Parent as TableGroup == null) - { // Group defined on table; means that Detail rows only put out once per group - _Details.RunPage(pgs, wc.Data, ge.StartRow, ge.StartRow, footerHeight); + { // Group defined on table; means that Detail rows only put out once per group + await _Details.RunPage(pgs, wc.Data, ge.StartRow, ge.StartRow, footerHeight); } else { - _Details.RunPage(pgs, wc.Data, ge.StartRow, ge.EndRow, footerHeight); + await _Details.RunPage(pgs, wc.Data, ge.StartRow, ge.EndRow, footerHeight); } } else // When no details we need to figure out whether any more fits on a page @@ -865,7 +869,7 @@ private void RunGroupsPage(Pages pgs, TableWorkClass wc, List groupE if (p.YOffset + footerHeight > pgs.BottomOfPage) // Do we need new page to fit footer? { p = RunPageNew(pgs, p); - RunPageHeader(pgs, wc.Data.Data[ge.EndRow], false, null); + await RunPageHeader(pgs, wc.Data.Data[ge.EndRow], false, null); } } @@ -874,19 +878,19 @@ private void RunGroupsPage(Pages pgs, TableWorkClass wc, List groupE { TableGroup tg = ge.Group.Parent as TableGroup; // detail groups will result in null if (tg != null && tg.Footer != null) - tg.Footer.RunPage(pgs, wc.Data.Data[ge.EndRow]); + await tg.Footer.RunPage(pgs, wc.Data.Data[ge.EndRow]); if (ge.Group.PageBreakAtEnd && !pgs.CurrentPage.IsEmpty()) { RunPageNew(pgs, pgs.CurrentPage); - RunPageHeader(pgs, wc.Data.Data[ge.StartRow], false, tg); + await RunPageHeader(pgs, wc.Data.Data[ge.StartRow], false, tg); } } } } - private float RunGroupsFooterHeight(Pages pgs, TableWorkClass wc, GroupEntry ge) + private async Task RunGroupsFooterHeight(Pages pgs, TableWorkClass wc, GroupEntry ge) { Grouping g = ge.Group; if (g == null) @@ -896,7 +900,7 @@ private float RunGroupsFooterHeight(Pages pgs, TableWorkClass wc, GroupEntry ge) if (tg == null || tg.Footer == null) return 0; - return tg.Footer.HeightOfRows(pgs, wc.Data.Data[ge.EndRow]); + return await tg.Footer.HeightOfRows(pgs, wc.Data.Data[ge.EndRow]); } private int RunGroupsCount(List groupEntries, int count) @@ -928,7 +932,7 @@ internal void RunGroupsSetGroups(Report rpt, TableWorkClass wc, List RunGroupsSetGroups(rpt, wc, ge.NestedGroup); } - private void RunRecursiveGroups(IPresent ip, TableWorkClass wc) + private async Task RunRecursiveGroups(IPresent ip, TableWorkClass wc) { List rows=wc.Data.Data; Row r; @@ -953,12 +957,12 @@ private void RunRecursiveGroups(IPresent ip, TableWorkClass wc) { bHeader = false; if (header != null) - header.Run(ip, r); + await header.Run(ip, r); } if (_Details != null) { - _Details.Run(ip, wc.Data, iRow, iRow); + await _Details.Run(ip, wc.Data, iRow, iRow); } // determine need for group headers and/or footers @@ -968,17 +972,17 @@ private void RunRecursiveGroups(IPresent ip, TableWorkClass wc) if (r.Level > r2.Level) { if (footer != null) - footer.Run(ip, r); + await footer.Run(ip, r); } else if (r.Level < r2.Level) bHeader = true; } } if (footer != null) - footer.Run(ip, rows[rows.Count-1] as Row); + await footer.Run(ip, rows[rows.Count-1] as Row); } - private void RunRecursiveGroupsPage(Pages pgs, TableWorkClass wc) + private async Task RunRecursiveGroupsPage(Pages pgs, TableWorkClass wc) { List rows=wc.Data.Data; Row r; @@ -1005,16 +1009,16 @@ private void RunRecursiveGroupsPage(Pages pgs, TableWorkClass wc) if (header != null) { Page p = pgs.CurrentPage; // this can change after running a row - float height = p.YOffset + header.HeightOfRows(pgs, r); + float height = p.YOffset + await header.HeightOfRows(pgs, r); if (height > pgs.BottomOfPage) { p = RunPageNew(pgs, p); - RunPageHeader(pgs, r, false, null); + await RunPageHeader(pgs, r, false, null); if (!header.RepeatOnNewPage) - header.RunPage(pgs, r); + await header.RunPage(pgs, r); } else - header.RunPage(pgs, r); + await header.RunPage(pgs, r); } } @@ -1030,7 +1034,7 @@ private void RunRecursiveGroupsPage(Pages pgs, TableWorkClass wc) if (footer != null) { bFooter = true; - footerHeight = footer.HeightOfRows(pgs, r); + footerHeight = await footer.HeightOfRows(pgs, r); } } else if (r.Level < r2.Level) @@ -1039,15 +1043,15 @@ private void RunRecursiveGroupsPage(Pages pgs, TableWorkClass wc) if (_Details != null) { - _Details.RunPage(pgs, wc.Data, iRow, iRow, footerHeight); + await _Details.RunPage(pgs, wc.Data, iRow, iRow, footerHeight); } // and output the footer if needed if (bFooter) - footer.RunPage(pgs, r); + await footer.RunPage(pgs, r); } if (footer != null) - footer.RunPage(pgs, rows[rows.Count-1] as Row); + await footer.RunPage(pgs, rows[rows.Count-1] as Row); } internal TableColumns TableColumns @@ -1126,13 +1130,13 @@ internal int GetGroupNestCount(Report rpt) return wc.GroupNestCount; } - internal int WidthInPixels(Report rpt, Row row) + internal async Task WidthInPixels(Report rpt, Row row) { // Calculate this based on the sum of TableColumns int width=0; foreach (TableColumn tc in this.TableColumns.Items) { - if (tc.Visibility == null || !tc.Visibility.Hidden.EvaluateBoolean(rpt, row)) + if (tc.Visibility == null || !await tc.Visibility.Hidden.EvaluateBoolean(rpt, row)) width += tc.Width.PixelsX; } return width; diff --git a/RdlEngine/Definition/TableCell.cs b/RdlEngine/Definition/TableCell.cs index ba8d252c..178ac7c2 100644 --- a/RdlEngine/Definition/TableCell.cs +++ b/RdlEngine/Definition/TableCell.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -106,39 +107,39 @@ internal TableCell(ReportDefn r, ReportLink p, XmlNode xNode, int colIndex) : ba return; } - override internal void FinalPass() + async override internal Task FinalPass() { - _ReportItems.FinalPass(); + await _ReportItems.FinalPass(); return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { // todo: visibility on the column should really only be evaluated once at the beginning // of the table processing; also this doesn't account for the affect of colspan correctly // where if any of the spanned columns are visible the value would show?? TableColumn tc = _OwnerTable.TableColumns[_ColIndex]; - if (tc.Visibility != null && tc.Visibility.IsHidden(ip.Report(), row)) // column visible? + if (tc.Visibility != null && await tc.Visibility.IsHidden(ip.Report(), row)) // column visible? return; // no nothing to do ip.TableCellStart(this, row); - - _ReportItems.Items[0].Run(ip, row); + + await _ReportItems.Items[0].Run(ip, row); ip.TableCellEnd(this, row); return; } - internal void RunPage(Pages pgs, Row row) + internal async Task RunPage(Pages pgs, Row row) { // todo: visibility on the column should really only be evaluated once at the beginning // of the table processing; also this doesn't account for the affect of colspan correctly // where if any of the spanned columns are visible the value would show?? TableColumn tc = _OwnerTable.TableColumns[_ColIndex]; - if (tc.Visibility != null && tc.Visibility.IsHidden(pgs.Report, row)) // column visible? - return; // no nothing to do + if (tc.Visibility != null && await tc.Visibility.IsHidden(pgs.Report, row)) // column visible? + return; // no nothing to do - _ReportItems.Items[0].RunPage(pgs, row); + await _ReportItems.Items[0].RunPage(pgs, row); return; } diff --git a/RdlEngine/Definition/TableCells.cs b/RdlEngine/Definition/TableCells.cs index dbeb2615..fc6a701c 100644 --- a/RdlEngine/Definition/TableCells.cs +++ b/RdlEngine/Definition/TableCells.cs @@ -25,6 +25,7 @@ the website www.fyiReporting.com. using System.Collections.Generic; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -65,25 +66,25 @@ internal TableCells(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (TableCell tc in _Items) { - tc.FinalPass(); + await tc.FinalPass(); } return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { foreach (TableCell tc in _Items) { - tc.Run(ip, row); + await tc.Run(ip, row); } return ; } - internal void RunPage(Pages pgs, Row row) + internal async Task RunPage(Pages pgs, Row row) { // Start each row in the same location // e.g. if there are two embedded tables in cells they both start at same location @@ -94,7 +95,7 @@ internal void RunPage(Pages pgs, Row row) foreach (TableCell tc in _Items) { - tc.RunPage(pgs, row); + await tc.RunPage(pgs, row); if (maxpg != pgs.CurrentPage) { // a page break if (maxpg.PageNumber < pgs.CurrentPage.PageNumber) diff --git a/RdlEngine/Definition/TableColumn.cs b/RdlEngine/Definition/TableColumn.cs index 9ba6e44d..7d4afa44 100644 --- a/RdlEngine/Definition/TableColumn.cs +++ b/RdlEngine/Definition/TableColumn.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -68,10 +69,10 @@ internal TableColumn(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "TableColumn requires the Width element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Visibility != null) - _Visibility.FinalPass(); + await _Visibility.FinalPass(); return; } @@ -103,11 +104,11 @@ internal Visibility Visibility set { _Visibility = value; } } - internal bool IsHidden(Report rpt, Row r) + internal async Task IsHidden(Report rpt, Row r) { if (_Visibility == null) return false; - return _Visibility.IsHidden(rpt, r); + return await _Visibility.IsHidden(rpt, r); } private WorkClass GetWC(Report rpt) diff --git a/RdlEngine/Definition/TableColumns.cs b/RdlEngine/Definition/TableColumns.cs index a39e92db..ebaf16a8 100644 --- a/RdlEngine/Definition/TableColumns.cs +++ b/RdlEngine/Definition/TableColumns.cs @@ -25,6 +25,7 @@ the website www.fyiReporting.com. using System.Collections.Generic; using System.Xml; using System.IO; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -73,11 +74,11 @@ internal TableColumn this[int ci] } } - override internal void FinalPass() + async override internal Task FinalPass() { foreach (TableColumn tc in _Items) { - tc.FinalPass(); + await tc.FinalPass(); } return; } @@ -92,13 +93,13 @@ internal void Run(IPresent ip, Row row) } // calculate the XPositions of all the columns - internal void CalculateXPositions(Report rpt, float startpos, Row row) + internal async Task CalculateXPositions(Report rpt, float startpos, Row row) { float x = startpos; foreach (TableColumn tc in _Items) { - if (tc.IsHidden(rpt, row)) + if (await tc.IsHidden(rpt, row)) continue; tc.SetXPosition(rpt, x); x += tc.Width.Points; diff --git a/RdlEngine/Definition/TableGroup.cs b/RdlEngine/Definition/TableGroup.cs index 886d525f..96fe2194 100644 --- a/RdlEngine/Definition/TableGroup.cs +++ b/RdlEngine/Definition/TableGroup.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -81,19 +82,19 @@ internal TableGroup(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "TableGroup requires the Grouping element."); } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Grouping != null) - _Grouping.FinalPass(); + await _Grouping.FinalPass(); if (_Sorting != null) - _Sorting.FinalPass(); + await _Sorting.FinalPass(); if (_Header != null) - _Header.FinalPass(); + await _Header.FinalPass(); if (_Footer != null) - _Footer.FinalPass(); + await _Footer.FinalPass(); if (_Visibility != null) { - _Visibility.FinalPass(); + await _Visibility.FinalPass(); if (_Visibility.ToggleItem != null) { _ToggleTextbox = (Textbox) (OwnerReport.LUReportItems[_Visibility.ToggleItem]); diff --git a/RdlEngine/Definition/TableGroups.cs b/RdlEngine/Definition/TableGroups.cs index cb0278af..f1350832 100644 --- a/RdlEngine/Definition/TableGroups.cs +++ b/RdlEngine/Definition/TableGroups.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -64,11 +65,11 @@ internal TableGroups(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { foreach(TableGroup tg in _Items) { - tg.FinalPass(); + await tg.FinalPass(); } return; diff --git a/RdlEngine/Definition/TableRow.cs b/RdlEngine/Definition/TableRow.cs index 446c6828..d1176037 100644 --- a/RdlEngine/Definition/TableRow.cs +++ b/RdlEngine/Definition/TableRow.cs @@ -27,6 +27,8 @@ the website www.fyiReporting.com. using System.Collections; using System.Collections.Generic; using RdlEngine.Resources; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Majorsilence.Drawing; #else @@ -83,11 +85,11 @@ internal TableRow(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) OwnerReport.rl.LogError(8, "TableRow requires the Height element."); } - override internal void FinalPass() + async override internal Task FinalPass() { - _TableCells.FinalPass(); + await _TableCells.FinalPass(); if (_Visibility != null) - _Visibility.FinalPass(); + await _Visibility.FinalPass(); foreach (TableCell tc in _TableCells.Items) { @@ -110,23 +112,23 @@ override internal void FinalPass() return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { - if (this.Visibility != null && Visibility.IsHidden(ip.Report(), row)) + if (this.Visibility != null && await Visibility.IsHidden(ip.Report(), row)) return; - ip.TableRowStart(this, row); - _TableCells.Run(ip, row); + await ip.TableRowStart(this, row); + await _TableCells.Run(ip, row); ip.TableRowEnd(this, row); return ; } - internal void RunPage(Pages pgs, Row row) + internal async Task RunPage(Pages pgs, Row row) { - if (this.Visibility != null && Visibility.IsHidden(pgs.Report, row)) + if (this.Visibility != null && await Visibility.IsHidden(pgs.Report, row)) return; - _TableCells.RunPage(pgs, row); + await _TableCells.RunPage(pgs, row); WorkClass wc = GetWC(pgs.Report); pgs.CurrentPage.YOffset += wc.CalcHeight; @@ -144,14 +146,14 @@ internal RSize Height get { return _Height; } set { _Height = value; } } - internal float HeightOfRow(Pages pgs, Row r) + internal async Task HeightOfRow(Pages pgs, Row r) { - return HeightOfRow(pgs.Report, pgs.G, r); + return await HeightOfRow(pgs.Report, pgs.G, r); } - internal float HeightOfRow(Report rpt, Graphics g, Row r) + internal async Task HeightOfRow(Report rpt, Graphics g, Row r) { WorkClass wc = GetWC(rpt); - if (this.Visibility != null && Visibility.IsHidden(rpt, r)) + if (this.Visibility != null && await Visibility.IsHidden(rpt, r)) { wc.CalcHeight = 0; return 0; @@ -169,9 +171,9 @@ internal float HeightOfRow(Report rpt, Graphics g, Row r) foreach (Textbox tb in this._GrowList) { int ci = tb.TC.ColIndex; - if (tcs[ci].IsHidden(rpt, r)) // if column is hidden don't use in calculation + if (await tcs[ci].IsHidden(rpt, r)) // if column is hidden don't use in calculation continue; - height = Math.Max(height, tb.RunTextCalcHeight(rpt, g, r)); + height = Math.Max(height, await tb.RunTextCalcHeight(rpt, g, r)); } wc.CalcHeight = Math.Max(height, defnHeight); return wc.CalcHeight; diff --git a/RdlEngine/Definition/TableRows.cs b/RdlEngine/Definition/TableRows.cs index 72a3dedd..ce60531c 100644 --- a/RdlEngine/Definition/TableRows.cs +++ b/RdlEngine/Definition/TableRows.cs @@ -26,6 +26,7 @@ the website www.fyiReporting.com. using System.Xml; using System.IO; using RdlEngine.Resources; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -69,54 +70,54 @@ internal TableRows(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) _Items.TrimExcess(); } - override internal void FinalPass() + async override internal Task FinalPass() { _HeightOfRows = 0; foreach (TableRow t in _Items) { _HeightOfRows += t.Height.Points; - t.FinalPass(); + await t.FinalPass(); _CanGrow |= t.CanGrow; } return; } - internal void Run(IPresent ip, Row row) + internal async Task Run(IPresent ip, Row row) { foreach (TableRow t in _Items) { - t.Run(ip, row); + await t.Run(ip, row); } return; } - internal void RunPage(Pages pgs, Row row) + internal async Task RunPage(Pages pgs, Row row) { - RunPage(pgs, row, false); + await RunPage(pgs, row, false); } - internal void RunPage(Pages pgs, Row row, bool bCheckRows) + internal async Task RunPage(Pages pgs, Row row, bool bCheckRows) { if (bCheckRows) { // we need to check to see if a row will fit on the page foreach (TableRow t in _Items) { Page p = pgs.CurrentPage; // this can change after running a row - float hrows = t.HeightOfRow(pgs, row); // height of this row + float hrows = await t.HeightOfRow(pgs, row); // height of this row float height = p.YOffset + hrows; if (height > pgs.BottomOfPage) { p = OwnerTable.RunPageNew(pgs, p); - OwnerTable.RunPageHeader(pgs, row, false, null); + await OwnerTable.RunPageHeader(pgs, row, false, null); } - t.RunPage(pgs, row); + await t.RunPage(pgs, row); } } else { // all rows will fit on the page foreach (TableRow t in _Items) - t.RunPage(pgs, row); + await t.RunPage(pgs, row); } return; } @@ -145,7 +146,7 @@ internal float DefnHeight() return height; } - internal float HeightOfRows(Pages pgs, Row r) + internal async Task HeightOfRows(Pages pgs, Row r) { if (!this._CanGrow) return _HeightOfRows; @@ -153,7 +154,7 @@ internal float HeightOfRows(Pages pgs, Row r) float height=0; foreach (TableRow tr in this._Items) { - height += tr.HeightOfRow(pgs, r); + height += await tr.HeightOfRow(pgs, r); } return Math.Max(height, _HeightOfRows); diff --git a/RdlEngine/Definition/Textbox.cs b/RdlEngine/Definition/Textbox.cs index b22253dc..0d6b9392 100644 --- a/RdlEngine/Definition/Textbox.cs +++ b/RdlEngine/Definition/Textbox.cs @@ -33,6 +33,7 @@ the website www.fyiReporting.com. using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -143,10 +144,10 @@ internal Textbox(ReportDefn r, ReportLink p, XmlNode xNode):base(r,p,xNode) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { - base.FinalPass(); - _Value.FinalPass(); + await base.FinalPass(); + await _Value.FinalPass(); //The Changes below were added from Forum, User: solidstate http://www.fyireporting.com/forum/viewtopic.php?t=905 if (this.DataElementName == null && this.Name == null) @@ -172,7 +173,7 @@ override internal void FinalPass() } if (_ToggleImage != null) - _ToggleImage.FinalPass(); + await _ToggleImage.FinalPass(); if (_HideDuplicates != null) { @@ -225,15 +226,15 @@ void ResetPrevious(TextboxRuntime tbr) tbr.PreviousPage=null; } - override internal void Run(IPresent ip, Row row) + async override internal Task Run(IPresent ip, Row row) { Report rpt = ip.Report(); - base.Run(ip, row); + await base.Run(ip, row); TextboxRuntime tbr = TextboxRuntime.GetTextboxRuntime(rpt, this); tbr.RunCount++; // Increment the run count - string t = RunText(rpt, row); + string t = await RunText(rpt, row); bool bDup = RunTextIsDuplicate(tbr, t, null); if (bDup) { @@ -241,20 +242,20 @@ override internal void Run(IPresent ip, Row row) return; t = ""; // still need to put out the cell } - ip.Textbox(this, t, row); + await ip.Textbox(this, t, row); if (!bDup) tbr.PreviousText=t; // set for next time } - override internal void RunPage(Pages pgs, Row row) + override internal async Task RunPage(Pages pgs, Row row) { Report r = pgs.Report; TextboxRuntime tbr = TextboxRuntime.GetTextboxRuntime(r, this); tbr.RunCount++; // Increment the run count - bool bHidden = IsHidden(r, row); + bool bHidden = await IsHidden(r, row); SetPagePositionBegin(pgs); @@ -262,7 +263,7 @@ override internal void RunPage(Pages pgs, Row row) if (bHidden) t = ""; else - t = RunText(r, row); // get the text + t = await RunText(r, row); // get the text bool bDup = RunTextIsDuplicate(tbr, t, pgs.CurrentPage); if (bDup) @@ -273,14 +274,14 @@ override internal void RunPage(Pages pgs, Row row) } PageText pt; PageTextHtml pth=null; - if (IsHtml(r, row)) + if (await IsHtml(r, row)) pt = pth = new PageTextHtml(t); else pt = new PageText(t); - SetPagePositionAndStyle(r, pt, row); + await SetPagePositionAndStyle(r, pt, row); if (this.CanGrow && tbr.RunHeight == 0) // when textbox is in a DataRegion this will already be called { - this.RunTextCalcHeight(r, pgs.G, row, pt as PageTextHtml); + await this.RunTextCalcHeight(r, pgs.G, row, pt as PageTextHtml); } pt.H = Math.Max(pt.H, tbr.RunHeight); // reset height if (pt.SI.BackgroundImage != null) @@ -321,10 +322,11 @@ override internal void RunPage(Pages pgs, Row row) SetPagePositionEnd(pgs, pt.Y+pt.H); if (pth != null) pth.Reset(); - if (this.CanGrow && !Value.IsConstant()) + if (this.CanGrow && !await Value.IsConstant()) { tbr.RunHeight = 0; // need to recalculate } + return; } // routine to determine if text is considered to be a duplicate; @@ -339,9 +341,9 @@ private bool RunTextIsDuplicate(TextboxRuntime tbr, string t, Page p) return false; } - internal string RunText(Report rpt, Row row) + internal async Task RunText(Report rpt, Row row) { - object o = Evaluate(rpt, row); + object o = await Evaluate(rpt, row); // AJM 15082008: Suppress NaN from appearing in a textbox if (o is double) { @@ -350,8 +352,8 @@ internal string RunText(Report rpt, Row row) o = null; } } - string t = Style.GetFormatedString(rpt, this.Style, row, o, _Value.GetTypeCode()); - if (IsHtml(rpt, row) && t != null && t.Contains("")) + string t = await Style.GetFormatedString(rpt, this.Style, row, o, _Value.GetTypeCode()); + if (await IsHtml(rpt, row) && t != null && t.Contains("")) { string[] parts = HTMLEXPR.Split(t); StringBuilder sb = new StringBuilder(t.Length); @@ -371,16 +373,16 @@ internal string RunText(Report rpt, Row row) return t; } - internal float RunTextCalcHeight(Report rpt, Graphics g, Row row) + internal async Task RunTextCalcHeight(Report rpt, Graphics g, Row row) { - return RunTextCalcHeight(rpt, g, row, null); + return await RunTextCalcHeight(rpt, g, row, null); } - internal float RunTextCalcHeight(Report rpt, Graphics g, Row row, PageTextHtml pth) + internal async Task RunTextCalcHeight(Report rpt, Graphics g, Row row, PageTextHtml pth) { // normally only called when CanGrow is true Size s = Size.Empty; - if (IsHidden(rpt, row)) + if (await IsHidden(rpt, row)) return 0; object o = Evaluate(rpt, row); @@ -390,36 +392,36 @@ internal float RunTextCalcHeight(Report rpt, Graphics g, Row row, PageTextHtml p if (this.Style != null) { - width -= (Style.EvalPaddingLeftPx(rpt, row) + Style.EvalPaddingRightPx(rpt, row)); + width -= (await Style.EvalPaddingLeftPx(rpt, row) + await Style.EvalPaddingRightPx(rpt, row)); - if (this.IsHtml(rpt, row)) + if (await this.IsHtml(rpt, row)) { if (pth == null) { pth = new PageTextHtml(o==null? "": o.ToString()); - SetPagePositionAndStyle(rpt, pth, row); + await SetPagePositionAndStyle(rpt, pth, row); } pth.Build(g); s.Height = RSize.PixelsFromPoints(pth.TotalHeight); } else - s = Style.MeasureString(rpt, g, o, tc, row, width); + s = await Style.MeasureString(rpt, g, o, tc, row, width); } else // call the class static method - s = Style.MeasureStringDefaults(rpt, g, o, tc, row, width); + s = await Style.MeasureStringDefaults(rpt, g, o, tc, row, width); TextboxRuntime tbr = TextboxRuntime.GetTextboxRuntime(rpt, this); tbr.RunHeight = RSize.PointsFromPixels(g, s.Height); if (Style != null) - tbr.RunHeight += (Style.EvalPaddingBottom(rpt, row) + Style.EvalPaddingTop(rpt, row)); + tbr.RunHeight += (await Style.EvalPaddingBottom(rpt, row) + await Style.EvalPaddingTop(rpt, row)); return tbr.RunHeight; } - internal object Evaluate(Report rpt, Row r) + internal async Task Evaluate(Report rpt, Row r) { if(r == null || lastValueForRow != r || lastValueForReport != rpt) { - lastEvaluatedValue = _Value.Evaluate(rpt, r); + lastEvaluatedValue = await _Value.Evaluate(rpt, r); lastValueForReport = rpt; lastValueForRow = r; } @@ -451,11 +453,11 @@ internal string HideDuplicates set { _HideDuplicates = value; } } - internal bool IsHtml(Report rpt, Row row) + internal async Task IsHtml(Report rpt, Row row) { if (this.Style == null || this.Style.Format == null) return false; - string format = Style.Format.EvaluateString(rpt, row); + string format = await Style.Format.EvaluateString(rpt, row); if (format == null) return false; return format.ToLower() == "html"; diff --git a/RdlEngine/Definition/ThreeDProperties.cs b/RdlEngine/Definition/ThreeDProperties.cs index 6bd5aa7d..613444ae 100644 --- a/RdlEngine/Definition/ThreeDProperties.cs +++ b/RdlEngine/Definition/ThreeDProperties.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -115,9 +116,9 @@ internal ThreeDProperties(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p } } - override internal void FinalPass() + override internal Task FinalPass() { - return; + return Task.CompletedTask; } internal bool Enabled diff --git a/RdlEngine/Definition/Title.cs b/RdlEngine/Definition/Title.cs index 7fa964fe..6150ed40 100644 --- a/RdlEngine/Definition/Title.cs +++ b/RdlEngine/Definition/Title.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -69,12 +70,12 @@ internal Title(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Caption != null) - _Caption.FinalPass(); + await _Caption.FinalPass(); if (_Style != null) - _Style.FinalPass(); + await _Style.FinalPass(); return; } diff --git a/RdlEngine/Definition/ToggleImage.cs b/RdlEngine/Definition/ToggleImage.cs index cc2cb735..5af4ddd7 100644 --- a/RdlEngine/Definition/ToggleImage.cs +++ b/RdlEngine/Definition/ToggleImage.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -63,10 +64,10 @@ internal ToggleImage(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_InitialState != null) - _InitialState.FinalPass(); + await _InitialState.FinalPass(); return; } diff --git a/RdlEngine/Definition/ValidValues.cs b/RdlEngine/Definition/ValidValues.cs index c7973798..87ac9ba0 100644 --- a/RdlEngine/Definition/ValidValues.cs +++ b/RdlEngine/Definition/ValidValues.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -72,12 +73,12 @@ internal ValidValues(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_DataSetReference != null) - _DataSetReference.FinalPass(); + await _DataSetReference.FinalPass(); if (_ParameterValues != null) - _ParameterValues.FinalPass(); + await _ParameterValues.FinalPass(); return; } @@ -93,75 +94,69 @@ internal ParameterValues ParameterValues set { _ParameterValues = value; } } - internal string[] DisplayValues(Report rpt) + internal async Task DisplayValues(Report rpt) { - lock (this) - { - string[] dsplValues = rpt.Cache.Get(this, "displayvalues") as string[]; - object[] dataValues; - - if (dsplValues != null) - return dsplValues; - - if (_DataSetReference != null) - _DataSetReference.SupplyValues(rpt, out dsplValues, out dataValues); - else - _ParameterValues.SupplyValues(rpt, out dsplValues, out dataValues); - - if (dataValues == null) - dataValues = new object[0]; - if (dsplValues == null) - dsplValues = new string[0]; - - // there shouldn't be a problem; but if there is it doesn't matter as values can be recreated - try {rpt.Cache.Add(this, "datavalues", dataValues);} - catch (Exception e1) - { - rpt.rl.LogError(4, "Error caching data values. " + e1.Message); - } - try {rpt.Cache.Add(this, "displayvalues", dsplValues);} - catch (Exception e2) - { - rpt.rl.LogError(4, "Error caching display values. " + e2.Message); - } + string[] dsplValues = rpt.Cache.Get(this, "displayvalues") as string[]; + object[] dataValues; + if (dsplValues != null) return dsplValues; - } - } - internal object[] DataValues(Report rpt) - { - lock (this) + if (_DataSetReference != null) + (dsplValues, dataValues) = await _DataSetReference.SupplyValues(rpt); + else + (dsplValues, dataValues) = await _ParameterValues.SupplyValues(rpt); + + if (dataValues == null) + dataValues = new object[0]; + if (dsplValues == null) + dsplValues = new string[0]; + + // there shouldn't be a problem; but if there is it doesn't matter as values can be recreated + try {rpt.Cache.Add(this, "datavalues", dataValues);} + catch (Exception e1) { - string[] dsplValues; - object[] dataValues = rpt.Cache.Get(this, "datavalues") as object[]; - - if (dataValues != null) - return dataValues; + rpt.rl.LogError(4, "Error caching data values. " + e1.Message); + } + try {rpt.Cache.Add(this, "displayvalues", dsplValues);} + catch (Exception e2) + { + rpt.rl.LogError(4, "Error caching display values. " + e2.Message); + } - if (_DataSetReference != null) - _DataSetReference.SupplyValues(rpt, out dsplValues, out dataValues); - else - _ParameterValues.SupplyValues(rpt, out dsplValues, out dataValues); + return dsplValues; + } - if (dataValues == null) - dataValues = new object[0]; - if (dsplValues == null) - dsplValues = new string[0]; + internal async Task DataValues(Report rpt) + { + string[] dsplValues; + object[] dataValues = rpt.Cache.Get(this, "datavalues") as object[]; - // there shouldn't be a problem; but if there is it doesn't matter as values can be recreated - try {rpt.Cache.Add(this, "datavalues", dataValues);} - catch (Exception e1) - { - rpt.rl.LogError(4, "Error caching data values. " + e1.Message); - } - try {rpt.Cache.Add(this, "displayvalues", dsplValues);} - catch (Exception e2) - { - rpt.rl.LogError(4, "Error caching display values. " + e2.Message); - } + if (dataValues != null) return dataValues; + + if (_DataSetReference != null) + (dsplValues, dataValues)= await _DataSetReference.SupplyValues(rpt); + else + (dsplValues, dataValues) = await _ParameterValues.SupplyValues(rpt); + + if (dataValues == null) + dataValues = new object[0]; + if (dsplValues == null) + dsplValues = new string[0]; + + // there shouldn't be a problem; but if there is it doesn't matter as values can be recreated + try {rpt.Cache.Add(this, "datavalues", dataValues);} + catch (Exception e1) + { + rpt.rl.LogError(4, "Error caching data values. " + e1.Message); + } + try {rpt.Cache.Add(this, "displayvalues", dsplValues);} + catch (Exception e2) + { + rpt.rl.LogError(4, "Error caching display values. " + e2.Message); } + return dataValues; } } } diff --git a/RdlEngine/Definition/ValueAxis.cs b/RdlEngine/Definition/ValueAxis.cs index 93042a58..9dc7d276 100644 --- a/RdlEngine/Definition/ValueAxis.cs +++ b/RdlEngine/Definition/ValueAxis.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -56,10 +57,10 @@ internal ValueAxis(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } } - override internal void FinalPass() + async override internal Task FinalPass() { if (_Axis != null) - _Axis.FinalPass(); + await _Axis.FinalPass(); return; } diff --git a/RdlEngine/Definition/Values.cs b/RdlEngine/Definition/Values.cs index 2a481d8a..93a7ef6a 100644 --- a/RdlEngine/Definition/Values.cs +++ b/RdlEngine/Definition/Values.cs @@ -23,6 +23,7 @@ the website www.fyiReporting.com. using System; using System.Collections; using System.Collections.Generic; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -63,11 +64,11 @@ internal Values(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { foreach (Expression e in _Items) - { - e.FinalPass(); + { + await e.FinalPass(); } return; } diff --git a/RdlEngine/Definition/Visibility.cs b/RdlEngine/Definition/Visibility.cs index b113b5a1..833f8ebd 100644 --- a/RdlEngine/Definition/Visibility.cs +++ b/RdlEngine/Definition/Visibility.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; +using System.Threading.Tasks; using System.Xml; namespace fyiReporting.RDL @@ -78,10 +79,10 @@ internal Visibility(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p) } // Handle parsing of function in final pass - override internal void FinalPass() + async override internal Task FinalPass() { if (_Hidden != null) - _Hidden.FinalPass(); + await _Hidden.FinalPass(); return; } @@ -91,12 +92,12 @@ internal Expression Hidden set { _Hidden = value; } } - internal bool IsHidden(Report rpt, Row r) + internal async Task IsHidden(Report rpt, Row r) { if (_Hidden == null) return false; - return _Hidden.EvaluateBoolean(rpt, r); + return await _Hidden.EvaluateBoolean(rpt, r); } internal string ToggleItem diff --git a/RdlEngine/ExprParser/Parser.cs b/RdlEngine/ExprParser/Parser.cs index 76da9677..26ff94a1 100644 --- a/RdlEngine/ExprParser/Parser.cs +++ b/RdlEngine/ExprParser/Parser.cs @@ -29,6 +29,7 @@ the website www.fyiReporting.com. using System.Reflection; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -87,7 +88,7 @@ internal Parser(List c) /// The NameLookUp class used to resolve names. /// The expression to be parsed. /// An expression that can be run after validation and binding. - internal IExpr Parse(NameLookup lu, string expr) + internal async Task Parse(NameLookup lu, string expr) { _InAggregate = false; @@ -95,7 +96,7 @@ internal IExpr Parse(NameLookup lu, string expr) return new Constant(expr); // this is a constant value idLookup = lu; - IExpr e = this.ParseExpr(new StringReader(expr)); + IExpr e = await this.ParseExpr(new StringReader(expr)); if (e == null) // Didn't get an expression? e = new Constant(expr); // then provide a constant @@ -124,7 +125,7 @@ private static string GetLocationInfoWithValue(Token token) /// /// The TextReader value to be parsed. /// A parsed Program instance. - private IExpr ParseExpr(TextReader reader) + private async Task ParseExpr(TextReader reader) { IExpr result=null; Lexer lexer = new Lexer(reader); @@ -134,7 +135,7 @@ private IExpr ParseExpr(TextReader reader) { tokens.Extract(); // skip over the equal curToken = tokens.Extract(); // set up the first token - MatchExprAndOr(out result); // start with lowest precedence and work up + result = await MatchExprAndOr(); // start with lowest precedence and work up } if (curToken.Type != TokenTypes.EOF) @@ -144,18 +145,18 @@ private IExpr ParseExpr(TextReader reader) } // ExprAndOr: - private void MatchExprAndOr(out IExpr result) + private async Task MatchExprAndOr() { TokenTypes t; // remember the type IExpr lhs; - MatchExprNot(out lhs); - result = lhs; // in case we get no matches + lhs = await MatchExprNot(); + IExpr result = lhs; // in case we get no matches while ((t = curToken.Type) == TokenTypes.AND || t == TokenTypes.OR) { curToken = tokens.Extract(); IExpr rhs; - MatchExprNot(out rhs); + rhs = await MatchExprNot(); bool bBool = (rhs.GetTypeCode() == TypeCode.Boolean && lhs.GetTypeCode() == TypeCode.Boolean); if (!bBool) @@ -172,9 +173,11 @@ private void MatchExprAndOr(out IExpr result) } lhs = result; // in case we have more AND/OR s } + + return result; } - private void MatchExprNot(out IExpr result) + private async Task MatchExprNot() { TokenTypes t; // remember the type t = curToken.Type; @@ -182,22 +185,23 @@ private void MatchExprNot(out IExpr result) { curToken = tokens.Extract(); } - MatchExprRelop(out result); + IExpr result = await MatchExprRelop(); if (t == TokenTypes.NOT) { if (result.GetTypeCode() != TypeCode.Boolean) throw new ParserException(Strings.Parser_ErrorP_NOTRequiresBoolean + GetLocationInfo(curToken)); result = new FunctionNot(result); } + return result; } // ExprRelop: - private void MatchExprRelop(out IExpr result) + private async Task MatchExprRelop() { - TokenTypes t; // remember the type - + TokenTypes t; // remember the type + IExpr result = null; IExpr lhs; - MatchExprAddSub(out lhs); + lhs = await MatchExprAddSub(); result = lhs; // in case we get no matches while ((t = curToken.Type) == TokenTypes.EQUAL || t == TokenTypes.NOTEQUAL || @@ -208,7 +212,7 @@ private void MatchExprRelop(out IExpr result) { curToken = tokens.Extract(); IExpr rhs; - MatchExprAddSub(out rhs); + rhs = await MatchExprAddSub(); switch(t) { @@ -233,21 +237,22 @@ private void MatchExprRelop(out IExpr result) } lhs = result; // in case we continue the loop } + return result; } // ExprAddSub: PlusMinusOperator Term ExprRhs - private void MatchExprAddSub(out IExpr result) + private async Task MatchExprAddSub() { - TokenTypes t; // remember the type - + TokenTypes t; // remember the type + IExpr result=null; IExpr lhs; - MatchExprMultDiv(out lhs); + lhs = await MatchExprMultDiv(); result = lhs; // in case we get no matches while ((t = curToken.Type) == TokenTypes.PLUS || t == TokenTypes.PLUSSTRING || t == TokenTypes.MINUS) { curToken = tokens.Extract(); IExpr rhs; - MatchExprMultDiv(out rhs); + rhs = await MatchExprMultDiv(); TypeCode lt = lhs.GetTypeCode(); TypeCode rt = rhs.GetTypeCode(); bool bDecimal = (rt == TypeCode.Decimal && @@ -285,14 +290,16 @@ private void MatchExprAddSub(out IExpr result) } lhs = result; // in case continue in the loop } + return result; } // TermRhs: MultDivOperator Factor TermRhs - private void MatchExprMultDiv(out IExpr result) + private async Task MatchExprMultDiv() { + IExpr result = null; TokenTypes t; // remember the type IExpr lhs; - MatchExprExp(out lhs); + lhs = await MatchExprExp(); result = lhs; // in case we get no matches while ((t = curToken.Type) == TokenTypes.FORWARDSLASH || t == TokenTypes.STAR || @@ -300,7 +307,7 @@ private void MatchExprMultDiv(out IExpr result) { curToken = tokens.Extract(); IExpr rhs; - MatchExprExp(out rhs); + rhs = await MatchExprExp(); bool bDecimal = (rhs.GetTypeCode() == TypeCode.Decimal && lhs.GetTypeCode() == TypeCode.Decimal); switch (t) @@ -323,33 +330,39 @@ private void MatchExprMultDiv(out IExpr result) } lhs = result; // in case continue in the loop } - } + + return result; + } // TermRhs: ExpOperator Factor TermRhs - private void MatchExprExp(out IExpr result) + private async Task MatchExprExp() { - IExpr lhs; - MatchExprUnary(out lhs); + IExpr result = null; + IExpr lhs; + lhs = await MatchExprUnary(); if (curToken.Type == TokenTypes.EXP) { curToken = tokens.Extract(); IExpr rhs; - MatchExprUnary(out rhs); + rhs = await MatchExprUnary(); result = new FunctionExp(lhs, rhs); } else result = lhs; + + return result; } - private void MatchExprUnary(out IExpr result) + private async Task MatchExprUnary() { + IExpr result = null; TokenTypes t; // remember the type t = curToken.Type; if (t == TokenTypes.PLUS || t == TokenTypes.MINUS) { curToken = tokens.Extract(); } - MatchExprParen(out result); + result = await MatchExprParen(); if (t == TokenTypes.MINUS) { if (result.GetTypeCode() == TypeCode.Decimal) @@ -359,57 +372,64 @@ private void MatchExprUnary(out IExpr result) else result = new FunctionUnaryMinus(result); } + + return result; } // Factor: ( Expr ) | BaseType | - BaseType | - ( Expr ) - private void MatchExprParen(out IExpr result) + private async Task MatchExprParen() { - // Match- ( Expr ) - if (curToken.Type == TokenTypes.LPAREN) + IExpr result = null; + // Match- ( Expr ) + if (curToken.Type == TokenTypes.LPAREN) { // trying to match ( Expr ) curToken = tokens.Extract(); - MatchExprAndOr(out result); + result = await MatchExprAndOr(); if (curToken.Type != TokenTypes.RPAREN) throw new ParserException(Strings.Parser_ErrorP_BracketExpected + GetLocationInfoWithValue(curToken)); curToken = tokens.Extract(); } else - MatchBaseType(out result); + result = await MatchBaseType(); + + return result; } // BaseType: FuncIdent | NUMBER | QUOTE - note certain types are restricted in expressions - private void MatchBaseType(out IExpr result) + private async Task MatchBaseType() { - if (MatchFuncIDent(out result)) - return; + var r = await MatchFuncIDent(); + + if (r.match) + return r.result; switch (curToken.Type) { case TokenTypes.NUMBER: - result = new ConstantDecimal(curToken.Value); + r.result = new ConstantDecimal(curToken.Value); break; case TokenTypes.DATETIME: - result = new ConstantDateTime(curToken.Value); + r.result = new ConstantDateTime(curToken.Value); break; case TokenTypes.DOUBLE: - result = new ConstantDouble(curToken.Value); + r.result = new ConstantDouble(curToken.Value); break; case TokenTypes.INTEGER: - result = new ConstantInteger(curToken.Value); + r.result = new ConstantInteger(curToken.Value); break; case TokenTypes.QUOTE: - result = new ConstantString(curToken.Value); + r.result = new ConstantString(curToken.Value); break; default: throw new ParserException(Strings.Parser_ErrorP_IdentifierExpected + GetLocationInfoWithValue(curToken)); } curToken = tokens.Extract(); - return; + return r.result; } // FuncIDent: IDENTIFIER ( [Expr] [, Expr]*) | IDENTIFIER - private bool MatchFuncIDent(out IExpr result) + private async Task<(bool match, IExpr result)> MatchFuncIDent() { IExpr e; string fullname; // will hold the full name @@ -418,10 +438,10 @@ private bool MatchFuncIDent(out IExpr result) string thirdPart; // will hold third part of name bool bOnePart; // simple name: no ! or . in name - result = null; + IExpr result = null; if (curToken.Type != TokenTypes.IDENTIFIER) - return false; + return (false, result); // Disentangle method calls from collection references method = fullname = curToken.Value; @@ -484,7 +504,7 @@ private bool MatchFuncIDent(out IExpr result) } else throw new ParserException(string.Format(Strings.Parser_ErrorP_FieldSupportsValueAndIsMissing, method)); - return true; + return (true, result); case "Parameters": // see ResolveParametersMethod for resolution of MultiValue parameter function reference ReportParameter p = idLookup.LookupParameter(method); if (p == null) @@ -503,7 +523,7 @@ private bool MatchFuncIDent(out IExpr result) r.SetParameterMethod("Count", null); result = r; - return true; + return (true, result); case "ReportItems": Textbox t = idLookup.LookupReportItem(method); if (t == null) @@ -511,25 +531,25 @@ private bool MatchFuncIDent(out IExpr result) if (thirdPart != null && thirdPart != "Value") throw new ParserException(string.Format(Strings.Parser_ErrorP_ItemSupportsValue, method)); result = new FunctionTextbox(t, idLookup.ExpressionName); - return true; + return (true, result); case "Globals": e = idLookup.LookupGlobal(method); if (e == null) throw new ParserException(string.Format(Strings.Parser_ErrorP_GlobalsNotFound, method)); result = e; - return true; + return (true, result); case "User": e = idLookup.LookupUser(method); if (e == null) throw new ParserException(string.Format(Strings.Parser_ErrorP_UserVarNotFound, method)); result = e; - return true; + return (true, result); case "Recursive": // Only valid for some aggregate functions result = new IdentifierKey(IdentifierKeyEnum.Recursive); - return true; + return (true, result); case "Simple": // Only valid for some aggregate functions result = new IdentifierKey(IdentifierKeyEnum.Simple); - return true; + return (true, result); default: if (!bOnePart) throw new ParserException(string.Format(Strings.Parser_ErrorP_UnknownIdentifer, fullname)); @@ -545,7 +565,7 @@ private bool MatchFuncIDent(out IExpr result) result = new Identifier(method); break; } - return true; + return (true, result); } // We've got an function reference @@ -613,7 +633,7 @@ private bool MatchFuncIDent(out IExpr result) else throw new ParserException(Strings.Parser_ErrorP_Invalid_function_arguments + GetLocationInfoWithValue(curToken)); - MatchExprAndOr(out e); + e = await MatchExprAndOr(); if (e == null) throw new ParserException(Strings.Parser_ErrorP_ExpectingComma + GetLocationInfoWithValue(curToken)); @@ -743,85 +763,85 @@ private bool MatchFuncIDent(out IExpr result) result = new FunctionUserCollection(idLookup.User, args[0]); break; case "sum": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrSum aggrFS = new FunctionAggrSum(_DataCache, args[0], scope); aggrFS.LevelCheck = bSimple; result = aggrFS; break; case "avg": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrAvg aggrFA = new FunctionAggrAvg(_DataCache, args[0], scope); aggrFA.LevelCheck = bSimple; result = aggrFA; break; case "min": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrMin aggrFMin = new FunctionAggrMin(_DataCache, args[0], scope); aggrFMin.LevelCheck = bSimple; result = aggrFMin; break; case "max": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrMax aggrFMax = new FunctionAggrMax(_DataCache, args[0], scope); aggrFMax.LevelCheck = bSimple; result = aggrFMax; break; case "first": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); result = new FunctionAggrFirst(_DataCache, args[0], scope); break; case "last": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); result = new FunctionAggrLast(_DataCache, args[0], scope); break; case "next": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); result = new FunctionAggrNext(_DataCache, args[0], scope); break; case "previous": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); result = new FunctionAggrPrevious(_DataCache, args[0], scope); break; case "level": - scope = ResolveAggrScope(args, 1, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 1); result = new FunctionAggrLevel(scope); break; case "aggregate": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrArray aggr = new FunctionAggrArray(_DataCache, args[0], scope); aggr.LevelCheck = bSimple; result = aggr; break; case "count": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrCount aggrFC = new FunctionAggrCount(_DataCache, args[0], scope); aggrFC.LevelCheck = bSimple; result = aggrFC; break; case "countrows": - scope = ResolveAggrScope(args, 1, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 1); FunctionAggrCountRows aggrFCR = new FunctionAggrCountRows(scope); aggrFCR.LevelCheck = bSimple; result = aggrFCR; break; case "countdistinct": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrCountDistinct aggrFCD = new FunctionAggrCountDistinct(_DataCache, args[0], scope); aggrFCD.LevelCheck = bSimple; result = aggrFCD; break; case "rownumber": - scope = ResolveAggrScope(args, 1, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 1); IExpr texpr = new ConstantDouble("0"); result = new FunctionAggrRvCount(_DataCache, texpr, scope); break; case "runningvalue": if (args.Length < 2 || args.Length > 3) throw new ParserException(Strings.Parser_ErrorP_RunningValue_takes_2_or_3_arguments + GetLocationInfo(curToken)); - string aggrFunc = args[1].EvaluateString(null, null); + string aggrFunc = await args[1].EvaluateString(null, null); if (aggrFunc == null) throw new ParserException(Strings.Parser_ErrorP_RunningValueArgumentInvalid + GetLocationInfo(curToken)); - scope = ResolveAggrScope(args, 3, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 3); switch(aggrFunc.ToLower()) { case "sum": @@ -856,25 +876,25 @@ private bool MatchFuncIDent(out IExpr result) } break; case "stdev": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrStdev aggrSDev = new FunctionAggrStdev(_DataCache, args[0], scope); aggrSDev.LevelCheck = bSimple; result = aggrSDev; break; case "stdevp": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrStdevp aggrSDevP = new FunctionAggrStdevp(_DataCache, args[0], scope); aggrSDevP.LevelCheck = bSimple; result = aggrSDevP; break; case "var": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrVar aggrVar = new FunctionAggrVar(_DataCache, args[0], scope); aggrVar.LevelCheck = bSimple; result = aggrVar; break; case "varp": - scope = ResolveAggrScope(args, 2, out bSimple); + (scope, bSimple) = await ResolveAggrScope(args, 2); FunctionAggrVarp aggrVarP = new FunctionAggrVarp(_DataCache, args[0], scope); aggrVarP.LevelCheck = bSimple; result = aggrVarP; @@ -884,7 +904,7 @@ private bool MatchFuncIDent(out IExpr result) break; } - return true; + return (true, result); } private bool IsAggregate(string method, bool onePart) @@ -921,18 +941,18 @@ private bool IsAggregate(string method, bool onePart) return rc; } - private object ResolveAggrScope(IExpr[] args, int indexOfScope, out bool bSimple) + private async Task<(object scope, bool bSimple)> ResolveAggrScope(IExpr[] args, int indexOfScope) { object scope; - bSimple = true; + bool bSimple = true; if (args.Length == 0 && indexOfScope > 1) throw new ParserException(Strings.Parser_ErrorP_AggregateMust1Argument); if (args.Length >= indexOfScope) { - string n = args[indexOfScope-1].EvaluateString(null, null); + string n = await args[indexOfScope-1].EvaluateString(null, null); if (idLookup.IsPageScope) throw new ParserException(string.Format(Strings.Parser_ErrorP_ScopeNotSpecifiedInHeaderOrFooter,n)); @@ -968,7 +988,7 @@ private object ResolveAggrScope(IExpr[] args, int indexOfScope, out bool bSimple } } - return scope; + return (scope, bSimple); } private IExpr ResolveParametersMethod(string pname, string vf, IExpr[] args) diff --git a/RdlEngine/Functions/Constant.cs b/RdlEngine/Functions/Constant.cs index 157954f1..11c4b0a2 100644 --- a/RdlEngine/Functions/Constant.cs +++ b/RdlEngine/Functions/Constant.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,49 +51,49 @@ public TypeCode GetTypeCode() return TypeCode.String; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // already constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult((object)_Value); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(_Value); + return Task.FromResult(Convert.ToDouble(_Value)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(_Value); + return Task.FromResult(Convert.ToDecimal(_Value)); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(_Value); + return Task.FromResult(Convert.ToInt32(_Value)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(_Value); + return Task.FromResult(Convert.ToDateTime(_Value)); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(_Value); + return Task.FromResult(Convert.ToBoolean(_Value)); } } } diff --git a/RdlEngine/Functions/ConstantBoolean.cs b/RdlEngine/Functions/ConstantBoolean.cs index 1549c869..dcb8ad6f 100644 --- a/RdlEngine/Functions/ConstantBoolean.cs +++ b/RdlEngine/Functions/ConstantBoolean.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,49 +56,49 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // already constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult((object)_Value); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(_Value); + return Task.FromResult(Convert.ToString(_Value)); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(_Value); + return Task.FromResult(Convert.ToDouble(_Value)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(_Value); + return Task.FromResult(Convert.ToDecimal(_Value)); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(_Value); + return Task.FromResult(Convert.ToInt32(_Value)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(_Value); + return Task.FromResult(Convert.ToDateTime(_Value)); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value); } } } diff --git a/RdlEngine/Functions/ConstantDateTime.cs b/RdlEngine/Functions/ConstantDateTime.cs index 6fffea68..225d5b1a 100644 --- a/RdlEngine/Functions/ConstantDateTime.cs +++ b/RdlEngine/Functions/ConstantDateTime.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,49 +56,49 @@ public TypeCode GetTypeCode() return TypeCode.DateTime; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // already constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult((object)_Value); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(_Value); + return Task.FromResult(Convert.ToString(_Value)); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(_Value); + return Task.FromResult(Convert.ToDouble(_Value)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(_Value); + return Task.FromResult(Convert.ToDecimal(_Value)); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(_Value); + return Task.FromResult(Convert.ToInt32(_Value)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(_Value); + return Task.FromResult(Convert.ToBoolean(_Value)); } } } diff --git a/RdlEngine/Functions/ConstantDecimal.cs b/RdlEngine/Functions/ConstantDecimal.cs index 071c9f8a..38dedee1 100644 --- a/RdlEngine/Functions/ConstantDecimal.cs +++ b/RdlEngine/Functions/ConstantDecimal.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Globalization; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -57,49 +58,49 @@ public TypeCode GetTypeCode() return TypeCode.Decimal; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // already constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult((object)_Value); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(_Value); + return Task.FromResult(Convert.ToString(_Value)); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(_Value); + return Task.FromResult(Convert.ToDouble(_Value)); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(_Value); + return Task.FromResult(Convert.ToInt32(_Value)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(_Value); + return Task.FromResult(Convert.ToDateTime(_Value)); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(_Value); + return Task.FromResult(Convert.ToBoolean(_Value)); } } } diff --git a/RdlEngine/Functions/ConstantDouble.cs b/RdlEngine/Functions/ConstantDouble.cs index 39c419b6..7bbee228 100644 --- a/RdlEngine/Functions/ConstantDouble.cs +++ b/RdlEngine/Functions/ConstantDouble.cs @@ -28,6 +28,7 @@ the website www.fyiReporting.com. using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -58,49 +59,49 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // already constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult((object)_Value); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(_Value); + return Task.FromResult(Convert.ToString(_Value)); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(_Value); + return Task.FromResult(Convert.ToDecimal(_Value)); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(_Value); + return Task.FromResult(Convert.ToInt32(_Value)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(_Value); + return Task.FromResult(Convert.ToDateTime(_Value)); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(_Value); + return Task.FromResult(Convert.ToBoolean(_Value)); } } } diff --git a/RdlEngine/Functions/ConstantError.cs b/RdlEngine/Functions/ConstantError.cs index 55bc6fef..01d964dd 100644 --- a/RdlEngine/Functions/ConstantError.cs +++ b/RdlEngine/Functions/ConstantError.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -51,49 +50,49 @@ public TypeCode GetTypeCode() return TypeCode.String; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // already constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult((object)_Value); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(_Value); + return Task.FromResult(Convert.ToDouble(_Value)); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(_Value); + return Task.FromResult(Convert.ToInt32(_Value)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(_Value); + return Task.FromResult(Convert.ToDecimal(_Value)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(_Value); + return Task.FromResult(Convert.ToDateTime(_Value)); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(_Value); + return Task.FromResult(Convert.ToBoolean(_Value)); } } } diff --git a/RdlEngine/Functions/ConstantInteger.cs b/RdlEngine/Functions/ConstantInteger.cs index 4b478afc..5ad513a2 100644 --- a/RdlEngine/Functions/ConstantInteger.cs +++ b/RdlEngine/Functions/ConstantInteger.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,49 +56,49 @@ public TypeCode GetTypeCode() return TypeCode.Int32; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // already constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult((object)_Value); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(_Value); + return Task.FromResult(Convert.ToString(_Value)); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return _Value; + return Task.FromResult((double)_Value); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(_Value); + return Task.FromResult(Convert.ToDecimal(_Value)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(_Value); + return Task.FromResult(Convert.ToDateTime(_Value)); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(_Value); + return Task.FromResult(Convert.ToBoolean(_Value)); } } } diff --git a/RdlEngine/Functions/ConstantString.cs b/RdlEngine/Functions/ConstantString.cs index f73bd7d4..c4765d6d 100644 --- a/RdlEngine/Functions/ConstantString.cs +++ b/RdlEngine/Functions/ConstantString.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,49 +51,49 @@ public TypeCode GetTypeCode() return TypeCode.String; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // already constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult((object)_Value); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(_Value); + return Task.FromResult(Convert.ToDouble(_Value)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(_Value); + return Task.FromResult(Convert.ToDecimal(_Value)); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(_Value); + return Task.FromResult(Convert.ToInt32(_Value)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(_Value); + return Task.FromResult(Convert.ToDateTime(_Value)); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(_Value); + return Task.FromResult(Convert.ToBoolean(_Value)); } } } diff --git a/RdlEngine/Functions/FunctionAggr.cs b/RdlEngine/Functions/FunctionAggr.cs index f652cbeb..aec621e1 100644 --- a/RdlEngine/Functions/FunctionAggr.cs +++ b/RdlEngine/Functions/FunctionAggr.cs @@ -25,7 +25,7 @@ the website www.fyiReporting.com. using System.Collections.Generic; using System.IO; using System.Reflection; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -55,21 +55,21 @@ public FunctionAggr(IExpr e, object scp) _LevelCheck = false; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { if (_Expr != null) - _Expr = _Expr.ConstantOptimization(); + _Expr = await _Expr.ConstantOptimization(); return (IExpr) this; } - public virtual bool EvaluateBoolean(Report rpt, Row row) + public virtual Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } public IExpr Expr diff --git a/RdlEngine/Functions/FunctionAggrArray.cs b/RdlEngine/Functions/FunctionAggrArray.cs index d519543b..e8de38f6 100644 --- a/RdlEngine/Functions/FunctionAggrArray.cs +++ b/RdlEngine/Functions/FunctionAggrArray.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,7 +57,7 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { bool bSave = true; RowEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -79,32 +79,32 @@ public object Evaluate(Report rpt, Row row) if (bSave) SetValue(rpt, v); } - return v; + return Task.FromResult(v); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.MinValue; + return Task.FromResult(double.MinValue); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { return null; } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } private object GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrAvg.cs b/RdlEngine/Functions/FunctionAggrAvg.cs index 9bc5c477..894288e0 100644 --- a/RdlEngine/Functions/FunctionAggrAvg.cs +++ b/RdlEngine/Functions/FunctionAggrAvg.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -64,12 +64,12 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return _tc==TypeCode.Decimal? (object) EvaluateDecimal(rpt, row): (object) EvaluateDouble(rpt, row); + return _tc==TypeCode.Decimal? (object)await EvaluateDecimal(rpt, row): (object) await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -85,7 +85,7 @@ public double EvaluateDouble(Report rpt, Row row) double temp; foreach (Row r in re) { - temp = _Expr.EvaluateDouble(rpt, r); + temp = await _Expr.EvaluateDouble(rpt, r); if (temp.CompareTo(double.NaN) != 0) { sum += temp; @@ -104,13 +104,13 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { if (row == null) return int.MinValue; - return Convert.ToInt32(EvaluateDouble(rpt, row)); + return Convert.ToInt32(await EvaluateDouble(rpt, row)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { bool bSave; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -126,7 +126,7 @@ public decimal EvaluateDecimal(Report rpt, Row row) decimal temp; foreach (Row r in re) { - temp = _Expr.EvaluateDecimal(rpt, r); + temp = await _Expr.EvaluateDecimal(rpt, r); if (temp != decimal.MinValue) // indicate null value { sum += temp; @@ -144,15 +144,15 @@ public decimal EvaluateDecimal(Report rpt, Row row) return result; } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrCount.cs b/RdlEngine/Functions/FunctionAggrCount.cs index e3b1b4ad..fbd23374 100644 --- a/RdlEngine/Functions/FunctionAggrCount.cs +++ b/RdlEngine/Functions/FunctionAggrCount.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,12 +57,12 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateInt32(rpt, row); + return (object)await EvaluateInt32(rpt, row); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -76,7 +76,7 @@ public int EvaluateInt32(Report rpt, Row row) int count=0; foreach (Row r in re) { - temp = _Expr.Evaluate(rpt, r); + temp = await _Expr.Evaluate(rpt, r); if (temp != null) { count++; @@ -90,29 +90,29 @@ public int EvaluateInt32(Report rpt, Row row) return v; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - int d = EvaluateInt32(rpt, row); + int d = await EvaluateInt32(rpt, row); return Convert.ToDouble(d); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); return Convert.ToDecimal(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrCountDistinct.cs b/RdlEngine/Functions/FunctionAggrCountDistinct.cs index 1c5b38af..8a201cc8 100644 --- a/RdlEngine/Functions/FunctionAggrCountDistinct.cs +++ b/RdlEngine/Functions/FunctionAggrCountDistinct.cs @@ -26,8 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,12 +58,12 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateDouble(rpt, row); + return (object)await EvaluateDouble(rpt, row); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { bool bSave=true; RowEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -79,7 +78,7 @@ public int EvaluateInt32(Report rpt, Row row) Hashtable ht = new Hashtable(count); foreach (Row r in re) { - temp = _Expr.Evaluate(rpt, r); + temp = await _Expr.Evaluate(rpt, r); if (temp != null) { object o = ht[temp]; // search for it @@ -96,29 +95,29 @@ public int EvaluateInt32(Report rpt, Row row) return v; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - int d = EvaluateInt32(rpt, row); + int d = await EvaluateInt32(rpt, row); return Convert.ToDouble(d); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - int d = EvaluateInt32(rpt, row); + int d = await EvaluateInt32(rpt, row); return Convert.ToDecimal(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrCountRows.cs b/RdlEngine/Functions/FunctionAggrCountRows.cs index 15f38a74..57b3eb1d 100644 --- a/RdlEngine/Functions/FunctionAggrCountRows.cs +++ b/RdlEngine/Functions/FunctionAggrCountRows.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,46 +51,46 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateInt32(rpt, row); + return (object)await EvaluateInt32(rpt, row); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { bool bSave=true; RowEnumerable re = this.GetDataScope(rpt, row, out bSave); if (re == null) - return 0; + return Task.FromResult(0); int count = re.LastRow - re.FirstRow + 1; - return count; + return Task.FromResult(count); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - int d = EvaluateInt32(rpt, row); + int d = await EvaluateInt32(rpt, row); return Convert.ToDouble(d); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - int d = EvaluateInt32(rpt, row); + int d = await EvaluateInt32(rpt, row); return Convert.ToDecimal(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } } diff --git a/RdlEngine/Functions/FunctionAggrFirst.cs b/RdlEngine/Functions/FunctionAggrFirst.cs index 263e3dd1..63d9b81f 100644 --- a/RdlEngine/Functions/FunctionAggrFirst.cs +++ b/RdlEngine/Functions/FunctionAggrFirst.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,7 +59,7 @@ public TypeCode GetTypeCode() return _tc; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { bool bSave=true; RowEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -73,46 +73,46 @@ public object Evaluate(Report rpt, Row row) if (re.Data.Count > 0) saver = re.Data[re.FirstRow] as Row; - v = _Expr.Evaluate(rpt, saver); + v = await _Expr.Evaluate(rpt, saver); if (bSave) SetValue(rpt, v); } return v; } - public override bool EvaluateBoolean(Report rpt,Row row) + public override async Task EvaluateBoolean(Report rpt,Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToBoolean(result); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrLast.cs b/RdlEngine/Functions/FunctionAggrLast.cs index 2cc7be71..35fbfb11 100644 --- a/RdlEngine/Functions/FunctionAggrLast.cs +++ b/RdlEngine/Functions/FunctionAggrLast.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,7 +59,7 @@ public TypeCode GetTypeCode() return _tc; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { bool bSave=true; RowEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -77,45 +77,45 @@ public object Evaluate(Report rpt, Row row) { saver=r; } - v = _Expr.Evaluate(rpt, saver); + v = await _Expr.Evaluate(rpt, saver); if (bSave) SetValue(rpt, v); } return v; } - public override bool EvaluateBoolean(Report rpt,Row row) + public override async Task EvaluateBoolean(Report rpt,Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToBoolean(result); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(Evaluate(rpt, row)); + return Convert.ToInt32(await Evaluate(rpt, row)); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private object GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrLevel.cs b/RdlEngine/Functions/FunctionAggrLevel.cs index 9306b9b7..afe76f12 100644 --- a/RdlEngine/Functions/FunctionAggrLevel.cs +++ b/RdlEngine/Functions/FunctionAggrLevel.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -51,48 +50,48 @@ public TypeCode GetTypeCode() return TypeCode.Double; // although it is always an integer } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateDouble(rpt, row); + return (object)await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { if (row == null || this._Scope == null) - return 0; + return Task.FromResult(0d); Grouping g = this._Scope as Grouping; if (g == null || g.ParentGroup == null) - return 0; + return Task.FromResult(0d); // GroupEntry ge = row.R.CurrentGroups[g.Index]; // current group entry - return row.Level; + return Task.FromResult((double)row.Level); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } } diff --git a/RdlEngine/Functions/FunctionAggrMax.cs b/RdlEngine/Functions/FunctionAggrMax.cs index e490aa45..24027f48 100644 --- a/RdlEngine/Functions/FunctionAggrMax.cs +++ b/RdlEngine/Functions/FunctionAggrMax.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,7 +59,7 @@ public TypeCode GetTypeCode() return _tc; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -74,7 +74,7 @@ public object Evaluate(Report rpt, Row row) foreach (Row r in re) { - current_value = _Expr.Evaluate(rpt, r); + current_value = await _Expr.Evaluate(rpt, r); if (current_value == null || (current_value is double && double.IsNaN((double)current_value))) continue; else if (max_value == null) @@ -89,33 +89,33 @@ public object Evaluate(Report rpt, Row row) return v; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrMin.cs b/RdlEngine/Functions/FunctionAggrMin.cs index bcca7352..c9b2e057 100644 --- a/RdlEngine/Functions/FunctionAggrMin.cs +++ b/RdlEngine/Functions/FunctionAggrMin.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,7 +59,7 @@ public TypeCode GetTypeCode() return _tc; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -74,7 +74,7 @@ public object Evaluate(Report rpt, Row row) foreach (Row r in re) { - current_value = _Expr.Evaluate(rpt, r); + current_value = await _Expr.Evaluate(rpt, r); if (current_value == null || (current_value is double && double.IsNaN((double)current_value))) continue; else if (min_value == null) @@ -89,33 +89,33 @@ public object Evaluate(Report rpt, Row row) return v; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrNext.cs b/RdlEngine/Functions/FunctionAggrNext.cs index d05a561a..5a5afefc 100644 --- a/RdlEngine/Functions/FunctionAggrNext.cs +++ b/RdlEngine/Functions/FunctionAggrNext.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,7 +59,7 @@ public TypeCode GetTypeCode() return _tc; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { object v = null; if (row == null) @@ -82,43 +82,43 @@ public object Evaluate(Report rpt, Row row) bNext = true; } if (crow != null) - v = _Expr.Evaluate(rpt, crow); + v = await _Expr.Evaluate(rpt, crow); return v; } - public override bool EvaluateBoolean(Report rpt,Row row) + public override async Task EvaluateBoolean(Report rpt,Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? false: Convert.ToBoolean(result); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? double.MinValue: Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? decimal.MinValue: Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null ? int.MinValue : Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? null: Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? DateTime.MinValue: Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrPrevious.cs b/RdlEngine/Functions/FunctionAggrPrevious.cs index b8718e1d..8b7ab7ca 100644 --- a/RdlEngine/Functions/FunctionAggrPrevious.cs +++ b/RdlEngine/Functions/FunctionAggrPrevious.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,7 +59,7 @@ public TypeCode GetTypeCode() return _tc; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { object v = null; if (row == null) @@ -77,43 +77,43 @@ public object Evaluate(Report rpt, Row row) crow = r; } if (crow != null) - v = _Expr.Evaluate(rpt, crow); + v = await _Expr.Evaluate(rpt, crow); return v; } - public override bool EvaluateBoolean(Report rpt,Row row) + public override async Task EvaluateBoolean(Report rpt,Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? false: Convert.ToBoolean(result); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? double.MinValue: Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? decimal.MinValue: Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null ? int.MinValue : Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? null: Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result == null? DateTime.MinValue: Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrRvAvg.cs b/RdlEngine/Functions/FunctionAggrRvAvg.cs index 1ddb0e83..5220afaa 100644 --- a/RdlEngine/Functions/FunctionAggrRvAvg.cs +++ b/RdlEngine/Functions/FunctionAggrRvAvg.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -64,12 +64,12 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return _tc==TypeCode.Decimal? (object) EvaluateDecimal(rpt, row): (object) EvaluateDouble(rpt, row); + return _tc==TypeCode.Decimal? (object)await EvaluateDecimal(rpt, row): (object)await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -82,7 +82,7 @@ public double EvaluateDouble(Report rpt, Row row) startrow = r; // We just want the first row break; } - double currentValue = _Expr.EvaluateDouble(rpt, row); + double currentValue = await _Expr.EvaluateDouble(rpt, row); WorkClass wc = GetValue(rpt); if (row == startrow) { @@ -99,7 +99,7 @@ public double EvaluateDouble(Report rpt, Row row) return (double) wc.Value / wc.Count; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { bool bSave; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -113,7 +113,7 @@ public decimal EvaluateDecimal(Report rpt, Row row) break; } - decimal currentValue = _Expr.EvaluateDecimal(rpt, row); + decimal currentValue = await _Expr.EvaluateDecimal(rpt, row); WorkClass wc = GetValue(rpt); if (row == startrow) { @@ -130,20 +130,20 @@ public decimal EvaluateDecimal(Report rpt, Row row) return (decimal) wc.Value / wc.Count; } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(Evaluate(rpt, row)); + return Convert.ToInt32(await Evaluate(rpt, row)); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrRvCount.cs b/RdlEngine/Functions/FunctionAggrRvCount.cs index d4931b11..80e1be78 100644 --- a/RdlEngine/Functions/FunctionAggrRvCount.cs +++ b/RdlEngine/Functions/FunctionAggrRvCount.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -58,12 +58,12 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateInt32(rpt, row); + return (object)await EvaluateInt32(rpt, row); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -79,7 +79,7 @@ public int EvaluateInt32(Report rpt, Row row) int count; - object currentValue = _Expr.Evaluate(rpt, row); + object currentValue = await _Expr.Evaluate(rpt, row); int incr = currentValue == null? 0: 1; if (row == startrow) { @@ -95,25 +95,25 @@ public int EvaluateInt32(Report rpt, Row row) return count; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - return (double)EvaluateInt32(rpt, row); + return (double)await EvaluateInt32(rpt, row); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - return (decimal) EvaluateInt32(rpt, row); + return (decimal)await EvaluateInt32(rpt, row); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = EvaluateDouble(rpt, row); + object result = await EvaluateDouble(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private int GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrRvMax.cs b/RdlEngine/Functions/FunctionAggrRvMax.cs index d3d7d177..34937933 100644 --- a/RdlEngine/Functions/FunctionAggrRvMax.cs +++ b/RdlEngine/Functions/FunctionAggrRvMax.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,7 +59,7 @@ public TypeCode GetTypeCode() return _tc; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -73,7 +73,7 @@ public object Evaluate(Report rpt, Row row) break; } - object current_value = _Expr.Evaluate(rpt, row); + object current_value = await _Expr.Evaluate(rpt, row); if (row == startrow) {} else @@ -92,33 +92,33 @@ public object Evaluate(Report rpt, Row row) return current_value; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrRvMin.cs b/RdlEngine/Functions/FunctionAggrRvMin.cs index 963be39b..e85aa7d4 100644 --- a/RdlEngine/Functions/FunctionAggrRvMin.cs +++ b/RdlEngine/Functions/FunctionAggrRvMin.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -59,7 +59,7 @@ public TypeCode GetTypeCode() return _tc; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -74,7 +74,7 @@ public object Evaluate(Report rpt, Row row) } object v = GetValue(rpt); - object current_value = _Expr.Evaluate(rpt, row); + object current_value = await _Expr.Evaluate(rpt, row); if (row == startrow) {} else @@ -92,33 +92,33 @@ public object Evaluate(Report rpt, Row row) return current_value; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private object GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrRvStdev.cs b/RdlEngine/Functions/FunctionAggrRvStdev.cs index da07430e..b37b56f1 100644 --- a/RdlEngine/Functions/FunctionAggrRvStdev.cs +++ b/RdlEngine/Functions/FunctionAggrRvStdev.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -56,12 +56,12 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateDouble(rpt, row); + return (object)await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -76,7 +76,7 @@ public double EvaluateDouble(Report rpt, Row row) } WorkClass wc = GetValue(rpt); - double currentValue = _Expr.EvaluateDouble(rpt, row); + double currentValue = await _Expr.EvaluateDouble(rpt, row); if (row == startrow) { // restart the group @@ -100,33 +100,33 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return decimal.MinValue; return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return int.MinValue; return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private WorkClass GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrRvStdevp.cs b/RdlEngine/Functions/FunctionAggrRvStdevp.cs index eefca483..90d6ec6f 100644 --- a/RdlEngine/Functions/FunctionAggrRvStdevp.cs +++ b/RdlEngine/Functions/FunctionAggrRvStdevp.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -56,12 +56,12 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateDouble(rpt, row); + return (object)await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -76,7 +76,7 @@ public double EvaluateDouble(Report rpt, Row row) } WorkClass wc = GetValue(rpt); - double currentValue = _Expr.EvaluateDouble(rpt, row); + double currentValue = await _Expr.EvaluateDouble(rpt, row); if (row == startrow) { // restart the group @@ -100,33 +100,33 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return decimal.MinValue; return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return int.MinValue; return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private WorkClass GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrRvSum.cs b/RdlEngine/Functions/FunctionAggrRvSum.cs index fefc560d..daa19e25 100644 --- a/RdlEngine/Functions/FunctionAggrRvSum.cs +++ b/RdlEngine/Functions/FunctionAggrRvSum.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -64,12 +64,12 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return _tc==TypeCode.Decimal? (object) EvaluateDecimal(rpt, row): (object) EvaluateDouble(rpt, row); + return _tc==TypeCode.Decimal? (object)await EvaluateDecimal(rpt, row): (object)await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -83,7 +83,7 @@ public double EvaluateDouble(Report rpt, Row row) break; } - double currentValue = _Expr.EvaluateDouble(rpt, row); + double currentValue = await _Expr.EvaluateDouble(rpt, row); WorkClass wc = GetValue(rpt); if (row == startrow) { @@ -96,7 +96,7 @@ public double EvaluateDouble(Report rpt, Row row) return (double) wc.Value; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { bool bSave; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -111,7 +111,7 @@ public decimal EvaluateDecimal(Report rpt, Row row) } WorkClass wc = GetValue(rpt); - decimal currentValue = _Expr.EvaluateDecimal(rpt, row); + decimal currentValue = await _Expr.EvaluateDecimal(rpt, row); if (row == startrow) { // must be the start of a new group @@ -123,21 +123,21 @@ public decimal EvaluateDecimal(Report rpt, Row row) return (decimal) wc.Value; } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private WorkClass GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrRvVar.cs b/RdlEngine/Functions/FunctionAggrRvVar.cs index b246c9b1..11ea51de 100644 --- a/RdlEngine/Functions/FunctionAggrRvVar.cs +++ b/RdlEngine/Functions/FunctionAggrRvVar.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -56,12 +56,12 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateDouble(rpt, row); + return (object)await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -76,7 +76,7 @@ public double EvaluateDouble(Report rpt, Row row) } WorkClass wc = GetValue(rpt); - double currentValue = _Expr.EvaluateDouble(rpt, row); + double currentValue = await _Expr.EvaluateDouble(rpt, row); if (row == startrow) { // restart the group @@ -100,33 +100,33 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return decimal.MinValue; return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return int.MinValue; return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private WorkClass GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrRvVarp.cs b/RdlEngine/Functions/FunctionAggrRvVarp.cs index 3f195c05..2db0c0f2 100644 --- a/RdlEngine/Functions/FunctionAggrRvVarp.cs +++ b/RdlEngine/Functions/FunctionAggrRvVarp.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -56,12 +56,12 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (object) EvaluateDouble(rpt, row); + return (object)await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -76,7 +76,7 @@ public double EvaluateDouble(Report rpt, Row row) } WorkClass wc = GetValue(rpt); - double currentValue = _Expr.EvaluateDouble(rpt, row); + double currentValue = await _Expr.EvaluateDouble(rpt, row); if (row == startrow) { // restart the group @@ -100,33 +100,33 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return decimal.MinValue; return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return int.MinValue; return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private WorkClass GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrStdev.cs b/RdlEngine/Functions/FunctionAggrStdev.cs index 173b8186..65182af0 100644 --- a/RdlEngine/Functions/FunctionAggrStdev.cs +++ b/RdlEngine/Functions/FunctionAggrStdev.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -60,15 +60,15 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return null; return (object) d; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -85,7 +85,7 @@ public double EvaluateDouble(Report rpt, Row row) double temp; foreach (Row r in re) { - temp = _Expr.EvaluateDouble(rpt, r); + temp = await _Expr.EvaluateDouble(rpt, r); if (temp.CompareTo(double.NaN) != 0) { sum += temp; @@ -108,35 +108,35 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return decimal.MinValue; return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return int.MinValue; return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); if (result.CompareTo(double.NaN) == 0) return null; return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrStdevp.cs b/RdlEngine/Functions/FunctionAggrStdevp.cs index 5498df20..74a535a2 100644 --- a/RdlEngine/Functions/FunctionAggrStdevp.cs +++ b/RdlEngine/Functions/FunctionAggrStdevp.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -61,15 +61,15 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return null; return (object) d; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -86,7 +86,7 @@ public double EvaluateDouble(Report rpt, Row row) double temp; foreach (Row r in re) { - temp = _Expr.EvaluateDouble(rpt, r); + temp = await _Expr.EvaluateDouble(rpt, r); if (temp.CompareTo(double.NaN) != 0) { sum += temp; @@ -109,35 +109,35 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return decimal.MinValue; return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return int.MinValue; return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); if (result.CompareTo(double.NaN) == 0) return null; return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrSum.cs b/RdlEngine/Functions/FunctionAggrSum.cs index 6bbe2996..8da4678f 100644 --- a/RdlEngine/Functions/FunctionAggrSum.cs +++ b/RdlEngine/Functions/FunctionAggrSum.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Linq; using System.Reflection; using System.Threading; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -62,21 +63,21 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { switch (_tc) { case TypeCode.Decimal: - return (object) EvaluateDecimal(rpt, row); + return (object)await EvaluateDecimal(rpt, row); case TypeCode.Object: return EvaluateObject(rpt, row); case TypeCode.Double: default: - return (object) EvaluateDouble(rpt, row); + return (object)await EvaluateDouble(rpt, row); } } - public object EvaluateObject(Report rpt, Row row) + public async Task EvaluateObject(Report rpt, Row row) { bool bSave; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -92,7 +93,7 @@ public object EvaluateObject(Report rpt, Row row) foreach (Row r in re) { - temp = _Expr.Evaluate(rpt, r); + temp = await _Expr.Evaluate(rpt, r); if (temp != null) { if (sum != null) @@ -108,7 +109,7 @@ public object EvaluateObject(Report rpt, Row row) } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -123,7 +124,7 @@ public double EvaluateDouble(Report rpt, Row row) double temp; foreach (Row r in re) { - temp = _Expr.EvaluateDouble(rpt, r); + temp = await _Expr.EvaluateDouble(rpt, r); if (temp.CompareTo(double.NaN) != 0) sum += temp; } @@ -133,13 +134,13 @@ public double EvaluateDouble(Report rpt, Row row) return sum; } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToInt32(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { bool bSave; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -154,7 +155,7 @@ public decimal EvaluateDecimal(Report rpt, Row row) decimal temp; foreach (Row r in re) { - temp = _Expr.EvaluateDecimal(rpt, r); + temp = await _Expr.EvaluateDecimal(rpt, r); if (temp != decimal.MinValue) // indicate null value sum += temp; } @@ -164,15 +165,15 @@ public decimal EvaluateDecimal(Report rpt, Row row) return sum; } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } diff --git a/RdlEngine/Functions/FunctionAggrVar.cs b/RdlEngine/Functions/FunctionAggrVar.cs index b08de47c..360bd277 100644 --- a/RdlEngine/Functions/FunctionAggrVar.cs +++ b/RdlEngine/Functions/FunctionAggrVar.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,15 +57,15 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return null; return (object) d; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -82,7 +82,7 @@ public double EvaluateDouble(Report rpt, Row row) double temp; foreach (Row r in re) { - temp = _Expr.EvaluateDouble(rpt, r); + temp = await _Expr.EvaluateDouble(rpt, r); if (temp.CompareTo(double.NaN) != 0) { sum += temp; @@ -104,35 +104,35 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return decimal.MinValue; return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return int.MinValue; return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); if (result.CompareTo(double.NaN) == 0) return null; return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private ODouble GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAggrVarp.cs b/RdlEngine/Functions/FunctionAggrVarp.cs index 5c2b38fe..45ed392f 100644 --- a/RdlEngine/Functions/FunctionAggrVarp.cs +++ b/RdlEngine/Functions/FunctionAggrVarp.cs @@ -26,7 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Reflection; using System.Threading; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,15 +57,15 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return null; return (object) d; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { bool bSave=true; IEnumerable re = this.GetDataScope(rpt, row, out bSave); @@ -82,7 +82,7 @@ public double EvaluateDouble(Report rpt, Row row) double temp; foreach (Row r in re) { - temp = _Expr.EvaluateDouble(rpt, r); + temp = await _Expr.EvaluateDouble(rpt, r); if (temp.CompareTo(double.NaN) != 0) { sum += temp; @@ -102,35 +102,35 @@ public double EvaluateDouble(Report rpt, Row row) return result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return decimal.MinValue; return Convert.ToDecimal(d); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double d = EvaluateDouble(rpt, row); + double d = await EvaluateDouble(rpt, row); if (d.CompareTo(double.NaN) == 0) return int.MinValue; return Convert.ToInt32(d); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); if (result.CompareTo(double.NaN) == 0) return null; return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } private ODouble GetValue(Report rpt) diff --git a/RdlEngine/Functions/FunctionAnd.cs b/RdlEngine/Functions/FunctionAnd.cs index 60d39c9d..3a09127f 100644 --- a/RdlEngine/Functions/FunctionAnd.cs +++ b/RdlEngine/Functions/FunctionAnd.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,20 +51,20 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } else if (bRightConst) { - bool b = _rhs.EvaluateBoolean(null, null); + bool b = await _rhs.EvaluateBoolean(null, null); if (b) return _lhs; else @@ -73,7 +72,7 @@ public IExpr ConstantOptimization() } else if (bLeftConst) { - bool b = _lhs.EvaluateBoolean(null, null); + bool b = await _lhs.EvaluateBoolean(null, null); if (b) return _rhs; else @@ -84,43 +83,43 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Double.NaN; + return Task.FromResult(Double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - bool r = _lhs.EvaluateBoolean(rpt, row); + bool r = await _lhs.EvaluateBoolean(rpt, row); if (!r) return false; - return _rhs.EvaluateBoolean(rpt, row); + return await _rhs.EvaluateBoolean(rpt, row); } } } diff --git a/RdlEngine/Functions/FunctionBinary.cs b/RdlEngine/Functions/FunctionBinary.cs index e11630b8..d6f4982a 100644 --- a/RdlEngine/Functions/FunctionBinary.cs +++ b/RdlEngine/Functions/FunctionBinary.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -55,10 +54,10 @@ public FunctionBinary(IExpr l, IExpr r) _rhs = r; } - public bool IsConstant() + public async Task IsConstant() { - if (_lhs.IsConstant()) - return _rhs.IsConstant(); + if (await _lhs.IsConstant()) + return await _rhs.IsConstant(); return false; } diff --git a/RdlEngine/Functions/FunctionChoose.cs b/RdlEngine/Functions/FunctionChoose.cs index 09518850..72e49652 100644 --- a/RdlEngine/Functions/FunctionChoose.cs +++ b/RdlEngine/Functions/FunctionChoose.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,26 +56,26 @@ public TypeCode GetTypeCode() return _tc; } - public bool IsConstant() + public Task IsConstant() { - return false; // we could be more sophisticated here; but not much benefit + return Task.FromResult(false); // we could be more sophisticated here; but not much benefit } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { // simplify all expression if possible for (int i=0; i < _expr.Length; i++) { - _expr[i] = _expr[i].ConstantOptimization(); + _expr[i] = await _expr[i].ConstantOptimization(); } return this; } // - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - double di = _expr[0].EvaluateDouble(rpt, row); + double di = await _expr[0].EvaluateDouble(rpt, row); int i = (int) di; // force it to integer; we'll accept truncation if (i >= _expr.Length || i <= 0) return null; @@ -84,39 +83,39 @@ public object Evaluate(Report rpt, Row row) return _expr[i].Evaluate(rpt, row); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToBoolean(result); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } } diff --git a/RdlEngine/Functions/FunctionCode.cs b/RdlEngine/Functions/FunctionCode.cs index 9a1c8feb..a330fd2a 100644 --- a/RdlEngine/Functions/FunctionCode.cs +++ b/RdlEngine/Functions/FunctionCode.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Reflection; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -65,18 +66,18 @@ public TypeCode GetTypeCode() return _ReturnTypeCode; } - public bool IsConstant() + public Task IsConstant() { - return false; // Can't know what the function does + return Task.FromResult(false); // Can't know what the function does } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { // Do constant optimization on all the arguments for (int i=0; i < _Args.GetLength(0); i++) { IExpr e = (IExpr)_Args[i]; - _Args[i] = e.ConstantOptimization(); + _Args[i] = await e.ConstantOptimization(); } // Can't assume that the function doesn't vary @@ -85,7 +86,7 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { if (rpt == null || rpt.CodeInstance == null) return null; @@ -97,7 +98,7 @@ public object Evaluate(Report rpt, Row row) bool bNull = false; foreach(IExpr a in _Args) { - argResults[i] = a.Evaluate(rpt, row); + argResults[i] = await a.Evaluate(rpt, row); if (argResults[i] == null) bNull = true; else if (argResults[i].GetType() != _ArgTypes[i]) @@ -123,35 +124,35 @@ public object Evaluate(Report rpt, Row row) return returnVal; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(Evaluate(rpt, row)); + return Convert.ToDouble(await Evaluate(rpt, row)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(Evaluate(rpt, row)); + return Convert.ToDecimal(await Evaluate(rpt, row)); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(Evaluate(rpt, row)); + return Convert.ToInt32(await Evaluate(rpt, row)); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } public string Func diff --git a/RdlEngine/Functions/FunctionCustomInstance.cs b/RdlEngine/Functions/FunctionCustomInstance.cs index 2062ee56..a3e85e9a 100644 --- a/RdlEngine/Functions/FunctionCustomInstance.cs +++ b/RdlEngine/Functions/FunctionCustomInstance.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Reflection; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -69,18 +70,18 @@ public TypeCode GetTypeCode() return _ReturnTypeCode; } - public bool IsConstant() + public Task IsConstant() { - return false; // Can't know what the function does + return Task.FromResult(false); // Can't know what the function does } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { // Do constant optimization on all the arguments for (int i=0; i < _Args.GetLength(0); i++) { IExpr e = (IExpr)_Args[i]; - _Args[i] = e.ConstantOptimization(); + _Args[i] = await e.ConstantOptimization(); } // Can't assume that the function doesn't vary @@ -89,7 +90,7 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { // get the results object[] argResults = new object[_Args.Length]; @@ -98,7 +99,7 @@ public object Evaluate(Report rpt, Row row) bool bNull = false; foreach(IExpr a in _Args) { - argResults[i] = a.Evaluate(rpt, row); + argResults[i] = await a.Evaluate(rpt, row); if (argResults[i] == null) bNull = true; else if (argResults[i].GetType() != _ArgTypes[i]) @@ -126,35 +127,35 @@ public object Evaluate(Report rpt, Row row) return returnVal; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(Evaluate(rpt, row)); + return Convert.ToDouble(await Evaluate(rpt, row)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(Evaluate(rpt, row)); + return Convert.ToDecimal(await Evaluate(rpt, row)); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(Evaluate(rpt, row)); + return Convert.ToInt32(await Evaluate(rpt, row)); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } public string Cls diff --git a/RdlEngine/Functions/FunctionCustomStatic.cs b/RdlEngine/Functions/FunctionCustomStatic.cs index 23909a68..61c4bdac 100644 --- a/RdlEngine/Functions/FunctionCustomStatic.cs +++ b/RdlEngine/Functions/FunctionCustomStatic.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; +using System.Threading.Tasks; using RdlEngine.Resources; @@ -67,18 +68,18 @@ public TypeCode GetTypeCode() return _ReturnTypeCode; } - public bool IsConstant() + public Task IsConstant() { - return false; // Can't know what the function does + return Task.FromResult(false); // Can't know what the function does } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { // Do constant optimization on all the arguments for (int i=0; i < _Args.GetLength(0); i++) { IExpr e = (IExpr)_Args[i]; - _Args[i] = e.ConstantOptimization(); + _Args[i] = await e.ConstantOptimization(); } // Can't assume that the function doesn't vary @@ -87,7 +88,7 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { // get the results object[] argResults = new object[_Args.Length]; @@ -95,7 +96,7 @@ public object Evaluate(Report rpt, Row row) bool bUseArg=true; foreach(IExpr a in _Args) { - argResults[i] = a.Evaluate(rpt, row); + argResults[i] = await a.Evaluate(rpt, row); if (argResults[i] != null && argResults[i].GetType() != _ArgTypes[i]) bUseArg = false; i++; @@ -119,35 +120,35 @@ public object Evaluate(Report rpt, Row row) return returnVal; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(Evaluate(rpt, row)); + return Convert.ToDouble(await Evaluate(rpt, row)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(Evaluate(rpt, row)); + return Convert.ToDecimal(await Evaluate(rpt, row)); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(Evaluate(rpt, row)); + return Convert.ToInt32(await Evaluate(rpt, row)); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } public string Cls diff --git a/RdlEngine/Functions/FunctionDiv.cs b/RdlEngine/Functions/FunctionDiv.cs index ad3641aa..d073fbbf 100644 --- a/RdlEngine/Functions/FunctionDiv.cs +++ b/RdlEngine/Functions/FunctionDiv.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -56,26 +55,26 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - double d = EvaluateDouble(null, null); + double d = await EvaluateDouble(null, null); return new ConstantDouble(d); } else if (bRightConst) { - double d = _rhs.EvaluateDouble(null, null); + double d = await _rhs.EvaluateDouble(null, null); if (d == 1) return _lhs; } else if (bLeftConst) { - double d = _lhs.EvaluateDouble(null, null); + double d = await _lhs.EvaluateDouble(null, null); if (d == 0) return new ConstantDouble(0); } @@ -84,48 +83,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDouble(rpt, row); + return await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - double lhs = _lhs.EvaluateDouble(rpt, row); - double rhs = _rhs.EvaluateDouble(rpt, row); + double lhs = await _lhs.EvaluateDouble(rpt, row); + double rhs = await _rhs.EvaluateDouble(rpt, row); return lhs/rhs; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionDivDecimal.cs b/RdlEngine/Functions/FunctionDivDecimal.cs index ce8d40b4..11d50666 100644 --- a/RdlEngine/Functions/FunctionDivDecimal.cs +++ b/RdlEngine/Functions/FunctionDivDecimal.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,26 +56,26 @@ public TypeCode GetTypeCode() return TypeCode.Decimal; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - decimal d = EvaluateDecimal(null, null); + decimal d = await EvaluateDecimal(null, null); return new ConstantDecimal(d); } else if (bRightConst) { - decimal d = _rhs.EvaluateDecimal(null, null); + decimal d = await _rhs.EvaluateDecimal(null, null); if (d == 1m) return _lhs; } else if (bLeftConst) { - decimal d = _lhs.EvaluateDecimal(null, null); + decimal d = await _lhs.EvaluateDecimal(null, null); if (d == 0) return new ConstantDecimal(0m); } @@ -85,48 +84,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDecimal(rpt, row); + return await EvaluateDecimal(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDouble(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToInt32(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - decimal lhs = _lhs.EvaluateDecimal(rpt, row); - decimal rhs = _rhs.EvaluateDecimal(rpt, row); + decimal lhs = await _lhs.EvaluateDecimal(rpt, row); + decimal rhs = await _rhs.EvaluateDecimal(rpt, row); return (decimal) (lhs/rhs); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionExecutionTime.cs b/RdlEngine/Functions/FunctionExecutionTime.cs index 1de7a934..69b83d81 100644 --- a/RdlEngine/Functions/FunctionExecutionTime.cs +++ b/RdlEngine/Functions/FunctionExecutionTime.cs @@ -22,7 +22,7 @@ the website www.fyiReporting.com. */ using System; using System.IO; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -46,56 +46,56 @@ public TypeCode GetTypeCode() return TypeCode.DateTime; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // not a constant expression - return this; + return Task.FromResult(this as IExpr); } // Evaluate is for interpretation - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDateTime(rpt, row); + return await EvaluateDateTime(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - DateTime result = EvaluateDateTime(rpt, row); + DateTime result = await EvaluateDateTime(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - DateTime result = EvaluateDateTime(rpt, row); + DateTime result = await EvaluateDateTime(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - DateTime result = EvaluateDateTime(rpt, row); + DateTime result = await EvaluateDateTime(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - DateTime result = EvaluateDateTime(rpt, row); + DateTime result = await EvaluateDateTime(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return rpt.ExecutionTime; + return Task.FromResult(rpt.ExecutionTime); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } } } diff --git a/RdlEngine/Functions/FunctionExp.cs b/RdlEngine/Functions/FunctionExp.cs index 1e0fe8c4..d1486c8f 100644 --- a/RdlEngine/Functions/FunctionExp.cs +++ b/RdlEngine/Functions/FunctionExp.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -56,26 +55,26 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - double d = EvaluateDouble(null, null); + double d = await EvaluateDouble(null, null); return new ConstantDouble(d); } else if (bRightConst) { - double d = _rhs.EvaluateDouble(null, null); + double d = await _rhs.EvaluateDouble(null, null); if (d == 1) return _lhs; } else if (bLeftConst) { - double d = _lhs.EvaluateDouble(null, null); + double d = await _lhs.EvaluateDouble(null, null); if (d == 0) return new ConstantDouble(0); } @@ -84,48 +83,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDouble(rpt, row); + return await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - double lhs = _lhs.EvaluateDouble(rpt, row); - double rhs = _rhs.EvaluateDouble(rpt, row); + double lhs = await _lhs.EvaluateDouble(rpt, row); + double rhs = await _rhs.EvaluateDouble(rpt, row); return Math.Pow(lhs,rhs); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionField.cs b/RdlEngine/Functions/FunctionField.cs index a13cc181..a42d2f62 100644 --- a/RdlEngine/Functions/FunctionField.cs +++ b/RdlEngine/Functions/FunctionField.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Globalization; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -69,27 +70,27 @@ public virtual Field Fld set { f = value; } } - public virtual bool IsConstant() + public virtual Task IsConstant() { - return false; + return Task.FromResult(false); } - public virtual IExpr ConstantOptimization() + public virtual async Task ConstantOptimization() { if (f.Value != null) - return f.Value.ConstantOptimization(); + return await f.Value.ConstantOptimization(); return this; // not a constant } // - public virtual object Evaluate(Report rpt, Row row) + public virtual async Task Evaluate(Report rpt, Row row) { if (row == null) return null; object o; if (f.Value != null) - o = f.Value.Evaluate(rpt, row); + o = await f.Value.Evaluate(rpt, row); else o = row.Data[f.ColumnNumber]; @@ -125,49 +126,49 @@ private bool IsNumericType(TypeCode tc) } } - public virtual double EvaluateDouble(Report rpt, Row row) + public virtual async Task EvaluateDouble(Report rpt, Row row) { if (row == null) return Double.NaN; - return Convert.ToDouble(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDouble(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual decimal EvaluateDecimal(Report rpt, Row row) + public virtual async Task EvaluateDecimal(Report rpt, Row row) { if (row == null) return decimal.MinValue; - var value = Evaluate(rpt, row); + var value = await Evaluate(rpt, row); if (value is double && double.IsNaN((double)value)) return decimal.MinValue; return Convert.ToDecimal(value, NumberFormatInfo.InvariantInfo); } - public virtual int EvaluateInt32(Report rpt, Row row) + public virtual async Task EvaluateInt32(Report rpt, Row row) { if (row == null) return int.MinValue; - return Convert.ToInt32(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToInt32(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual string EvaluateString(Report rpt, Row row) + public virtual async Task EvaluateString(Report rpt, Row row) { if (row == null) return null; - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public virtual DateTime EvaluateDateTime(Report rpt, Row row) + public virtual async Task EvaluateDateTime(Report rpt, Row row) { if (row == null) return DateTime.MinValue; - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public virtual bool EvaluateBoolean(Report rpt, Row row) + public virtual async Task EvaluateBoolean(Report rpt, Row row) { if (row == null) return false; - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } } } diff --git a/RdlEngine/Functions/FunctionFieldCollection.cs b/RdlEngine/Functions/FunctionFieldCollection.cs index 42b3afc9..0b9360ea 100644 --- a/RdlEngine/Functions/FunctionFieldCollection.cs +++ b/RdlEngine/Functions/FunctionFieldCollection.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Globalization; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -54,18 +55,18 @@ public virtual TypeCode GetTypeCode() return TypeCode.Object; // we don't know the typecode until we run the function } - public virtual bool IsConstant() + public virtual Task IsConstant() { - return false; + return Task.FromResult(false); } - public virtual IExpr ConstantOptimization() + public virtual async Task ConstantOptimization() { - _ArgExpr = _ArgExpr.ConstantOptimization(); + _ArgExpr = await _ArgExpr.ConstantOptimization(); - if (_ArgExpr.IsConstant()) + if (await _ArgExpr.IsConstant()) { - string o = _ArgExpr.EvaluateString(null, null); + string o = await _ArgExpr.EvaluateString(null, null); if (o == null) throw new Exception(Strings.FunctionFieldCollection_Error_FieldCollectionNull); Field f = _Fields[o] as Field; @@ -78,12 +79,12 @@ public virtual IExpr ConstantOptimization() } // - public virtual object Evaluate(Report rpt, Row row) + public virtual async Task Evaluate(Report rpt, Row row) { if (row == null) return null; Field f; - string field = _ArgExpr.EvaluateString(rpt, row); + string field = await _ArgExpr.EvaluateString(rpt, row); if (field == null) return null; f = _Fields[field] as Field; @@ -92,7 +93,7 @@ public virtual object Evaluate(Report rpt, Row row) object o; if (f.Value != null) - o = f.Value.Evaluate(rpt, row); + o = await f.Value.Evaluate(rpt, row); else o = row.Data[f.ColumnNumber]; @@ -105,46 +106,46 @@ public virtual object Evaluate(Report rpt, Row row) return o; } - public virtual double EvaluateDouble(Report rpt, Row row) + public virtual async Task EvaluateDouble(Report rpt, Row row) { if (row == null) return Double.NaN; - return Convert.ToDouble(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDouble(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual decimal EvaluateDecimal(Report rpt, Row row) + public virtual async Task EvaluateDecimal(Report rpt, Row row) { if (row == null) return decimal.MinValue; - return Convert.ToDecimal(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDecimal(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual int EvaluateInt32(Report rpt, Row row) + public virtual async Task EvaluateInt32(Report rpt, Row row) { if (row == null) return int.MinValue; - return Convert.ToInt32(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToInt32(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual string EvaluateString(Report rpt, Row row) + public virtual async Task EvaluateString(Report rpt, Row row) { if (row == null) return null; - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public virtual DateTime EvaluateDateTime(Report rpt, Row row) + public virtual async Task EvaluateDateTime(Report rpt, Row row) { if (row == null) return DateTime.MinValue; - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public virtual bool EvaluateBoolean(Report rpt, Row row) + public virtual async Task EvaluateBoolean(Report rpt, Row row) { if (row == null) return false; - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } } } diff --git a/RdlEngine/Functions/FunctionFieldIsMissing.cs b/RdlEngine/Functions/FunctionFieldIsMissing.cs index 74e20381..871f8a70 100644 --- a/RdlEngine/Functions/FunctionFieldIsMissing.cs +++ b/RdlEngine/Functions/FunctionFieldIsMissing.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,45 +51,45 @@ public override TypeCode GetTypeCode() return TypeCode.Boolean; } - public override bool IsConstant() + public override Task IsConstant() { - return false; + return Task.FromResult(false); } - public override IExpr ConstantOptimization() + public override Task ConstantOptimization() { - return this; // not a constant + return Task.FromResult(this as IExpr); // not a constant } // - public override object Evaluate(Report rpt, Row row) + public override async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public override double EvaluateDouble(Report rpt, Row row) + public override async Task EvaluateDouble(Report rpt, Row row) { - return EvaluateBoolean(rpt, row)? 1: 0; + return await EvaluateBoolean(rpt, row)? 1: 0; } - public override decimal EvaluateDecimal(Report rpt, Row row) + public override async Task EvaluateDecimal(Report rpt, Row row) { - return EvaluateBoolean(rpt, row)? 1m: 0m; + return await EvaluateBoolean(rpt, row)? 1m: 0m; } - public override string EvaluateString(Report rpt, Row row) + public override async Task EvaluateString(Report rpt, Row row) { - return EvaluateBoolean(rpt, row)? "True": "False"; + return await EvaluateBoolean(rpt, row)? "True": "False"; } - public override DateTime EvaluateDateTime(Report rpt, Row row) + public override Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } - public override bool EvaluateBoolean(Report rpt, Row row) + public override async Task EvaluateBoolean(Report rpt, Row row) { - object o = base.Evaluate(rpt, row); + object o = await base.Evaluate(rpt, row); if(o is double) return double.IsNaN((double)o) ? true : false; else diff --git a/RdlEngine/Functions/FunctionFormat.cs b/RdlEngine/Functions/FunctionFormat.cs index 214d6aeb..5bd515cc 100644 --- a/RdlEngine/Functions/FunctionFormat.cs +++ b/RdlEngine/Functions/FunctionFormat.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -54,64 +53,64 @@ public TypeCode GetTypeCode() } // - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateString(rpt, row); + return await EvaluateString(rpt, row); } - public bool IsConstant() + public async Task IsConstant() { - if (_Formatee.IsConstant()) - return _Format.IsConstant(); + if (await _Formatee.IsConstant()) + return await _Format.IsConstant(); return false; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _Formatee = _Formatee.ConstantOptimization(); - _Format = _Format.ConstantOptimization(); - if (_Formatee.IsConstant() && _Format.IsConstant()) + _Formatee = await _Formatee.ConstantOptimization(); + _Format = await _Format.ConstantOptimization(); + if (await _Formatee.IsConstant() && await _Format.IsConstant()) { - string s = EvaluateString(null, null); + string s = await EvaluateString(null, null); return new ConstantString(s); } return this; } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToBoolean(result); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object o = _Formatee.Evaluate(rpt, row); + object o = await _Formatee.Evaluate(rpt, row); if (o == null) return null; - string format = _Format.EvaluateString(rpt, row); + string format = await _Format.EvaluateString(rpt, row); if (format == null) return o.ToString(); // just return string version of object @@ -128,9 +127,9 @@ public string EvaluateString(Report rpt, Row row) return result; } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDateTime(result); } } diff --git a/RdlEngine/Functions/FunctionGlobalCollection.cs b/RdlEngine/Functions/FunctionGlobalCollection.cs index 2aff8107..a6ed0af5 100644 --- a/RdlEngine/Functions/FunctionGlobalCollection.cs +++ b/RdlEngine/Functions/FunctionGlobalCollection.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Globalization; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -54,18 +55,18 @@ public virtual TypeCode GetTypeCode() return TypeCode.Object; // we don't know the typecode until we run the function } - public virtual bool IsConstant() + public virtual Task IsConstant() { - return false; + return Task.FromResult(false); } - public virtual IExpr ConstantOptimization() + public virtual async Task ConstantOptimization() { - _ArgExpr = _ArgExpr.ConstantOptimization(); + _ArgExpr = await _ArgExpr.ConstantOptimization(); - if (_ArgExpr.IsConstant()) + if (await _ArgExpr.IsConstant()) { - string o = _ArgExpr.EvaluateString(null, null); + string o = await _ArgExpr.EvaluateString(null, null); if (o == null) throw new Exception(Strings.FunctionGlobalCollection_Error_GlobalsNull); switch (o.ToLower()) @@ -89,12 +90,12 @@ public virtual IExpr ConstantOptimization() } // - public virtual object Evaluate(Report rpt, Row row) + public virtual async Task Evaluate(Report rpt, Row row) { if (rpt == null) return null; - string g = _ArgExpr.EvaluateString(rpt, row); + string g = await _ArgExpr.EvaluateString(rpt, row); if (g == null) return null; @@ -115,46 +116,46 @@ public virtual object Evaluate(Report rpt, Row row) } } - public virtual double EvaluateDouble(Report rpt, Row row) + public virtual async Task EvaluateDouble(Report rpt, Row row) { if (row == null) return Double.NaN; - return Convert.ToDouble(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDouble(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual decimal EvaluateDecimal(Report rpt, Row row) + public virtual async Task EvaluateDecimal(Report rpt, Row row) { if (row == null) return decimal.MinValue; - return Convert.ToDecimal(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDecimal(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual int EvaluateInt32(Report rpt, Row row) + public virtual async Task EvaluateInt32(Report rpt, Row row) { if (row == null) return int.MinValue; - return Convert.ToInt32(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToInt32(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual string EvaluateString(Report rpt, Row row) + public virtual async Task EvaluateString(Report rpt, Row row) { if (row == null) return null; - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public virtual DateTime EvaluateDateTime(Report rpt, Row row) + public virtual async Task EvaluateDateTime(Report rpt, Row row) { if (row == null) return DateTime.MinValue; - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public virtual bool EvaluateBoolean(Report rpt, Row row) + public virtual async Task EvaluateBoolean(Report rpt, Row row) { if (row == null) return false; - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } } } diff --git a/RdlEngine/Functions/FunctionIif.cs b/RdlEngine/Functions/FunctionIif.cs index cf5b2391..d1064016 100644 --- a/RdlEngine/Functions/FunctionIif.cs +++ b/RdlEngine/Functions/FunctionIif.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -56,20 +55,20 @@ public TypeCode GetTypeCode() return _IfTrue.GetTypeCode(); } - public bool IsConstant() + public async Task IsConstant() { - return _If.IsConstant() && _IfTrue.IsConstant() && _IfFalse.IsConstant(); + return await _If.IsConstant() && await _IfTrue.IsConstant() && await _IfFalse.IsConstant(); } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _If = _If.ConstantOptimization(); - _IfTrue = _IfTrue.ConstantOptimization(); - _IfFalse = _IfFalse.ConstantOptimization(); + _If = await _If.ConstantOptimization(); + _IfTrue = await _IfTrue.ConstantOptimization(); + _IfFalse = await _IfFalse.ConstantOptimization(); - if (_If.IsConstant()) + if (await _If.IsConstant()) { - bool result = _If.EvaluateBoolean(null, null); + bool result = await _If.EvaluateBoolean(null, null); return result? _IfTrue: _IfFalse; } @@ -77,13 +76,13 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - bool result = _If.EvaluateBoolean(rpt, row); + bool result = await _If.EvaluateBoolean(rpt, row); if (result) - return _IfTrue.Evaluate(rpt, row); + return await _IfTrue.Evaluate(rpt, row); - object o = _IfFalse.Evaluate(rpt, row); + object o = await _IfFalse.Evaluate(rpt, row); // We may need to convert IfFalse to same type as IfTrue if (_IfTrue.GetTypeCode() == _IfFalse.GetTypeCode()) return o; @@ -91,39 +90,39 @@ public object Evaluate(Report rpt, Row row) return Convert.ChangeType(o, _IfTrue.GetTypeCode()); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToBoolean(result); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } } diff --git a/RdlEngine/Functions/FunctionMinus.cs b/RdlEngine/Functions/FunctionMinus.cs index 0815ca4f..81ccd150 100644 --- a/RdlEngine/Functions/FunctionMinus.cs +++ b/RdlEngine/Functions/FunctionMinus.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,21 +56,21 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - double d = EvaluateDouble(null, null); + double d = await EvaluateDouble(null, null); return new ConstantDouble(d); } else if (bRightConst) { - double d = _rhs.EvaluateDouble(null, null); + double d = await _rhs.EvaluateDouble(null, null); if (d == 0) return _lhs; } @@ -80,48 +79,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDouble(rpt, row); + return await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - double lhs = _lhs.EvaluateDouble(rpt, row); - double rhs = _rhs.EvaluateDouble(rpt, row); + double lhs = await _lhs.EvaluateDouble(rpt, row); + double rhs = await _rhs.EvaluateDouble(rpt, row); return lhs - rhs; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionMinusDecimal.cs b/RdlEngine/Functions/FunctionMinusDecimal.cs index 380f0d9d..6b539cad 100644 --- a/RdlEngine/Functions/FunctionMinusDecimal.cs +++ b/RdlEngine/Functions/FunctionMinusDecimal.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -58,20 +57,20 @@ public TypeCode GetTypeCode() return TypeCode.Decimal; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - decimal d = EvaluateDecimal(null, null); + decimal d = await EvaluateDecimal(null, null); return new ConstantDecimal(d); } else if (bRightConst) { - decimal d = _rhs.EvaluateDecimal(null, null); + decimal d = await _rhs.EvaluateDecimal(null, null); if (d == 0m) return _lhs; } @@ -80,48 +79,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDecimal(rpt, row); + return await EvaluateDecimal(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDouble(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToInt32(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - decimal lhs = _lhs.EvaluateDecimal(rpt, row); - decimal rhs = _rhs.EvaluateDecimal(rpt, row); + decimal lhs = await _lhs.EvaluateDecimal(rpt, row); + decimal rhs = await _rhs.EvaluateDecimal(rpt, row); return (decimal) (lhs-rhs); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionMinusInt32.cs b/RdlEngine/Functions/FunctionMinusInt32.cs index f1da8d09..d26bf828 100644 --- a/RdlEngine/Functions/FunctionMinusInt32.cs +++ b/RdlEngine/Functions/FunctionMinusInt32.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -58,20 +57,20 @@ public TypeCode GetTypeCode() return TypeCode.Int32; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - int d = EvaluateInt32(null, null); + int d = await EvaluateInt32(null, null); return new ConstantInteger(d); } else if (bRightConst) { - int d = _rhs.EvaluateInt32(null, null); + int d = await _rhs.EvaluateInt32(null, null); if (d == 0) return _lhs; } @@ -80,48 +79,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateInt32(rpt, row); + return await EvaluateInt32(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDouble(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - int lhs = _lhs.EvaluateInt32(rpt, row); - int rhs = _rhs.EvaluateInt32(rpt, row); + int lhs = await _lhs.EvaluateInt32(rpt, row); + int rhs = await _rhs.EvaluateInt32(rpt, row); return (lhs - rhs); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDecimal(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionModulus.cs b/RdlEngine/Functions/FunctionModulus.cs index a2e073a7..a3e2bf7a 100644 --- a/RdlEngine/Functions/FunctionModulus.cs +++ b/RdlEngine/Functions/FunctionModulus.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,26 +51,26 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - double d = EvaluateDouble(null, null); + double d = await EvaluateDouble(null, null); return new ConstantDouble(d); } else if (bRightConst) { - double d = _rhs.EvaluateDouble(null, null); + double d = await _rhs.EvaluateDouble(null, null); if (d == 1) return _lhs; } else if (bLeftConst) { - double d = _lhs.EvaluateDouble(null, null); + double d = await _lhs.EvaluateDouble(null, null); if (d == 0) return new ConstantDouble(0); } @@ -80,50 +79,50 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDouble(rpt, row); + return await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - double lhs = _lhs.EvaluateDouble(rpt, row); - double rhs = _rhs.EvaluateDouble(rpt, row); + double lhs = await _lhs.EvaluateDouble(rpt, row); + double rhs = await _rhs.EvaluateDouble(rpt, row); // n % d = n - d*INT(n/d) where INT rounds a number down to the nearest integer double temp = (int) (lhs/rhs); return lhs - (rhs*temp); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToInt32(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDecimal(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionMult.cs b/RdlEngine/Functions/FunctionMult.cs index 2008d8f3..930a1f62 100644 --- a/RdlEngine/Functions/FunctionMult.cs +++ b/RdlEngine/Functions/FunctionMult.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -58,20 +57,20 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - double d = EvaluateDouble(null, null); + double d = await EvaluateDouble(null, null); return new ConstantDouble(d); } else if (bLeftConst) { - double d = _lhs.EvaluateDouble(null, null); + double d = await _lhs.EvaluateDouble(null, null); if (d == 1) return _rhs; else if (d == 0) @@ -79,7 +78,7 @@ public IExpr ConstantOptimization() } else if (bRightConst) { - double d = _rhs.EvaluateDouble(null, null); + double d = await _rhs.EvaluateDouble(null, null); if (d == 1) return _lhs; else if (d == 0) @@ -90,48 +89,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDouble(rpt, row); + return await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - double lhs = _lhs.EvaluateDouble(rpt, row); - double rhs = _rhs.EvaluateDouble(rpt, row); + double lhs = await _lhs.EvaluateDouble(rpt, row); + double rhs = await _rhs.EvaluateDouble(rpt, row); return lhs*rhs; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionMultDecimal.cs b/RdlEngine/Functions/FunctionMultDecimal.cs index e2dbaf21..33d3f063 100644 --- a/RdlEngine/Functions/FunctionMultDecimal.cs +++ b/RdlEngine/Functions/FunctionMultDecimal.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -58,20 +57,20 @@ public TypeCode GetTypeCode() return TypeCode.Decimal; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - decimal d = EvaluateDecimal(null, null); + decimal d = await EvaluateDecimal(null, null); return new ConstantDecimal(d); } else if (bLeftConst) { - decimal d = _lhs.EvaluateDecimal(null, null); + decimal d = await _lhs.EvaluateDecimal(null, null); if (d == 1m) return _rhs; else if (d == 0m) @@ -79,7 +78,7 @@ public IExpr ConstantOptimization() } else if (bRightConst) { - decimal d = _rhs.EvaluateDecimal(null, null); + decimal d = await _rhs.EvaluateDecimal(null, null); if (d == 1m) return _lhs; else if (d == 0m) @@ -90,48 +89,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDecimal(rpt, row); + return await EvaluateDecimal(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDouble(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToInt32(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - decimal lhs = _lhs.EvaluateDecimal(rpt, row); - decimal rhs = _rhs.EvaluateDecimal(rpt, row); + decimal lhs = await _lhs.EvaluateDecimal(rpt, row); + decimal rhs = await _rhs.EvaluateDecimal(rpt, row); return (decimal) (lhs*rhs); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionNot.cs b/RdlEngine/Functions/FunctionNot.cs index 13adb662..e0366b36 100644 --- a/RdlEngine/Functions/FunctionNot.cs +++ b/RdlEngine/Functions/FunctionNot.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,17 +51,17 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public bool IsConstant() + public async Task IsConstant() { - return _rhs.IsConstant(); + return await _rhs.IsConstant(); } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _rhs = _rhs.ConstantOptimization(); - if (_rhs.IsConstant()) + _rhs = await _rhs.ConstantOptimization(); + if (await _rhs.IsConstant()) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } @@ -70,40 +69,40 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Double.NaN; + return Task.FromResult(Double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - return ! _rhs.EvaluateBoolean(rpt, row); + return !await _rhs.EvaluateBoolean(rpt, row); } } } diff --git a/RdlEngine/Functions/FunctionOr.cs b/RdlEngine/Functions/FunctionOr.cs index 826700ed..b65c9674 100644 --- a/RdlEngine/Functions/FunctionOr.cs +++ b/RdlEngine/Functions/FunctionOr.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,20 +51,20 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } else if (bRightConst) { - bool b = _rhs.EvaluateBoolean(null, null); + bool b = await _rhs.EvaluateBoolean(null, null); if (b) return new ConstantBoolean(true); else @@ -73,7 +72,7 @@ public IExpr ConstantOptimization() } else if (bLeftConst) { - bool b = _lhs.EvaluateBoolean(null, null); + bool b = await _lhs.EvaluateBoolean(null, null); if (b) return new ConstantBoolean(true); else @@ -84,43 +83,43 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Double.NaN; + return Task.FromResult(Double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - bool r = _lhs.EvaluateBoolean(rpt, row); + bool r = await _lhs.EvaluateBoolean(rpt, row); if (r) return true; - return _rhs.EvaluateBoolean(rpt, row); + return await _rhs.EvaluateBoolean(rpt, row); } } } diff --git a/RdlEngine/Functions/FunctionPageNumber.cs b/RdlEngine/Functions/FunctionPageNumber.cs index e2876ff2..807be2a8 100644 --- a/RdlEngine/Functions/FunctionPageNumber.cs +++ b/RdlEngine/Functions/FunctionPageNumber.cs @@ -22,7 +22,7 @@ the website www.fyiReporting.com. */ using System; using System.IO; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -46,54 +46,54 @@ public TypeCode GetTypeCode() return TypeCode.Int32; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // not a constant expression - return this; + return Task.FromResult(this as IExpr); } // Evaluate is for interpretation - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return rpt == null ? (int) 0 : (int) rpt.PageNumber; + return rpt == null ? Task.FromResult((int) 0 as object) : Task.FromResult((int) rpt.PageNumber as object); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return rpt == null? 0: rpt.PageNumber; + return rpt == null? Task.FromResult(0d): Task.FromResult((double)rpt.PageNumber); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return rpt == null ? 0 : rpt.PageNumber; + return rpt == null ? Task.FromResult(0) : Task.FromResult(rpt.PageNumber); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDecimal(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } } } diff --git a/RdlEngine/Functions/FunctionParameterCollection.cs b/RdlEngine/Functions/FunctionParameterCollection.cs index 9ba86523..1c7621ce 100644 --- a/RdlEngine/Functions/FunctionParameterCollection.cs +++ b/RdlEngine/Functions/FunctionParameterCollection.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Globalization; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -54,18 +55,18 @@ public virtual TypeCode GetTypeCode() return TypeCode.Object; // we don't know the typecode until we run the function } - public virtual bool IsConstant() + public virtual Task IsConstant() { - return false; + return Task.FromResult(false); } - public virtual IExpr ConstantOptimization() + public virtual async Task ConstantOptimization() { - _ArgExpr = _ArgExpr.ConstantOptimization(); + _ArgExpr = await _ArgExpr.ConstantOptimization(); - if (_ArgExpr.IsConstant()) + if (await _ArgExpr.IsConstant()) { - string o = _ArgExpr.EvaluateString(null, null); + string o = await _ArgExpr.EvaluateString(null, null); if (o == null) throw new Exception(Strings.FunctionParameterCollection_Error_ParameterCollectionNull); ReportParameter rp = _Parameters[o] as ReportParameter; @@ -78,9 +79,9 @@ public virtual IExpr ConstantOptimization() } // - public virtual object Evaluate(Report rpt, Row row) + public virtual async Task Evaluate(Report rpt, Row row) { - string o = _ArgExpr.EvaluateString(rpt, row); + string o = await _ArgExpr.EvaluateString(rpt, row); if (o == null) return null; ReportParameter rp = _Parameters[o] as ReportParameter; @@ -90,46 +91,46 @@ public virtual object Evaluate(Report rpt, Row row) return rp.GetRuntimeValue(rpt); } - public virtual double EvaluateDouble(Report rpt, Row row) + public virtual async Task EvaluateDouble(Report rpt, Row row) { if (row == null) return Double.NaN; - return Convert.ToDouble(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDouble(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual decimal EvaluateDecimal(Report rpt, Row row) + public virtual async Task EvaluateDecimal(Report rpt, Row row) { if (row == null) return decimal.MinValue; - return Convert.ToDecimal(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDecimal(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual int EvaluateInt32(Report rpt, Row row) + public virtual async Task EvaluateInt32(Report rpt, Row row) { if (row == null) return int.MinValue; - return Convert.ToInt32(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToInt32(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual string EvaluateString(Report rpt, Row row) + public virtual async Task EvaluateString(Report rpt, Row row) { if (row == null) return null; - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public virtual DateTime EvaluateDateTime(Report rpt, Row row) + public virtual async Task EvaluateDateTime(Report rpt, Row row) { if (row == null) return DateTime.MinValue; - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public virtual bool EvaluateBoolean(Report rpt, Row row) + public virtual async Task EvaluateBoolean(Report rpt, Row row) { if (row == null) return false; - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } } } diff --git a/RdlEngine/Functions/FunctionPlus.cs b/RdlEngine/Functions/FunctionPlus.cs index b338d740..d6f31257 100644 --- a/RdlEngine/Functions/FunctionPlus.cs +++ b/RdlEngine/Functions/FunctionPlus.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -55,26 +54,26 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - double d = EvaluateDouble(null, null); + double d = await EvaluateDouble(null, null); return new ConstantDouble(d); } else if (bRightConst) { - double d = _rhs.EvaluateDouble(null, null); + double d = await _rhs.EvaluateDouble(null, null); if (d == 0) return _lhs; } else if (bLeftConst) { - double d = _lhs.EvaluateDouble(null, null); + double d = await _lhs.EvaluateDouble(null, null); if (d == 0) return _rhs; } @@ -83,48 +82,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDouble(rpt, row); + return await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - double lhs = _lhs.EvaluateDouble(rpt, row); - double rhs = _rhs.EvaluateDouble(rpt, row); + double lhs = await _lhs.EvaluateDouble(rpt, row); + double rhs = await _rhs.EvaluateDouble(rpt, row); return lhs+rhs; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionPlusDecimal.cs b/RdlEngine/Functions/FunctionPlusDecimal.cs index 3220ec1e..5faf83e3 100644 --- a/RdlEngine/Functions/FunctionPlusDecimal.cs +++ b/RdlEngine/Functions/FunctionPlusDecimal.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -55,26 +54,26 @@ public TypeCode GetTypeCode() return TypeCode.Decimal; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - decimal d = EvaluateDecimal(null, null); + decimal d = await EvaluateDecimal(null, null); return new ConstantDecimal(d); } else if (bRightConst) { - decimal d = _rhs.EvaluateDecimal(null, null); + decimal d = await _rhs.EvaluateDecimal(null, null); if (d == 0m) return _lhs; } else if (bLeftConst) { - decimal d = _lhs.EvaluateDecimal(null, null); + decimal d = await _lhs.EvaluateDecimal(null, null); if (d == 0m) return _rhs; } @@ -83,48 +82,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDecimal(rpt, row); + return await EvaluateDecimal(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDouble(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToInt32(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - decimal lhs = _lhs.EvaluateDecimal(rpt, row); - decimal rhs = _rhs.EvaluateDecimal(rpt, row); + decimal lhs = await _lhs.EvaluateDecimal(rpt, row); + decimal rhs = await _rhs.EvaluateDecimal(rpt, row); return (decimal) (lhs+rhs); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionPlusInt32.cs b/RdlEngine/Functions/FunctionPlusInt32.cs index 54c812d8..3dcdb5db 100644 --- a/RdlEngine/Functions/FunctionPlusInt32.cs +++ b/RdlEngine/Functions/FunctionPlusInt32.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -55,26 +54,26 @@ public TypeCode GetTypeCode() return TypeCode.Int32; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - bool bLeftConst = _lhs.IsConstant(); - bool bRightConst = _rhs.IsConstant(); + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + bool bLeftConst = await _lhs.IsConstant(); + bool bRightConst = await _rhs.IsConstant(); if (bLeftConst && bRightConst) { - int d = EvaluateInt32(null, null); + int d = await EvaluateInt32(null, null); return new ConstantInteger(d); } else if (bRightConst) { - int d = _rhs.EvaluateInt32(null, null); + int d = await _rhs.EvaluateInt32(null, null); if (d == 0) return _lhs; } else if (bLeftConst) { - int d = _lhs.EvaluateInt32(null, null); + int d = await _lhs.EvaluateInt32(null, null); if (d == 0) return _rhs; } @@ -83,48 +82,48 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateInt32(rpt, row); + return await EvaluateInt32(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - int lhs = _lhs.EvaluateInt32(rpt, row); - int rhs = _rhs.EvaluateInt32(rpt, row); + int lhs = await _lhs.EvaluateInt32(rpt, row); + int rhs = await _rhs.EvaluateInt32(rpt, row); return (lhs+rhs); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionPlusString.cs b/RdlEngine/Functions/FunctionPlusString.cs index 5012a7e6..52c4bef6 100644 --- a/RdlEngine/Functions/FunctionPlusString.cs +++ b/RdlEngine/Functions/FunctionPlusString.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -53,47 +52,47 @@ public TypeCode GetTypeCode() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateString(rpt, row); + return await EvaluateString(rpt, row); } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - if (_lhs.IsConstant() && _rhs.IsConstant()) + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + if (await _lhs.IsConstant() && await _rhs.IsConstant()) { - string s = EvaluateString(null, null); + string s = await EvaluateString(null, null); return new ConstantString(s); } return this; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - string lhs = _lhs.EvaluateString(rpt, row); - string rhs = _rhs.EvaluateString(rpt, row); + string lhs = await _lhs.EvaluateString(rpt, row); + string rhs = await _rhs.EvaluateString(rpt, row); if (lhs != null && rhs != null) return lhs + rhs; @@ -101,15 +100,15 @@ public string EvaluateString(Report rpt, Row row) return null; } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionRelopEQ.cs b/RdlEngine/Functions/FunctionRelopEQ.cs index 897901d3..2a9f75d4 100644 --- a/RdlEngine/Functions/FunctionRelopEQ.cs +++ b/RdlEngine/Functions/FunctionRelopEQ.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -51,13 +50,13 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - if (_lhs.IsConstant() && _rhs.IsConstant()) + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + if (await _lhs.IsConstant() && await _rhs.IsConstant()) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } @@ -65,45 +64,45 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object left = _lhs.Evaluate(rpt, row); - object right = _rhs.Evaluate(rpt, row); + object left = await _lhs.Evaluate(rpt, row); + object right = await _rhs.Evaluate(rpt, row); if (Filter.ApplyCompare(_lhs.GetTypeCode(), left, right) == 0) return true; else return false; } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.NaN; + return Task.FromResult(double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } } } diff --git a/RdlEngine/Functions/FunctionRelopGT.cs b/RdlEngine/Functions/FunctionRelopGT.cs index f292a0a0..ec1440df 100644 --- a/RdlEngine/Functions/FunctionRelopGT.cs +++ b/RdlEngine/Functions/FunctionRelopGT.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -51,13 +50,13 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - if (_lhs.IsConstant() && _rhs.IsConstant()) + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + if (await _lhs.IsConstant() && await _rhs.IsConstant()) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } @@ -65,45 +64,45 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object left = _lhs.Evaluate(rpt, row); - object right = _rhs.Evaluate(rpt, row); + object left = await _lhs.Evaluate(rpt, row); + object right = await _rhs.Evaluate(rpt, row); if (Filter.ApplyCompare(_lhs.GetTypeCode(), left, right) > 0) return true; else return false; } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.NaN; + return Task.FromResult(double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } } } diff --git a/RdlEngine/Functions/FunctionRelopGTE.cs b/RdlEngine/Functions/FunctionRelopGTE.cs index d4874a64..99888678 100644 --- a/RdlEngine/Functions/FunctionRelopGTE.cs +++ b/RdlEngine/Functions/FunctionRelopGTE.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -51,13 +50,13 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - if (_lhs.IsConstant() && _rhs.IsConstant()) + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + if (await _lhs.IsConstant() && await _rhs.IsConstant()) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } @@ -65,45 +64,45 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object left = _lhs.Evaluate(rpt, row); - object right = _rhs.Evaluate(rpt, row); + object left = await _lhs.Evaluate(rpt, row); + object right = await _rhs.Evaluate(rpt, row); if (Filter.ApplyCompare(_lhs.GetTypeCode(), left, right) >= 0) return true; else return false; } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.NaN; + return Task.FromResult(double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } } } diff --git a/RdlEngine/Functions/FunctionRelopLT.cs b/RdlEngine/Functions/FunctionRelopLT.cs index 99033feb..e4919d0a 100644 --- a/RdlEngine/Functions/FunctionRelopLT.cs +++ b/RdlEngine/Functions/FunctionRelopLT.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -51,13 +50,13 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - if (_lhs.IsConstant() && _rhs.IsConstant()) + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + if (await _lhs.IsConstant() && await _rhs.IsConstant()) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } @@ -65,45 +64,45 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object left = _lhs.Evaluate(rpt, row); - object right = _rhs.Evaluate(rpt, row); + object left = await _lhs.Evaluate(rpt, row); + object right = await _rhs.Evaluate(rpt, row); if (Filter.ApplyCompare(_lhs.GetTypeCode(), left, right) < 0) return true; else return false; } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.NaN; + return Task.FromResult(double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } } } diff --git a/RdlEngine/Functions/FunctionRelopLTE.cs b/RdlEngine/Functions/FunctionRelopLTE.cs index 75d48993..8271e7ae 100644 --- a/RdlEngine/Functions/FunctionRelopLTE.cs +++ b/RdlEngine/Functions/FunctionRelopLTE.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -51,13 +50,13 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - if (_lhs.IsConstant() && _rhs.IsConstant()) + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + if (await _lhs.IsConstant() && await _rhs.IsConstant()) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } @@ -65,45 +64,45 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object left = _lhs.Evaluate(rpt, row); - object right = _rhs.Evaluate(rpt, row); + object left = await _lhs.Evaluate(rpt, row); + object right = await _rhs.Evaluate(rpt, row); if (Filter.ApplyCompare(_lhs.GetTypeCode(), left, right) <= 0) return true; else return false; } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.NaN; + return Task.FromResult(double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } } } diff --git a/RdlEngine/Functions/FunctionRelopNE.cs b/RdlEngine/Functions/FunctionRelopNE.cs index 619b00bd..0ce6bb97 100644 --- a/RdlEngine/Functions/FunctionRelopNE.cs +++ b/RdlEngine/Functions/FunctionRelopNE.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -51,13 +50,13 @@ public TypeCode GetTypeCode() return TypeCode.Boolean; } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _lhs = _lhs.ConstantOptimization(); - _rhs = _rhs.ConstantOptimization(); - if (_lhs.IsConstant() && _rhs.IsConstant()) + _lhs = await _lhs.ConstantOptimization(); + _rhs = await _rhs.ConstantOptimization(); + if (await _lhs.IsConstant() && await _rhs.IsConstant()) { - bool b = EvaluateBoolean(null, null); + bool b = await EvaluateBoolean(null, null); return new ConstantBoolean(b); } @@ -65,45 +64,45 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateBoolean(rpt, row); + return await EvaluateBoolean(rpt, row); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object left = _lhs.Evaluate(rpt, row); - object right = _rhs.Evaluate(rpt, row); + object left = await _lhs.Evaluate(rpt, row); + object right = await _rhs.Evaluate(rpt, row); if (Filter.ApplyCompare(_lhs.GetTypeCode(), left, right) != 0) return true; else return false; } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.NaN; + return Task.FromResult(double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - bool result = EvaluateBoolean(rpt, row); + bool result = await EvaluateBoolean(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } } } diff --git a/RdlEngine/Functions/FunctionReportFolder.cs b/RdlEngine/Functions/FunctionReportFolder.cs index 2592fd9a..227db618 100644 --- a/RdlEngine/Functions/FunctionReportFolder.cs +++ b/RdlEngine/Functions/FunctionReportFolder.cs @@ -22,7 +22,7 @@ the website www.fyiReporting.com. */ using System; using System.IO; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -46,50 +46,50 @@ public TypeCode GetTypeCode() return TypeCode.String; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // not a constant expression - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return rpt.Folder; + return Task.FromResult(rpt.Folder as object); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.NaN; + return Task.FromResult(double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Decimal.MinValue; + return Task.FromResult(Decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return rpt == null? "": rpt.Folder; + return rpt == null? Task.FromResult(""): Task.FromResult(rpt.Folder); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } } } diff --git a/RdlEngine/Functions/FunctionReportItemCollection.cs b/RdlEngine/Functions/FunctionReportItemCollection.cs index 2ebfe3ee..91cecc3a 100644 --- a/RdlEngine/Functions/FunctionReportItemCollection.cs +++ b/RdlEngine/Functions/FunctionReportItemCollection.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Globalization; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -54,18 +55,18 @@ public virtual TypeCode GetTypeCode() return TypeCode.Object; // we don't know the typecode until we run the function } - public virtual bool IsConstant() + public virtual Task IsConstant() { - return false; + return Task.FromResult(false); } - public virtual IExpr ConstantOptimization() + public virtual async Task ConstantOptimization() { - _ArgExpr = _ArgExpr.ConstantOptimization(); + _ArgExpr = await _ArgExpr.ConstantOptimization(); - if (_ArgExpr.IsConstant()) + if (await _ArgExpr.IsConstant()) { - string o = _ArgExpr.EvaluateString(null, null); + string o = await _ArgExpr.EvaluateString(null, null); if (o == null) throw new Exception(Strings.FunctionReportItemCollection_Error_ReportItemCollectionNull); Textbox ri = _ReportItems[o] as Textbox; @@ -78,12 +79,12 @@ public virtual IExpr ConstantOptimization() } // - public virtual object Evaluate(Report rpt, Row row) + public virtual async Task Evaluate(Report rpt, Row row) { if (row == null) return null; Textbox tb; - string t = _ArgExpr.EvaluateString(rpt, row); + string t = await _ArgExpr.EvaluateString(rpt, row); if (t == null) return null; tb = _ReportItems[t] as Textbox; @@ -93,45 +94,45 @@ public virtual object Evaluate(Report rpt, Row row) return tb.Evaluate(rpt, row); } - public virtual double EvaluateDouble(Report rpt, Row row) + public virtual async Task EvaluateDouble(Report rpt, Row row) { if (row == null) return Double.NaN; - return Convert.ToDouble(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDouble(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual decimal EvaluateDecimal(Report rpt, Row row) + public virtual async Task EvaluateDecimal(Report rpt, Row row) { if (row == null) return decimal.MinValue; - return Convert.ToDecimal(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDecimal(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual int EvaluateInt32(Report rpt, Row row) + public virtual async Task EvaluateInt32(Report rpt, Row row) { if (row == null) return int.MinValue; - return Convert.ToInt32(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToInt32(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual string EvaluateString(Report rpt, Row row) + public virtual async Task EvaluateString(Report rpt, Row row) { if (row == null) return null; - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public virtual DateTime EvaluateDateTime(Report rpt, Row row) + public virtual async Task EvaluateDateTime(Report rpt, Row row) { if (row == null) return DateTime.MinValue; - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public virtual bool EvaluateBoolean(Report rpt, Row row) + public virtual async Task EvaluateBoolean(Report rpt, Row row) { if (row == null) return false; - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } } } diff --git a/RdlEngine/Functions/FunctionReportName.cs b/RdlEngine/Functions/FunctionReportName.cs index 6df5455a..40e8631b 100644 --- a/RdlEngine/Functions/FunctionReportName.cs +++ b/RdlEngine/Functions/FunctionReportName.cs @@ -22,7 +22,7 @@ the website www.fyiReporting.com. */ using System; using System.IO; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -46,50 +46,50 @@ public TypeCode GetTypeCode() return TypeCode.String; } - public bool IsConstant() + public Task IsConstant() { - return true; + return Task.FromResult(true); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // not a constant expression - return this; + return Task.FromResult(this as IExpr); } // Evaluate is for interpretation - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateString(rpt, row); + return await EvaluateString(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return double.NaN; + return Task.FromResult(double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return decimal.MinValue; + return Task.FromResult(decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { - return rpt == null? "": rpt.Name; + return rpt == null? Task.FromResult(""): Task.FromResult(rpt.Name); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } } } diff --git a/RdlEngine/Functions/FunctionReportParameter.cs b/RdlEngine/Functions/FunctionReportParameter.cs index 6e9341ac..7e53c6a1 100644 --- a/RdlEngine/Functions/FunctionReportParameter.cs +++ b/RdlEngine/Functions/FunctionReportParameter.cs @@ -26,6 +26,7 @@ the website www.fyiReporting.com. using System.Reflection; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -111,25 +112,25 @@ public virtual TypeCode GetTypeCode() } } - public virtual bool IsConstant() + public virtual Task IsConstant() { - return false; + return Task.FromResult(false); } - public virtual IExpr ConstantOptimization() + public virtual Task ConstantOptimization() { // not a constant expression - return this; + return Task.FromResult(this as IExpr); } // Evaluate is for interpretation (and is relatively slow) - public virtual object Evaluate(Report rpt, Row row) + public async virtual Task Evaluate(Report rpt, Row row) { - return this.p.MultiValue? EvaluateMV(rpt, row): p.GetRuntimeValue(rpt); + return this.p.MultiValue? await EvaluateMV(rpt, row): await p.GetRuntimeValue(rpt); } - private object EvaluateMV(Report rpt, Row row) + private async Task EvaluateMV(Report rpt, Row row) { - ArrayList ar = p.GetRuntimeValues(rpt); + ArrayList ar = await p.GetRuntimeValues(rpt); object va = this._arg == null ? null : _arg.Evaluate(rpt, row); @@ -155,9 +156,9 @@ private object EvaluateMV(Report rpt, Row row) } } - public virtual double EvaluateDouble(Report rpt, Row row) + public virtual async Task EvaluateDouble(Report rpt, Row row) { - object rtv = Evaluate(rpt, row); + object rtv = await Evaluate(rpt, row); if (rtv == null) return Double.NaN; @@ -180,9 +181,9 @@ public virtual double EvaluateDouble(Report rpt, Row row) } } - public virtual decimal EvaluateDecimal(Report rpt, Row row) + public virtual async Task EvaluateDecimal(Report rpt, Row row) { - object rtv = Evaluate(rpt, row); + object rtv = await Evaluate(rpt, row); if (rtv == null) return Decimal.MinValue; @@ -205,9 +206,9 @@ public virtual decimal EvaluateDecimal(Report rpt, Row row) } } - public virtual int EvaluateInt32(Report rpt, Row row) + public virtual async Task EvaluateInt32(Report rpt, Row row) { - object rtv = Evaluate(rpt, row); + object rtv = await Evaluate(rpt, row); if (rtv == null) return int.MinValue; @@ -233,9 +234,9 @@ public virtual int EvaluateInt32(Report rpt, Row row) } - public virtual string EvaluateString(Report rpt, Row row) + public virtual async Task EvaluateString(Report rpt, Row row) { - object rtv = this.p.MultiValue ? EvaluateMV(rpt, row) : p.GetRuntimeValue(rpt); + object rtv = this.p.MultiValue ? await EvaluateMV(rpt, row) : await p.GetRuntimeValue(rpt); // object rtv = Evaluate(rpt, row); if (rtv == null) return null; @@ -243,9 +244,9 @@ public virtual string EvaluateString(Report rpt, Row row) return rtv.ToString(); } - public virtual DateTime EvaluateDateTime(Report rpt, Row row) + public virtual async Task EvaluateDateTime(Report rpt, Row row) { - object rtv = Evaluate(rpt, row); + object rtv = await Evaluate(rpt, row); if (rtv == null) return DateTime.MinValue; @@ -268,9 +269,9 @@ public virtual DateTime EvaluateDateTime(Report rpt, Row row) } } - public virtual bool EvaluateBoolean(Report rpt, Row row) + public virtual async Task EvaluateBoolean(Report rpt, Row row) { - object rtv = Evaluate(rpt, row); + object rtv = await Evaluate(rpt, row); if (rtv == null) return false; diff --git a/RdlEngine/Functions/FunctionReportParameterLabel.cs b/RdlEngine/Functions/FunctionReportParameterLabel.cs index 7d837804..8f807db5 100644 --- a/RdlEngine/Functions/FunctionReportParameterLabel.cs +++ b/RdlEngine/Functions/FunctionReportParameterLabel.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -52,26 +51,26 @@ public override TypeCode GetTypeCode() return base.GetTypeCode(); } - public override bool IsConstant() + public override Task IsConstant() { - return false; + return Task.FromResult(false); } - public override IExpr ConstantOptimization() + public override Task ConstantOptimization() { // not a constant expression - return this; + return Task.FromResult(this as IExpr); } // Evaluate is for interpretation (and is relatively slow) - public override object Evaluate(Report rpt, Row row) + public async override Task Evaluate(Report rpt, Row row) { - string v = base.EvaluateString(rpt, row); + string v = await base.EvaluateString(rpt, row); if (p.ValidValues == null) return v; - string[] displayValues = p.ValidValues.DisplayValues(rpt); - object[] dataValues = p.ValidValues.DataValues(rpt); + string[] displayValues = await p.ValidValues.DisplayValues(rpt); + object[] dataValues = await p.ValidValues.DataValues(rpt); for (int i=0; i < dataValues.Length; i++) { @@ -82,35 +81,35 @@ public override object Evaluate(Report rpt, Row row) return v; } - public override double EvaluateDouble(Report rpt, Row row) + public async override Task EvaluateDouble(Report rpt, Row row) { - string r = EvaluateString(rpt, row); + string r = await EvaluateString(rpt, row); return r == null? double.MinValue: Convert.ToDouble(r); } - public override decimal EvaluateDecimal(Report rpt, Row row) + public override async Task EvaluateDecimal(Report rpt, Row row) { - string r = EvaluateString(rpt, row); + string r = await EvaluateString(rpt, row); return r == null? decimal.MinValue: Convert.ToDecimal(r); } - public override string EvaluateString(Report rpt, Row row) + public async override Task EvaluateString(Report rpt, Row row) { - return (string) Evaluate(rpt, row); + return (string)await Evaluate(rpt, row); } - public override DateTime EvaluateDateTime(Report rpt, Row row) + public async override Task EvaluateDateTime(Report rpt, Row row) { - string r = EvaluateString(rpt, row); + string r = await EvaluateString(rpt, row); return r == null? DateTime.MinValue: Convert.ToDateTime(r); } - public override bool EvaluateBoolean(Report rpt, Row row) + public async override Task EvaluateBoolean(Report rpt, Row row) { - string r = EvaluateString(rpt, row); + string r = await EvaluateString(rpt, row); return r.ToLower() == "true"? true: false; } diff --git a/RdlEngine/Functions/FunctionSwitch.cs b/RdlEngine/Functions/FunctionSwitch.cs index 96734e34..1ef8cc4e 100644 --- a/RdlEngine/Functions/FunctionSwitch.cs +++ b/RdlEngine/Functions/FunctionSwitch.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -55,29 +54,29 @@ public TypeCode GetTypeCode() return _tc; } - public bool IsConstant() + public Task IsConstant() { - return false; // we could be more sophisticated here; but not much benefit + return Task.FromResult(false); // we could be more sophisticated here; but not much benefit } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { // simplify all expression if possible for (int i=0; i < _expr.Length; i++) { - _expr[i] = _expr[i].ConstantOptimization(); + _expr[i] = await _expr[i].ConstantOptimization(); } return this; } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { bool result; for (int i=0; i < _expr.Length; i = i+2) { - result = _expr[i].EvaluateBoolean(rpt, row); + result = await _expr[i].EvaluateBoolean(rpt, row); if (result) { object o = _expr[i+1].Evaluate(rpt, row); @@ -92,39 +91,39 @@ public object Evaluate(Report rpt, Row row) return null; } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToBoolean(result); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToString(result); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } } diff --git a/RdlEngine/Functions/FunctionSystem.cs b/RdlEngine/Functions/FunctionSystem.cs index 5cd0b309..09a8f3cc 100644 --- a/RdlEngine/Functions/FunctionSystem.cs +++ b/RdlEngine/Functions/FunctionSystem.cs @@ -24,6 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; +using System.Threading.Tasks; using RdlEngine.Resources; @@ -58,18 +59,18 @@ public TypeCode GetTypeCode() return _ReturnTypeCode; } - public bool IsConstant() + public Task IsConstant() { - return false; // Can't know what the function does + return Task.FromResult(false); // Can't know what the function does } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { // Do constant optimization on all the arguments for (int i=0; i < _Args.GetLength(0); i++) { IExpr e = (IExpr)_Args[i]; - _Args[i] = e.ConstantOptimization(); + _Args[i] = await e.ConstantOptimization(); } // Can't assume that the function doesn't vary @@ -78,7 +79,7 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { // get the results object[] argResults = new object[_Args.Length]; @@ -86,7 +87,7 @@ public object Evaluate(Report rpt, Row row) bool bNull = false; foreach(IExpr a in _Args) { - argResults[i] = a.Evaluate(rpt, row); + argResults[i] = await a.Evaluate(rpt, row); if (argResults[i] == null) bNull = true; i++; @@ -125,35 +126,35 @@ public object Evaluate(Report rpt, Row row) return returnVal; } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(Evaluate(rpt, row)); + return Convert.ToDouble(await Evaluate(rpt, row)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(Evaluate(rpt, row)); + return Convert.ToDecimal(await Evaluate(rpt, row)); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(Evaluate(rpt, row)); + return Convert.ToInt32(await Evaluate(rpt, row)); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } public string Cls diff --git a/RdlEngine/Functions/FunctionTextbox.cs b/RdlEngine/Functions/FunctionTextbox.cs index 1004ec68..90b61f2d 100644 --- a/RdlEngine/Functions/FunctionTextbox.cs +++ b/RdlEngine/Functions/FunctionTextbox.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -56,55 +55,55 @@ public TypeCode GetTypeCode() return TypeCode.Object; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // not a constant expression - return this; + return Task.FromResult(this as IExpr); } // Evaluate the value for the expression - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return t.Evaluate(rpt, row); + return await t.Evaluate(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - object result = Evaluate(rpt, row); + object result = await Evaluate(rpt, row); return Convert.ToBoolean(result); } } diff --git a/RdlEngine/Functions/FunctionTotalPages.cs b/RdlEngine/Functions/FunctionTotalPages.cs index 0cf64831..ea4f16ac 100644 --- a/RdlEngine/Functions/FunctionTotalPages.cs +++ b/RdlEngine/Functions/FunctionTotalPages.cs @@ -22,7 +22,7 @@ the website www.fyiReporting.com. */ using System; using System.IO; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -46,54 +46,54 @@ public TypeCode GetTypeCode() return TypeCode.Int32; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { // not a constant expression - return this; + return Task.FromResult(this as IExpr); } // Evaluate is for interpretation - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return rpt == null ? (int) 1 : (int) rpt.TotalPages; + return rpt == null ? Task.FromResult((int) 1 as object) : Task.FromResult((int) rpt.TotalPages as object); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return rpt == null? 1: rpt.TotalPages; + return rpt == null? Task.FromResult(1d): Task.FromResult((double)rpt.TotalPages); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return rpt == null ? 1 : rpt.TotalPages; + return rpt == null ? Task.FromResult(1) : Task.FromResult(rpt.TotalPages); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDecimal(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToBoolean(result); } diff --git a/RdlEngine/Functions/FunctionUnaryMinus.cs b/RdlEngine/Functions/FunctionUnaryMinus.cs index 4df8f7b6..61fa0207 100644 --- a/RdlEngine/Functions/FunctionUnaryMinus.cs +++ b/RdlEngine/Functions/FunctionUnaryMinus.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,62 +56,62 @@ public TypeCode GetTypeCode() return TypeCode.Double; } - public bool IsConstant() + public async Task IsConstant() { - return _rhs.IsConstant(); + return await _rhs.IsConstant(); } - public IExpr ConstantOptimization() - { - _rhs.ConstantOptimization(); - if (_rhs.IsConstant()) - return new ConstantDouble(EvaluateDouble(null, null)); + public async Task ConstantOptimization() + { + await _rhs.ConstantOptimization(); + if (await _rhs.IsConstant()) + return new ConstantDouble(await EvaluateDouble(null, null)); else return this; } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDouble(rpt, row); + return await EvaluateDouble(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - double rhs = _rhs.EvaluateDouble(rpt, row); + double rhs = await _rhs.EvaluateDouble(rpt, row); return -rhs; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - double result = EvaluateDouble(rpt, row); + double result = await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } public IExpr Rhs diff --git a/RdlEngine/Functions/FunctionUnaryMinusDecimal.cs b/RdlEngine/Functions/FunctionUnaryMinusDecimal.cs index 7120a878..16d8f101 100644 --- a/RdlEngine/Functions/FunctionUnaryMinusDecimal.cs +++ b/RdlEngine/Functions/FunctionUnaryMinusDecimal.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,17 +56,17 @@ public TypeCode GetTypeCode() return TypeCode.Decimal; } - public bool IsConstant() + public async Task IsConstant() { - return _rhs.IsConstant(); + return await _rhs.IsConstant(); } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _rhs = _rhs.ConstantOptimization(); - if (_rhs.IsConstant()) + _rhs = await _rhs.ConstantOptimization(); + if (await _rhs.IsConstant()) { - decimal d = EvaluateDecimal(null, null); + decimal d = await EvaluateDecimal(null, null); return new ConstantDecimal(d); } @@ -75,47 +74,47 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateDecimal(rpt, row); + return await EvaluateDecimal(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDouble(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToInt32(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - decimal rhs = _rhs.EvaluateDecimal(rpt, row); + decimal rhs = await _rhs.EvaluateDecimal(rpt, row); return (decimal) (-rhs); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - decimal result = EvaluateDecimal(rpt, row); + decimal result = await EvaluateDecimal(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } public IExpr Rhs diff --git a/RdlEngine/Functions/FunctionUnaryMinusInteger.cs b/RdlEngine/Functions/FunctionUnaryMinusInteger.cs index 3e236819..6fe31eb9 100644 --- a/RdlEngine/Functions/FunctionUnaryMinusInteger.cs +++ b/RdlEngine/Functions/FunctionUnaryMinusInteger.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,17 +56,17 @@ public TypeCode GetTypeCode() return TypeCode.Int32; } - public bool IsConstant() + public async Task IsConstant() { - return _rhs.IsConstant(); + return await _rhs.IsConstant(); } - public IExpr ConstantOptimization() + public async Task ConstantOptimization() { - _rhs = _rhs.ConstantOptimization(); - if (_rhs.IsConstant()) + _rhs = await _rhs.ConstantOptimization(); + if (await _rhs.IsConstant()) { - double d = EvaluateDouble(null, null); + double d = await EvaluateDouble(null, null); return new ConstantInteger((int) d); } @@ -75,47 +74,47 @@ public IExpr ConstantOptimization() } // Evaluate is for interpretation (and is relatively slow) - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return (int) EvaluateInt32(rpt, row); + return (int)await EvaluateInt32(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - double result = _rhs.EvaluateDouble(rpt, row); + double result = await _rhs.EvaluateDouble(rpt, row); return -result; } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - int result = _rhs.EvaluateInt32(rpt, row); + int result = await _rhs.EvaluateInt32(rpt, row); return -result; } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - int result = EvaluateInt32(rpt, row); + int result = await EvaluateInt32(rpt, row); return Convert.ToDecimal(result); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - int result = (int) EvaluateDouble(rpt, row); + int result = (int)await EvaluateDouble(rpt, row); return result.ToString(); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - int result = (int) EvaluateDouble(rpt, row); + int result = (int)await EvaluateDouble(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - int result = (int) EvaluateDouble(rpt, row); + int result = (int)await EvaluateDouble(rpt, row); return result == 0? false:true; } diff --git a/RdlEngine/Functions/FunctionUserCollection.cs b/RdlEngine/Functions/FunctionUserCollection.cs index ef462dac..55e6d0d4 100644 --- a/RdlEngine/Functions/FunctionUserCollection.cs +++ b/RdlEngine/Functions/FunctionUserCollection.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.Globalization; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -54,18 +55,18 @@ public virtual TypeCode GetTypeCode() return TypeCode.String; // all the user types happen to be string } - public virtual bool IsConstant() + public virtual Task IsConstant() { - return false; + return Task.FromResult(false); } - public virtual IExpr ConstantOptimization() + public virtual async Task ConstantOptimization() { - _ArgExpr = _ArgExpr.ConstantOptimization(); + _ArgExpr = await _ArgExpr.ConstantOptimization(); - if (_ArgExpr.IsConstant()) + if (await _ArgExpr.IsConstant()) { - string o = _ArgExpr.EvaluateString(null, null); + string o = await _ArgExpr.EvaluateString(null, null); if (o == null) throw new Exception(Strings.FunctionUserCollection_Error_UserCollectionNull); string lo = o.ToLower(); @@ -80,11 +81,11 @@ public virtual IExpr ConstantOptimization() } // - public virtual object Evaluate(Report rpt, Row row) + public virtual async Task Evaluate(Report rpt, Row row) { if (rpt == null) return null; - string u = _ArgExpr.EvaluateString(rpt, row); + string u = await _ArgExpr.EvaluateString(rpt, row); if (u == null) return null; switch (u.ToLower()) @@ -100,46 +101,46 @@ public virtual object Evaluate(Report rpt, Row row) } } - public virtual double EvaluateDouble(Report rpt, Row row) + public virtual async Task EvaluateDouble(Report rpt, Row row) { if (row == null) return Double.NaN; - return Convert.ToDouble(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDouble(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual decimal EvaluateDecimal(Report rpt, Row row) + public virtual async Task EvaluateDecimal(Report rpt, Row row) { if (row == null) return decimal.MinValue; - return Convert.ToDecimal(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToDecimal(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual int EvaluateInt32(Report rpt, Row row) + public virtual async Task EvaluateInt32(Report rpt, Row row) { if (row == null) return int.MinValue; - return Convert.ToInt32(Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); + return Convert.ToInt32(await Evaluate(rpt, row), NumberFormatInfo.InvariantInfo); } - public virtual string EvaluateString(Report rpt, Row row) + public virtual async Task EvaluateString(Report rpt, Row row) { if (row == null) return null; - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public virtual DateTime EvaluateDateTime(Report rpt, Row row) + public virtual async Task EvaluateDateTime(Report rpt, Row row) { if (row == null) return DateTime.MinValue; - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public virtual bool EvaluateBoolean(Report rpt, Row row) + public virtual async Task EvaluateBoolean(Report rpt, Row row) { if (row == null) return false; - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } } } diff --git a/RdlEngine/Functions/FunctionUserID.cs b/RdlEngine/Functions/FunctionUserID.cs index 5b8a65c2..036304d0 100644 --- a/RdlEngine/Functions/FunctionUserID.cs +++ b/RdlEngine/Functions/FunctionUserID.cs @@ -22,7 +22,7 @@ the website www.fyiReporting.com. */ using System; using System.IO; - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -46,58 +46,58 @@ public TypeCode GetTypeCode() return TypeCode.String; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { - return this; + return Task.FromResult(this as IExpr); } // Evaluate is for interpretation - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateString(rpt, row); + return await EvaluateString(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDouble(result); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDecimal(result); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToInt32(result); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { if (rpt == null || rpt.UserID == null) - return Environment.UserName; + return Task.FromResult(Environment.UserName); else - return rpt.UserID; + return Task.FromResult(rpt.UserID); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - string result = EvaluateString(rpt, row); + string result = await EvaluateString(rpt, row); return Convert.ToDateTime(result); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } } } diff --git a/RdlEngine/Functions/FunctionUserLanguage.cs b/RdlEngine/Functions/FunctionUserLanguage.cs index a47a3192..3edba176 100644 --- a/RdlEngine/Functions/FunctionUserLanguage.cs +++ b/RdlEngine/Functions/FunctionUserLanguage.cs @@ -25,6 +25,7 @@ the website www.fyiReporting.com. using System.Globalization; using RdlEngine.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -47,50 +48,50 @@ public TypeCode GetTypeCode() return TypeCode.String; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { - return this; + return Task.FromResult(this as IExpr); } // Evaluate is for interpretation - public object Evaluate(Report rpt, Row row) + public async Task Evaluate(Report rpt, Row row) { - return EvaluateString(rpt, row); + return await EvaluateString(rpt, row); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { throw new Exception(Strings.FunctionUserLanguage_Error_ConvertToDouble); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { throw new Exception(Strings.FunctionUserLanguage_Error_ConvertToDecimal); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { throw new Exception(Strings.FunctionUserLanguage_Error_ConvertToInt32); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { if (rpt == null || rpt.ClientLanguage == null) - return CultureInfo.CurrentCulture.ThreeLetterISOLanguageName; + return Task.FromResult(CultureInfo.CurrentCulture.ThreeLetterISOLanguageName); else - return rpt.ClientLanguage; + return Task.FromResult(rpt.ClientLanguage); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { throw new Exception(Strings.FunctionUserLanguage_Error_ConvertToDateTime); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { throw new Exception(Strings.FunctionUserLanguage_Error_ConvertToBoolean); } diff --git a/RdlEngine/Functions/IExpr.cs b/RdlEngine/Functions/IExpr.cs index db7ca403..f096f942 100644 --- a/RdlEngine/Functions/IExpr.cs +++ b/RdlEngine/Functions/IExpr.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; using System.IO; +using System.Threading.Tasks; using fyiReporting.RDL; @@ -33,16 +34,16 @@ namespace fyiReporting.RDL internal interface IExpr { TypeCode GetTypeCode(); // return the type of the expression - bool IsConstant(); // expression returns a constant - IExpr ConstantOptimization(); // constant optimization + Task IsConstant(); // expression returns a constant + Task ConstantOptimization(); // constant optimization // Evaluate is for interpretation - object Evaluate(Report r, Row row); // return an object - string EvaluateString(Report r, Row row); // return a string - double EvaluateDouble(Report r, Row row); // return a double - decimal EvaluateDecimal(Report r, Row row); // return a decimal - int EvaluateInt32(Report r, Row row); // return an Int32 - DateTime EvaluateDateTime(Report r, Row row); // return a DateTime - bool EvaluateBoolean(Report r, Row row); // return boolean + Task Evaluate(Report r, Row row); // return an object + Task EvaluateString(Report r, Row row); // return a string + Task EvaluateDouble(Report r, Row row); // return a double + Task EvaluateDecimal(Report r, Row row); // return a decimal + Task EvaluateInt32(Report r, Row row); // return an Int32 + Task EvaluateDateTime(Report r, Row row); // return a DateTime + Task EvaluateBoolean(Report r, Row row); // return boolean } } diff --git a/RdlEngine/Functions/Identifier.cs b/RdlEngine/Functions/Identifier.cs index 407203d4..24467560 100644 --- a/RdlEngine/Functions/Identifier.cs +++ b/RdlEngine/Functions/Identifier.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -61,49 +60,49 @@ public TypeCode GetTypeCode() return TypeCode.Object; // TODO } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value as object); } - public double EvaluateDouble(Report rpt, Row row) + public async Task EvaluateDouble(Report rpt, Row row) { - return Convert.ToDouble(Evaluate(rpt, row)); + return Convert.ToDouble(await Evaluate(rpt, row)); } - public decimal EvaluateDecimal(Report rpt, Row row) + public async Task EvaluateDecimal(Report rpt, Row row) { - return Convert.ToDecimal(Evaluate(rpt, row)); + return Convert.ToDecimal(await Evaluate(rpt, row)); } - public int EvaluateInt32(Report rpt, Row row) + public async Task EvaluateInt32(Report rpt, Row row) { - return Convert.ToInt32(Evaluate(rpt, row)); + return Convert.ToInt32(await Evaluate(rpt, row)); } - public string EvaluateString(Report rpt, Row row) + public async Task EvaluateString(Report rpt, Row row) { - return Convert.ToString(Evaluate(rpt, row)); + return Convert.ToString(await Evaluate(rpt, row)); } - public DateTime EvaluateDateTime(Report rpt, Row row) + public async Task EvaluateDateTime(Report rpt, Row row) { - return Convert.ToDateTime(Evaluate(rpt, row)); + return Convert.ToDateTime(await Evaluate(rpt, row)); } - public bool EvaluateBoolean(Report rpt, Row row) + public async Task EvaluateBoolean(Report rpt, Row row) { - return Convert.ToBoolean(Evaluate(rpt, row)); + return Convert.ToBoolean(await Evaluate(rpt, row)); } } } diff --git a/RdlEngine/Functions/IdentifierKey.cs b/RdlEngine/Functions/IdentifierKey.cs index 03fb734c..ee5b47eb 100644 --- a/RdlEngine/Functions/IdentifierKey.cs +++ b/RdlEngine/Functions/IdentifierKey.cs @@ -24,8 +24,7 @@ the website www.fyiReporting.com. using System.Collections; using System.IO; using System.Reflection; - - +using System.Threading.Tasks; using fyiReporting.RDL; @@ -64,9 +63,9 @@ public TypeCode GetTypeCode() return TypeCode.Object; } - public bool IsConstant() + public Task IsConstant() { - return false; + return Task.FromResult(false); } public IdentifierKeyEnum Value @@ -74,44 +73,44 @@ public IdentifierKeyEnum Value get {return _Value;} } - public IExpr ConstantOptimization() + public Task ConstantOptimization() { - return this; + return Task.FromResult(this as IExpr); } - public object Evaluate(Report rpt, Row row) + public Task Evaluate(Report rpt, Row row) { - return _Value; + return Task.FromResult(_Value as object); } - public double EvaluateDouble(Report rpt, Row row) + public Task EvaluateDouble(Report rpt, Row row) { - return Double.NaN; + return Task.FromResult(Double.NaN); } - public decimal EvaluateDecimal(Report rpt, Row row) + public Task EvaluateDecimal(Report rpt, Row row) { - return Decimal.MinValue; + return Task.FromResult(Decimal.MinValue); } - public int EvaluateInt32(Report rpt, Row row) + public Task EvaluateInt32(Report rpt, Row row) { - return int.MinValue; + return Task.FromResult(int.MinValue); } - public string EvaluateString(Report rpt, Row row) + public Task EvaluateString(Report rpt, Row row) { return null; } - public DateTime EvaluateDateTime(Report rpt, Row row) + public Task EvaluateDateTime(Report rpt, Row row) { - return DateTime.MinValue; + return Task.FromResult(DateTime.MinValue); } - public bool EvaluateBoolean(Report rpt, Row row) + public Task EvaluateBoolean(Report rpt, Row row) { - return false; + return Task.FromResult(false); } } } diff --git a/RdlEngine/GlobalSuppressions.cs b/RdlEngine/GlobalSuppressions.cs new file mode 100644 index 00000000..2e2dabb4 --- /dev/null +++ b/RdlEngine/GlobalSuppressions.cs @@ -0,0 +1,11 @@ +// This file is used by Code Analysis to maintain SuppressMessage +// attributes that are applied to this project. +// Project-level suppressions either have no target or are given +// a specific target and scoped to a namespace, type, member, etc. + +using System.Diagnostics.CodeAnalysis; + +#if !DRAWINGCOMPAT +[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", + Justification = "System.Drawing usage is intentional")] +#endif diff --git a/RdlEngine/RdlEngine.csproj b/RdlEngine/RdlEngine.csproj index 4585183f..ba005f83 100644 --- a/RdlEngine/RdlEngine.csproj +++ b/RdlEngine/RdlEngine.csproj @@ -12,6 +12,7 @@ Majorsilence.Reporting.RdlEngine Debug;Release;Debug-DrawingCompat net8.0 + 4014 diff --git a/RdlEngine/Render/ExcelConverter/ExcelCellsBuilder.cs b/RdlEngine/Render/ExcelConverter/ExcelCellsBuilder.cs index f2e50e44..3e8c97b9 100644 --- a/RdlEngine/Render/ExcelConverter/ExcelCellsBuilder.cs +++ b/RdlEngine/Render/ExcelConverter/ExcelCellsBuilder.cs @@ -2,6 +2,8 @@ using System.Linq; using System.Collections.Generic; using fyiReporting.RDL; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Majorsilence.Drawing; using Majorsilence.Drawing.Drawing2D; @@ -104,12 +106,12 @@ public void AddTable(Table table) Tables.Add(CurrentExcelTable); } - public void AddRow(TableRow tr, Row row) + public async Task AddRow(TableRow tr, Row row) { if(CurrentExcelTable.Table == null) { return; } - float rowHeight = tr.CanGrow ? tr.HeightOfRow(Report, g, row) : tr.Height.Points; + float rowHeight = tr.CanGrow ? await tr.HeightOfRow(Report, g, row) : tr.Height.Points; var shiftingRows = Rows.Where(x => x.YPosition >= rowPosition); ShiftBottomRows(shiftingRows, rowHeight); @@ -117,12 +119,12 @@ public void AddRow(TableRow tr, Row row) var currentRow = AddRow(rowPosition, rowHeight); foreach(var cell in tr.TableCells.Items) { var column = CurrentExcelTable.Table.TableColumns.Items[cell.ColIndex]; - if(column.IsHidden(Report, row)) + if(await column.IsHidden(Report, row)) continue; var xPosition = CurrentExcelTable.Table.Left?.Points ?? 0; for(int i = 0; i < cell.ColIndex; i++) { var columnBefore = CurrentExcelTable.Table.TableColumns.Items[i]; - if(columnBefore.IsHidden(Report, row)) + if(await columnBefore.IsHidden(Report, row)) continue; xPosition += columnBefore.Width.Points; } @@ -131,7 +133,7 @@ public void AddRow(TableRow tr, Row row) if(cellTextBox == null || (cellTextBox as Textbox) == null) { continue; } - string value = (cellTextBox as Textbox).RunText(Report, row); + string value = await (cellTextBox as Textbox).RunText(Report, row); ExcelCell currentCell = new ExcelCell(cellTextBox, value, currentRow, currentColumn); currentCell.ExcelTable = CurrentExcelTable; currentCell.OriginalWidth = column.Width.Points; @@ -145,7 +147,7 @@ public void AddRow(TableRow tr, Row row) currentCell.OriginalWidth = spanWidth; } currentCell.GrowedBottomPosition = rowPosition + rowHeight; - SetCellStyle(currentCell, cellTextBox, row); + await SetCellStyle(currentCell, cellTextBox, row); Cells.Add(currentCell); } @@ -166,7 +168,7 @@ private void FillAbsolutePosition(ReportItem reportItem, ref float top, ref floa } } - public void AddTextbox(Textbox reportItem, string value, Row row) + public async Task AddTextbox(Textbox reportItem, string value, Row row) { if(reportItem.InPageHeaderOrFooter()) { return; @@ -181,7 +183,7 @@ public void AddTextbox(Textbox reportItem, string value, Row row) float topPosition = reportItem.Top.Points; float leftPosition = reportItem.Left.Points; - float height = reportItem.CanGrow ? reportItem.RunTextCalcHeight(Report, g, row) : reportItem.Height.Points; + float height = reportItem.CanGrow ? await reportItem.RunTextCalcHeight(Report, g, row) : reportItem.Height.Points; float width = reportItem.Width.Points; FillAbsolutePosition(reportItem, ref topPosition, ref leftPosition); @@ -196,17 +198,17 @@ public void AddTextbox(Textbox reportItem, string value, Row row) ExcelCell currentCell = new ExcelCell(reportItem, value, currentRow, currentColumn); currentCell.OriginalBottomPosition = OriginalBottomPosition; - SetCellStyle(currentCell, reportItem, row); + await SetCellStyle(currentCell, reportItem, row); Cells.Add(currentCell); currentCell.OriginalHeight = height; currentCell.GrowedBottomPosition = topPosition + height; } - private void SetCellStyle(ExcelCell excelCell, ReportItem reportItem, Row row) + private async Task SetCellStyle(ExcelCell excelCell, ReportItem reportItem, Row row) { StyleInfo si = new StyleInfo(); if(reportItem.Style != null) { - var itemStyleInfo = reportItem.Style.GetStyleInfo(Report, row); + var itemStyleInfo = await reportItem.Style.GetStyleInfo(Report, row); if(itemStyleInfo != null) { si = itemStyleInfo; } diff --git a/RdlEngine/Render/HtmlConverter/RenderHtmlTable.cs b/RdlEngine/Render/HtmlConverter/RenderHtmlTable.cs index 5c917452..0eac7af8 100644 --- a/RdlEngine/Render/HtmlConverter/RenderHtmlTable.cs +++ b/RdlEngine/Render/HtmlConverter/RenderHtmlTable.cs @@ -29,6 +29,8 @@ the website www.fyiReporting.com. using System.Text; using System.Xml; using System.Globalization; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Majorsilence.Drawing; using Majorsilence.Drawing.Imaging; @@ -39,123 +41,123 @@ the website www.fyiReporting.com. namespace fyiReporting.RDL { - - /// - /// Renders a report to HTML. All positioning is handled via tables. - /// - internal class RenderHtmlTable: IPresent - { - Report r; // report - // Stack _Container; // container for body/list/rectangle/ ... - StringWriter tw; // temporary location where the output is going - IStreamGen _sg; // stream generater - Hashtable _styles; // hash table of styles we've generated - int cssId=1; // ID for css when names are usable or available - bool bScriptToggle=false; // need to generate toggle javascript in header - bool bScriptTableSort=false; // need to generate table sort javascript in header - Bitmap _bm=null; // bm and - Graphics _g=null; // g are needed when calculating string heights - bool _Asp=false; // denotes ASP.NET compatible HTML; e.g. no , - // separate JavaScript and CSS - string _Prefix=""; // prefix to generating all HTML names (e.g. css, ... - string _CSS; // when ASP we put the CSS into a string - string _JavaScript; // as well as any required javascript - int _SkipMatrixCols=0; // # of matrix columns to skip - - public RenderHtmlTable(Report rep, IStreamGen sg) - { - r = rep; - _sg = sg; // We need this in future - tw = new StringWriter(); // will hold the bulk of the HTML until we generate - // final file - _styles = new Hashtable(); - } + /// + /// Renders a report to HTML. All positioning is handled via tables. + /// + internal class RenderHtmlTable : IPresent + { + Report r; // report + // Stack _Container; // container for body/list/rectangle/ ... + StringWriter tw; // temporary location where the output is going + IStreamGen _sg; // stream generater + Hashtable _styles; // hash table of styles we've generated + int cssId = 1; // ID for css when names are usable or available + bool bScriptToggle = false; // need to generate toggle javascript in header + bool bScriptTableSort = false; // need to generate table sort javascript in header + Bitmap _bm = null; // bm and + Graphics _g = null; // g are needed when calculating string heights + bool _Asp = false; // denotes ASP.NET compatible HTML; e.g. no , + // separate JavaScript and CSS + string _Prefix = ""; // prefix to generating all HTML names (e.g. css, ... + string _CSS; // when ASP we put the CSS into a string + string _JavaScript; // as well as any required javascript + int _SkipMatrixCols = 0; // # of matrix columns to skip + + public RenderHtmlTable(Report rep, IStreamGen sg) + { + r = rep; + _sg = sg; // We need this in future + + tw = new StringWriter(); // will hold the bulk of the HTML until we generate + // final file + _styles = new Hashtable(); + } //Replaced from forum, User: Aulofee http://www.fyireporting.com/forum/viewtopic.php?t=793 - //~RenderHtmlTable() - public void Dispose() - { - // These should already be cleaned up; but in case of an unexpected error - // these still need to be disposed of - if (_bm != null) - _bm.Dispose(); - if (_g != null) - _g.Dispose(); - } - - public Report Report() - { - return r; - } - - public bool Asp - { - get {return _Asp;} - set {_Asp = value;} - } - - public string JavaScript - { - get {return _JavaScript;} - } - - public string CSS - { - get {return _CSS;} - } - - public string Prefix - { - get {return _Prefix;} - set - { - _Prefix = value==null? "": value; - if (_Prefix.Length > 0 && - _Prefix[0] == '_') - _Prefix = "a" + _Prefix; // not perfect but underscores as first letter don't work - } - } - - public bool IsPagingNeeded() - { - return false; - } - - public void Start() - { + //~RenderHtmlTable() + public void Dispose() + { + // These should already be cleaned up; but in case of an unexpected error + // these still need to be disposed of + if (_bm != null) + _bm.Dispose(); + if (_g != null) + _g.Dispose(); + } + + public Report Report() + { + return r; + } + + public bool Asp + { + get { return _Asp; } + set { _Asp = value; } + } + + public string JavaScript + { + get { return _JavaScript; } + } + + public string CSS + { + get { return _CSS; } + } + + public string Prefix + { + get { return _Prefix; } + set + { + _Prefix = value == null ? "" : value; + if (_Prefix.Length > 0 && + _Prefix[0] == '_') + _Prefix = "a" + _Prefix; // not perfect but underscores as first letter don't work + } + } + + public bool IsPagingNeeded() + { + return false; + } + + public void Start() + { // Create three tables that represent how each top level report item (e.g. those not in a table // or matrix) will be positioned. - - return; - } + return; + } - string FixupRelativeName(string relativeName) - { - if (_sg is OneFileStreamGen) - { - if (relativeName[0] == Path.DirectorySeparatorChar || relativeName[0] == Path.AltDirectorySeparatorChar) - relativeName = relativeName.Substring(1); - } - else if (relativeName[0] != Path.DirectorySeparatorChar) - relativeName = Path.DirectorySeparatorChar + relativeName; - return relativeName; - } - // puts the JavaScript into the header - private void ScriptGenerate(TextWriter ftw) - { - if (bScriptToggle || bScriptTableSort) - { - ftw.WriteLine(""); - } - - return; - } - - // handle the Action tag - private string Action(Action a, Row r, string t, string tooltip) - { - if (a == null) - return t; - - string result = t; - if (a.Hyperlink != null) - { // Handle a hyperlink - string url = a.HyperLinkValue(this.r, r); - if (tooltip == null) - result = String.Format("{1}", url, t); - else - result = String.Format("{2}", url, tooltip, t); - } - else if (a.Drill != null) - { // Handle a drill through - StringBuilder args= new StringBuilder(""); - args.Append(t); - args.Append(""); - result = args.ToString(); - } - else if (a.BookmarkLink != null) - { // Handle a bookmark - string bm = a.BookmarkLinkValue(this.r, r); - if (tooltip == null) - result = String.Format("{1}", bm, t); - else - result = String.Format("{2}", bm, tooltip, t); - } - - return result; - } - - private string Bookmark(string bm, string t) - { - if (bm == null) - return t; - - return String.Format("
{1}
", bm, t); - } - - // Generate the CSS styles and put them in the header - private void CssGenerate(TextWriter ftw) - { - if (_styles.Count <= 0) - return; - - if (!_Asp) - ftw.WriteLine(""); - } - - private string CssAdd(Style s, ReportLink rl, Row row) - { - return CssAdd(s, rl, row, false, float.MinValue, float.MinValue); - } - - private string CssAdd(Style s, ReportLink rl, Row row, bool bForceRelative) - { - return CssAdd(s, rl, row, bForceRelative, float.MinValue, float.MinValue); - } - private string CssAdd(Style s, ReportLink rl, Row row, bool bForceRelative, float h, float w) - { - string css; - string prefix = CssPrefix(s, rl); - if (_Asp && prefix == "table#") - bForceRelative = true; - - if (s != null) - css = prefix + "{" + CssPosition(rl, row, bForceRelative, h, w) + s.GetCSS(this.r, row, true) + "}"; - else if (rl is Table || rl is Matrix) - css = prefix + "{" + CssPosition(rl, row, bForceRelative, h, w) + "border-collapse:collapse;}"; - else - css = prefix + "{" + CssPosition(rl, row, bForceRelative, h, w) + "}"; - - CssCacheEntry2 cce = (CssCacheEntry2) _styles[css]; - if (cce == null) - { - string name = prefix + this.Prefix + "css" + cssId++.ToString(); - cce = new CssCacheEntry2(css, name); - _styles.Add(cce.Css, cce); - } - - int i = cce.Name.IndexOf('#'); - if (i > 0) - return cce.Name.Substring(i+1); - else - return cce.Name; - } - - private string CssPosition(ReportLink rl,Row row, bool bForceRelative, float h, float w) - { - if (!(rl is ReportItem)) // if not a report item then no position - return ""; - - // no positioning within a table - for (ReportLink p=rl.Parent; p != null; p=p.Parent) - { - if (p is TableCell) - return ""; - if (p is RowGrouping || - p is MatrixCell || - p is ColumnGrouping || - p is Corner) - { - StringBuilder sb2 = new StringBuilder(); - if (h != float.MinValue) - sb2.AppendFormat(NumberFormatInfo.InvariantInfo, "height: {0}pt; ", h); - if (w != float.MinValue) - sb2.AppendFormat(NumberFormatInfo.InvariantInfo, "width: {0}pt; ", w); - return sb2.ToString(); - } - } - - // TODO: optimize by putting this into ReportItem and caching result??? - ReportItem ri = (ReportItem) rl; - - StringBuilder sb = new StringBuilder(); - - if (ri.Left != null) - { - sb.AppendFormat(NumberFormatInfo.InvariantInfo, "left: {0}; ", ri.Left.CSS); - } - if (!(ri is Matrix)) - { - if (ri.Width != null) - sb.AppendFormat(NumberFormatInfo.InvariantInfo, "width: {0}; ", ri.Width.CSS); - } - if (ri.Top != null) - { - sb.AppendFormat(NumberFormatInfo.InvariantInfo, "top: {0}pt; ", ri.Gap(this.r)); - } - if (ri is List) - { - List l = ri as List; - sb.AppendFormat(NumberFormatInfo.InvariantInfo, "height: {0}pt; ", l.HeightOfList(this.r, GetGraphics,row)); - } - else if (ri is Matrix || ri is Table) - {} - else if (ri.Height != null) - sb.AppendFormat(NumberFormatInfo.InvariantInfo, "height: {0}; ", ri.Height.CSS); - - if (sb.Length > 0) - { - if (bForceRelative || ri.YParents != null) - sb.Insert(0, "position: relative; "); - else - sb.Insert(0, "position: absolute; "); - } - - return sb.ToString(); - } - - private Graphics GetGraphics - { - get - { - if (_g == null) - { - _bm = new Bitmap(10, 10); - _g = Graphics.FromImage(_bm); - } - return _g; - } - } - - private string CssPrefix(Style s, ReportLink rl) - { - string cssPrefix=null; - ReportLink p; - - if (rl is Table || rl is Matrix || rl is Rectangle) - { - cssPrefix = "table#"; - } - else if (rl is Body) - { - cssPrefix = "body#"; - } - else if (rl is Line) - { - cssPrefix = "table#"; - } - else if (rl is List) - { - cssPrefix = ""; - } - else if (rl is Subreport) - { - cssPrefix = ""; - } - else if (rl is Chart) - { - cssPrefix = ""; - } - if (cssPrefix != null) - return cssPrefix; - - // now find what the style applies to - for (p=rl.Parent; p != null; p=p.Parent) - { - if (p is TableCell) - { - bool bHead = false; - ReportLink p2; - for (p2=p.Parent; p2 != null; p2=p2.Parent) - { - Type t2 = p2.GetType(); - if (t2 == typeof(Header)) - { - if (p2.Parent is Table) - bHead=true; - break; - } - } - if (bHead) - cssPrefix = "th#"; - else - cssPrefix = "td#"; - break; - } - else if (p is RowGrouping || - p is MatrixCell || - p is ColumnGrouping || - p is Corner) - { - cssPrefix = "td#"; - break; - } - } - - return cssPrefix == null? "": cssPrefix; - } - - public void End() - { - string bodyCssId; - if (r.ReportDefinition.Body != null) - bodyCssId = CssAdd(r.ReportDefinition.Body.Style, r.ReportDefinition.Body, null); // add the style for the body - else - bodyCssId = null; - - TextWriter ftw = _sg.GetTextWriter(); // the final text writer location - - if (_Asp) - { - // do any required JavaScript - StringWriter sw = new StringWriter(); - ScriptGenerate(sw); - _JavaScript = sw.ToString(); - sw.Close(); - // do any required CSS - sw = new StringWriter(); - CssGenerate(sw); - _CSS = sw.ToString(); - sw.Close(); - } - else - { - ftw.WriteLine(@""); - - // handle the : description, javascript and CSS goes here - ftw.WriteLine(""); - - ScriptGenerate(ftw); - CssGenerate(ftw); - - if (r.Description != null) // Use description as title if provided - ftw.WriteLine(string.Format(@"{0}", XmlUtil.XmlAnsi(r.Description))); - - ftw.WriteLine(@""); - } - - // Always want an HTML body - even if report doesn't have a body stmt - if (this._Asp) - { - ftw.WriteLine(""); - } - else if (bodyCssId != null) - ftw.WriteLine(@"
", bodyCssId); - else - ftw.WriteLine("
"); - - ftw.Write(tw.ToString()); - - if (this._Asp) - ftw.WriteLine(@"
"); - else - ftw.WriteLine(@""); - - if (_g != null) - { - _g.Dispose(); - _g = null; - } - if (_bm != null) - { - _bm.Dispose(); - _bm = null; - } - return; - } - - // Body: main container for the report - public void BodyStart(Body b) - { - if (b.ReportItems != null && b.ReportItems.Items.Count > 0) - tw.WriteLine("
"); - } - - public void BodyEnd(Body b) - { - if (b.ReportItems != null && b.ReportItems.Items.Count > 0) - tw.WriteLine("
"); - } - - public void PageHeaderStart(PageHeader ph) - { - if (ph.ReportItems != null && ph.ReportItems.Items.Count > 0) - tw.WriteLine("
", ph.Height.CSS); - } - - public void PageHeaderEnd(PageHeader ph) - { - if (ph.ReportItems != null && ph.ReportItems.Items.Count > 0) - tw.WriteLine("
"); - } - - public void PageFooterStart(PageFooter pf) - { - if (pf.ReportItems != null && pf.ReportItems.Items.Count > 0) - tw.WriteLine("
", pf.Height.CSS); - } - - public void PageFooterEnd(PageFooter pf) - { - if (pf.ReportItems != null && pf.ReportItems.Items.Count > 0) - tw.WriteLine("
"); - } - - public void Textbox(Textbox tb, string t, Row row) - { - if (!tb.IsHtml(this.r, row)) // we leave the text as is when request is to treat as html - { // this can screw up the generated HTML if not properly formed HTML - // make all the characters browser readable - t = XmlUtil.XmlAnsi(t); - - // handle any specified bookmark - t = Bookmark(tb.BookmarkValue(this.r, row), t); - - // handle any specified actions - t = Action(tb.Action, row, t, tb.ToolTipValue(this.r, row)); - } - // determine if we're in a tablecell - Type tp = tb.Parent.Parent.GetType(); - bool bCell; - if (tp == typeof(TableCell) || - tp == typeof(Corner) || - tp == typeof(DynamicColumns) || - tp == typeof(DynamicRows) || - tp == typeof(StaticRow) || - tp == typeof(StaticColumn) || - tp == typeof(Subtotal) || - tp == typeof(MatrixCell)) - bCell = true; - else - bCell = false; - - if (tp == typeof(Rectangle)) - tw.Write(""); - - if (bCell) - { // The cell has the formatting for this text - if (t == "") - tw.Write("
"); // must have something in cell for formating - else - tw.Write(t); - } - else - { // Formatting must be specified - string cssName = CssAdd(tb.Style, tb, row); // get the style name for this item - - tw.Write("
{1}
", cssName, t); - } - - if (tp == typeof(Rectangle)) - tw.Write(""); - } - - public void DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table - { - if (noRowsMsg == null) - noRowsMsg = ""; - - bool bTableCell = d.Parent.Parent.GetType() == typeof(TableCell); - - if (bTableCell) - { - if (noRowsMsg == "") - tw.Write("
"); - else - tw.Write(noRowsMsg); - } - else - { - string cssName = CssAdd(d.Style, d, null); // get the style name for this item - tw.Write("
{1}
", cssName, noRowsMsg); - } - } - - // Lists - public bool ListStart(List l, Row r) - { - // identifiy reportitem it if necessary - string bookmark = l.BookmarkValue(this.r, r); - if (bookmark != null) // - tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style - return true; - } - - public void ListEnd(List l, Row r) - { - string bookmark = l.BookmarkValue(this.r, r); - if (bookmark != null) - tw.WriteLine("
"); - } - - public void ListEntryBegin(List l, Row r) - { - string cssName = CssAdd(l.Style, l, r, true); // get the style name for this item; force to be relative - tw.WriteLine(); - tw.WriteLine("
", cssName); - } - - public void ListEntryEnd(List l, Row r) - { - tw.WriteLine(); - tw.WriteLine("
"); - } - - // Tables // Report item table - public bool TableStart(Table t, Row row) - { - string cssName = CssAdd(t.Style, t, row); // get the style name for this item - - // Determine if report custom defn want this table to be sortable - if (IsTableSortable(t)) - { - this.bScriptTableSort = true; - } - - string bookmark = t.BookmarkValue(this.r, row); - if (bookmark != null) - tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style - - // Calculate the width of all the columns - int width = t.WidthInPixels(this.r, row); - if (width <= 0) - tw.WriteLine("", cssName); - else - tw.WriteLine("
", cssName, width); - - return true; - } - - public bool IsTableSortable(Table t) - { - if (t.TableGroups != null || t.Details == null || - t.Details.TableRows == null || t.Details.TableRows.Items.Count != 1) - return false; // can't have tableGroups; must have 1 detail row - - // Determine if report custom defn want this table to be sortable - bool bReturn = false; - if (t.Custom != null) - { - // Loop thru all the child nodes - foreach(XmlNode xNodeLoop in t.Custom.CustomXmlNode.ChildNodes) - { - if (xNodeLoop.Name == "HTML") - { - if (xNodeLoop.LastChild.InnerText.ToLower() == "true") - { - bReturn = true; - } - break; - } - } - } - return bReturn; - } - - public void TableEnd(Table t, Row row) - { - string bookmark = t.BookmarkValue(this.r, row); - if (bookmark != null) - tw.WriteLine(""); - tw.WriteLine("
"); - return; - } - - public void TableBodyStart(Table t, Row row) - { - tw.WriteLine(""); - } - - public void TableBodyEnd(Table t, Row row) - { - tw.WriteLine(""); - } - public void TableFooterStart(Footer f, Row row) - { - tw.WriteLine(""); - } - - public void TableFooterEnd(Footer f, Row row) - { - tw.WriteLine(""); - } - - public void TableHeaderStart(Header h, Row row) - { - tw.WriteLine(""); - } - - public void TableHeaderEnd(Header h, Row row) - { - tw.WriteLine(""); - } - - public void TableRowStart(TableRow tr, Row row) - { - tw.Write("\t"); - } + } + + if (bScriptTableSort) + { + ftw.WriteLine("var SORT_INDEX;"); + ftw.WriteLine("var SORT_DIR;"); + + ftw.WriteLine("function sort_getInnerText(element) {"); + ftw.WriteLine(" if (typeof element == 'string') return element;"); + ftw.WriteLine(" if (typeof element == 'undefined') return element;"); + ftw.WriteLine(" if (element.innerText) return element.innerText;"); + ftw.WriteLine(" var s = '';"); + + ftw.WriteLine(" var cn = element.childNodes;"); + ftw.WriteLine(" for (var i = 0; i < cn.length; i++) {"); + ftw.WriteLine(" switch (cn[i].nodeType) {"); + ftw.WriteLine(" case 1:"); // element node + ftw.WriteLine(" s += sort_getInnerText(cn[i]);"); + ftw.WriteLine(" break;"); + ftw.WriteLine(" case 3:"); // text node + ftw.WriteLine(" s += cn[i].nodeValue;"); + ftw.WriteLine(" break;"); + ftw.WriteLine(" }"); + ftw.WriteLine(" }"); + ftw.WriteLine(" return s;"); + ftw.WriteLine("}"); + + ftw.WriteLine("function sort_table(node, sortfn, header_rows, footer_rows) {"); + ftw.WriteLine(" var arrowNode;"); // arrow node + ftw.WriteLine(" for (var ci=0;ci"); + } + + return; + } + + // handle the Action tag + private async Task Action(Action a, Row r, string t, string tooltip) + { + if (a == null) + return t; + + string result = t; + if (a.Hyperlink != null) + { // Handle a hyperlink + string url = await a.HyperLinkValue(this.r, r); + if (tooltip == null) + result = String.Format("{1}", url, t); + else + result = String.Format("{2}", url, tooltip, t); + } + else if (a.Drill != null) + { // Handle a drill through + StringBuilder args = new StringBuilder(""); + args.Append(t); + args.Append(""); + result = args.ToString(); + } + else if (a.BookmarkLink != null) + { // Handle a bookmark + string bm = await a.BookmarkLinkValue(this.r, r); + if (tooltip == null) + result = String.Format("{1}", bm, t); + else + result = String.Format("{2}", bm, tooltip, t); + } + + return result; + } + + private string Bookmark(string bm, string t) + { + if (bm == null) + return t; + + return String.Format("
{1}
", bm, t); + } + + // Generate the CSS styles and put them in the header + private void CssGenerate(TextWriter ftw) + { + if (_styles.Count <= 0) + return; + + if (!_Asp) + ftw.WriteLine(""); + } + + private string CssAdd(Style s, ReportLink rl, Row row) + { + return CssAdd(s, rl, row, false, float.MinValue, float.MinValue); + } + + private string CssAdd(Style s, ReportLink rl, Row row, bool bForceRelative) + { + return CssAdd(s, rl, row, bForceRelative, float.MinValue, float.MinValue); + } + private string CssAdd(Style s, ReportLink rl, Row row, bool bForceRelative, float h, float w) + { + string css; + string prefix = CssPrefix(s, rl); + if (_Asp && prefix == "table#") + bForceRelative = true; + + if (s != null) + css = prefix + "{" + CssPosition(rl, row, bForceRelative, h, w) + s.GetCSS(this.r, row, true) + "}"; + else if (rl is Table || rl is Matrix) + css = prefix + "{" + CssPosition(rl, row, bForceRelative, h, w) + "border-collapse:collapse;}"; + else + css = prefix + "{" + CssPosition(rl, row, bForceRelative, h, w) + "}"; + + CssCacheEntry2 cce = (CssCacheEntry2)_styles[css]; + if (cce == null) + { + string name = prefix + this.Prefix + "css" + cssId++.ToString(); + cce = new CssCacheEntry2(css, name); + _styles.Add(cce.Css, cce); + } + + int i = cce.Name.IndexOf('#'); + if (i > 0) + return cce.Name.Substring(i + 1); + else + return cce.Name; + } + + private string CssPosition(ReportLink rl, Row row, bool bForceRelative, float h, float w) + { + if (!(rl is ReportItem)) // if not a report item then no position + return ""; + + // no positioning within a table + for (ReportLink p = rl.Parent; p != null; p = p.Parent) + { + if (p is TableCell) + return ""; + if (p is RowGrouping || + p is MatrixCell || + p is ColumnGrouping || + p is Corner) + { + StringBuilder sb2 = new StringBuilder(); + if (h != float.MinValue) + sb2.AppendFormat(NumberFormatInfo.InvariantInfo, "height: {0}pt; ", h); + if (w != float.MinValue) + sb2.AppendFormat(NumberFormatInfo.InvariantInfo, "width: {0}pt; ", w); + return sb2.ToString(); + } + } + + // TODO: optimize by putting this into ReportItem and caching result??? + ReportItem ri = (ReportItem)rl; + + StringBuilder sb = new StringBuilder(); + + if (ri.Left != null) + { + sb.AppendFormat(NumberFormatInfo.InvariantInfo, "left: {0}; ", ri.Left.CSS); + } + if (!(ri is Matrix)) + { + if (ri.Width != null) + sb.AppendFormat(NumberFormatInfo.InvariantInfo, "width: {0}; ", ri.Width.CSS); + } + if (ri.Top != null) + { + sb.AppendFormat(NumberFormatInfo.InvariantInfo, "top: {0}pt; ", ri.Gap(this.r)); + } + if (ri is List) + { + List l = ri as List; + sb.AppendFormat(NumberFormatInfo.InvariantInfo, "height: {0}pt; ", l.HeightOfList(this.r, GetGraphics, row)); + } + else if (ri is Matrix || ri is Table) + { } + else if (ri.Height != null) + sb.AppendFormat(NumberFormatInfo.InvariantInfo, "height: {0}; ", ri.Height.CSS); + + if (sb.Length > 0) + { + if (bForceRelative || ri.YParents != null) + sb.Insert(0, "position: relative; "); + else + sb.Insert(0, "position: absolute; "); + } + + return sb.ToString(); + } + + private Graphics GetGraphics + { + get + { + if (_g == null) + { + _bm = new Bitmap(10, 10); + _g = Graphics.FromImage(_bm); + } + return _g; + } + } + + private string CssPrefix(Style s, ReportLink rl) + { + string cssPrefix = null; + ReportLink p; + + if (rl is Table || rl is Matrix || rl is Rectangle) + { + cssPrefix = "table#"; + } + else if (rl is Body) + { + cssPrefix = "body#"; + } + else if (rl is Line) + { + cssPrefix = "table#"; + } + else if (rl is List) + { + cssPrefix = ""; + } + else if (rl is Subreport) + { + cssPrefix = ""; + } + else if (rl is Chart) + { + cssPrefix = ""; + } + if (cssPrefix != null) + return cssPrefix; + + // now find what the style applies to + for (p = rl.Parent; p != null; p = p.Parent) + { + if (p is TableCell) + { + bool bHead = false; + ReportLink p2; + for (p2 = p.Parent; p2 != null; p2 = p2.Parent) + { + Type t2 = p2.GetType(); + if (t2 == typeof(Header)) + { + if (p2.Parent is Table) + bHead = true; + break; + } + } + if (bHead) + cssPrefix = "th#"; + else + cssPrefix = "td#"; + break; + } + else if (p is RowGrouping || + p is MatrixCell || + p is ColumnGrouping || + p is Corner) + { + cssPrefix = "td#"; + break; + } + } + + return cssPrefix == null ? "" : cssPrefix; + } + + public void End() + { + string bodyCssId; + if (r.ReportDefinition.Body != null) + bodyCssId = CssAdd(r.ReportDefinition.Body.Style, r.ReportDefinition.Body, null); // add the style for the body + else + bodyCssId = null; + + TextWriter ftw = _sg.GetTextWriter(); // the final text writer location + + if (_Asp) + { + // do any required JavaScript + StringWriter sw = new StringWriter(); + ScriptGenerate(sw); + _JavaScript = sw.ToString(); + sw.Close(); + // do any required CSS + sw = new StringWriter(); + CssGenerate(sw); + _CSS = sw.ToString(); + sw.Close(); + } + else + { + ftw.WriteLine(@""); - public void TableRowEnd(TableRow tr, Row row) - { - tw.WriteLine(""); - } + // handle the : description, javascript and CSS goes here + ftw.WriteLine(""); - public void TableCellStart(TableCell t, Row row) - { - string cellType = t.InTableHeader? "th": "td"; + ScriptGenerate(ftw); + CssGenerate(ftw); - ReportItem r = t.ReportItems.Items[0]; + if (r.Description != null) // Use description as title if provided + ftw.WriteLine(string.Format(@"{0}", XmlUtil.XmlAnsi(r.Description))); - string cssName = CssAdd(r.Style, r, row); // get the style name for this item + ftw.WriteLine(@""); + } - tw.Write("<{0} id='{1}'", cellType, cssName); + // Always want an HTML body - even if report doesn't have a body stmt + if (this._Asp) + { + ftw.WriteLine(""); + } + else if (bodyCssId != null) + ftw.WriteLine(@"
", bodyCssId); + else + ftw.WriteLine("
"); - // calculate width of column - if (t.InTableHeader && t.OwnerTable.TableColumns != null) - { - // Calculate the width across all the spanned columns - int width = 0; - for (int ci=t.ColIndex; ci < t.ColIndex + t.ColSpan; ci++) - { - TableColumn tc = t.OwnerTable.TableColumns.Items[ci] as TableColumn; - if (tc != null && tc.Width != null) - width += tc.Width.PixelsX; - } - if (width > 0) - tw.Write(" width={0}", width); - } + ftw.Write(tw.ToString()); - if (t.ColSpan > 1) - tw.Write(" colspan={0}", t.ColSpan); - - Textbox tb = r as Textbox; - if (tb != null && // have textbox - tb.IsToggle && // and its a toggle - tb.Name != null) // and need name as well - { - int groupNestCount = t.OwnerTable.GetGroupNestCount(this.r); - if (groupNestCount > 0) // anything to toggle? - { - string name = tb.Name.Nm + "_" + (tb.RunCount(this.r)+1).ToString(); - bScriptToggle = true; - - // need both hand and pointer because IE and Firefox use different names - tw.Write(" onClick=\"hideShow(this, {0}, '{1}')\" onMouseOver=\"style.cursor ='hand';style.cursor ='pointer'\">", groupNestCount, name); + if (this._Asp) + ftw.WriteLine(@"
"); + else + ftw.WriteLine(@""); + + if (_g != null) + { + _g.Dispose(); + _g = null; + } + if (_bm != null) + { + _bm.Dispose(); + _bm = null; + } + return; + } + + // Body: main container for the report + public void BodyStart(Body b) + { + if (b.ReportItems != null && b.ReportItems.Items.Count > 0) + tw.WriteLine("
"); + } + + public void BodyEnd(Body b) + { + if (b.ReportItems != null && b.ReportItems.Items.Count > 0) + tw.WriteLine("
"); + } + + public void PageHeaderStart(PageHeader ph) + { + if (ph.ReportItems != null && ph.ReportItems.Items.Count > 0) + tw.WriteLine("
", ph.Height.CSS); + } + + public void PageHeaderEnd(PageHeader ph) + { + if (ph.ReportItems != null && ph.ReportItems.Items.Count > 0) + tw.WriteLine("
"); + } + + public void PageFooterStart(PageFooter pf) + { + if (pf.ReportItems != null && pf.ReportItems.Items.Count > 0) + tw.WriteLine("
", pf.Height.CSS); + } + + public void PageFooterEnd(PageFooter pf) + { + if (pf.ReportItems != null && pf.ReportItems.Items.Count > 0) + tw.WriteLine("
"); + } + + public async Task Textbox(Textbox tb, string t, Row row) + { + if (!await tb.IsHtml(this.r, row)) // we leave the text as is when request is to treat as html + { // this can screw up the generated HTML if not properly formed HTML + // make all the characters browser readable + t = XmlUtil.XmlAnsi(t); + + // handle any specified bookmark + t = Bookmark(await tb.BookmarkValue(this.r, row), t); + + // handle any specified actions + t = await Action(tb.Action, row, t, await tb.ToolTipValue(this.r, row)); + } + // determine if we're in a tablecell + Type tp = tb.Parent.Parent.GetType(); + bool bCell; + if (tp == typeof(TableCell) || + tp == typeof(Corner) || + tp == typeof(DynamicColumns) || + tp == typeof(DynamicRows) || + tp == typeof(StaticRow) || + tp == typeof(StaticColumn) || + tp == typeof(Subtotal) || + tp == typeof(MatrixCell)) + bCell = true; + else + bCell = false; + + if (tp == typeof(Rectangle)) + tw.Write(""); + + if (bCell) + { // The cell has the formatting for this text + if (t == "") + tw.Write("
"); // must have something in cell for formating + else + tw.Write(t); + } + else + { // Formatting must be specified + string cssName = CssAdd(tb.Style, tb, row); // get the style name for this item + + tw.Write("
{1}
", cssName, t); + } + + if (tp == typeof(Rectangle)) + tw.Write(""); + } + + public Task DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table + { + if (noRowsMsg == null) + noRowsMsg = ""; + + bool bTableCell = d.Parent.Parent.GetType() == typeof(TableCell); + + if (bTableCell) + { + if (noRowsMsg == "") + tw.Write("
"); + else + tw.Write(noRowsMsg); + } + else + { + string cssName = CssAdd(d.Style, d, null); // get the style name for this item + tw.Write("
{1}
", cssName, noRowsMsg); + } + + return Task.CompletedTask; + } + + // Lists + public async Task ListStart(List l, Row r) + { + // identifiy reportitem it if necessary + string bookmark = await l.BookmarkValue(this.r, r); + if (bookmark != null) // + tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style + return true; + } + + public async Task ListEnd(List l, Row r) + { + string bookmark = await l.BookmarkValue(this.r, r); + if (bookmark != null) + tw.WriteLine("
"); + } + + public void ListEntryBegin(List l, Row r) + { + string cssName = CssAdd(l.Style, l, r, true); // get the style name for this item; force to be relative + tw.WriteLine(); + tw.WriteLine("
", cssName); + } + + public void ListEntryEnd(List l, Row r) + { + tw.WriteLine(); + tw.WriteLine("
"); + } + + // Tables // Report item table + public async Task TableStart(Table t, Row row) + { + string cssName = CssAdd(t.Style, t, row); // get the style name for this item + + // Determine if report custom defn want this table to be sortable + if (IsTableSortable(t)) + { + this.bScriptTableSort = true; + } + + string bookmark = await t.BookmarkValue(this.r, row); + if (bookmark != null) + tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style + + // Calculate the width of all the columns + int width = await t.WidthInPixels(this.r, row); + if (width <= 0) + tw.WriteLine("", cssName); + else + tw.WriteLine("
", cssName, width); + + return true; + } + + public bool IsTableSortable(Table t) + { + if (t.TableGroups != null || t.Details == null || + t.Details.TableRows == null || t.Details.TableRows.Items.Count != 1) + return false; // can't have tableGroups; must have 1 detail row + + // Determine if report custom defn want this table to be sortable + bool bReturn = false; + if (t.Custom != null) + { + // Loop thru all the child nodes + foreach (XmlNode xNodeLoop in t.Custom.CustomXmlNode.ChildNodes) + { + if (xNodeLoop.Name == "HTML") + { + if (xNodeLoop.LastChild.InnerText.ToLower() == "true") + { + bReturn = true; + } + break; + } + } + } + return bReturn; + } + + public async Task TableEnd(Table t, Row row) + { + string bookmark = await t.BookmarkValue(this.r, row); + if (bookmark != null) + tw.WriteLine(""); + tw.WriteLine("
"); + return; + } + + public void TableBodyStart(Table t, Row row) + { + tw.WriteLine(""); + } + + public void TableBodyEnd(Table t, Row row) + { + tw.WriteLine(""); + } + + public void TableFooterStart(Footer f, Row row) + { + tw.WriteLine(""); + } + + public void TableFooterEnd(Footer f, Row row) + { + tw.WriteLine(""); + } + + public void TableHeaderStart(Header h, Row row) + { + tw.WriteLine(""); + } + + public void TableHeaderEnd(Header h, Row row) + { + tw.WriteLine(""); + } + + public async Task TableRowStart(TableRow tr, Row row) + { + tw.Write("\t"); + } + + public void TableRowEnd(TableRow tr, Row row) + { + tw.WriteLine(""); + } + + public void TableCellStart(TableCell t, Row row) + { + string cellType = t.InTableHeader ? "th" : "td"; + + ReportItem r = t.ReportItems.Items[0]; + + string cssName = CssAdd(r.Style, r, row); // get the style name for this item + + tw.Write("<{0} id='{1}'", cellType, cssName); + + // calculate width of column + if (t.InTableHeader && t.OwnerTable.TableColumns != null) + { + // Calculate the width across all the spanned columns + int width = 0; + for (int ci = t.ColIndex; ci < t.ColIndex + t.ColSpan; ci++) + { + TableColumn tc = t.OwnerTable.TableColumns.Items[ci] as TableColumn; + if (tc != null && tc.Width != null) + width += tc.Width.PixelsX; + } + if (width > 0) + tw.Write(" width={0}", width); + } + + if (t.ColSpan > 1) + tw.Write(" colspan={0}", t.ColSpan); + + Textbox tb = r as Textbox; + if (tb != null && // have textbox + tb.IsToggle && // and its a toggle + tb.Name != null) // and need name as well + { + int groupNestCount = t.OwnerTable.GetGroupNestCount(this.r); + if (groupNestCount > 0) // anything to toggle? + { + string name = tb.Name.Nm + "_" + (tb.RunCount(this.r) + 1).ToString(); + bScriptToggle = true; + + // need both hand and pointer because IE and Firefox use different names + tw.Write(" onClick=\"hideShow(this, {0}, '{1}')\" onMouseOver=\"style.cursor ='hand';style.cursor ='pointer'\">", groupNestCount, name); tw.Write(""); - } - else + } + else tw.Write(""); - } - else - tw.Write(">"); - - if (t.InTableHeader) - { - // put the second half of the sort tags for the column; if needed - // first half ---- - // next half follows text ----     - - string sortcmp = SortType(t, tb); // obtain the sort type - if (sortcmp != null) // null if sort not needed - { - int headerRows, footerRows; - headerRows = t.OwnerTable.Header.TableRows.Items.Count; // since we're in header we know we have some rows - if (t.OwnerTable.Footer != null && - t.OwnerTable.Footer.TableRows != null) - footerRows = t.OwnerTable.Footer.TableRows.Items.Count; - else - footerRows = 0; - tw.Write("",sortcmp, headerRows, footerRows); - } - } - - return; - } - - private string SortType(TableCell tc, Textbox tb) - { - // return of null means don't sort - if (tb == null || !IsTableSortable(tc.OwnerTable)) - return null; - - // default is true if table is sortable; - // but user may place override on Textbox custom tag - if (tb.Custom != null) - { - // Loop thru all the child nodes - foreach(XmlNode xNodeLoop in tb.Custom.CustomXmlNode.ChildNodes) - { - if (xNodeLoop.Name == "HTML") - { - if (xNodeLoop.LastChild.InnerText.ToLower() == "false") - { - return null; - } - break; - } - } - } - - // Must find out the type of the detail column - Details d = tc.OwnerTable.Details; - if (d == null) - return null; - TableRow tr = d.TableRows.Items[0] as TableRow; - if (tr == null) - return null; - TableCell dtc = tr.TableCells.Items[tc.ColIndex] as TableCell; - if (dtc == null) - return null; - Textbox dtb = dtc.ReportItems.Items[0] as Textbox; - if (dtb == null) - return null; - - string sortcmp; - switch (dtb.Value.Type) - { - case TypeCode.DateTime: - sortcmp = "sort_cmp_date"; - break; - case TypeCode.Int16: - case TypeCode.UInt16: - case TypeCode.Int32: - case TypeCode.UInt32: - case TypeCode.Int64: - case TypeCode.UInt64: - case TypeCode.Decimal: - case TypeCode.Single: - case TypeCode.Double: - sortcmp = "sort_cmp_number"; - break; - case TypeCode.String: - sortcmp = "sort_cmp_string"; - break; - case TypeCode.Empty: // Not a type we know how to sort - default: - sortcmp = null; - break; - } - - return sortcmp; - } - - public void TableCellEnd(TableCell t, Row row) - { - string cellType = t.InTableHeader? "th": "td"; - Textbox tb = t.ReportItems.Items[0] as Textbox; - if (cellType == "th" && SortType(t, tb) != null) - { // put the second half of the sort tags for the column - // first half ---- - // next half follows text ----     - tw.Write("   "); - } - - tw.Write("", cellType); - return; - } - - public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first - { - string bookmark = m.BookmarkValue(this.r, r); - if (bookmark != null) - tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style - - // output some of the table styles - string cssName = CssAdd(m.Style, m, r); // get the style name for this item - - tw.WriteLine("", cssName); - return true; - } - - public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after MatrixStart - { - } - - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) - { - if (ri == null) // Empty cell? - { - if (_SkipMatrixCols == 0) - tw.Write(""); - else if (_SkipMatrixCols < 0) - { - tw.Write(""); - _SkipMatrixCols = -_SkipMatrixCols; - } - else - _SkipMatrixCols--; - return; - } - - public void MatrixRowStart(Matrix m, int row, Row r) - { - tw.Write("\t"); - } - - public void MatrixRowEnd(Matrix m, int row, Row r) - { - tw.WriteLine(""); - } - - public void MatrixEnd(Matrix m, Row r) // called last - { - tw.Write("
"); - return; - } - - string cssName = CssAdd(ri.Style, ri, r, false, h, w); // get the style name for this item - - tw.Write(" - } - else - _SkipMatrixCols=0; - if (ri is Textbox) - { - Textbox tb = (Textbox) ri; - if (tb.IsToggle && tb.Name != null) // name is required for this - { - string name = tb.Name.Nm + "_" + (tb.RunCount(this.r)+1).ToString(); - - bScriptToggle = true; // we need to generate JavaScript in header - // TODO -- need to calculate the hide count correctly - tw.Write(" onClick=\"hideShow(this, {0}, '{1}')\" onMouseOver=\"style.cursor ='hand'\"", 0, name); - } - } - - tw.Write(">"); - } - - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) - { - if (_SkipMatrixCols == 0) - tw.Write("
"); - - string bookmark = m.BookmarkValue(this.r, r); - if (bookmark != null) - tw.WriteLine("
"); - return; - } - - public void Chart(Chart c, Row r, ChartBase cb) - { - string relativeName; - - Stream io = _sg.GetIOStream(out relativeName, "png"); - try - { - cb.Save(this.r, io, ImageFormat.Png); - } - finally - { - io.Flush(); - io.Close(); - } - - relativeName = FixupRelativeName(relativeName); - - // Create syntax in a string buffer - StringWriter sw = new StringWriter(); - - string bookmark = c.BookmarkValue(this.r, r); - if (bookmark != null) - sw.WriteLine("
", bookmark); // can't use the table id since we're using for css style - - string cssName = CssAdd(c.Style, c, null); // get the style name for this item - - sw.Write("\"{0}\"","); - if (bookmark != null) - sw.Write("
"); - - tw.Write(Action(c.Action, r, sw.ToString(), tooltip)); - - return; - } - - public void Image(Image i, Row r, string mimeType, Stream ioin) - { - string relativeName; - string suffix; - - switch (mimeType) - { - case "image/bmp": - suffix = "bmp"; - break; - case "image/jpeg": - suffix = "jpeg"; - break; - case "image/gif": - suffix = "gif"; - break; - case "image/png": - case "image/x-png": - suffix = "png"; - break; - default: - suffix = "unk"; - break; - } - Stream io = _sg.GetIOStream(out relativeName, suffix); - try - { - if (ioin.CanSeek) // ioin.Length requires Seek support - { - byte[] ba = new byte[ioin.Length]; - ioin.Read(ba, 0, ba.Length); - io.Write(ba, 0, ba.Length); - } - else - { - byte[] ba = new byte[1000]; // read a 1000 bytes at a time - while (true) - { - int length = ioin.Read(ba, 0, ba.Length); - if (length <= 0) - break; - io.Write(ba, 0, length); - } - } - } - finally - { - io.Flush(); - io.Close(); - } + } + else + tw.Write(">"); + + if (t.InTableHeader) + { + // put the second half of the sort tags for the column; if needed + // first half ---- + // next half follows text ----     + + string sortcmp = SortType(t, tb); // obtain the sort type + if (sortcmp != null) // null if sort not needed + { + int headerRows, footerRows; + headerRows = t.OwnerTable.Header.TableRows.Items.Count; // since we're in header we know we have some rows + if (t.OwnerTable.Footer != null && + t.OwnerTable.Footer.TableRows != null) + footerRows = t.OwnerTable.Footer.TableRows.Items.Count; + else + footerRows = 0; + tw.Write("", sortcmp, headerRows, footerRows); + } + } + + return; + } + + private string SortType(TableCell tc, Textbox tb) + { + // return of null means don't sort + if (tb == null || !IsTableSortable(tc.OwnerTable)) + return null; + + // default is true if table is sortable; + // but user may place override on Textbox custom tag + if (tb.Custom != null) + { + // Loop thru all the child nodes + foreach (XmlNode xNodeLoop in tb.Custom.CustomXmlNode.ChildNodes) + { + if (xNodeLoop.Name == "HTML") + { + if (xNodeLoop.LastChild.InnerText.ToLower() == "false") + { + return null; + } + break; + } + } + } + + // Must find out the type of the detail column + Details d = tc.OwnerTable.Details; + if (d == null) + return null; + TableRow tr = d.TableRows.Items[0] as TableRow; + if (tr == null) + return null; + TableCell dtc = tr.TableCells.Items[tc.ColIndex] as TableCell; + if (dtc == null) + return null; + Textbox dtb = dtc.ReportItems.Items[0] as Textbox; + if (dtb == null) + return null; + + string sortcmp; + switch (dtb.Value.Type) + { + case TypeCode.DateTime: + sortcmp = "sort_cmp_date"; + break; + case TypeCode.Int16: + case TypeCode.UInt16: + case TypeCode.Int32: + case TypeCode.UInt32: + case TypeCode.Int64: + case TypeCode.UInt64: + case TypeCode.Decimal: + case TypeCode.Single: + case TypeCode.Double: + sortcmp = "sort_cmp_number"; + break; + case TypeCode.String: + sortcmp = "sort_cmp_string"; + break; + case TypeCode.Empty: // Not a type we know how to sort + default: + sortcmp = null; + break; + } + + return sortcmp; + } + + public void TableCellEnd(TableCell t, Row row) + { + string cellType = t.InTableHeader ? "th" : "td"; + Textbox tb = t.ReportItems.Items[0] as Textbox; + if (cellType == "th" && SortType(t, tb) != null) + { // put the second half of the sort tags for the column + // first half ---- + // next half follows text ----     + tw.Write("   "); + } + + tw.Write("", cellType); + return; + } + + public async Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first + { + string bookmark = await m.BookmarkValue(this.r, r); + if (bookmark != null) + tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style + + // output some of the table styles + string cssName = CssAdd(m.Style, m, r); // get the style name for this item + + tw.WriteLine("", cssName); + return true; + } + + public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after MatrixStart + { + } + + public Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + { + if (ri == null) // Empty cell? + { + if (_SkipMatrixCols == 0) + tw.Write(""); + else if (_SkipMatrixCols < 0) + { + tw.Write(""); + _SkipMatrixCols = -_SkipMatrixCols; + } + else + _SkipMatrixCols--; + return Task.CompletedTask; + } + + public void MatrixRowStart(Matrix m, int row, Row r) + { + tw.Write("\t"); + } + + public void MatrixRowEnd(Matrix m, int row, Row r) + { + tw.WriteLine(""); + } + + public async Task MatrixEnd(Matrix m, Row r) // called last + { + tw.Write("
"); + return Task.CompletedTask; + } + + string cssName = CssAdd(ri.Style, ri, r, false, h, w); // get the style name for this item + + tw.Write(" + } + else + _SkipMatrixCols = 0; + if (ri is Textbox) + { + Textbox tb = (Textbox)ri; + if (tb.IsToggle && tb.Name != null) // name is required for this + { + string name = tb.Name.Nm + "_" + (tb.RunCount(this.r) + 1).ToString(); + + bScriptToggle = true; // we need to generate JavaScript in header + // TODO -- need to calculate the hide count correctly + tw.Write(" onClick=\"hideShow(this, {0}, '{1}')\" onMouseOver=\"style.cursor ='hand'\"", 0, name); + } + } + + tw.Write(">"); + return Task.CompletedTask; + } + + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + { + if (_SkipMatrixCols == 0) + tw.Write("
"); + + string bookmark = await m.BookmarkValue(this.r, r); + if (bookmark != null) + tw.WriteLine("
"); + return; + } + + public async Task Chart(Chart c, Row r, ChartBase cb) + { + string relativeName; + + Stream io = _sg.GetIOStream(out relativeName, "png"); + try + { + cb.Save(this.r, io, ImageFormat.Png); + } + finally + { + io.Flush(); + io.Close(); + } + + relativeName = FixupRelativeName(relativeName); + + // Create syntax in a string buffer + StringWriter sw = new StringWriter(); + + string bookmark = await c.BookmarkValue(this.r, r); + if (bookmark != null) + sw.WriteLine("
", bookmark); // can't use the table id since we're using for css style + + string cssName = CssAdd(c.Style, c, null); // get the style name for this item + + sw.Write("\"{0}\"","); + if (bookmark != null) + sw.Write("
"); + + tw.Write(Action(c.Action, r, sw.ToString(), tooltip)); + + return; + } + + public async Task Image(Image i, Row r, string mimeType, Stream ioin) + { + string relativeName; + string suffix; + + switch (mimeType) + { + case "image/bmp": + suffix = "bmp"; + break; + case "image/jpeg": + suffix = "jpeg"; + break; + case "image/gif": + suffix = "gif"; + break; + case "image/png": + case "image/x-png": + suffix = "png"; + break; + default: + suffix = "unk"; + break; + } + Stream io = _sg.GetIOStream(out relativeName, suffix); + try + { + if (ioin.CanSeek) // ioin.Length requires Seek support + { + byte[] ba = new byte[ioin.Length]; + ioin.Read(ba, 0, ba.Length); + io.Write(ba, 0, ba.Length); + } + else + { + byte[] ba = new byte[1000]; // read a 1000 bytes at a time + while (true) + { + int length = ioin.Read(ba, 0, ba.Length); + if (length <= 0) + break; + io.Write(ba, 0, length); + } + } + } + finally + { + io.Flush(); + io.Close(); + } if (i.ImageSource == ImageSourceEnum.Embedded) // embedded image in html relativeName = "data:" + mimeType + ";base64," + i.EmbeddedImageData; else relativeName = FixupRelativeName(relativeName); - // Create syntax in a string buffer - StringWriter sw = new StringWriter(); - - string bookmark = i.BookmarkValue(this.r, r); - if (bookmark != null) - sw.WriteLine("
", bookmark); // we're using for css style - - string cssName = CssAdd(i.Style, i, null); // get the style name for this item - - sw.Write("\"{0}\"","); - - if (bookmark != null) - sw.Write("
"); - - tw.Write(Action(i.Action, r, sw.ToString(), tooltip)); - return; - } - - public void Line(Line l, Row r) - { - bool bVertical; - string t; - if (l.Height == null || l.Height.PixelsY > 0) // only handle horizontal rule - { - if (l.Width == null || l.Width.PixelsX > 0) // and vertical rules - return; - bVertical = true; - t = "
"; - } - else - { - bVertical = false; - t = "
"; - } - - string width, left, top, height, color; - Style s = l.Style; - - left = l.Left == null? "0px": l.Left.CSS; - top = l.Top == null? "0px": l.Top.CSS; - - if (bVertical) - { - height = l.Height == null? "0px": l.Height.CSS; - // width comes from the BorderWidth - if (s != null && s.BorderWidth != null && s.BorderWidth.Default != null) - width = s.BorderWidth.Default.EvaluateString(this.r, r); - else - width = "1px"; - } - else - { - width = l.Width == null? "0px": l.Width.CSS; - // height comes from the BorderWidth - if (s != null && s.BorderWidth != null && s.BorderWidth.Default != null) - height = s.BorderWidth.Default.EvaluateString(this.r, r); - else - height = "1px"; - } - - if (s != null && s.BorderColor != null && s.BorderColor.Default != null) - color = s.BorderColor.Default.EvaluateString(this.r, r); - else - color = "black"; - - tw.WriteLine(t, width, left, top, height, color); - return; - } - - public bool RectangleStart(RDL.Rectangle rect, Row r) - { - string cssName = CssAdd(rect.Style, rect, r); // get the style name for this item - - string bookmark = rect.BookmarkValue(this.r, r); - if (bookmark != null) - tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style - - // Calculate the width of all the columns - int width = rect.Width.PixelsX; - if (width < 0) - tw.WriteLine("", cssName); - else - tw.WriteLine("
", cssName, width); - - return true; - } - - public void RectangleEnd(RDL.Rectangle rect, Row r) - { - tw.WriteLine("
"); - string bookmark = rect.BookmarkValue(this.r, r); - if (bookmark != null) - tw.WriteLine("
"); - return; - } - - // Subreport: - public void Subreport(Subreport s, Row r) - { - string cssName = CssAdd(s.Style, s, r); // get the style name for this item - - tw.WriteLine("
", cssName); - - s.ReportDefn.Run(this); - - tw.WriteLine("
"); - } - public void GroupingStart(Grouping g) // called at start of grouping - { - } - public void GroupingInstanceStart(Grouping g) // called at start for each grouping instance - { - } - public void GroupingInstanceEnd(Grouping g) // called at start for each grouping instance - { - } - public void GroupingEnd(Grouping g) // called at end of grouping - { - } - public void RunPages(Pages pgs) // we don't have paging turned on for html - { - } - } - + // Create syntax in a string buffer + StringWriter sw = new StringWriter(); + + string bookmark = await i.BookmarkValue(this.r, r); + if (bookmark != null) + sw.WriteLine("
", bookmark); // we're using for css style + + string cssName = CssAdd(i.Style, i, null); // get the style name for this item + + sw.Write("\"{0}\"","); + + if (bookmark != null) + sw.Write("
"); + + tw.Write(Action(i.Action, r, sw.ToString(), tooltip)); + return; + } + + public async Task Line(Line l, Row r) + { + bool bVertical; + string t; + if (l.Height == null || l.Height.PixelsY > 0) // only handle horizontal rule + { + if (l.Width == null || l.Width.PixelsX > 0) // and vertical rules + return; + bVertical = true; + t = "
"; + } + else + { + bVertical = false; + t = "
"; + } + + string width, left, top, height, color; + Style s = l.Style; + + left = l.Left == null ? "0px" : l.Left.CSS; + top = l.Top == null ? "0px" : l.Top.CSS; + + if (bVertical) + { + height = l.Height == null ? "0px" : l.Height.CSS; + // width comes from the BorderWidth + if (s != null && s.BorderWidth != null && s.BorderWidth.Default != null) + width = await s.BorderWidth.Default.EvaluateString(this.r, r); + else + width = "1px"; + } + else + { + width = l.Width == null ? "0px" : l.Width.CSS; + // height comes from the BorderWidth + if (s != null && s.BorderWidth != null && s.BorderWidth.Default != null) + height = await s.BorderWidth.Default.EvaluateString(this.r, r); + else + height = "1px"; + } + + if (s != null && s.BorderColor != null && s.BorderColor.Default != null) + color = await s.BorderColor.Default.EvaluateString(this.r, r); + else + color = "black"; - class CssCacheEntry2 - { - string _Css; // css - string _Name; // name of entry + tw.WriteLine(t, width, left, top, height, color); + return; + } - public CssCacheEntry2(string css, string name) - { - _Css = css; - _Name = name; - } + public async Task RectangleStart(RDL.Rectangle rect, Row r) + { + string cssName = CssAdd(rect.Style, rect, r); // get the style name for this item - public string Css - { - get { return _Css; } - set { _Css = value; } - } + string bookmark = await rect.BookmarkValue(this.r, r); + if (bookmark != null) + tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style - public string Name - { - get { return _Name; } - set { _Name = value; } - } - } + // Calculate the width of all the columns + int width = rect.Width.PixelsX; + if (width < 0) + tw.WriteLine("", cssName); + else + tw.WriteLine("
", cssName, width); + + return true; + } + + public async Task RectangleEnd(RDL.Rectangle rect, Row r) + { + tw.WriteLine("
"); + string bookmark = await rect.BookmarkValue(this.r, r); + if (bookmark != null) + tw.WriteLine("
"); + return; + } + + // Subreport: + public async Task Subreport(Subreport s, Row r) + { + string cssName = CssAdd(s.Style, s, r); // get the style name for this item + + tw.WriteLine("
", cssName); + + await s.ReportDefn.Run(this); + + tw.WriteLine("
"); + return; + } + public void GroupingStart(Grouping g) // called at start of grouping + { + } + public void GroupingInstanceStart(Grouping g) // called at start for each grouping instance + { + } + public void GroupingInstanceEnd(Grouping g) // called at start for each grouping instance + { + } + public void GroupingEnd(Grouping g) // called at end of grouping + { + } + public void RunPages(Pages pgs) // we don't have paging turned on for html + { + } + } + + + class CssCacheEntry2 + { + string _Css; // css + string _Name; // name of entry + + public CssCacheEntry2(string css, string name) + { + _Css = css; + _Name = name; + } + + public string Css + { + get { return _Css; } + set { _Css = value; } + } + + public string Name + { + get { return _Name; } + set { _Name = value; } + } + } } diff --git a/RdlEngine/Render/IPresent.cs b/RdlEngine/Render/IPresent.cs index 29d07546..a1350c81 100644 --- a/RdlEngine/Render/IPresent.cs +++ b/RdlEngine/Render/IPresent.cs @@ -22,6 +22,7 @@ the website www.fyiReporting.com. */ using System; using System.IO; +using System.Threading.Tasks; using fyiReporting.RDL; @@ -57,53 +58,53 @@ internal interface IPresent : IDisposable void PageFooterEnd(PageFooter pf); // ReportItems - void Textbox(Textbox tb, string t, Row r); // encountered a textbox - void DataRegionNoRows(DataRegion d, string noRowsMsg); // no rows in DataRegion + Task Textbox(Textbox tb, string t, Row r); // encountered a textbox + Task DataRegionNoRows(DataRegion d, string noRowsMsg); // no rows in DataRegion // Lists - bool ListStart(List l, Row r); // called first in list - void ListEnd(List l, Row r); // called last in list + Task ListStart(List l, Row r); // called first in list + Task ListEnd(List l, Row r); // called last in list void ListEntryBegin(List l, Row r); // called to begin each list entry void ListEntryEnd(List l, Row r); // called to end each list entry // Tables // Report item table - bool TableStart(Table t, Row r); // called first in table - void TableEnd(Table t, Row r); // called last in table + Task TableStart(Table t, Row r); // called first in table + Task TableEnd(Table t, Row r); // called last in table void TableBodyStart(Table t, Row r); // table body void TableBodyEnd(Table t, Row r); // void TableFooterStart(Footer f, Row r); // footer row(s) void TableFooterEnd(Footer f, Row r); // void TableHeaderStart(Header h, Row r); // header row(s) void TableHeaderEnd(Header h, Row r); // - void TableRowStart(TableRow tr, Row r); // row + Task TableRowStart(TableRow tr, Row r); // row void TableRowEnd(TableRow tr, Row r); // void TableCellStart(TableCell t, Row r); // report item will be called after void TableCellEnd(TableCell t, Row r); // report item will be called before // Matrix // Report item matrix - bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols); // called first + Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols); // called first void MatrixColumns(Matrix m, MatrixColumns mc); // called just after MatrixStart void MatrixRowStart(Matrix m, int row, Row r); // row void MatrixRowEnd(Matrix m, int row, Row r); // - void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan); - void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r); - void MatrixEnd(Matrix m, Row r); // called last + Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan); + Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r); + Task MatrixEnd(Matrix m, Row r); // called last // Chart - void Chart(Chart c, Row r, ChartBase cb); + Task Chart(Chart c, Row r, ChartBase cb); // Image - void Image(Image i, Row r, string mimeType, Stream io); + Task Image(Image i, Row r, string mimeType, Stream io); // Line - void Line(Line l, Row r); + Task Line(Line l, Row r); // Rectangle - bool RectangleStart(Rectangle rect, Row r); // called before any reportitems - void RectangleEnd(Rectangle rect, Row r); // called after any reportitems + Task RectangleStart(Rectangle rect, Row r); // called before any reportitems + Task RectangleEnd(Rectangle rect, Row r); // called after any reportitems // Subreport - void Subreport(Subreport s, Row r); + Task Subreport(Subreport s, Row r); // Grouping void GroupingStart(Grouping g); // called at start of grouping diff --git a/RdlEngine/Render/ProcessReport.cs b/RdlEngine/Render/ProcessReport.cs index c27bdaa6..8b12841b 100644 --- a/RdlEngine/Render/ProcessReport.cs +++ b/RdlEngine/Render/ProcessReport.cs @@ -84,7 +84,7 @@ public async Task Run(IDictionary parms, OutputPresentationType type) { await r.RunGetData(parms); - r.RunRender(_sg, type); + await r.RunRender(_sg, type); return; } diff --git a/RdlEngine/Render/RenderBase.cs b/RdlEngine/Render/RenderBase.cs index 57db1eb4..021a3972 100644 --- a/RdlEngine/Render/RenderBase.cs +++ b/RdlEngine/Render/RenderBase.cs @@ -42,6 +42,7 @@ limitations under the License. using System.Text; using fyiReporting.RDL.Utility; using System.Security; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -77,7 +78,7 @@ internal protected PdfPageSize PageSize #region abstract methods - internal protected void AddLine(float x, float y, float x2, float y2, StyleInfo si) + internal protected void AddLine(float x, float y, float x2, float y2, StyleInfo si) { AddLine(x, y, x2, y2, si.BWidthTop, si.BColorTop, si.BStyleTop); } @@ -92,13 +93,13 @@ internal protected void AddLine(float x, float y, float x2, float y2, StyleInfo internal abstract protected void AddBookmark(PageText pt); internal abstract protected void AddLine(float x, float y, float x2, float y2, float width, Drawing.Color c, BorderStyleEnum ls); - - + + /// /// Add image to the page. /// /// string Image name - internal abstract protected void AddImage(string name, StyleInfo si, + internal abstract protected void AddImage(string name, StyleInfo si, Drawing2D.ImageFormat imf, float x, float y, float width, float height, Drawing.RectangleF clipRect, byte[] im, int samplesW, int samplesH, string url, string tooltip); @@ -111,17 +112,17 @@ internal abstract protected void AddImage(string name, StyleInfo si, /// internal abstract protected void AddPolygon(Drawing.PointF[] pts, StyleInfo si, string url); - + /// /// Page Rectangle element at the X Y position /// /// - internal abstract protected void AddRectangle(float x, float y, float height, float width, StyleInfo si, string url, string tooltip); + internal abstract protected void AddRectangle(float x, float y, float height, float width, StyleInfo si, string url, string tooltip); /// /// Draw a pie /// /// - internal abstract protected void AddPie(float x, float y, float height, float width, StyleInfo si, string url, string tooltip); + internal abstract protected void AddPie(float x, float y, float height, float width, StyleInfo si, string url, string tooltip); /// /// Draw a curve @@ -130,25 +131,25 @@ internal abstract protected void AddImage(string name, StyleInfo si, internal abstract protected void AddCurve(Drawing.PointF[] pts, StyleInfo si); - + //25072008 GJL Draw 4 bezier curves to approximate a circle internal abstract protected void AddEllipse(float x, float y, float height, float width, StyleInfo si, string url); - + /// /// Page Text element at the X Y position; multiple lines handled /// /// internal abstract protected void AddText(float x, float y, float height, float width, string[] sa, - StyleInfo si, float[] tw, bool bWrap, string url, bool bNoClip, string tooltip); + StyleInfo si, float[] tw, bool bWrap, string url, bool bNoClip, string tooltip); #endregion //Replaced from forum, User: Aulofee http://www.fyireporting.com/forum/viewtopic.php?t=793 public void Dispose() { } - + public RenderBase(Report rep, IStreamGen sg) { _streamGen = sg.GetStream(); @@ -182,9 +183,9 @@ public void RunPages(Pages pgs) // this does all the work { PageSize = new PdfPageSize((int)_report.ReportDefinition.PageWidth.ToPoints(), (int)_report.ReportDefinition.PageHeight.ToPoints()); - + //Create a Page - CreatePage(); + CreatePage(); ProcessPage(pgs, p); // after a page AfterProcessPage(); @@ -242,12 +243,12 @@ private void ProcessPage(Pages pgs, IEnumerable items) { currX = startX + (i * imW); currY = startY + (j * imH); - - - AddImage( bgImg.Name,bgImg.SI, bgImg.ImgFormat, - currX, currY, imW, imH, Drawing.RectangleF.Empty, bgImg.GetImageData(), bgImg.SamplesW, bgImg.SamplesH, null, pi.Tooltip); - + + + AddImage(bgImg.Name, bgImg.SI, bgImg.ImgFormat, + currX, currY, imW, imH, Drawing.RectangleF.Empty, bgImg.GetImageData(), bgImg.SamplesW, bgImg.SamplesH, null, pi.Tooltip); + } } } @@ -265,10 +266,10 @@ private void ProcessPage(Pages pgs, IEnumerable items) PageText pt = pi as PageText; float[] textwidth; string[] sa = MeasureString(pt, pgs.G, out textwidth); - + AddText(pt.X, pt.Y, pt.H, pt.W, sa, pt.SI, textwidth, pt.CanGrow, pt.HyperLink, pt.NoClip, pt.Tooltip); - + if (pt.Bookmark != null) { AddBookmark(pt); @@ -309,10 +310,10 @@ private void ProcessPage(Pages pgs, IEnumerable items) break; case ImageSizingEnum.Clip: - //Set samples size - i.GetImageData((int)r2.Width, (int)r2.Height); + //Set samples size + i.GetImageData((int)r2.Width, (int)r2.Height); - adjustedRect = new Drawing.RectangleF(r2.Left, r2.Top, + adjustedRect = new Drawing.RectangleF(r2.Left, r2.Top, Measurement.PointsFromPixels(i.SamplesW, pgs.G.DpiX), Measurement.PointsFromPixels(i.SamplesH, pgs.G.DpiY)); clipRect = new Drawing.RectangleF(r2.Left, r2.Top, r2.Width, r2.Height); @@ -347,9 +348,9 @@ private void ProcessPage(Pages pgs, IEnumerable items) else { #endif - - AddImage(i.Name, i.SI, i.ImgFormat, - adjustedRect.X, adjustedRect.Y, adjustedRect.Width, adjustedRect.Height, clipRect, i.GetImageData((int)clipRect.Width, (int)clipRect.Height), i.SamplesW, i.SamplesH, i.HyperLink, i.Tooltip); + + AddImage(i.Name, i.SI, i.ImgFormat, + adjustedRect.X, adjustedRect.Y, adjustedRect.Width, adjustedRect.Height, clipRect, i.GetImageData((int)clipRect.Width, (int)clipRect.Height), i.SamplesW, i.SamplesH, i.HyperLink, i.Tooltip); #if !DRAWINGCOMPAT } #endif @@ -359,14 +360,14 @@ private void ProcessPage(Pages pgs, IEnumerable items) if (pi is PageRectangle) { PageRectangle pr = pi as PageRectangle; - AddRectangle(pr.X, pr.Y, pr.H, pr.W, pi.SI, pi.HyperLink, pi.Tooltip); + AddRectangle(pr.X, pr.Y, pr.H, pr.W, pi.SI, pi.HyperLink, pi.Tooltip); continue; } if (pi is PagePie) { // TODO PagePie pp = pi as PagePie; // - AddPie(pp.X, pp.Y, pp.H, pp.W, pi.SI, pi.HyperLink, pi.Tooltip); + AddPie(pp.X, pp.Y, pp.H, pp.W, pi.SI, pi.HyperLink, pi.Tooltip); continue; } if (pi is PagePolygon) @@ -386,7 +387,7 @@ private void ProcessPage(Pages pgs, IEnumerable items) } - + private string[] MeasureString(PageText pt, Drawing.Graphics g, out float[] width) { StyleInfo si = pt.SI; @@ -665,7 +666,7 @@ private Drawing.SizeF MeasureString(string s, Drawing.Graphics g, Drawing.Font d return new Drawing.SizeF(mr.Width, mr.Height); } - + // Body: main container for the report public void BodyStart(Body b) { @@ -691,22 +692,25 @@ public void PageFooterEnd(PageFooter pf) { } - public void Textbox(Textbox tb, string t, Row row) + public Task Textbox(Textbox tb, string t, Row row) { + return Task.CompletedTask; } - public void DataRegionNoRows(DataRegion d, string noRowsMsg) + public Task DataRegionNoRows(DataRegion d, string noRowsMsg) { + return Task.CompletedTask; } // Lists - public bool ListStart(List l, Row r) + public Task ListStart(List l, Row r) { - return true; + return Task.FromResult(true); } - public void ListEnd(List l, Row r) + public Task ListEnd(List l, Row r) { + return Task.CompletedTask; } public void ListEntryBegin(List l, Row r) @@ -718,13 +722,14 @@ public void ListEntryEnd(List l, Row r) } // Tables // Report item table - public bool TableStart(Table t, Row row) + public Task TableStart(Table t, Row row) { - return true; + return Task.FromResult(true); } - public void TableEnd(Table t, Row row) + public Task TableEnd(Table t, Row row) { + return Task.CompletedTask; } public void TableBodyStart(Table t, Row row) @@ -751,8 +756,9 @@ public void TableHeaderEnd(Header h, Row row) { } - public void TableRowStart(TableRow tr, Row row) + public Task TableRowStart(TableRow tr, Row row) { + return Task.CompletedTask; } public void TableRowEnd(TableRow tr, Row row) @@ -769,21 +775,23 @@ public void TableCellEnd(TableCell t, Row row) return; } - public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first + public Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first { - return true; + return Task.FromResult(true); } public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after MatrixStart { } - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + public Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) { + return Task.CompletedTask; } - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) { + return Task.CompletedTask; } public void MatrixRowStart(Matrix m, int row, Row r) @@ -794,34 +802,39 @@ public void MatrixRowEnd(Matrix m, int row, Row r) { } - public void MatrixEnd(Matrix m, Row r) // called last + public Task MatrixEnd(Matrix m, Row r) // called last { + return Task.CompletedTask; } - public void Chart(Chart c, Row r, ChartBase cb) + public Task Chart(Chart c, Row r, ChartBase cb) { + return Task.CompletedTask; } - public void Image(fyiReporting.RDL.Image i, Row r, string mimeType, Stream ior) + public Task Image(fyiReporting.RDL.Image i, Row r, string mimeType, Stream ior) { + return Task.CompletedTask; } - public void Line(Line l, Row r) + public Task Line(Line l, Row r) { - return; + return Task.CompletedTask; } - public bool RectangleStart(fyiReporting.RDL.Rectangle rect, Row r) + public Task RectangleStart(fyiReporting.RDL.Rectangle rect, Row r) { - return true; + return Task.FromResult(true); } - public void RectangleEnd(fyiReporting.RDL.Rectangle rect, Row r) + public Task RectangleEnd(fyiReporting.RDL.Rectangle rect, Row r) { + return Task.CompletedTask; } - public void Subreport(Subreport s, Row r) + public Task Subreport(Subreport s, Row r) { + return Task.CompletedTask; } public void GroupingStart(Grouping g) // called at start of grouping diff --git a/RdlEngine/Render/RenderCsv.cs b/RdlEngine/Render/RenderCsv.cs index b03de3a7..074b5b31 100644 --- a/RdlEngine/Render/RenderCsv.cs +++ b/RdlEngine/Render/RenderCsv.cs @@ -26,6 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Collections; using System.Text; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -95,24 +96,26 @@ public void PageFooterEnd(PageFooter pf) if (pf.PrintOnLastPage || pf.PrintOnFirstPage) {tw.WriteLine();} } - public void Textbox(Textbox tb, string t, Row r) + public async Task Textbox(Textbox tb, string t, Row r) { - object value = tb.Evaluate(report, r); + object value = await tb.Evaluate(report, r); tw.Write(value); } - public void DataRegionNoRows(DataRegion d, string noRowsMsg) + public Task DataRegionNoRows(DataRegion d, string noRowsMsg) { + return Task.CompletedTask; } - public bool ListStart(List l, Row r) + public Task ListStart(List l, Row r) { - return true; + return Task.FromResult(true); } - public void ListEnd(List l, Row r) + public Task ListEnd(List l, Row r) { tw.WriteLine(); + return Task.CompletedTask; } public void ListEntryBegin(List l, Row r) @@ -123,13 +126,14 @@ public void ListEntryEnd(List l, Row r) tw.WriteLine(); } - public bool TableStart(Table t, Row r) + public Task TableStart(Table t, Row r) { - return true; + return Task.FromResult(true); } - public void TableEnd(Table t, Row r) + public Task TableEnd(Table t, Row r) { + return Task.CompletedTask; } public void TableBodyStart(Table t, Row r) @@ -156,8 +160,9 @@ public void TableHeaderEnd(Header h, Row r) { } - public void TableRowStart(TableRow tr, Row r) + public Task TableRowStart(TableRow tr, Row r) { + return Task.CompletedTask; } public void TableRowEnd(TableRow tr, Row r) @@ -173,9 +178,9 @@ public void TableCellEnd(TableCell t, Row r) { } - public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) + public Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) { - return true; + return Task.FromResult(true); } public void MatrixColumns(Matrix m, MatrixColumns mc) @@ -191,41 +196,49 @@ public void MatrixRowEnd(Matrix m, int row, Row r) tw.WriteLine(); } - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + public Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) { + return Task.CompletedTask; } - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) { + return Task.CompletedTask; } - public void MatrixEnd(Matrix m, Row r) + public Task MatrixEnd(Matrix m, Row r) { + return Task.CompletedTask; } - public void Chart(Chart c, Row r, ChartBase cb) + public Task Chart(Chart c, Row r, ChartBase cb) { + return Task.CompletedTask; } - public void Image(Image i, Row r, string mimeType, Stream io) + public Task Image(Image i, Row r, string mimeType, Stream io) { + return Task.CompletedTask; } - public void Line(Line l, Row r) + public Task Line(Line l, Row r) { + return Task.CompletedTask; } - public bool RectangleStart(Rectangle rect, Row r) + public Task RectangleStart(Rectangle rect, Row r) { - return true; + return Task.FromResult(true); } - public void RectangleEnd(Rectangle rect, Row r) + public Task RectangleEnd(Rectangle rect, Row r) { + return Task.CompletedTask; } - public void Subreport(Subreport s, Row r) + public Task Subreport(Subreport s, Row r) { + return Task.CompletedTask; } public void GroupingStart(Grouping g) diff --git a/RdlEngine/Render/RenderExcel2007.cs b/RdlEngine/Render/RenderExcel2007.cs index 631911ab..9ca41986 100644 --- a/RdlEngine/Render/RenderExcel2007.cs +++ b/RdlEngine/Render/RenderExcel2007.cs @@ -31,6 +31,7 @@ the website www.fyiReporting.com. using System.Linq; using NPOI.SS.Util; using NPOI.Util; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -273,19 +274,19 @@ public void PageFooterEnd(PageFooter pf) { } - public void Textbox(Textbox tb, string t, Row row) + public async Task Textbox(Textbox tb, string t, Row row) { - if(!tb.IsHidden(report, row)) { - excelBuilder.AddTextbox(tb, t, row); + if(!await tb.IsHidden(report, row)) { + await excelBuilder.AddTextbox(tb, t, row); } } - private StyleInfo GetStyle(ReportItem ri, Row row) + private async Task GetStyle(ReportItem ri, Row row) { if(ri.Style == null) return null; - return ri.Style.GetStyleInfo(report, row); + return await ri.Style.GetStyleInfo(report, row); } private static bool InTable(ReportItem tb) @@ -307,18 +308,20 @@ private static bool InList(ReportItem tb) return (tp == typeof(List)); } - public void DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table + public Task DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table { + return Task.CompletedTask; } // Lists - public bool ListStart(List l, Row r) + public Task ListStart(List l, Row r) { - return true; + return Task.FromResult(true); } - public void ListEnd(List l, Row r) + public Task ListEnd(List l, Row r) { + return Task.CompletedTask; } public void ListEntryBegin(List l, Row r) @@ -330,9 +333,9 @@ public void ListEntryEnd(List l, Row r) } // Tables // Report item table - public bool TableStart(Table t, Row row) + public async Task TableStart(Table t, Row row) { - if(t.Visibility == null || (t.Visibility != null && !t.Visibility.IsHidden(report, row))) { + if(t.Visibility == null || (t.Visibility != null && !await t.Visibility.IsHidden(report, row))) { excelBuilder.AddTable(t); return true; } @@ -344,9 +347,9 @@ public bool IsTableSortable(Table t) return false; // can't have tableGroups; must have 1 detail row } - public void TableEnd(Table t, Row row) + public Task TableEnd(Table t, Row row) { - return; + return Task.CompletedTask; } public void TableBodyStart(Table t, Row row) @@ -373,9 +376,9 @@ public void TableHeaderEnd(Header h, Row row) { } - public void TableRowStart(TableRow tr, Row row) + public async Task TableRowStart(TableRow tr, Row row) { - excelBuilder.AddRow(tr, row); + await excelBuilder.AddRow(tr, row); } public void TableRowEnd(TableRow tr, Row row) @@ -392,21 +395,23 @@ public void TableCellEnd(TableCell t, Row row) return; } - public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first + public Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first { - return true; + return Task.FromResult(true); } public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after MatrixStart { } - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + public Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) { + return Task.CompletedTask; } - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) { + return Task.CompletedTask; } public void MatrixRowStart(Matrix m, int row, Row r) @@ -417,47 +422,49 @@ public void MatrixRowEnd(Matrix m, int row, Row r) { } - public void MatrixEnd(Matrix m, Row r) // called last + public Task MatrixEnd(Matrix m, Row r) // called last { - return; + return Task.CompletedTask; } - public void Chart(Chart c, Row row, ChartBase cb) + public Task Chart(Chart c, Row row, ChartBase cb) { + return Task.CompletedTask; } - public void Image(Image i, Row r, string mimeType, Stream ioin) + public async Task Image(Image i, Row r, string mimeType, Stream ioin) { - if(i.Visibility == null || (i.Visibility != null && !i.Visibility.IsHidden(report, r))) { + if(i.Visibility == null || (i.Visibility != null && !await i.Visibility.IsHidden(report, r))) { int picIndex = workbook.AddPicture(ioin, XSSFWorkbook.PICTURE_TYPE_JPEG); excelBuilder.AddImage(i, picIndex); } } - public void Line(Line l, Row row) + public async Task Line(Line l, Row row) { float borderWidth = 1; if(l.Style.BorderWidth != null) { - borderWidth = l.Style.BorderWidth.EvalDefault(report, row); + borderWidth = await l.Style.BorderWidth.EvalDefault(report, row); } else if(l.Style.BorderStyle != null) { - borderWidth = (float)l.Style.BorderStyle.EvalDefault(report, row); + borderWidth = (float)await l.Style.BorderStyle.EvalDefault(report, row); } excelBuilder.AddLine(l, borderWidth); - } - public bool RectangleStart(RDL.Rectangle rect, Row r) + public Task RectangleStart(RDL.Rectangle rect, Row r) { - return true; + return Task.FromResult(true); } - public void RectangleEnd(RDL.Rectangle rect, Row r) + public Task RectangleEnd(RDL.Rectangle rect, Row r) { + return Task.CompletedTask; } // Subreport: - public void Subreport(Subreport s, Row r) + public Task Subreport(Subreport s, Row r) { - } + return Task.CompletedTask; + } public void GroupingStart(Grouping g) // called at start of grouping { } diff --git a/RdlEngine/Render/RenderExcel2007DataOnly.cs b/RdlEngine/Render/RenderExcel2007DataOnly.cs index 1cc1a092..f1d5af3d 100644 --- a/RdlEngine/Render/RenderExcel2007DataOnly.cs +++ b/RdlEngine/Render/RenderExcel2007DataOnly.cs @@ -31,6 +31,7 @@ the website www.fyiReporting.com. using System.Linq; using NPOI.SS.Util; using NPOI.Util; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -225,25 +226,27 @@ public void PageFooterEnd(PageFooter pf) { } - public void Textbox(Textbox tb, string t, Row row) + public async Task Textbox(Textbox tb, string t, Row row) { - if(!tb.IsHidden(report, row)) { - excelBuilder.AddTextbox(tb, t, row); + if(!await tb.IsHidden(report, row)) { + await excelBuilder.AddTextbox(tb, t, row); } } - public void DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table + public Task DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table { - } + return Task.CompletedTask; + } // Lists - public bool ListStart(List l, Row r) + public Task ListStart(List l, Row r) { - return true; + return Task.FromResult(true); } - public void ListEnd(List l, Row r) + public Task ListEnd(List l, Row r) { + return Task.FromResult(true); } public void ListEntryBegin(List l, Row r) @@ -255,9 +258,9 @@ public void ListEntryEnd(List l, Row r) } // Tables // Report item table - public bool TableStart(Table t, Row row) + public async Task TableStart(Table t, Row row) { - if(t.Visibility == null || (t.Visibility != null && !t.Visibility.IsHidden(report, row))) { + if(t.Visibility == null || (t.Visibility != null && !await t.Visibility.IsHidden(report, row))) { excelBuilder.AddTable(t); return true; } @@ -269,9 +272,9 @@ public bool IsTableSortable(Table t) return false; // can't have tableGroups; must have 1 detail row } - public void TableEnd(Table t, Row row) + public Task TableEnd(Table t, Row row) { - return; + return Task.CompletedTask; } public void TableBodyStart(Table t, Row row) @@ -298,9 +301,9 @@ public void TableHeaderEnd(Header h, Row row) { } - public void TableRowStart(TableRow tr, Row row) + public async Task TableRowStart(TableRow tr, Row row) { - excelBuilder.AddRow(tr, row); + await excelBuilder.AddRow(tr, row); } public void TableRowEnd(TableRow tr, Row row) @@ -317,21 +320,23 @@ public void TableCellEnd(TableCell t, Row row) return; } - public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first + public Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first { - return true; + return Task.FromResult(true); } public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after MatrixStart { } - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + public Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) { + return Task.FromResult(true); } - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) { + return Task.FromResult(true); } public void MatrixRowStart(Matrix m, int row, Row r) @@ -342,47 +347,49 @@ public void MatrixRowEnd(Matrix m, int row, Row r) { } - public void MatrixEnd(Matrix m, Row r) // called last + public Task MatrixEnd(Matrix m, Row r) // called last { - return; + return Task.CompletedTask; } - public void Chart(Chart c, Row row, ChartBase cb) + public Task Chart(Chart c, Row row, ChartBase cb) { + return Task.CompletedTask; } - public void Image(Image i, Row r, string mimeType, Stream ioin) + public async Task Image(Image i, Row r, string mimeType, Stream ioin) { - if(i.Visibility == null || (i.Visibility != null && !i.Visibility.IsHidden(report, r))) { + if(i.Visibility == null || (i.Visibility != null && !await i.Visibility.IsHidden(report, r))) { int picIndex = workbook.AddPicture(ioin, XSSFWorkbook.PICTURE_TYPE_JPEG); excelBuilder.AddImage(i, picIndex); } } - public void Line(Line l, Row row) + public async Task Line(Line l, Row row) { float borderWidth = 1; if(l.Style.BorderWidth != null) { - borderWidth = l.Style.BorderWidth.EvalDefault(report, row); + borderWidth = await l.Style.BorderWidth.EvalDefault(report, row); } else if(l.Style.BorderStyle != null) { - borderWidth = (float)l.Style.BorderStyle.EvalDefault(report, row); + borderWidth = (float)await l.Style.BorderStyle.EvalDefault(report, row); } excelBuilder.AddLine(l, borderWidth); - } - public bool RectangleStart(RDL.Rectangle rect, Row r) + public Task RectangleStart(RDL.Rectangle rect, Row r) { - return true; + return Task.FromResult(true); } - public void RectangleEnd(RDL.Rectangle rect, Row r) + public Task RectangleEnd(RDL.Rectangle rect, Row r) { + return Task.CompletedTask; } // Subreport: - public void Subreport(Subreport s, Row r) + public Task Subreport(Subreport s, Row r) { - } + return Task.CompletedTask; + } public void GroupingStart(Grouping g) // called at start of grouping { } diff --git a/RdlEngine/Render/RenderHtml.cs b/RdlEngine/Render/RenderHtml.cs index 7471a439..94842b0f 100644 --- a/RdlEngine/Render/RenderHtml.cs +++ b/RdlEngine/Render/RenderHtml.cs @@ -35,6 +35,7 @@ the website www.fyiReporting.com. using System.Text; using System.Xml; using System.Globalization; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -355,7 +356,7 @@ function findObject(id) { } // handle the Action tag - private string Action(Action a, Row r, string t, string tooltip) + private async Task Action(Action a, Row r, string t, string tooltip) { if (a == null) return t; @@ -363,7 +364,7 @@ private string Action(Action a, Row r, string t, string tooltip) string result = t; if (a.Hyperlink != null) { // Handle a hyperlink - string url = a.HyperLinkValue(this.r, r); + string url = await a.HyperLinkValue(this.r, r); if (tooltip == null) result = String.Format("{1}", url, t); else @@ -381,7 +382,7 @@ private string Action(Action a, Row r, string t, string tooltip) bool bFirst = !_Asp; // ASP already have an argument foreach (DrillthroughParameter dtp in a.Drill.DrillthroughParameters.Items) { - if (!dtp.OmitValue(this.r, r)) + if (!await dtp.OmitValue(this.r, r)) { if (bFirst) { // First parameter - prefixed by '?' @@ -408,7 +409,7 @@ private string Action(Action a, Row r, string t, string tooltip) } else if (a.BookmarkLink != null) { // Handle a bookmark - string bm = a.BookmarkLinkValue(this.r, r); + string bm = await a.BookmarkLinkValue(this.r, r); if (tooltip == null) result = String.Format("{1}", bm, t); else @@ -738,9 +739,9 @@ public void PageFooterEnd(PageFooter pf) tw.WriteLine("
"); } - public void Textbox(Textbox tb, string t, Row row) + public async Task Textbox(Textbox tb, string t, Row row) { - if (tb.IsHtml(this.r, row)) // we leave the text as is (except to handle unicode) when request is to treat as html + if (await tb.IsHtml(this.r, row)) // we leave the text as is (except to handle unicode) when request is to treat as html { // this can screw up the generated HTML if not properly formed HTML t = XmlUtil.HtmlAnsi(t); } @@ -750,10 +751,10 @@ public void Textbox(Textbox tb, string t, Row row) t = XmlUtil.XmlAnsi(t); // handle any specified bookmark - t = Bookmark(tb.BookmarkValue(this.r, row), t); + t = Bookmark(await tb.BookmarkValue(this.r, row), t); // handle any specified actions - t = Action(tb.Action, row, t, tb.ToolTipValue(this.r, row)); + t = await Action(tb.Action, row, t, await tb.ToolTipValue(this.r, row)); } // determine if we're in a tablecell Type tp = tb.Parent.Parent.GetType(); @@ -791,7 +792,7 @@ public void Textbox(Textbox tb, string t, Row row) tw.Write(""); } - public void DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table + public Task DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table { if (noRowsMsg == null) noRowsMsg = ""; @@ -810,21 +811,22 @@ public void DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in tab string cssName = CssAdd(d.Style, d, null); // get the style name for this item tw.Write("
{1}
", cssName, noRowsMsg); } + return Task.CompletedTask; } // Lists - public bool ListStart(List l, Row r) + public async Task ListStart(List l, Row r) { // identifiy reportitem it if necessary - string bookmark = l.BookmarkValue(this.r, r); + string bookmark = await l.BookmarkValue(this.r, r); if (bookmark != null) // tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style return true; } - public void ListEnd(List l, Row r) + public async Task ListEnd(List l, Row r) { - string bookmark = l.BookmarkValue(this.r, r); + string bookmark = await l.BookmarkValue(this.r, r); if (bookmark != null) tw.WriteLine("
"); } @@ -843,7 +845,7 @@ public void ListEntryEnd(List l, Row r) } // Tables // Report item table - public bool TableStart(Table t, Row row) + public async Task TableStart(Table t, Row row) { string cssName = CssAdd(t.Style, t, row); // get the style name for this item @@ -853,12 +855,12 @@ public bool TableStart(Table t, Row row) this.bScriptTableSort = true; } - string bookmark = t.BookmarkValue(this.r, row); + string bookmark = await t.BookmarkValue(this.r, row); if (bookmark != null) tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style // Calculate the width of all the columns - int width = t.WidthInPixels(this.r, row); + int width = await t.WidthInPixels(this.r, row); if (width <= 0) tw.WriteLine("", cssName); else @@ -893,9 +895,9 @@ public bool IsTableSortable(Table t) return bReturn; } - public void TableEnd(Table t, Row row) + public async Task TableEnd(Table t, Row row) { - string bookmark = t.BookmarkValue(this.r, row); + string bookmark = await t.BookmarkValue(this.r, row); if (bookmark != null) tw.WriteLine(""); tw.WriteLine("
"); @@ -932,7 +934,7 @@ public void TableHeaderEnd(Header h, Row row) tw.WriteLine(""); } - public void TableRowStart(TableRow tr, Row row) + public async Task TableRowStart(TableRow tr, Row row) { tw.Write("\t MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first { - string bookmark = m.BookmarkValue(this.r, r); + string bookmark = await m.BookmarkValue(this.r, r); if (bookmark != null) tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style @@ -1144,7 +1146,7 @@ public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after Matri { } - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + public async Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) { if (ri == null) // Empty cell? { @@ -1155,7 +1157,7 @@ public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, string cssName = CssAdd(ri.Style, ri, r, false, h, w); // get the style name for this item - tw.Write(""); } - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) { if (_SkipMatrixCols == 0) tw.Write(""); @@ -1190,7 +1192,7 @@ public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) } else _SkipMatrixCols--; - return; + return Task.CompletedTask; } public void MatrixRowStart(Matrix m, int row, Row r) @@ -1205,17 +1207,17 @@ public void MatrixRowEnd(Matrix m, int row, Row r) tw.WriteLine(""); } - public void MatrixEnd(Matrix m, Row r) // called last + public async Task MatrixEnd(Matrix m, Row r) // called last { tw.Write(""); - string bookmark = m.BookmarkValue(this.r, r); + string bookmark = await m.BookmarkValue(this.r, r); if (bookmark != null) tw.WriteLine("
"); return; } - public void Chart(Chart c, Row r, ChartBase cb) + public async Task Chart(Chart c, Row r, ChartBase cb) { string relativeName; @@ -1235,14 +1237,14 @@ public void Chart(Chart c, Row r, ChartBase cb) // Create syntax in a string buffer StringWriter sw = new StringWriter(); - string bookmark = c.BookmarkValue(this.r, r); + string bookmark = await c.BookmarkValue(this.r, r); if (bookmark != null) sw.WriteLine("
", bookmark); // can't use the table id since we're using for css style string cssName = CssAdd(c.Style, c, null); // get the style name for this item sw.Write("\"{0}\"",", bookmark); // we're using for css style @@ -1325,7 +1327,7 @@ public void Image(Image i, Row r, string mimeType, Stream ioin) sw.Write("\"{0}\"", RectangleStart(RDL.Rectangle rect, Row r) { string cssName = CssAdd(rect.Style, rect, r); // get the style name for this item - string bookmark = rect.BookmarkValue(this.r, r); + string bookmark = await rect.BookmarkValue(this.r, r); if (bookmark != null) tw.WriteLine("
", bookmark); // can't use the table id since we're using for css style @@ -1424,26 +1426,27 @@ public bool RectangleStart(RDL.Rectangle rect, Row r) return true; } - public void RectangleEnd(RDL.Rectangle rect, Row r) + public async Task RectangleEnd(RDL.Rectangle rect, Row r) { tw.WriteLine(""); - string bookmark = rect.BookmarkValue(this.r, r); + string bookmark = await rect.BookmarkValue(this.r, r); if (bookmark != null) tw.WriteLine("
"); return; } // Subreport: - public void Subreport(Subreport s, Row r) + public async Task Subreport(Subreport s, Row r) { string cssName = CssAdd(s.Style, s, r); // get the style name for this item tw.WriteLine("
", cssName); - s.ReportDefn.Run(this); + await s.ReportDefn.Run(this); tw.WriteLine("
"); - } + return; + } public void GroupingStart(Grouping g) // called at start of grouping { } diff --git a/RdlEngine/Render/RenderRtf.cs b/RdlEngine/Render/RenderRtf.cs index 8ea0c0a0..a8910178 100644 --- a/RdlEngine/Render/RenderRtf.cs +++ b/RdlEngine/Render/RenderRtf.cs @@ -29,6 +29,8 @@ the website www.fyiReporting.com. using System.Text; using System.Xml; using System.Globalization; +using System.Threading.Tasks; + #if DRAWINGCOMPAT using Drawing = Majorsilence.Drawing; @@ -273,9 +275,9 @@ public void PageFooterEnd(PageFooter pf) { } - public void Textbox(Textbox tb, string t, Row row) + public async Task Textbox(Textbox tb, string t, Row row) { - if (tb.IsHtml(this.r, row)) + if (await tb.IsHtml(this.r, row)) { // just do escape chars > 128? t = RtfAnsi(t); } @@ -290,7 +292,7 @@ public void Textbox(Textbox tb, string t, Row row) if (t != "") { tw.Write("{"); - DoStyle(tb.Style, row); + await DoStyle(tb.Style, row); tw.Write(t); tw.Write("}"); } @@ -347,12 +349,12 @@ private string RtfAnsi(string s) return rs.ToString(); } - private void DoStyle(Style style, Row row) + private async Task DoStyle(Style style, Row row) { if (style == null) return; - StyleInfo si = style.GetStyleInfo(r, row); + StyleInfo si = await style.GetStyleInfo(r, row); // tw.Write(@"\plain"); // reset current attributes @@ -390,14 +392,14 @@ private void DoStyle(Style style, Row row) tw.Write(@"\cf{0} ", ic); } - public void DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table + public async Task DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in table { if (noRowsMsg == null) noRowsMsg = ""; bool bTableCell = d.Parent.Parent.GetType() == typeof(TableCell); - DoStyle(d.Style, null); + await DoStyle(d.Style, null); tw.Write(noRowsMsg); if (bTableCell) { @@ -406,14 +408,15 @@ public void DataRegionNoRows(DataRegion d, string noRowsMsg) // no rows in tab } // Lists - public bool ListStart(List l, Row r) + public Task ListStart(List l, Row r) { - return true; + return Task.FromResult(true); } - public void ListEnd(List l, Row r) + public Task ListEnd(List l, Row r) { - } + return Task.CompletedTask; + } public void ListEntryBegin(List l, Row r) { @@ -424,11 +427,11 @@ public void ListEntryEnd(List l, Row r) } // Tables // Report item table - public bool TableStart(Table t, Row row) + public Task TableStart(Table t, Row row) { tw.Write(@"\par{"); - return true; + return Task.FromResult(true); } public bool IsTableSortable(Table t) @@ -436,10 +439,10 @@ public bool IsTableSortable(Table t) return false; // can't have tableGroups; must have 1 detail row } - public void TableEnd(Table t, Row row) + public Task TableEnd(Table t, Row row) { tw.Write(@"}"); - return; + return Task.CompletedTask; } public void TableBodyStart(Table t, Row row) @@ -466,7 +469,7 @@ public void TableHeaderEnd(Header h, Row row) { } - public void TableRowStart(TableRow tr, Row row) + public async Task TableRowStart(TableRow tr, Row row) { Table t = null; Header head = null; @@ -499,7 +502,7 @@ public void TableRowStart(TableRow tr, Row row) ReportItem ri = tr.TableCells.Items[ci].ReportItems[0]; if (ri.Style != null) { - StyleInfo si = ri.Style.GetStyleInfo(r, row); + StyleInfo si = await ri.Style.GetStyleInfo(r, row); border = string.Format(@"\clbrdrt\{0}\clbrdrl\{1}\clbrdrb\{2}\clbrdrr\{3}", GetBorderStyle(si.BStyleTop), GetBorderStyle(si.BStyleLeft), @@ -568,7 +571,7 @@ public void TableCellEnd(TableCell t, Row row) return; } - public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first + public Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first { _MatrixCellSpan = 0; _MatrixCols = maxCols; @@ -582,14 +585,14 @@ public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRo _MatrixColumnWidths[i] = RSize.TwipsFromPoints(widths[i]); tw.Write(@"\par{"); - return true; + return Task.FromResult(true); } public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after MatrixStart { } - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + public async Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) { _MatrixCellSpan = colSpan; // save this so that we can put out the right number of \cell @@ -609,7 +612,7 @@ public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, string border; if (ri != null && ri.Style != null) { - StyleInfo si = ri.Style.GetStyleInfo(this.r, r); + StyleInfo si = await ri.Style.GetStyleInfo(this.r, r); border = string.Format(@"\clbrdrt\{0}\clbrdrl\{1}\clbrdrb\{2}\clbrdrr\{3}", GetBorderStyle(si.BStyleTop), GetBorderStyle(si.BStyleLeft), @@ -625,9 +628,10 @@ public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, } - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) { tw.Write(@"\cell"); + return Task.CompletedTask; } public void MatrixRowStart(Matrix m, int row, Row r) @@ -640,16 +644,16 @@ public void MatrixRowEnd(Matrix m, int row, Row r) tw.WriteLine(@"\row"); } - public void MatrixEnd(Matrix m, Row r) // called last + public Task MatrixEnd(Matrix m, Row r) // called last { _MatrixCellSpan = _MatrixCols = _MatrixRows = _MatrixHeaderRows = 0; _MatrixData = null; _MatrixColumnWidths = null; tw.WriteLine(@"}"); - return; + return Task.CompletedTask; } - public void Chart(Chart c, Row row, ChartBase cb) + public Task Chart(Chart c, Row row, ChartBase cb) { Drawing.Image im = cb.Image(r); @@ -657,8 +661,10 @@ public void Chart(Chart c, Row row, ChartBase cb) if (InTable(c)) tw.Write(@"\cell"); + + return Task.CompletedTask; } - public void Image(Image i, Row r, string mimeType, Stream ioin) + public Task Image(Image i, Row r, string mimeType, Stream ioin) { using (Drawing.Image im = Drawing.Image.FromStream(ioin)) { @@ -682,6 +688,8 @@ public void Image(Image i, Row r, string mimeType, Stream ioin) // case ImageSizingEnum.FitProportional: // break; // would have to create an image to handle this //} + + return Task.CompletedTask; } /// /// Put an image stream out. Use by Chart and Image @@ -725,24 +733,26 @@ private int GetTwipsFromPixels(int pixels) return (int)Math.Round(RSize.PointsFromPixels(GetGraphics, pixels) * 20, 0); } - public void Line(Line l, Row r) + public Task Line(Line l, Row r) { - return; + return Task.CompletedTask; } - public bool RectangleStart(RDL.Rectangle rect, Row r) + public Task RectangleStart(RDL.Rectangle rect, Row r) { - return true; + return Task.FromResult(true); } - public void RectangleEnd(RDL.Rectangle rect, Row r) + public Task RectangleEnd(RDL.Rectangle rect, Row r) { - } + return Task.CompletedTask; + } // Subreport: - public void Subreport(Subreport s, Row r) + public Task Subreport(Subreport s, Row r) { - } + return Task.CompletedTask; + } public void GroupingStart(Grouping g) // called at start of grouping { } diff --git a/RdlEngine/Render/RenderTif.cs b/RdlEngine/Render/RenderTif.cs index 38d48365..c9d5bdea 100644 --- a/RdlEngine/Render/RenderTif.cs +++ b/RdlEngine/Render/RenderTif.cs @@ -32,6 +32,7 @@ the website www.fyiReporting.com. using System.Text; using System.Runtime.InteropServices; +using System.Threading.Tasks; namespace fyiReporting.RDL @@ -873,22 +874,25 @@ public void PageFooterEnd(PageFooter pf) { } - public void Textbox(Textbox tb, string t, Row row) + public Task Textbox(Textbox tb, string t, Row row) { + return Task.CompletedTask; } - public void DataRegionNoRows(DataRegion d, string noRowsMsg) + public Task DataRegionNoRows(DataRegion d, string noRowsMsg) { + return Task.CompletedTask; } // Lists - public bool ListStart(List l, Row r) + public Task ListStart(List l, Row r) { - return true; + return Task.FromResult(true); } - public void ListEnd(List l, Row r) + public Task ListEnd(List l, Row r) { + return Task.CompletedTask; } public void ListEntryBegin(List l, Row r) @@ -900,13 +904,14 @@ public void ListEntryEnd(List l, Row r) } // Tables // Report item table - public bool TableStart(Table t, Row row) + public Task TableStart(Table t, Row row) { - return true; + return Task.FromResult(true); } - public void TableEnd(Table t, Row row) + public Task TableEnd(Table t, Row row) { + return Task.CompletedTask; } public void TableBodyStart(Table t, Row row) @@ -933,8 +938,9 @@ public void TableHeaderEnd(Header h, Row row) { } - public void TableRowStart(TableRow tr, Row row) + public Task TableRowStart(TableRow tr, Row row) { + return Task.CompletedTask; } public void TableRowEnd(TableRow tr, Row row) @@ -951,21 +957,23 @@ public void TableCellEnd(TableCell t, Row row) return; } - public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first + public Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first { - return true; + return Task.FromResult(true); } public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after MatrixStart { } - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + public Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) { + return Task.CompletedTask; } - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) { + return Task.CompletedTask; } public void MatrixRowStart(Matrix m, int row, Row r) @@ -976,34 +984,39 @@ public void MatrixRowEnd(Matrix m, int row, Row r) { } - public void MatrixEnd(Matrix m, Row r) // called last + public Task MatrixEnd(Matrix m, Row r) // called last { + return Task.CompletedTask; } - public void Chart(Chart c, Row r, ChartBase cb) + public Task Chart(Chart c, Row r, ChartBase cb) { + return Task.CompletedTask; } - public void Image(fyiReporting.RDL.Image i, Row r, string mimeType, Stream ior) + public Task Image(fyiReporting.RDL.Image i, Row r, string mimeType, Stream ior) { + return Task.CompletedTask; } - public void Line(Line l, Row r) + public Task Line(Line l, Row r) { - return; + return Task.CompletedTask; } - public bool RectangleStart(RDL.Rectangle rect, Row r) + public Task RectangleStart(RDL.Rectangle rect, Row r) { - return true; + return Task.FromResult(true); } - public void RectangleEnd(RDL.Rectangle rect, Row r) + public Task RectangleEnd(RDL.Rectangle rect, Row r) { + return Task.CompletedTask; } - public void Subreport(Subreport s, Row r) + public Task Subreport(Subreport s, Row r) { + return Task.CompletedTask; } public void GroupingStart(Grouping g) // called at start of grouping diff --git a/RdlEngine/Render/RenderXml.cs b/RdlEngine/Render/RenderXml.cs index 6f4c3bde..5f97d071 100644 --- a/RdlEngine/Render/RenderXml.cs +++ b/RdlEngine/Render/RenderXml.cs @@ -26,6 +26,7 @@ the website www.fyiReporting.com. using System.IO; using System.Collections; using System.Text; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -106,11 +107,11 @@ public void PageFooterEnd(PageFooter pf) { } - public void Textbox(Textbox tb, string t, Row row) + public Task Textbox(Textbox tb, string t, Row row) { if (tb.DataElementOutput != DataElementOutputEnum.Output || tb.DataElementName == null) - return; + return Task.CompletedTask; if (rowstart != null) // In case no items in row are visible { // we delay until we get one. @@ -127,32 +128,34 @@ public void Textbox(Textbox tb, string t, Row row) { // write out as element WriteElement("<{0}>{1}", tb.DataElementName, t); } - } + return Task.CompletedTask; + } - public void DataRegionNoRows(DataRegion t, string noRowMsg) + public Task DataRegionNoRows(DataRegion t, string noRowMsg) { - } + return Task.CompletedTask; + } // Lists - public bool ListStart(List l, Row r) + public Task ListStart(List l, Row r) { if (l.DataElementOutput == DataElementOutputEnum.NoOutput) - return false; + return Task.FromResult(false); if (l.DataElementOutput == DataElementOutputEnum.ContentsOnly) - return true; + return Task.FromResult(true); WriteElementLine("<{0}>", l.DataElementName); - return true; //want to continue + return Task.FromResult(true); //want to continue } - public void ListEnd(List l, Row r) + public Task ListEnd(List l, Row r) { if (l.DataElementOutput == DataElementOutputEnum.NoOutput || l.DataElementOutput == DataElementOutputEnum.ContentsOnly) - return; + return Task.CompletedTask; WriteElementLine("", l.DataElementName); - return; + return Task.CompletedTask; } public void ListEntryBegin(List l, Row r) @@ -186,10 +189,10 @@ public void ListEntryEnd(List l, Row r) } // Tables // Report item table - public bool TableStart(Table t, Row row) + public Task TableStart(Table t, Row row) { if (t.DataElementOutput == DataElementOutputEnum.NoOutput) - return false; + return Task.FromResult(false); PushContainer(t.DataElementName); @@ -198,20 +201,20 @@ public bool TableStart(Table t, Row row) if (cName != null) WriteAttributeLine("><{0}", cName); - return true; + return Task.FromResult(true); } - public void TableEnd(Table t, Row row) + public Task TableEnd(Table t, Row row) { if (t.DataElementOutput == DataElementOutputEnum.NoOutput) - return; + return Task.CompletedTask; string cName = TableGetCollectionName(t); PopContainer(cName); WriteElementLine("", t.DataElementName); stkReportItem.Pop(); - return; + return Task.CompletedTask; } string TableGetCollectionName(Table t) @@ -254,12 +257,13 @@ public void TableHeaderEnd(Header h, Row row) { } - public void TableRowStart(TableRow tr, Row row) + public Task TableRowStart(TableRow tr, Row row) { string n = TableGetRowElementName(tr); if (n == null) - return; + return Task.CompletedTask; PushContainer(n); + return Task.CompletedTask; } public void TableRowEnd(TableRow tr, Row row) @@ -306,26 +310,28 @@ public void TableCellEnd(TableCell t, Row row) return; } - public bool MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first + public Task MatrixStart(Matrix m, MatrixCellEntry[,] matrix, Row r, int headerRows, int maxRows, int maxCols) // called first { if (m.DataElementOutput != DataElementOutputEnum.Output) - return false; + return Task.FromResult(false); tw.WriteLine("<" + (m.DataElementName == null? "Matrix": m.DataElementName) + ">"); - return true; + return Task.FromResult(true); } public void MatrixColumns(Matrix m, MatrixColumns mc) // called just after MatrixStart { } - public void MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) + public Task MatrixCellStart(Matrix m, ReportItem ri, int row, int column, Row r, float h, float w, int colSpan) { + return Task.CompletedTask; } - public void MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) + public Task MatrixCellEnd(Matrix m, ReportItem ri, int row, int column, Row r) { - } + return Task.CompletedTask; + } public void MatrixRowStart(Matrix m, int row, Row r) { @@ -335,24 +341,28 @@ public void MatrixRowEnd(Matrix m, int row, Row r) { } - public void MatrixEnd(Matrix m, Row r) // called last + public Task MatrixEnd(Matrix m, Row r) // called last { tw.WriteLine(""); - } + return Task.CompletedTask; + } - public void Chart(Chart c, Row r, ChartBase cb) + public Task Chart(Chart c, Row r, ChartBase cb) { + return Task.CompletedTask; } - public void Image(Image i, Row r, string mimeType, Stream io) + public Task Image(Image i, Row r, string mimeType, Stream io) { - } + return Task.CompletedTask; + } - public void Line(Line l, Row r) + public Task Line(Line l, Row r) { - } + return Task.CompletedTask; + } - public bool RectangleStart(RDL.Rectangle rect, Row r) + public Task RectangleStart(RDL.Rectangle rect, Row r) { bool rc=true; switch (rect.DataElementOutput) @@ -374,28 +384,30 @@ public bool RectangleStart(RDL.Rectangle rect, Row r) break; } - return rc; + return Task.FromResult(rc); } - public void RectangleEnd(RDL.Rectangle rect, Row r) + public Task RectangleEnd(RDL.Rectangle rect, Row r) { if (rect.DataElementOutput != DataElementOutputEnum.Output) - return; + return Task.CompletedTask; PopContainer(rect.DataElementName); + + return Task.CompletedTask; } - public void Subreport(Subreport s, Row r) + public async Task Subreport(Subreport s, Row r) { if (s.DataElementOutput != DataElementOutputEnum.Output) - return; + return; - PushContainer(s.DataElementName); + PushContainer(s.DataElementName); - s.ReportDefn.Run(this); + await s.ReportDefn.Run(this); PopContainer(s.DataElementName); - return; - } + return; + } public void GroupingStart(Grouping g) // called at start of grouping { if (g.DataElementOutput != DataElementOutputEnum.Output) diff --git a/RdlEngine/Runtime/DataSet.cs b/RdlEngine/Runtime/DataSet.cs index 8eccc3b0..a4d99254 100644 --- a/RdlEngine/Runtime/DataSet.cs +++ b/RdlEngine/Runtime/DataSet.cs @@ -27,6 +27,7 @@ the website www.fyiReporting.com. using System.IO; using System.Data; using System.Data.SqlClient; +using System.Threading.Tasks; namespace fyiReporting.RDL { @@ -45,19 +46,19 @@ internal DataSet(Report rpt, DataSetDefn dsd) _dsd = dsd; } - public void SetData(IDataReader dr) + public async Task SetData(IDataReader dr) { - _dsd.Query.SetData(_rpt, dr, _dsd.Fields, _dsd.Filters); // get the data (and apply the filters + await _dsd.Query.SetData(_rpt, dr, _dsd.Fields, _dsd.Filters); // get the data (and apply the filters } - public void SetData(DataTable dt) + public async Task SetData(DataTable dt) { - _dsd.Query.SetData(_rpt, dt, _dsd.Fields, _dsd.Filters); + await _dsd.Query.SetData(_rpt, dt, _dsd.Fields, _dsd.Filters); } - public void SetData(XmlDocument xmlDoc) + public async Task SetData(XmlDocument xmlDoc) { - _dsd.Query.SetData(_rpt, xmlDoc, _dsd.Fields, _dsd.Filters); + await _dsd.Query.SetData(_rpt, xmlDoc, _dsd.Fields, _dsd.Filters); } /// @@ -70,14 +71,14 @@ public void SetData(XmlDocument xmlDoc) /// /// /// - public void SetData(IEnumerable ie, bool collection = false) + public async Task SetData(IEnumerable ie, bool collection = false) { - _dsd.Query.SetData(_rpt, ie, _dsd.Fields, _dsd.Filters, collection); + await _dsd.Query.SetData(_rpt, ie, _dsd.Fields, _dsd.Filters, collection); } - public void SetSource(string sql) + public async Task SetSource(string sql) { - _dsd.Query.CommandText.SetSource(sql); + await _dsd.Query.CommandText.SetSource(sql); } diff --git a/RdlEngine/Runtime/Report.cs b/RdlEngine/Runtime/Report.cs index 01aacc6b..e0c5c199 100644 --- a/RdlEngine/Runtime/Report.cs +++ b/RdlEngine/Runtime/Report.cs @@ -152,9 +152,9 @@ public async Task RunGetData(IDictionary parms) /// /// IStreamGen for generating result stream /// Presentation type: HTML, XML, PDF, or ASP compatible HTML - public void RunRender(IStreamGen sg, OutputPresentationType type) + public async Task RunRender(IStreamGen sg, OutputPresentationType type) { - RunRender(sg, type, ""); + await RunRender(sg, type, ""); } /// @@ -163,7 +163,7 @@ public void RunRender(IStreamGen sg, OutputPresentationType type) /// IStreamGen for generating result stream /// Presentation type: HTML, XML, PDF, MHT, or ASP compatible HTML /// For HTML puts prefix allowing unique name generation - public void RunRender(IStreamGen sg, OutputPresentationType type, string prefix) + public async Task RunRender(IStreamGen sg, OutputPresentationType type, string prefix) { if (sg == null) throw new ArgumentException("IStreamGen argument cannot be null.", "sg"); @@ -179,18 +179,18 @@ public void RunRender(IStreamGen sg, OutputPresentationType type, string prefix) case OutputPresentationType.RenderPdf_iTextSharp: case OutputPresentationType.PDFOldStyle: ip =new RenderPdf_iTextSharp(this, sg); - _Report.Run(ip); + await _Report.Run(ip); break; #if !DRAWINGCOMPAT case OutputPresentationType.TIF: ip = new RenderTif(this, sg); - _Report.Run(ip); + await _Report.Run(ip); break; case OutputPresentationType.TIFBW: RenderTif rtif = new RenderTif(this, sg); rtif.RenderColor = false; ip = rtif; - _Report.Run(ip); + await _Report.Run(ip); break; #endif case OutputPresentationType.XML: @@ -198,35 +198,35 @@ public void RunRender(IStreamGen sg, OutputPresentationType type, string prefix) { msg = new MemoryStreamGen(); ip = new RenderXml(this, msg); - _Report.Run(ip); + await _Report.Run(ip); RunRenderXmlTransform(sg, msg); } else { - ip = new RenderXml(this, sg); - _Report.Run(ip); + ip = new RenderXml(this, sg); + await _Report.Run(ip); } break; case OutputPresentationType.MHTML: - this.RunRenderMht(sg); + await this.RunRenderMht(sg); break; case OutputPresentationType.CSV: ip = new RenderCsv(this, sg); - _Report.Run(ip); + await _Report.Run(ip); break; case OutputPresentationType.RTF: ip = new RenderRtf(this, sg); - _Report.Run(ip); + await _Report.Run(ip); break; case OutputPresentationType.Excel2003: case OutputPresentationType.Excel2007: ip = new RenderExcel2007(this, sg); - _Report.Run(ip); + await _Report.Run(ip); break; case OutputPresentationType.ExcelTableOnly: case OutputPresentationType.Excel2007DataOnly: ip = new RenderExcel2007DataOnly(this, sg); - _Report.Run(ip); + await _Report.Run(ip); break; case OutputPresentationType.ASPHTML: case OutputPresentationType.HTML: @@ -234,7 +234,7 @@ public void RunRender(IStreamGen sg, OutputPresentationType type, string prefix) ip = rh = new RenderHtml(this, sg); rh.Asp = (type == OutputPresentationType.ASPHTML); rh.Prefix = prefix; - _Report.Run(ip); + await _Report.Run(ip); // Retain the CSS and JavaScript if (rh != null) { @@ -249,7 +249,7 @@ public void RunRender(IStreamGen sg, OutputPresentationType type, string prefix) return; } - private void RunRenderMht(IStreamGen sg) + private async Task RunRenderMht(IStreamGen sg) { OneFileStreamGen temp = null; FileStream fs=null; @@ -257,7 +257,7 @@ private void RunRenderMht(IStreamGen sg) { string tempHtmlReportFileName = Path.ChangeExtension(Path.GetTempFileName(), "htm"); temp = new OneFileStreamGen(tempHtmlReportFileName, true); - RunRender(temp, OutputPresentationType.HTML); + await RunRender(temp, OutputPresentationType.HTML); temp.CloseMainStream(); // Create the mht file (into a temporary file position) @@ -384,7 +384,7 @@ private void RunRenderXmlTransform(IStreamGen sg, MemoryStreamGen msg) /// Build the Pages for this report. /// /// - public Pages BuildPages() + public async Task BuildPages() { PageNumber = 1; // reset page numbers TotalPages = 1; @@ -397,17 +397,17 @@ public Pages BuildPages() Page p = new Page(1); // kick it off with a new page pgs.AddPage(p); - // Create all the pages - _Report.Body.RunPage(pgs); + // Create all the pages + await _Report.Body.RunPage(pgs); if (pgs.LastPage.IsEmpty() && pgs.PageCount > 1) // get rid of extraneous pages which pgs.RemoveLastPage(); // can be caused by region page break at end // Now create the headers and footers for all the pages (as needed) if (_Report.PageHeader != null) - _Report.PageHeader.RunPage(pgs); + await _Report.PageHeader.RunPage(pgs); if (_Report.PageFooter != null) - _Report.PageFooter.RunPage(pgs); + await _Report.PageFooter.RunPage(pgs); // clear out any runtime clutter foreach (Page pg in pgs) pg.ResetPageExpressions(); @@ -656,8 +656,11 @@ public string ClientLanguage { get { - if (_Report.Language != null) - return _Report.Language.EvaluateString(this, null); + if (_Report.Language != null) + { + // HACK: async + return Task.Run(async () => await _Report.Language.EvaluateString(this, null)).GetAwaiter().GetResult(); + } if (_ClientLanguage != null) return _ClientLanguage; diff --git a/RdlGtk3/CairoPdfWriter.cs b/RdlGtk3/CairoPdfWriter.cs index 23985243..3fbdeb29 100644 --- a/RdlGtk3/CairoPdfWriter.cs +++ b/RdlGtk3/CairoPdfWriter.cs @@ -22,6 +22,7 @@ // limitations under the License. using System; using System.IO; +using System.Threading.Tasks; using fyiReporting.RDL; @@ -35,9 +36,9 @@ public CairoPdfWriter() #region IPdfWriter implementation - public byte[] GetFileBytes(Report report) + public async Task GetFileBytes(Report report) { - var pages = report.BuildPages(); + var pages = await report.BuildPages(); int width = (int)report.PageWidthPoints; int height = (int)report.PageHeightPoints; string filename = string.Format("gen-{0}.pdf", Guid.NewGuid()); diff --git a/RdlGtk3/MainWindow.cs b/RdlGtk3/MainWindow.cs index f3f2aea4..d01c4566 100644 --- a/RdlGtk3/MainWindow.cs +++ b/RdlGtk3/MainWindow.cs @@ -176,7 +176,7 @@ protected async void OnFileOpen_Activated(object sender, System.EventArgs e) if (System.IO.File.Exists(filename)) { - string parameters = this.GetParameters(new Uri(filename)); + string parameters = await this.GetParameters(new Uri(filename)); await this.reportviewer1.LoadReport(new Uri(filename), parameters); } } @@ -224,12 +224,12 @@ public void OnLastPageButton_Activated(object sender, System.EventArgs e) //this.reportviewer1.LastPage(); } - private string GetParameters(Uri sourcefile) + private async Task GetParameters(Uri sourcefile) { string parameters = ""; string sourceRdl = System.IO.File.ReadAllText(sourcefile.LocalPath); fyiReporting.RDL.RDLParser parser = new fyiReporting.RDL.RDLParser(sourceRdl); - parser.Parse(); + await parser.Parse(); if (parser.Report.UserReportParameters.Count > 0) { diff --git a/RdlGtk3/ReportExporter.cs b/RdlGtk3/ReportExporter.cs index ef724708..9ab63305 100644 --- a/RdlGtk3/ReportExporter.cs +++ b/RdlGtk3/ReportExporter.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Threading.Tasks; using fyiReporting.RDL; namespace fyiReporting.RdlGtk3 @@ -21,14 +22,14 @@ public static class ReportExporter /// Example: parameter1=someValue¶meter2=anotherValue /// Relace all Connection string in report. /// If true connection string in subreport also will be overwrite - public static void Export(Uri filename, string parameters, string connectionStr, string fileName, OutputPresentationType exportType, bool overwriteSubreportCon = false) + public static async Task Export(Uri filename, string parameters, string connectionStr, string fileName, OutputPresentationType exportType, bool overwriteSubreportCon = false) { //SourceFile = filename; connectionString = connectionStr; overwriteSubreportConnection = overwriteSubreportCon; - Export(filename, parameters, fileName, exportType); + await Export(filename, parameters, fileName, exportType); } /// @@ -38,12 +39,12 @@ public static void Export(Uri filename, string parameters, string connectionStr, /// Example: parameter1=someValue¶meter2=anotherValue /// Relace all Connection string in report. /// If true connection string in subreport also will be overwrite - public static void Export(string source, string parameters, string connectionStr, string fileName, OutputPresentationType exportType, bool overwriteSubreportCon = false) + public static async Task Export(string source, string parameters, string connectionStr, string fileName, OutputPresentationType exportType, bool overwriteSubreportCon = false) { connectionString = connectionStr; overwriteSubreportConnection = overwriteSubreportCon; - Export(source, parameters, fileName, exportType); + await Export(source, parameters, fileName, exportType); } /// @@ -52,9 +53,9 @@ public static void Export(string source, string parameters, string connectionStr /// /// Filename. /// - public static void Export(Uri filename, string fileName, OutputPresentationType exportType) + public static async Task Export(Uri filename, string fileName, OutputPresentationType exportType) { - Export(filename, "", fileName, exportType); + await Export(filename, "", fileName, exportType); } /// @@ -66,13 +67,13 @@ public static void Export(Uri filename, string fileName, OutputPresentationType /// /// Example: parameter1=someValue¶meter2=anotherValue /// - public static void Export(Uri sourcefile, string parameters, string fileName, OutputPresentationType exportType) + public static async Task Export(Uri sourcefile, string parameters, string fileName, OutputPresentationType exportType) { sourceFileUri = sourcefile; workingDirectory = System.IO.Path.GetDirectoryName(sourcefile.LocalPath); string source = System.IO.File.ReadAllText(sourcefile.LocalPath); - Export(source, parameters, fileName, exportType); + await Export(source, parameters, fileName, exportType); } /// @@ -80,23 +81,23 @@ public static void Export(Uri sourcefile, string parameters, string fileName, Ou /// /// Xml source of report /// Example: parameter1=someValue¶meter2=anotherValue - public static void Export(string source, string parameters, string fileName, OutputPresentationType exportType) + public static async Task Export(string source, string parameters, string fileName, OutputPresentationType exportType) { // Compile the report - report = GetReport(source); + report = await GetReport(source); if(report == null) { throw new ArgumentException("Can not compile report"); } - report.RunGetData(GetParmeters(parameters)); + await report.RunGetData(GetParmeters(parameters)); OneFileStreamGen sg = null; try { sg = new OneFileStreamGen(fileName, true); - report.RunRender(sg, exportType); + await report.RunRender(sg, exportType); } catch(Exception ex) { - throw ex; + throw; } finally { if(sg != null) { sg.CloseMainStream(); @@ -115,14 +116,14 @@ public static void Export(string source, string parameters, string fileName, Out /// Example: parameter1=someValue¶meter2=anotherValue /// Relace all Connection string in report. /// If true connection string in subreport also will be overwrite - public static MemoryStream ExportToMemoryStream(Uri filename, string parameters, string connectionStr, OutputPresentationType exportType, bool overwriteSubreportCon = false) + public static async Task ExportToMemoryStream(Uri filename, string parameters, string connectionStr, OutputPresentationType exportType, bool overwriteSubreportCon = false) { //SourceFile = filename; connectionString = connectionStr; overwriteSubreportConnection = overwriteSubreportCon; - return ExportToMemoryStream(filename, parameters, exportType); + return await ExportToMemoryStream(filename, parameters, exportType); } /// @@ -132,12 +133,12 @@ public static MemoryStream ExportToMemoryStream(Uri filename, string parameters, /// Example: parameter1=someValue¶meter2=anotherValue /// Relace all Connection string in report. /// If true connection string in subreport also will be overwrite - public static MemoryStream ExportToMemoryStream(string source, string parameters, string connectionStr, OutputPresentationType exportType, bool overwriteSubreportCon = false) + public static async Task ExportToMemoryStream(string source, string parameters, string connectionStr, OutputPresentationType exportType, bool overwriteSubreportCon = false) { connectionString = connectionStr; overwriteSubreportConnection = overwriteSubreportCon; - return ExportToMemoryStream(source, parameters, exportType); + return await ExportToMemoryStream(source, parameters, exportType); } /// @@ -146,9 +147,9 @@ public static MemoryStream ExportToMemoryStream(string source, string parameters /// /// Filename. /// - public static MemoryStream ExportToMemoryStream(Uri filename, OutputPresentationType exportType) + public static async Task ExportToMemoryStream(Uri filename, OutputPresentationType exportType) { - return ExportToMemoryStream(filename, "", exportType); + return await ExportToMemoryStream(filename, "", exportType); } /// @@ -160,13 +161,13 @@ public static MemoryStream ExportToMemoryStream(Uri filename, OutputPresentation /// /// Example: parameter1=someValue¶meter2=anotherValue /// - public static MemoryStream ExportToMemoryStream(Uri sourcefile, string parameters, OutputPresentationType exportType) + public static async Task ExportToMemoryStream(Uri sourcefile, string parameters, OutputPresentationType exportType) { sourceFileUri = sourcefile; workingDirectory = System.IO.Path.GetDirectoryName(sourcefile.LocalPath); string source = System.IO.File.ReadAllText(sourcefile.LocalPath); - return ExportToMemoryStream(source, parameters, exportType); + return await ExportToMemoryStream(source, parameters, exportType); } /// @@ -174,26 +175,26 @@ public static MemoryStream ExportToMemoryStream(Uri sourcefile, string parameter /// /// Xml source of report /// Example: parameter1=someValue¶meter2=anotherValue - public static MemoryStream ExportToMemoryStream(string source, string parameters, OutputPresentationType exportType) + public static async Task ExportToMemoryStream(string source, string parameters, OutputPresentationType exportType) { // Compile the report - report = GetReport(source); + report = await GetReport(source); if(report == null) { throw new ArgumentException("Can not compile report"); } - report.RunGetData(GetParmeters(parameters)); + await report.RunGetData(GetParmeters(parameters)); using(MemoryStreamGen ms = new MemoryStreamGen()) { try { - report.RunRender(ms, exportType); + await report.RunRender(ms, exportType); return ms.GetStream() as MemoryStream; } catch(Exception ex) { - throw ex; + throw; } finally { @@ -234,7 +235,7 @@ private static System.Collections.Specialized.ListDictionary GetParmeters(string return ld; } - private static Report GetReport(string reportSource) + private static async Task GetReport(string reportSource) { // Now parse the file @@ -247,7 +248,7 @@ private static Report GetReport(string reportSource) rdlp.OverwriteInSubreport = overwriteSubreportConnection; // RDLParser takes RDL XML and Parse compiles the report - r = rdlp.Parse(); + r = await rdlp.Parse(); if(r.ErrorMaxSeverity > 0) { foreach(string emsg in r.ErrorItems) { Console.WriteLine(emsg); diff --git a/RdlGtk3/ReportViewer.cs b/RdlGtk3/ReportViewer.cs index 1f5e991e..16fa0768 100644 --- a/RdlGtk3/ReportViewer.cs +++ b/RdlGtk3/ReportViewer.cs @@ -285,7 +285,7 @@ public async Task LoadReport(string source, string parameters, OutputPresentatio this.Parameters = new ListDictionary(); // Compile the report - report = this.GetReport(source); + report = await this.GetReport(source); if (report == null) return; AddParameterControls(); @@ -298,7 +298,7 @@ async Task RefreshReport() if (ShowParameters) SetParametersFromControls(); await report.RunGetData(Parameters); - pages = report.BuildPages(); + pages = await report.BuildPages(); foreach (Gtk.Widget w in vboxPages.AllChildren) { @@ -378,7 +378,7 @@ private System.Collections.Specialized.ListDictionary GetParmeters(string parms) return ld; } - private Report GetReport(string reportSource) + private async Task GetReport(string reportSource) { // Now parse the file @@ -391,7 +391,7 @@ private Report GetReport(string reportSource) rdlp.OverwriteInSubreport = overwriteSubreportConnection; // RDLParser takes RDL XML and Parse compiles the report - r = rdlp.Parse(); + r = await rdlp.Parse(); if (r.ErrorMaxSeverity > 0) { foreach (string emsg in r.ErrorItems) @@ -748,7 +748,7 @@ public async Task SaveReport() { // Must use the RunGetData before each export or there is no data. await report.RunGetData(this.Parameters); - ExportReport(report, filename, exportType); + await ExportReport(report, filename, exportType); break; } else @@ -762,7 +762,7 @@ public async Task SaveReport() //If no files with the same name found in directory // Must use the RunGetData before each export or there is no data. await report.RunGetData(this.Parameters); - ExportReport(report, filename, exportType); + await ExportReport(report, filename, exportType); break; } } @@ -772,7 +772,7 @@ public async Task SaveReport() //If no files found in directory // Must use the RunGetData before each export or there is no data. await report.RunGetData(this.Parameters); - ExportReport(report, filename, exportType); + await ExportReport(report, filename, exportType); } } catch (Exception ex) @@ -799,14 +799,14 @@ public async Task SaveReport() /// /// File name. /// - private void ExportReport(Report report, string FileName, OutputPresentationType exportType) + private async Task ExportReport(Report report, string FileName, OutputPresentationType exportType) { OneFileStreamGen sg = null; try { sg = new OneFileStreamGen(FileName, true); - report.RunRender(sg, exportType); + await report.RunRender(sg, exportType); } catch (Exception ex) { diff --git a/RdlReader/RdlReader.cs b/RdlReader/RdlReader.cs index b2d1650e..2047eed2 100644 --- a/RdlReader/RdlReader.cs +++ b/RdlReader/RdlReader.cs @@ -36,6 +36,7 @@ the website www.fyiReporting.com. namespace fyiReporting.RdlReader { using System.Diagnostics; + using System.Threading.Tasks; /// /// RdlReader is a application for displaying reports based on RDL. @@ -168,7 +169,7 @@ string GetPassword() /// The main entry point for the application. /// [STAThread] - static void Main() + static async Task Main() { bool bMono = false; string[] args = Environment.GetCommandLineArgs(); @@ -236,7 +237,7 @@ static void Main() { if (!string.IsNullOrWhiteSpace(printerName)) { - SilentPrint(reportFile, parameters, printerName); + await SilentPrint(reportFile, parameters, printerName); return; } @@ -259,13 +260,13 @@ static void Main() } - public static void SilentPrint(string reportPath, string parameters, string printerName = null) + public static async Task SilentPrint(string reportPath, string parameters, string printerName = null) { var rdlViewer = new fyiReporting.RdlViewer.RdlViewer(); rdlViewer.Visible = false; rdlViewer.SourceFile = new Uri(reportPath); rdlViewer.Parameters = parameters; - rdlViewer.Rebuild(); + await rdlViewer.Rebuild(); var pd = new PrintDocument(); pd.DocumentName = rdlViewer.SourceFile.LocalPath; @@ -293,7 +294,7 @@ public static void SilentPrint(string reportPath, string parameters, string prin pd.PrinterSettings.FromPage = rdlViewer.PageCurrent; } - rdlViewer.Print(pd); + await rdlViewer.Print(pd); } catch (Exception ex) { @@ -418,7 +419,7 @@ private void CreateMDIChild(Uri file, bool bMenuUpdate) mcOpen.Activate(); } - private void menuFilePrint_Click(object sender, EventArgs e) + private async void menuFilePrint_Click(object sender, EventArgs e) { MDIChild mc = this.ActiveMdiChild as MDIChild; if (mc == null) @@ -454,7 +455,7 @@ private void menuFilePrint_Click(object sender, EventArgs e) { pd.PrinterSettings.FromPage = mc.Viewer.PageCurrent; } - mc.Viewer.Print(pd); + await mc.Viewer.Print(pd); } catch (Exception ex) { @@ -464,7 +465,7 @@ private void menuFilePrint_Click(object sender, EventArgs e) printChild = null; } - private void menuFileSaveAs_Click(object sender, EventArgs e) + private async void menuFileSaveAs_Click(object sender, EventArgs e) { MDIChild mc = this.ActiveMdiChild as MDIChild; if (mc == null) @@ -547,7 +548,7 @@ private void menuFileSaveAs_Click(object sender, EventArgs e) if (type != OutputPresentationType.Internal) { - try { mc.Viewer.SaveAs(sfd.FileName, type); } + try { await mc.Viewer.SaveAs(sfd.FileName, type); } catch (Exception ex) { MessageBox.Show(this, @@ -574,7 +575,7 @@ private void menuCopy_Click(object sender, System.EventArgs ea) mc.Viewer.Copy(); } - private void menuFind_Click(object sender, System.EventArgs ea) + private async void menuFind_Click(object sender, System.EventArgs ea) { MDIChild mc = this.ActiveMdiChild as MDIChild; if (mc == null) @@ -582,7 +583,7 @@ private void menuFind_Click(object sender, System.EventArgs ea) if (!mc.Viewer.ShowFindPanel) mc.Viewer.ShowFindPanel = true; - mc.Viewer.FindNext(); + await mc.Viewer.FindNext(); } private void menuSelection_Click(object sender, System.EventArgs ea) diff --git a/RdlViewer/RdlViewer.cs b/RdlViewer/RdlViewer.cs index fe0cb465..e8f6a6c8 100644 --- a/RdlViewer/RdlViewer.cs +++ b/RdlViewer/RdlViewer.cs @@ -38,11 +38,12 @@ the website www.fyiReporting.com. namespace fyiReporting.RdlViewer { using System.Threading; + using System.Threading.Tasks; /// - /// RdlViewer displays RDL files or syntax. - /// - public partial class RdlViewer : System.Windows.Forms.UserControl + /// RdlViewer displays RDL files or syntax. + /// + public partial class RdlViewer : System.Windows.Forms.UserControl { public delegate void HyperlinkEventHandler(object source, HyperlinkEventArgs e); @@ -300,7 +301,8 @@ public bool ShowParameterPanel { get { - LoadPageIfNeeded(); + // HACK: async + Task.Run(async () => await LoadPageIfNeeded()).GetAwaiter().GetResult(); return _ShowParameters; } set @@ -329,9 +331,9 @@ public bool ShowFindPanel /// /// Causes the find panel to find the next item /// - public void FindNext() + public async Task FindNext() { - _FindCtl.FindNext(); + await _FindCtl.FindNext(); } /// @@ -415,7 +417,8 @@ public int PageCount { get { - LoadPageIfNeeded(); + // HACK: async + Task.Run(async () => await LoadPageIfNeeded()).GetAwaiter().GetResult(); if (_pgs == null) return 0; else @@ -472,7 +475,8 @@ public Report Report { get { - LoadPageIfNeeded(); + // HACK: async + Task.Run(async () => await LoadPageIfNeeded()).GetAwaiter().GetResult(); return _Report; } } @@ -480,12 +484,12 @@ public Report Report /// /// Forces the report to get rebuilt especially after changing parameters or data. /// - public void Rebuild() + public async Task Rebuild() { // Aulofee customization - start. Code added (2 lines) to avoid to execute twice GetPages and so the SQL query (custo end). if (_pgs == null) { - LoadPageIfNeeded(); + await LoadPageIfNeeded(); if (_Report == null) throw new Exception(Strings.RdlViewer_Error_Report_must_be_loaded_prior_to_Rebuild_being_called); @@ -493,7 +497,7 @@ public void Rebuild() } else { - _pgs = GetPages(_Report); + _pgs = await GetPages(_Report); } _DrawPanel.Pgs = _pgs; _vScroll.Value = 0; @@ -592,7 +596,8 @@ public Uri SourceFile _loadFailed = false; // attempt to load the report if (this.Visible) { - LoadPageIfNeeded(); // force load of report + // HACK: async + Task.Run(async () => await LoadPageIfNeeded()).GetAwaiter().GetResult(); // force load of report this._DrawPanel.Invalidate(); } } @@ -605,20 +610,22 @@ public Uri SourceFile public string SourceRdl { get { return _SourceRdl; } - set + } + + public async Task SetSourceRdl(string value) + { + _SourceRdl = value; + if (value != null) + _SourceFileName = null; + _pgs = null; // reset pages + _DrawPanel.Pgs = null; + _loadFailed = false; // attempt to load the report + _vScroll.Value = _hScroll.Value = 0; + if (this.Visible) { - _SourceRdl = value; - if (value != null) - _SourceFileName = null; - _pgs = null; // reset pages - _DrawPanel.Pgs = null; - _loadFailed = false; // attempt to load the report - _vScroll.Value = _hScroll.Value = 0; - if (this.Visible) - { - LoadPageIfNeeded(); // force load of report - this._DrawPanel.Invalidate(); - } + // HACK: async + await LoadPageIfNeeded(); + this._DrawPanel.Invalidate(); } } @@ -725,7 +732,8 @@ public float PageHeight { get { - LoadPageIfNeeded(); + // HACK: async + Task.Run(async () => await LoadPageIfNeeded()).GetAwaiter().GetResult(); return _PageHeight; } } @@ -737,7 +745,8 @@ public float PageWidth { get { - LoadPageIfNeeded(); + // HACK: async + Task.Run(async () => await LoadPageIfNeeded()).GetAwaiter().GetResult(); return _PageWidth; } } @@ -749,7 +758,8 @@ public string ReportDescription { get { - LoadPageIfNeeded(); + // HACK: async + Task.Run(async () => await LoadPageIfNeeded()).GetAwaiter().GetResult(); return _ReportDescription; } } @@ -761,7 +771,8 @@ public string ReportAuthor { get { - LoadPageIfNeeded(); + // HACK: async + Task.Run(async () => await LoadPageIfNeeded()).GetAwaiter().GetResult(); return _ReportAuthor; } } @@ -811,9 +822,9 @@ public ZoomEnum ZoomMode /// /// Print the report. /// - public void Print(PrintDocument pd) + public async Task Print(PrintDocument pd) { - LoadPageIfNeeded(); + await LoadPageIfNeeded(); pd.PrintPage += new PrintPageEventHandler(PrintPage); @@ -909,9 +920,9 @@ private void PrintPage(object sender, PrintPageEventArgs e) /// /// Name of the file to be saved to. /// Type of file to save. Should be "pdf", "xml", "html", "mhtml", "csv", "rtf", "excel", "tif". - public void SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type) + public async Task SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type) { - LoadPageIfNeeded(); + await LoadPageIfNeeded(); OneFileStreamGen sg = new OneFileStreamGen(FileName, true); // overwrite with this name @@ -919,7 +930,7 @@ public void SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type type == OutputPresentationType.TIF || type == OutputPresentationType.TIFBW)) { var ld = GetParameters(); // split parms into dictionary - _Report.RunGetData(ld); // obtain the data (again) + await _Report.RunGetData(ld); // obtain the data (again) } try { @@ -940,26 +951,26 @@ public void SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type _Report.RunRenderTif(sg, _pgs, false); break; case OutputPresentationType.CSV: - _Report.RunRender(sg, OutputPresentationType.CSV); + await _Report.RunRender(sg, OutputPresentationType.CSV); break; case OutputPresentationType.Word: case OutputPresentationType.RTF: - _Report.RunRender(sg, OutputPresentationType.RTF); + await _Report.RunRender(sg, OutputPresentationType.RTF); break; case OutputPresentationType.ExcelTableOnly: - _Report.RunRender(sg, OutputPresentationType.ExcelTableOnly); + await _Report.RunRender(sg, OutputPresentationType.ExcelTableOnly); break; case OutputPresentationType.Excel2007: - _Report.RunRender(sg, OutputPresentationType.Excel2007); + await _Report.RunRender(sg, OutputPresentationType.Excel2007); break; case OutputPresentationType.XML: - _Report.RunRender(sg, OutputPresentationType.XML); + await _Report.RunRender(sg, OutputPresentationType.XML); break; case OutputPresentationType.HTML: - _Report.RunRender(sg, OutputPresentationType.HTML); + await _Report.RunRender(sg, OutputPresentationType.HTML); break; case OutputPresentationType.MHTML: - _Report.RunRender(sg, OutputPresentationType.MHTML); + await _Report.RunRender(sg, OutputPresentationType.MHTML); break; default: throw new Exception(Strings.RdlViewer_Error_UnsupportedExtension); @@ -982,9 +993,9 @@ public void SaveAs(string FileName, fyiReporting.RDL.OutputPresentationType type /// /// /// null if not found - public PageItem Find(string search) + public async Task Find(string search) { - return Find(search, null, RdlViewerFinds.None); + return await Find(search, null, RdlViewerFinds.None); } /// @@ -995,9 +1006,9 @@ public PageItem Find(string search) /// PageItem after which to start search. null starts at beginning /// Multiple options can be or'ed together. /// null if not found - public PageItem Find(string search, PageItem position, RdlViewerFinds options) + public async Task Find(string search, PageItem position, RdlViewerFinds options) { - LoadPageIfNeeded(); + await LoadPageIfNeeded(); if (_pgs == null || _pgs.Count == 0) // no report nothing to find return null; @@ -1064,9 +1075,9 @@ public PageItem Find(string search, PageItem position, RdlViewerFinds options) return found; } - public void ScrollToPageItem(PageItem pi) + public async Task ScrollToPageItem(PageItem pi) { - LoadPageIfNeeded(); + await LoadPageIfNeeded(); if (_pgs == null || _pgs.PageCount <= 0) // nothing to scroll to return; @@ -1115,7 +1126,7 @@ public void ScrollToPageItem(PageItem pi) } } - private void DrawPanelPaint(object sender, System.Windows.Forms.PaintEventArgs e) + private async void DrawPanelPaint(object sender, System.Windows.Forms.PaintEventArgs e) { // Only handle one paint at a time lock (this) @@ -1130,7 +1141,7 @@ private void DrawPanelPaint(object sender, System.Windows.Forms.PaintEventArgs e { if (!_InLoading) // If we're in the process of loading don't paint { - LoadPageIfNeeded(); // make sure we have something to show + await LoadPageIfNeeded(); // make sure we have something to show if (_zoom < 0) CalcZoom(); // new report or resize client requires new zoom factor @@ -1249,7 +1260,7 @@ private void CalcZoomFitWidth() } // Obtain the Pages by running the report - private Report GetReport() + private async Task GetReport() { string prog; @@ -1281,7 +1292,7 @@ private Report GetReport() // Cross objects rdlp.OnSubReportGetContent.SubReportGetContent = dSubReportGetContent; - r = rdlp.Parse(); + r = await rdlp.Parse(); if (r.ErrorMaxSeverity > 0) { _errorMsgs = r.ErrorItems; // keep a copy of the errors @@ -1446,16 +1457,16 @@ private string GetReportErrorMsg() return sb.ToString(); } - private Pages GetPages() + private async Task GetPages() { - this._Report = GetReport(); + this._Report = await GetReport(); if (_loadFailed) // retry on failure; this will get error report - this._Report = GetReport(); + this._Report = await GetReport(); - return GetPages(this._Report); + return await GetPages(this._Report); } - private Pages GetPages(Report report) + private async Task GetPages(Report report) { Pages pgs = null; @@ -1463,9 +1474,9 @@ private Pages GetPages(Report report) try { - report.RunGetData(ld); + await report.RunGetData(ld); - pgs = report.BuildPages(); + pgs = await report.BuildPages(); if (report.ErrorMaxSeverity > 0) { @@ -1577,7 +1588,7 @@ public bool StopWaitDialog() /// Call LoadPageIfNeeded when a routine requires the report to be loaded in order /// to fulfill the request. /// - private void LoadPageIfNeeded() + private async Task LoadPageIfNeeded() { if (_pgs == null) { @@ -1598,8 +1609,8 @@ private void LoadPageIfNeeded() } _InLoading = true; savec = this.Cursor; // this could take a while so put up wait cursor - this.Cursor = Cursors.WaitCursor; - _pgs = GetPages(); + this.Cursor = Cursors.WaitCursor; + _pgs = await GetPages(); _DrawPanel.Pgs = _pgs; CalcZoom(); // this could affect zoom } @@ -1737,7 +1748,7 @@ private void ParametersTextValidated(object sender, System.EventArgs e) } } - private void ParametersViewClick(object sender, System.EventArgs e) + private async void ParametersViewClick(object sender, System.EventArgs e) { Cursor.Current = Cursors.WaitCursor; System.Threading.Thread t = null; @@ -1791,7 +1802,7 @@ private void ParametersViewClick(object sender, System.EventArgs e) System.Threading.Thread.Sleep(1); } } - _pgs = GetPages(this._Report); + _pgs = await GetPages(this._Report); _DrawPanel.Pgs = _pgs; _vScroll.Value = 0; CalcZoom(); @@ -2004,7 +2015,7 @@ private void DrawPanelMouseWheel(object sender, MouseEventArgs e) ChangePageEvent(); } - private void DrawPanelKeyDown(object sender, KeyEventArgs e) + private async void DrawPanelKeyDown(object sender, KeyEventArgs e) { // Force scroll up and down if (e.KeyCode == Keys.Down) @@ -2060,7 +2071,7 @@ private void DrawPanelKeyDown(object sender, KeyEventArgs e) if (last.Count > 0) { PageItem lastItem = last[last.Count - 1]; - this.ScrollToPageItem(lastItem); + await this.ScrollToPageItem(lastItem); e.Handled = true; } } diff --git a/RdlViewer/RdlViewerFind.cs b/RdlViewer/RdlViewerFind.cs index 01c64f60..d12c372d 100644 --- a/RdlViewer/RdlViewerFind.cs +++ b/RdlViewer/RdlViewerFind.cs @@ -31,6 +31,7 @@ the website www.fyiReporting.com. using System.Text; using fyiReporting.RdlViewer.Resources; using fyiReporting.RDL; +using System.Threading.Tasks; namespace fyiReporting.RdlViewer { @@ -152,12 +153,12 @@ private void bClose_Click(object sender, EventArgs e) this.Visible = false; } - private void bFindNext_Click(object sender, EventArgs e) + private async void bFindNext_Click(object sender, EventArgs e) { - FindNext(); + await FindNext(); } - public void FindNext() + public async Task FindNext() { if (_Viewer == null) throw new ApplicationException(Strings.RdlViewerFind_ErrorA_PropertyMustSetPriorFindNext); @@ -171,33 +172,33 @@ public void FindNext() RdlViewerFinds.None; bool begin = position == null; - position = _Viewer.Find(tbFind.Text, position, findOptions); + position = await _Viewer.Find(tbFind.Text, position, findOptions); if (position == null) { if (!begin) // if we didn't start from beginning already; try from beginning - position = _Viewer.Find(tbFind.Text, position, findOptions); + position = await _Viewer.Find(tbFind.Text, position, findOptions); lStatus.Text = position == null ? Strings.RdlViewerFind_FindNext_Phrase_not_found : Strings.RdlViewerFind_FindNext_Reached_end_of_report; _Viewer.HighlightPageItem = position; if (position != null) - _Viewer.ScrollToPageItem(position); + await _Viewer.ScrollToPageItem(position); } else { lStatus.Text = ""; _Viewer.HighlightPageItem = position; - _Viewer.ScrollToPageItem(position); + await _Viewer.ScrollToPageItem(position); } } - private void bFindPrevious_Click(object sender, EventArgs e) + private async void bFindPrevious_Click(object sender, EventArgs e) { - FindPrevious(); + await FindPrevious(); } - public void FindPrevious() + public async Task FindPrevious() { if (_Viewer == null) throw new ApplicationException(Strings.RdlViewerFind_ErrorA_PropertyMustSetPriorFindPrevious); @@ -209,35 +210,35 @@ public void FindPrevious() (ckMatchCase.Checked ? RdlViewerFinds.MatchCase : RdlViewerFinds.None); bool begin = position == null; - position = _Viewer.Find(tbFind.Text, position, findOptions); + position = await _Viewer.Find(tbFind.Text, position, findOptions); if (position == null) { if (!begin) // if we didn't start from beginning already; try from bottom - position = _Viewer.Find(tbFind.Text, position, findOptions); + position = await _Viewer.Find(tbFind.Text, position, findOptions); lStatus.Text = position == null ? Strings.RdlViewerFind_FindNext_Phrase_not_found : Strings.RdlViewerFind_FindPrevious_Reached_top_of_report; _Viewer.HighlightPageItem = position; if (position != null) - _Viewer.ScrollToPageItem(position); + await _Viewer.ScrollToPageItem(position); } else { lStatus.Text = ""; _Viewer.HighlightPageItem = position; - _Viewer.ScrollToPageItem(position); + await _Viewer.ScrollToPageItem(position); } } - private void RdlViewerFind_VisibleChanged(object sender, EventArgs e) + private async void RdlViewerFind_VisibleChanged(object sender, EventArgs e) { lStatus.Text = ""; if (this.Visible) { _Viewer.HighlightText = tbFind.Text; tbFind.Focus(); - FindNext(); // and go find the contents of the textbox + await FindNext(); // and go find the contents of the textbox } else { // turn off any highlighting when find control not visible @@ -248,7 +249,7 @@ private void RdlViewerFind_VisibleChanged(object sender, EventArgs e) } } - private void tbFind_TextChanged(object sender, EventArgs e) + private async void tbFind_TextChanged(object sender, EventArgs e) { lStatus.Text = ""; position = null; // reset position when edit changes?? todo not really @@ -256,7 +257,7 @@ private void tbFind_TextChanged(object sender, EventArgs e) ckHighlightAll.Enabled = bFindNext.Enabled = bFindPrevious.Enabled = tbFind.Text.Length > 0; if (tbFind.Text.Length > 0) - FindNext(); + await FindNext(); } private void ckHighlightAll_CheckedChanged(object sender, EventArgs e) diff --git a/RdlViewer/ViewerToolstrip.cs b/RdlViewer/ViewerToolstrip.cs index 2682c742..ec02f35a 100644 --- a/RdlViewer/ViewerToolstrip.cs +++ b/RdlViewer/ViewerToolstrip.cs @@ -44,7 +44,7 @@ private void Init() } - private void OpenClicked(object sender, System.EventArgs e) + private async void OpenClicked(object sender, System.EventArgs e) { var dlg = new OpenFileDialog(); var result = dlg.ShowDialog(); @@ -54,13 +54,13 @@ private void OpenClicked(object sender, System.EventArgs e) } Viewer.SourceFile = new Uri(dlg.FileName); - Viewer.Rebuild(); + await Viewer.Rebuild(); currentPage.Text = Viewer.PageCurrent.ToString(); pageCount.Text = "/" + Viewer.PageCount; } - private void PrintClicked(object sender, System.EventArgs e) + private async void PrintClicked(object sender, System.EventArgs e) { if (Viewer == null) { @@ -81,13 +81,13 @@ private void PrintClicked(object sender, System.EventArgs e) dlg.AllowSomePages = true; if (dlg.ShowDialog() == DialogResult.OK) { - Viewer.Print(pd); + await Viewer.Print(pd); } } } - private void SaveAsClicked(object sender, System.EventArgs e) + private async void SaveAsClicked(object sender, System.EventArgs e) { if (Viewer == null) { @@ -155,7 +155,7 @@ private void SaveAsClicked(object sender, System.EventArgs e) break; } - Viewer.SaveAs(dlg.FileName, type); + await Viewer.SaveAs(dlg.FileName, type); } private void FirstPageClicked(object sender, System.EventArgs e) diff --git a/ReportTests/ExcelValetTests.cs b/ReportTests/ExcelValetTests.cs index c3f2732e..3748933d 100644 --- a/ReportTests/ExcelValetTests.cs +++ b/ReportTests/ExcelValetTests.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Validation; using fyiReporting.RDL; @@ -81,7 +82,7 @@ public void Prepare2Tests() }; [Test, TestCaseSource("TestCasesExcelValetFormat")] - public void ExcelValet_Format(string file2test, + public async Task ExcelValet_Format(string file2test, string cultureName, string suffixFileName, Func> fillDatasets) @@ -90,7 +91,7 @@ public void ExcelValet_Format(string file2test, OneFileStreamGen sg = null; Uri fileRdlUri = new Uri(_reportFolder, file2test); - Report rap = RdlUtils.GetReport(fileRdlUri); + Report rap = await RdlUtils.GetReport(fileRdlUri); rap.Folder = _reportFolder.LocalPath; if (fillDatasets != null) { @@ -98,10 +99,10 @@ public void ExcelValet_Format(string file2test, foreach (var dataset in dataSets) { - rap.DataSets[dataset.Key].SetData(dataset.Value); + await rap.DataSets[dataset.Key].SetData(dataset.Value); } } - rap.RunGetData(null); + await rap.RunGetData(null); string fileNameOut = string.Format("{0}_{1}_{2}{3}", file2test, @@ -111,7 +112,7 @@ public void ExcelValet_Format(string file2test, string fullOutputPath = System.IO.Path.Combine(_outputFolder.LocalPath, fileNameOut); sg = new OneFileStreamGen(fullOutputPath, true); - rap.RunRender(sg, OutputPresentationType.ExcelTableOnly); + await rap.RunRender(sg, OutputPresentationType.ExcelTableOnly); diff --git a/ReportTests/RenderPdf_iTextSharpTests.cs b/ReportTests/RenderPdf_iTextSharpTests.cs index e87037a0..1432dd6a 100644 --- a/ReportTests/RenderPdf_iTextSharpTests.cs +++ b/ReportTests/RenderPdf_iTextSharpTests.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Validation; using fyiReporting.RDL; @@ -64,7 +65,7 @@ public void Prepare2Tests() }; [Test, TestCaseSource("TestCasesRenderPdf_iTextSharpDraw")] - public void RenderPdf_iTextSharpDraw(string file2test, + public async Task RenderPdf_iTextSharpDraw(string file2test, string cultureName, string suffixFileName, Func> fillDatasets) @@ -75,7 +76,7 @@ public void RenderPdf_iTextSharpDraw(string file2test, Uri fileRdlUri = new Uri(_reportFolder, file2test); // We change dir so the SQL lite database is found System.IO.Directory.SetCurrentDirectory(_reportFolder.LocalPath); - Report rap = RdlUtils.GetReport(fileRdlUri); + Report rap = await RdlUtils.GetReport(fileRdlUri); rap.Folder = _reportFolder.LocalPath; if (fillDatasets != null) { @@ -83,10 +84,10 @@ public void RenderPdf_iTextSharpDraw(string file2test, foreach (var dataset in dataSets) { - rap.DataSets[dataset.Key].SetData(dataset.Value); + await rap.DataSets[dataset.Key].SetData(dataset.Value); } } - rap.RunGetData(null); + await rap.RunGetData(null); string fileNameOut = string.Format("{0}_{1}_{2}{3}", file2test, @@ -96,7 +97,7 @@ public void RenderPdf_iTextSharpDraw(string file2test, string fullOutputPath = System.IO.Path.Combine(_outputFolder.LocalPath, fileNameOut); sg = new OneFileStreamGen(fullOutputPath, true); - rap.RunRender(sg, OutputPresentationType.RenderPdf_iTextSharp); + await rap.RunRender(sg, OutputPresentationType.RenderPdf_iTextSharp); } } diff --git a/ReportTests/ReportTests.csproj b/ReportTests/ReportTests.csproj index 8ebbd3d1..dc5a3288 100644 --- a/ReportTests/ReportTests.csproj +++ b/ReportTests/ReportTests.csproj @@ -62,6 +62,7 @@ + diff --git a/ReportTests/Utils/RdlUtils.cs b/ReportTests/Utils/RdlUtils.cs index 61cc914f..ae9cee79 100644 --- a/ReportTests/Utils/RdlUtils.cs +++ b/ReportTests/Utils/RdlUtils.cs @@ -2,13 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading.Tasks; using fyiReporting.RDL; namespace ReportTests.Utils { public static class RdlUtils { - public static Report GetReport(Uri uri2Rdl) + public static async Task GetReport(Uri uri2Rdl) { //string cwd = System.Environment.CurrentDirectory; @@ -24,7 +25,7 @@ public static Report GetReport(Uri uri2Rdl) rdlp = new RDLParser(source); // RDLParser takes RDL XML and Parse compiles the report - r = rdlp.Parse(); + r = await rdlp.Parse(); if (r.ErrorMaxSeverity > 0) { diff --git a/ReportTests/iTextSharpTests.cs b/ReportTests/iTextSharpTests.cs index 4cc8e053..5ecd7f44 100644 --- a/ReportTests/iTextSharpTests.cs +++ b/ReportTests/iTextSharpTests.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Validation; using fyiReporting.RDL; @@ -46,7 +47,7 @@ public void Prepare2Tests() }; [Test, TestCaseSource("TestCasesiTextSharpDraw")] - public void iTextSharpDraw(string file2test, + public async Task iTextSharpDraw(string file2test, string cultureName, string suffixFileName, Func> fillDatasets) @@ -55,7 +56,7 @@ public void iTextSharpDraw(string file2test, OneFileStreamGen sg = null; Uri fileRdlUri = new Uri(_reportFolder, file2test); - Report rap = RdlUtils.GetReport(fileRdlUri); + Report rap = await RdlUtils.GetReport(fileRdlUri); rap.Folder = _reportFolder.LocalPath; if (fillDatasets != null) { @@ -63,10 +64,10 @@ public void iTextSharpDraw(string file2test, foreach (var dataset in dataSets) { - rap.DataSets[dataset.Key].SetData(dataset.Value); + await rap.DataSets[dataset.Key].SetData(dataset.Value); } } - rap.RunGetData(null); + await rap.RunGetData(null); string fileNameOut = string.Format("{0}_{1}_{2}{3}", file2test, @@ -76,7 +77,7 @@ public void iTextSharpDraw(string file2test, string fullOutputPath = System.IO.Path.Combine(_outputFolder.LocalPath, fileNameOut); sg = new OneFileStreamGen(fullOutputPath, true); - rap.RunRender(sg, OutputPresentationType.PDF); + await rap.RunRender(sg, OutputPresentationType.PDF); } }