forked from teocomi/BCFier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error handling for Navisworks internal errors
- Loading branch information
1 parent
0a55ce2
commit d0e174f
Showing
18 changed files
with
439 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Microsoft.AspNetCore.SignalR; | ||
|
||
namespace IPA.Bcfier.App.Hubs | ||
{ | ||
public class BcfierHub : Hub | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using IPA.Bcfier.App.Hubs; | ||
using IPA.Bcfier.Ipc; | ||
using Microsoft.AspNetCore.SignalR; | ||
using Newtonsoft.Json; | ||
|
||
namespace IPA.Bcfier.App.Services | ||
{ | ||
public class PluginErrorListenerService : IHostedService | ||
{ | ||
private bool _isListening; | ||
private readonly IServiceProvider _serviceProvider; | ||
|
||
public PluginErrorListenerService(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
} | ||
|
||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
_isListening = true; | ||
Task.Run(() => ListenAsync()); | ||
return Task.CompletedTask; | ||
} | ||
|
||
private async Task ListenAsync() | ||
{ | ||
while (_isListening) | ||
{ | ||
if (IpcHandler.ReceivedMessages.TryDequeue(out var message)) | ||
{ | ||
var ipcMessage = JsonConvert.DeserializeObject<IpcMessage>(message)!; | ||
if (ipcMessage.Command == IpcMessageCommand.PluginErrorEncountered) | ||
{ | ||
using var scope = _serviceProvider.CreateScope(); | ||
var hubContext = scope.ServiceProvider.GetRequiredService<IHubContext<BcfierHub>>(); | ||
await hubContext.Clients.All.SendAsync("InternalError", ipcMessage.Data); | ||
} | ||
else | ||
{ | ||
IpcHandler.ReceivedMessages.Enqueue(message); | ||
} | ||
} | ||
|
||
|
||
await Task.Delay(500); | ||
} | ||
} | ||
|
||
public Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
_isListening = true; | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.