Sunday 18 October 2020

SignalRCore - Unable to get updated data. - Using Timer manager

I am learning how to implement signalr. I referred a tutorial LINK and created the sample application without a database connection which worked fine.

Tech - SinalRCore,Entityframework Core, Dontnet Core API, Angular 8

Without a database connection the SingalR was able to update the data that I am sending to angular. I can see the changed the data without any issues.

When I tried to fetch the data from database I am getting the data, but when I do an updated in the database, the update is not reflecting in the resultant json I am getting.

I am using an empty hub. A timer is used which will fire every 2 seconds.

This is my API Action.

namespace MyUtilities.Controllers
{

[Route("api/[controller]")]
[ApiController]
public class AlertsController : ControllerBase
{
    private IHubContext<AlertHub> _hub;
    private readonly FolderContext  dbContext;

    public AlertsController(IHubContext<AlertHub> hub,FolderContext Context )
    {
        _hub = hub;
        dbContext= Context;
    }

    public IActionResult Get()
    {
        var res = dbContext.Folder.Join(dbContext.FilterCount,
            f => f.lFolderId,
            e => e.lFolderId,
            (f, e) => new
            {
                lFolderId = f.lFolderId,
                sTileName = f.sMnemonic,
                Icon = f.sIcon,
                Count = e.lNewCount
            })
            .GroupBy(f => new { f.sTileName, f.Icon, f.lFolderId }).Select(x => new { Count = x.Sum(f => f.Count), x.Key.lFolderId, x.Key.Icon, x.Key.sTileName }).ToList();
        var timerManager = new TimerManager(() => _hub.Clients.All.SendAsync("transferalertdata", res));


        return Ok(new { Message = "Request Completed" });

    }

}
}

Is there any problem using context in the above way?



from SignalRCore - Unable to get updated data. - Using Timer manager

No comments:

Post a Comment