3 Commits

Author SHA1 Message Date
cc1dca84d3 Added throw after sentry's CaptureException 2026-01-04 15:33:24 +03:30
f3bfa59889 Added sentry support 2025-12-31 17:38:34 +03:30
f764776321 Added DotEnv package and example.env file 2025-12-31 17:38:21 +03:30
6 changed files with 38 additions and 9 deletions

View File

@@ -0,0 +1,24 @@
namespace PdfService;
public class ExceptionHandlerMiddleware
{
private readonly RequestDelegate _next;
public ExceptionHandlerMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception ex)
{
SentrySdk.CaptureException(ex);
throw;
}
}
}

Binary file not shown.

View File

@@ -7,7 +7,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="dotenv.net" Version="4.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Sentry" Version="6.0.0" />
<PackageReference Include="Stimulsoft.Reports.Engine.NetCore" Version="2025.2.3" /> <PackageReference Include="Stimulsoft.Reports.Engine.NetCore" Version="2025.2.3" />
</ItemGroup> </ItemGroup>

View File

@@ -1,11 +1,21 @@
using System.Data; using System.Data;
using dotenv.net;
using Microsoft.AspNetCore.WebUtilities; using Microsoft.AspNetCore.WebUtilities;
using Newtonsoft.Json; using Newtonsoft.Json;
using PdfService; using PdfService;
DotEnv.Load();
SentrySdk.Init(options =>
{
options.Dsn = Environment.GetEnvironmentVariable("SENTRY_DSN");
});
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
var app = builder.Build(); var app = builder.Build();
app.UseMiddleware<ExceptionHandlerMiddleware>();
app.MapPost("/Print", async (HttpContext context) => app.MapPost("/Print", async (HttpContext context) =>
{ {
var request = context.Request; var request = context.Request;

View File

@@ -1,6 +1,5 @@
using Stimulsoft.Base;
using Stimulsoft.Report; using Stimulsoft.Report;
using Stimulsoft.Report.Dictionary; using Stimulsoft.Report.Export;
namespace PdfService; namespace PdfService;
@@ -12,13 +11,6 @@ public static class Reporter
report.LoadFromString(reportTemplate); report.LoadFromString(reportTemplate);
report.RegBusinessObject("Data", data); report.RegBusinessObject("Data", data);
var currentDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"../../.."));
var fileContent = File.ReadAllBytes(Path.Combine(currentDirectory, "Fonts", "IRANSansWeb.ttf"));
var resource = new StiResource("IRANSansMonoSpacedNum", "IRANSansMonoSpacedNum", false, StiResourceType.FontTtf, fileContent, false);
report.Dictionary.Resources.Add(resource);
StiFontCollection.AddResourceFont(resource.Name, resource.Content, "ttf", resource.Alias);
report.Render(false); report.Render(false);
var stream = new MemoryStream(); var stream = new MemoryStream();

1
PdfService/example.env Normal file
View File

@@ -0,0 +1 @@
SENTRY_DSN=https://d3fd87d14e555556d3f76e42d94a63a0@sentry.rayvarz.center/10