forked from ddrilling/AsbCloudServer
fix report progress notification mech
This commit is contained in:
parent
1c6990487f
commit
d57f495ff0
@ -4,8 +4,8 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IBackgroundQueue
|
||||
{
|
||||
int EnqueueTask(Action action);
|
||||
int EnqueueTask(Action<int> action);
|
||||
|
||||
bool TryDequeue(out (Action action, int id) item);
|
||||
bool TryDequeue(out (Action<int> action, int id) item);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace AsbCloudApp.Services
|
||||
{
|
||||
string RootPath { get; }
|
||||
int CreateReport(int wellId, int stepSeconds, int format, DateTime begin, DateTime end,
|
||||
EventHandler<(float progress, string operation)> handleReportProgress);
|
||||
Action<float, string, int > handleReportProgress);
|
||||
int GetReportPagesCount(int wellId, DateTime begin, DateTime end, int stepSeconds, int format);
|
||||
DatesRangeDto GetReportsDatesRange(int wellId);
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
class BackgroundQueue : IBackgroundQueue
|
||||
{
|
||||
private readonly ConcurrentQueue<(Action action, int id)> tasks =
|
||||
new ConcurrentQueue<(Action action, int id)>();
|
||||
private readonly ConcurrentQueue<(Action<int> action, int id)> tasks =
|
||||
new ConcurrentQueue<(Action<int> action, int id)>();
|
||||
|
||||
private int id = 0;
|
||||
|
||||
public int EnqueueTask(Action action)
|
||||
public int EnqueueTask(Action<int> action)
|
||||
{
|
||||
if (action == null)
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
@ -20,7 +20,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return id;
|
||||
}
|
||||
|
||||
public bool TryDequeue(out (Action action, int id) item)
|
||||
public bool TryDequeue(out (Action<int> action, int id) item)
|
||||
=> tasks.TryDequeue(out item);
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
while (!token.IsCancellationRequested)
|
||||
{
|
||||
if (tasksQueue.TryDequeue(out var item))
|
||||
await Task.Run(item.action, token);
|
||||
await Task.Run(()=>item.action(item.id), token);
|
||||
else
|
||||
await Task.Delay(100, token);
|
||||
}
|
||||
|
@ -28,9 +28,9 @@ namespace AsbCloudInfrastructure.Services
|
||||
public string RootPath { get ; private set; }
|
||||
|
||||
public int CreateReport(int wellId, int stepSeconds, int format, DateTime begin,
|
||||
DateTime end, EventHandler<(float progress, string operation)> progressHandler)
|
||||
DateTime end, Action<float , string , int> progressHandler)
|
||||
{
|
||||
var newReportId = queue.EnqueueTask(() =>
|
||||
var newReportId = queue.EnqueueTask((id) =>
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<AsbCloudDbContext>();
|
||||
optionsBuilder.UseNpgsql(configuration.GetConnectionString("DefaultConnection"));
|
||||
@ -38,7 +38,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
using (var context = new AsbCloudDbContext(optionsBuilder.Options))
|
||||
{
|
||||
var generator = GetReportGenerator(wellId, begin, end, stepSeconds, format, context);
|
||||
generator.OnProgress += progressHandler;
|
||||
generator.OnProgress += (s,e)=>progressHandler.Invoke(e.progress, e.operation, id);
|
||||
generator.Make();
|
||||
}
|
||||
});
|
||||
|
@ -28,10 +28,9 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
private string signalRConnectionId = "0";
|
||||
|
||||
private void HandleReportProgress(object sender, (float progress, string operation) e)
|
||||
{
|
||||
reportsHubContext.Clients.Client(signalRConnectionId).SendAsync("GetReportProgress", e.progress);
|
||||
}
|
||||
private void HandleReportProgress (float progress, string operation, int id) =>
|
||||
reportsHubContext.Clients.Group($"Report{id}").SendAsync("GetReportProgress", progress);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Создает отчет по скважине с указанными параметрами
|
||||
|
Loading…
Reference in New Issue
Block a user