public WorkPackage FetchWork(OSEnum pOS, String pAssignedClient) { if (!QueuedWorkItems.Any()) { return(null); } //get first item in list and create package for it var item = QueuedWorkItems.First(); var package = item.Start(pOS, pAssignedClient); //move from queued to active QueuedWorkItems.Remove(item); ActiveWorkItems.Add(item); return(package); }
private void AddNewWorkItem(String pParameters) { var newitem = new WorkItem(pParameters); newitem.OnTimeoutHappenedEvent += sender => { //remove ActiveWorkItems.Remove(sender); //check if result items already exist; if it does, skip it if (_resultManager.CheckIfResultExists(pParameters)) { return; } //create new AddNewWorkItem(sender.Parameters); }; QueuedWorkItems.Add(newitem); }
public void SendResults(ResultPackage pResults) { //if save results have been successfully saved, remove item from active operations if (_resultManager.VerifyAndSave(pResults)) { NotifyNewLogMessageEvent($"Attempt to remove \"{pResults.WorkPackage.Commands.First().Parameters}\" from queue."); //remove from active var workitem = ActiveWorkItems.FirstOrDefault(t => t.Parameters == pResults.WorkPackage.Commands.First().Parameters); if (workitem != null) { ActiveWorkItems.Remove(workitem); NotifyNewLogMessageEvent($"Removed {workitem.Parameters} from active work."); } //(edge case): remove from queued (e.g. restarting server) var queueitem = QueuedWorkItems.FirstOrDefault(t => t.Parameters == pResults.WorkPackage.Commands.First().Parameters); if (queueitem != null) { QueuedWorkItems.Remove(queueitem); NotifyNewLogMessageEvent($"Removed {queueitem.Parameters} from queue."); } } }
private bool IsAlreadyInList(String pParameters) { return(QueuedWorkItems.Any(t => t.Parameters == pParameters) || ActiveWorkItems.Any(t => t.Parameters == pParameters)); }