Added queue storaging
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Step.Model.Constants;
|
||||
|
||||
namespace Step.Database.Controllers
|
||||
{
|
||||
public class QueueController : IDisposable
|
||||
{
|
||||
private DatabaseContext dbCtx;
|
||||
public static Dictionary<int, List<DTOQueueModel>> PartProgramQueue = new Dictionary<int, List<DTOQueueModel>>();
|
||||
public static Dictionary<int, int> QueueRunningIndexes = new Dictionary<int, int>();
|
||||
|
||||
public QueueController()
|
||||
{
|
||||
// Initialize database context
|
||||
dbCtx = new DatabaseContext();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Clear database context
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public void UpdateQueue()
|
||||
{
|
||||
dbCtx.Queue.RemoveRange(dbCtx.Queue);
|
||||
|
||||
foreach(var item in PartProgramQueue)
|
||||
{
|
||||
// Create database model
|
||||
var dbRows = item.Value.Select(x => new QueueItemsModel()
|
||||
{
|
||||
Id = x.Id,
|
||||
AbsolutePath = x.AbsolutePath,
|
||||
PartProgramName = x.PartProgramName,
|
||||
Process = item.Key, // Process
|
||||
Reps = x.Reps,
|
||||
RemainingReps = x.RemainingReps,
|
||||
Status = (int)x.Status
|
||||
}).ToList();
|
||||
|
||||
// Add to db
|
||||
dbCtx.Queue.AddRange(dbRows);
|
||||
}
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public void ReadAndPopulateQueue()
|
||||
{
|
||||
var dbQueue = dbCtx.Queue.ToList();
|
||||
|
||||
foreach(var entity in dbQueue)
|
||||
{
|
||||
// Check if process queue exists
|
||||
if (!PartProgramQueue.ContainsKey(entity.Process))
|
||||
PartProgramQueue.Add(entity.Process, new List<DTOQueueModel>());
|
||||
|
||||
// Add db row to queue
|
||||
PartProgramQueue[entity.Process].Add(new DTOQueueModel()
|
||||
{
|
||||
Id = entity.Id,
|
||||
AbsolutePath = entity.AbsolutePath,
|
||||
PartProgramName = entity.PartProgramName,
|
||||
Reps = entity.Reps,
|
||||
RemainingReps = entity.RemainingReps,
|
||||
Status = (QUEUE_ITEM_STATUS)entity.Status
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user