-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
102 lines (89 loc) · 2.82 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using Reveal.Sdk;
using Reveal.Sdk.Data;
using Reveal.Sdk.Dom;
using RevealSdk.Server.Reveal;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers().AddReveal(builder =>
{
builder
//.AddSettings(settings =>
//{
// settings.License = "eyJhbGciOicCI6IkpXVCJ9.e";
//})
.AddAuthenticationProvider<AuthenticationProvider>()
.AddDataSourceProvider<DataSourceProvider>()
.AddUserContextProvider<UserContextProvider>()
.AddObjectFilter<ObjectFilterProvider>()
.DataSources.RegisterMicrosoftSqlServer();
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll",
builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()
);
});
var app = builder.Build();
app.UseCors("AllowAll");
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapGet("/dashboards/{name}/thumbnail", async (string name) =>
{
var path = "dashboards/" + name + ".rdash";
if (File.Exists(path))
{
var dashboard = new Dashboard(path);
var info = await dashboard.GetInfoAsync(Path.GetFileNameWithoutExtension(path));
return TypedResults.Ok(info);
}
else
{
return Results.NotFound();
}
});
app.MapGet("/dashboards/names", () =>
{
try
{
string folderPath = Path.Combine(Directory.GetCurrentDirectory(), "Dashboards");
var files = Directory.GetFiles(folderPath);
Random rand = new();
var fileNames = files.Select(file =>
{
try
{
return new DashboardNames
{
DashboardFileName = Path.GetFileNameWithoutExtension(file),
DashboardTitle = RdashDocument.Load(file).Title
};
}
catch (Exception ex)
{
Console.WriteLine($"Error Reading FileData {file}: {ex.Message}");
return null;
}
}).Where(fileData => fileData != null).ToList();
return Results.Ok(fileNames);
}
catch (Exception ex)
{
Console.WriteLine($"Error Reading Directory : {ex.Message}");
return Results.Problem("An unexpected error occurred while processing the request.");
}
}).Produces<IEnumerable<DashboardNames>>(StatusCodes.Status200OK)
.Produces(StatusCodes.Status404NotFound)
.ProducesProblem(StatusCodes.Status500InternalServerError);
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
public class DashboardNames
{
public string? DashboardFileName { get; set; }
public string? DashboardTitle { get; set; }
}