Interface IReportGenerator
- Namespace
- GroupeIsa.Neos.Application.Reports
- Assembly
- GroupeIsa.Neos.Application.Abstractions.dll
Provides the functionalities of a report generating.
public interface IReportGenerator
Methods
RequestAsync<T>(ReportRequestArguments, Expression<Func<T, ReportGenerationResponse, Task>>)
Request report generation and execute callback based on a given method call expression.
The following example shows how to use RequestAsync method.
Sample code for responding to an asynchronous report generation:
public class EmailSender
{
private readonly ILogger<EmailSender> _logger = null!; // << Dependency injection
public Task SendEmailWithReportAttachmentAsync(ReportGenerationResponse response, string email, string subject, string body)
{
_logger.LogInformation("The process should {Verb}.", response.GenerationSucceed ? "succeed" : "fail");
if (response.GenerationSucceed)
{
_logger.LogInformation("Template name: {Report}", response.ReportName);
// By default, FilenameToUse = the Stimulsoft ReportAlias property = the name of the
// template (unless it is redefined inside the template, in the Export event).
_logger.LogInformation("Filename to use: {FilenameToUse}", response.FilenameToUse);
// The actual job...
// Build the file out of the response...
// byte[] bytes = Convert.FromBase64String(response.ReportContentInBase64)
// and attach it to the email...
_logger.LogInformation("Sending email to {Email} with subject {Subject} and body {Body}", email, subject, body);
}
else
{
// Handle failure...
// e.g. await _notificationContext.SendToCurrentConnectionAsync( /* message... */ )
}
return Task.CompletedTask;
}
}
Sample code for triggering the whole process:
string template = "ReportsCustomerForSendEmail";
string? filter = null;
Dictionary<string, object?>? parameters = null; // << Custom report parameters
Dictionary<string, object?> entityViewParameters = new()
{
{ "Country", "France" },
{ "FromDate", new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc) },
};
// Explicitly provide report localization preference for the report data (including
// language for labels, native variables and business data, as well as culture for time,
// numbers, and currencies formatting):
// 1. preferably use the culture associated with the UserAccount of the sender
// - and/or the destination user,
// 2. and if not available, fallback to using the same culture as the user's interface.
// 3. or hardcode a specific culture code.
string dataCultureCode = CultureInfo.CurrentUICulture.Name; // Using option 2. for demo purposes.
await _reportGenerator.RequestAsync<EmailSender>(
new ReportRequestArguments(template, filter, parameters, entityViewParameters, dataCultureCode),
(emailSender, response) => emailSender.SendEmailWithReportAttachmentAsync(response, "[email protected]", "subject01", "body01"));
// Log output:
// Template name: ReportsCustomerForSendEmail
// Filename to use: ReportsCustomerForSendEmail
// Sending email to [email protected] with subject01 and body01
After the generation is completed the callback will be called and the business code can handle the result (i.e. the newly created file if the generation was successful).
Please find the method's signature below.
Task RequestAsync<T>(ReportRequestArguments requestArguments, Expression<Func<T, ReportGenerationResponse, Task>> callbackMethod) where T : class
Parameters
requestArgumentsReportRequestArgumentsInformation needed for generating the report.
callbackMethodExpression<Func<T, ReportGenerationResponse, Task>>Method call expression that will be executed after the generation process.
<p> The <code>callbackMethod</code> parameter must be a method call expression and a lambda expression: <ul><li> <a href="https://learn.microsoft.com/en-us/dotnet/api/system.linq.expressions.methodcallexpression?view=net-10.0"> Method call expression </a>. </li><li> <a href="https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions"> Lambda expression </a>. </li></ul> </p>
Returns
- Task
Task completed.
Type Parameters
TType containing the method to call after the generation process. Example:
EmailSender(see above).