-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (59 loc) · 2.13 KB
/
Copy pathProgram.cs
File metadata and controls
65 lines (59 loc) · 2.13 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
using Microsoft.AspNetCore.DataProtection;
using TXTextControl.Web;
using TXTextControl.Web.Collaboration;
using TXTextControl.Web.Collaboration.TestApp.Services;
using TXTextControl.Web.DocumentEditor.Backend;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Services.AddControllersWithViews();
builder.Services.AddSingleton<SampleDocumentService>();
builder.Services.AddDataProtection()
.SetApplicationName("TXTextControl.Web.Collaboration.TestApp")
.PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(
builder.Environment.ContentRootPath,
"App_Data",
"DataProtectionKeys")));
builder.Services.AddTXTextControlCollaboration(
builder.Configuration.GetSection(TxTextControlCollaborationOptions.DefaultSectionName));
if (builder.Configuration.GetValue("TextControl:StartEditorBackend", true))
{
builder.Services.AddHostedService<DocumentEditorWorkerManager>();
}
var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.UseWebSockets();
app.UseTXWebSocketMiddleware();
app.MapStaticAssets();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.WithStaticAssets();
app.MapTxTextControlCollaboration();
app.MapGet("/_test/services", (IEnumerable<IHostedService> hostedServices) =>
Results.Ok(hostedServices.Select(service => service.GetType().FullName).ToArray()));
app.MapGet("/_test/resolve", (IServiceProvider services) =>
{
var collaboration = services.GetService<ITxTextControlCollaboration>();
return Results.Ok(new
{
collaboration = collaboration?.GetType().FullName
});
});
app.MapGet("/_test/collaboration/{roomId}", async (
string roomId,
ITxTextControlCollaboration collaboration,
CancellationToken cancellationToken) =>
{
try
{
var data = await collaboration.ExportDocumentAsync(roomId, cancellationToken);
return Results.Ok(new { exists = data is not null, length = data?.Length ?? 0 });
}
catch (Exception exception)
{
return Results.Problem(exception.ToString());
}
});
app.Run();