Skip to content

Commit

Permalink
remove all DISABLE_FW_BRIDGE conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Jul 26, 2024
1 parent dd7ad96 commit 760ec6d
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 58 deletions.
4 changes: 0 additions & 4 deletions backend/FwLite/LocalWebApp/HttpHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ public static class HttpHelpers

public static string? GetFwDataName(this HttpContext? context)
{
#if DISABLE_FW_BRIDGE
return null;
#else
var name = context?.Request.RouteValues.GetValueOrDefault(FwDataMiniLcmHub.ProjectRouteKey, null)?.ToString();
return string.IsNullOrWhiteSpace(name) ? null : name;
#endif
}
}
4 changes: 1 addition & 3 deletions backend/FwLite/LocalWebApp/Hubs/FwDataMiniLcmHub.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if !DISABLE_FW_BRIDGE
using FwDataMiniLcmBridge;
using FwDataMiniLcmBridge;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Options;
using MiniLcm;
Expand Down Expand Up @@ -43,4 +42,3 @@ public override async Task OnDisconnectedAsync(Exception? exception)
await Groups.RemoveFromGroupAsync(Context.ConnectionId, project.Name);
}
}
#endif
10 changes: 1 addition & 9 deletions backend/FwLite/LocalWebApp/Hubs/LockedProjectFilter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Microsoft.AspNetCore.SignalR;
#if !DISABLE_FW_BRIDGE
using SIL.LCModel;
#endif

namespace LocalWebApp.Hubs;

Expand All @@ -13,13 +11,7 @@ public class LockedProjectFilter: IHubFilter
{
return await next(invocationContext);
}
catch (
#if !DISABLE_FW_BRIDGE
LcmFileLockedException
#else
IOException
#endif
)
catch (LcmFileLockedException)
{
await TypedHubHelper<ILexboxHubClient>.TypeClients(invocationContext.Hub.Clients)
.Caller.OnProjectClosed(CloseReason.Locked);
Expand Down
2 changes: 0 additions & 2 deletions backend/FwLite/LocalWebApp/LocalAppKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public static IServiceCollection AddLocalAppServices(this IServiceCollection ser
services.AddSingleton<BackgroundSyncService>();
services.AddSingleton<IHostedService>(s => s.GetRequiredService<BackgroundSyncService>());
services.AddLcmCrdtClient();
#if !DISABLE_FW_BRIDGE
services.AddFwDataBridge();
#endif

services.AddOptions<JsonOptions>().PostConfigure<IOptions<CrdtConfig>>((jsonOptions, crdtConfig) =>
{
Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/LocalWebApp/LocalWebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Condition="!$(DefineConstants.Contains('DISABLE_FW_BRIDGE'))" Include="..\FwDataMiniLcmBridge\FwDataMiniLcmBridge.csproj" />
<ProjectReference Include="..\FwDataMiniLcmBridge\FwDataMiniLcmBridge.csproj" />
<ProjectReference Include="..\LcmCrdt\LcmCrdt.csproj" />
<ProjectReference Include="..\MiniLcm\MiniLcm.csproj" />
</ItemGroup>
Expand Down
29 changes: 10 additions & 19 deletions backend/FwLite/LocalWebApp/LocalWebAppServer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#if !DISABLE_FW_BRIDGE
using FwDataMiniLcmBridge;
using FwDataMiniLcmBridge;
using FwDataMiniLcmBridge.LcmUtils;
#endif
using LcmCrdt;
using LocalWebApp;
using LocalWebApp.Hubs;
Expand All @@ -23,10 +21,8 @@ public static WebApplication SetupAppServer(string[] args, Action<WebApplication
builder.WebHost.UseUrls("http://127.0.0.1:0");
if (builder.Environment.IsDevelopment())
{
#if !DISABLE_FW_BRIDGE
//do this early so we catch bugs on startup
ProjectLoader.Init();
#endif
//do this early so we catch bugs on startup
ProjectLoader.Init();
}

builder.ConfigureDev<AuthConfig>(config =>
Expand Down Expand Up @@ -73,22 +69,17 @@ public static WebApplication SetupAppServer(string[] args, Action<WebApplication
$"Project {projectName} not found"));
await context.RequestServices.GetRequiredService<CurrentProjectService>().PopulateProjectDataCache();
}
#if !DISABLE_FW_BRIDGE
var fwData = context.GetFwDataName();
if (!string.IsNullOrWhiteSpace(fwData))
{
var fwDataProjectContext = context.RequestServices.GetRequiredService<FwDataProjectContext>();
fwDataProjectContext.Project =
FieldWorksProjectList.GetProject(fwData) ?? throw new InvalidOperationException($"FwData {fwData} not found");
}
#endif
var fwData = context.GetFwDataName();
if (!string.IsNullOrWhiteSpace(fwData))
{
var fwDataProjectContext = context.RequestServices.GetRequiredService<FwDataProjectContext>();
fwDataProjectContext.Project = FieldWorksProjectList.GetProject(fwData) ?? throw new InvalidOperationException($"FwData {fwData} not found");
}

await next(context);
});
app.MapHub<CrdtMiniLcmApiHub>($"/api/hub/{{{CrdtMiniLcmApiHub.ProjectRouteKey}}}/lexbox");
#if !DISABLE_FW_BRIDGE
app.MapHub<FwDataMiniLcmHub>($"/api/hub/{{{FwDataMiniLcmHub.ProjectRouteKey}}}/fwdata");
#endif
app.MapHub<FwDataMiniLcmHub>($"/api/hub/{{{FwDataMiniLcmHub.ProjectRouteKey}}}/fwdata");
app.MapHistoryRoutes();
app.MapActivities();
app.MapProjectRoutes();
Expand Down
8 changes: 1 addition & 7 deletions backend/FwLite/LocalWebApp/Routes/FwIntegrationRoutes.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#if !DISABLE_FW_BRIDGE
using FwDataMiniLcmBridge;
#endif
using FwDataMiniLcmBridge;
using LocalWebApp.Hubs;
using Microsoft.AspNetCore.SignalR;
using Microsoft.OpenApi.Models;
Expand All @@ -11,7 +9,6 @@ public static class FwIntegrationRoutes
{
public static IEndpointConventionBuilder MapFwIntegrationRoutes(this WebApplication app)
{
#if !DISABLE_FW_BRIDGE
var group = app.MapGroup($"/api/fw/{{{FwDataMiniLcmHub.ProjectRouteKey}}}").WithOpenApi(
operation =>
{
Expand All @@ -31,8 +28,5 @@ public static IEndpointConventionBuilder MapFwIntegrationRoutes(this WebApplicat
return Results.Redirect($"silfw://localhost/link?database={context.Project.Name}&tool=lexiconEdit&guid={id}");
});
return group;
#else
return app.MapGroup($"/api/fw/");
#endif
}
}
2 changes: 0 additions & 2 deletions backend/FwLite/LocalWebApp/Routes/ProjectRoutes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static IEndpointConventionBuilder MapProjectRoutes(this WebApplication ap
{
var crdtProjects = await projectService.ListProjects();
var projects = crdtProjects.ToDictionary(p => p.Name, p => new ProjectModel(p.Name, true, false));
#if !DISABLE_FW_BRIDGE
//basically populate projects and indicate if they are lexbox or fwdata
foreach (var p in FwDataMiniLcmBridge.FieldWorksProjectList.EnumerateProjects())
{
Expand All @@ -31,7 +30,6 @@ public static IEndpointConventionBuilder MapProjectRoutes(this WebApplication ap
projects.Add(p.Name, new ProjectModel(p.Name, false, true));
}
}
#endif
//todo split this out into it's own request so we can return other project types right away
foreach (var lexboxProject in await lexboxProjectService.GetLexboxProjects())
{
Expand Down
12 changes: 1 addition & 11 deletions backend/FwLite/LocalWebApp/Services/ImportFwdataService.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
using System.Diagnostics;
#if !DISABLE_FW_BRIDGE
using FwDataMiniLcmBridge;
#endif
using Humanizer;
using LcmCrdt;
using MiniLcm;

namespace LocalWebApp.Services;

public class ImportFwdataService(ProjectsService projectsService, ILogger<ImportFwdataService> logger
#if !DISABLE_FW_BRIDGE
, FwDataFactory fwDataFactory
#endif
)
public class ImportFwdataService(ProjectsService projectsService, ILogger<ImportFwdataService> logger, FwDataFactory fwDataFactory)
{
public async Task<CrdtProject> Import(string projectName)
{
#if DISABLE_FW_BRIDGE
throw new NotSupportedException("FW bridge is disabled");
#else
var startTime = Stopwatch.GetTimestamp();
var fwDataProject = FieldWorksProjectList.GetProject(projectName);
if (fwDataProject is null)
Expand All @@ -44,7 +35,6 @@ public async Task<CrdtProject> Import(string projectName)
logger.LogError("Import of {ProjectName} failed, deleting project", fwDataApi.Project.Name);
throw;
}
#endif
}

private async Task ImportProject(ILexboxApi importTo, ILexboxApi importFrom, int entryCount)
Expand Down

0 comments on commit 760ec6d

Please sign in to comment.