-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
115 lines (101 loc) · 3.14 KB
/
Program.cs
File metadata and controls
115 lines (101 loc) · 3.14 KB
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
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 = Environment.GetEnvironmentVariable("REVEAL_KEY");
})
.AddAuthenticationProvider<AuthenticationProvider>()
.AddDataSourceProvider<DataSourceProvider>()
.AddUserContextProvider<UserContextProvider>()
.AddObjectFilter<ObjectFilterProvider>()
.DataSources.RegisterMicrosoftSqlServer();
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowDev", policy =>
{
policy.WithOrigins(
"http://127.0.0.1:5082",
"http://localhost:3000",
"http://127.0.0.1:3000",
"https://jubilant-halibut-x5gq5w4w657cvj79-3000.app.github.dev/"
)
.AllowAnyMethod()
.AllowAnyHeader();
});
});
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();
if (!app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}
app.UseAuthorization();
app.MapControllers();
app.Run();
public class DashboardNames
{
public string? DashboardFileName { get; set; }
public string? DashboardTitle { get; set; }
}