From 0127abfa233d72a79c69058e04b75d01fea3cbd8 Mon Sep 17 00:00:00 2001 From: Lucio Maranta Date: Mon, 17 Sep 2018 09:38:17 +0200 Subject: [PATCH] Fix start&stop & queue running index after swap --- Step.NC/NcHandler.cs | 16 +++++++++++----- Step/Controllers/WebApi/NcFileController.cs | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 9ace6b13..46d681fb 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -354,9 +354,15 @@ namespace Step.NC return NO_ERROR; } - public CmsError MoveQueueItems(int processId, int oldIndex, int newIndex, out List queue) + public CmsError MoveQueueItems(int processId, int itemId, int newIndex, out List queue) { - oldIndex = oldIndex - 1; + itemId = itemId - 1; + + // Update queue running index + if (itemId < QueueRunningIndex && newIndex > QueueRunningIndex) + QueueRunningIndex -= 1; + if (newIndex < QueueRunningIndex && itemId > QueueRunningIndex) + QueueRunningIndex += 1; queue = new List(); @@ -364,12 +370,12 @@ namespace Step.NC if (!PartProgramQueue.ContainsKey(processId)) return INCORRECT_PARAMETERS_ERROR; // Check if items exists - if (PartProgramQueue[processId].ElementAtOrDefault(oldIndex) == null) + if (PartProgramQueue[processId].ElementAtOrDefault(itemId) == null) return INCORRECT_PARAMETERS_ERROR; - var item = PartProgramQueue[processId][oldIndex]; + var item = PartProgramQueue[processId][itemId]; // Remove item in the old positions - PartProgramQueue[processId].RemoveAt(oldIndex); + PartProgramQueue[processId].RemoveAt(itemId); // Add in the new position PartProgramQueue[processId].Insert(newIndex, item); diff --git a/Step/Controllers/WebApi/NcFileController.cs b/Step/Controllers/WebApi/NcFileController.cs index 1880c4f3..ebf2eb72 100644 --- a/Step/Controllers/WebApi/NcFileController.cs +++ b/Step/Controllers/WebApi/NcFileController.cs @@ -264,6 +264,8 @@ namespace Step.Controllers.WebApi { using (NcHandler ncHandler = new NcHandler()) { + ncHandler.Connect(); + CmsError cmsError = ncHandler.StartWorkingQueue(processId); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); @@ -277,6 +279,8 @@ namespace Step.Controllers.WebApi { using (NcHandler ncHandler = new NcHandler()) { + ncHandler.Connect(); + CmsError cmsError = ncHandler.StopWorkingQueue(processId); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey);