-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
124 lines (109 loc) · 3.41 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
// ****
// Set your license here or in a file in your home directory
// https://help.revealbi.io/web/adding-license-key/
//
//.AddSettings(settings =>
//{
// settings.License = "eyJhbGciOicCI6IkpXVCJ9.e";
//})
// ***
// required
.AddAuthenticationProvider<AuthenticationProvider>()
.AddDataSourceProvider<DataSourceProvider>()
// optional
.AddUserContextProvider<UserContextProvider>()
// optional
.AddObjectFilter<ObjectFilterProvider>()
// optional
//.AddDashboardProvider<DashboardProvider>()
// Required. Register any data source connector you are using.
.DataSources.RegisterMySql();
});
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();
}
// ****
// Optional endpoint to get the thumbnail of a dashboard
// ****
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();
}
});
// ****
// Optional endpoint to get the list of dashboard names
// ****
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();
// ***
// This is a helper class to store the dashboard names
// ***
public class DashboardNames
{
public string? DashboardFileName { get; set; }
public string? DashboardTitle { get; set; }
}