Above image represents the scenario I am trying to solve.
I know from my previous experience that the Progress reporting pattern can be used to solve the problem of keeping the client updated but back then client was communicating to the hub directly, meaning there was no controller or code behind.
In the above image, the problem is that controller needs to do stuff before it can make call to the DB.
Also, the DB returns segments in the form of files, so I added an async filesystemwatcher for notifying me every time a response file gets created.
The goal is to keep feeding client browser with response segments as when you receive it, until we reach the end of responses.
The question is: how do I trigger the signalR Hub from controller / service methods and keep feeding responses to client browser?
UPDATE:
To narrow down the problem
My controller calls service method
string contents = await _logService. ResponseFileWaiterAsync (myData.guid.ToString());
In the
ResponseFilewaiterAsync
method, when the first file gets created I trigger the hubBroadcastResponseToClient(responseFilePath, hubConnection); private void BroadcastResponseToClient(string responseFilePath, HubConnection hubConnection) { var hub = hubConnection.CreateHubProxy(typeof(string).Name); hubConnection .Start() .ContinueWith(_ => hub.Invoke("UpdateResponseToClient", ResponseHtml)); }
The hub reports the responses to client as well as go look for next file until it is done
public async Task UpdateResponseToClient(IProgress<string> progress,string filePath) { // Clients.Caller.appendReportToPage(ResponseHtml); string result = await _jbaseLoggingService.ResponseFileWaiterAsync(filePath); progress.Report(result); }
Problem: how to trigger a progress report hub from service method / controller? Where should I complete my request when it is done with updates – should it go back to the controller?