Skip to content

Commit

Permalink
wip; Add support for async database calls, requiring widespread use o…
Browse files Browse the repository at this point in the history
…f 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<T> 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.
  • Loading branch information
majorsilence committed Jan 11, 2025
1 parent 64f7141 commit 9b0fe2e
Show file tree
Hide file tree
Showing 265 changed files with 9,490 additions and 9,143 deletions.
18 changes: 10 additions & 8 deletions LibRdlWpfViewer/RdlWpfViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions RdlAsp.Mvc/RdlReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -455,7 +458,7 @@ private OutputPresentationType GetRenderType(string type)
}


private Report GetReport(string prog, string file)
private async Task<Report> GetReport(string prog, string file)
{
// Now parse the file
RDLParser rdlp;
Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions RdlCmd/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -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
51 changes: 26 additions & 25 deletions RdlCmd/RdlCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<int> Main(string[] args)
{
// Handle the arguments
if (args == null || args.Length==0)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -282,7 +283,7 @@ private string GetSource(string file)
return prog;
}

private Report GetReport(string prog, string file)
private async Task<Report> GetReport(string prog, string file)
{
// Now parse the file
RDLParser rdlp;
Expand All @@ -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
Expand Down Expand Up @@ -335,7 +336,7 @@ private Report GetReport(string prog, string file)
/// </summary>
/// <param name="FileName">Name of the file to be saved to.</param>
/// <param name="ext">Type of file to save. Should be "pdf", "xml", "html", mht.</param>
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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
Loading

0 comments on commit 9b0fe2e

Please sign in to comment.