public bool canCompleteOrder(TabletMagazine mag, OrderConfiguration orderConfiguration) { foreach (var pair in orderConfiguration.Tablets.Where(x => x.Value > 0)) { if (pair.Value > mag.GetSlotDepth(pair.Key)) { return false; } } return true; }
private void AssembleAsync(TabletMagazine mag, OrderConfiguration orderConfiguration) { var ct = _cancelTokenSource.Token; Task.Run(() => { var status = Assemble(mag, orderConfiguration, ct); IsRunning = false; OnCompleted(new AssemblerEventArgs() { OperationStatus = status, AssemblerOperationStatus = AssemblerOperationStatus.Normal }); }, ct); }
private Tray<Tablet> MapOrderToTray(OrderConfiguration orderConfig) { int trayIndex = 0; var tray = new Tray<Tablet>(); var tabletCollection = orderConfig.Tablets.Where(x => x.Value > 0); int totalTablets = 0; tabletCollection.ToList().ForEach(x => totalTablets += x.Value); if (totalTablets > Tray<Tablet>.MaxUsableCells) { throw new Exception(String.Format("The number of tablets in the order exceeds number of usable tray cells ({0} > {1})", totalTablets, Tray<Tablet>.MaxUsableCells)); } foreach (var pair in tabletCollection) { var numTablets = pair.Value; for (int i = 0; i < numTablets; i++) { if (trayIndex == Tray<Tablet>.MiddleCellIndex) { trayIndex++; } tray.Cells[trayIndex] = new Tablet() { Color = pair.Key }; trayIndex++; } } return tray; }
private ControllerOperationStatus Assemble(TabletMagazine mag, OrderConfiguration orderConfiguration, CancellationToken ct) { var status = ControllerOperationStatus.Succeeded; try { var tray = MapOrderToTray(orderConfiguration); for (int i = 0; i < tray.Cells.Count; i++) { var tablet = tray.Cells[i]; if(tablet == null) { continue; } if (ct.IsCancellationRequested) { status = ControllerOperationStatus.Cancelled; return status; } else { var slotDepth = mag.GetSlotDepth(tablet.Color); mag.RemoveTablet(tablet.Color); var slotIndex = mag.GetSlotIndexReversed(tablet.Color); Logger.Instance.Write(String.Format("[Assembler] Placing ({0}) tablet from slot {1} into slot {2}", tablet.Color, slotIndex, i)); _assemblerRobot.PlaceTablet(slotIndex, slotDepth, i); } } status = ControllerOperationStatus.Succeeded; LastOrderTray = tray; } catch (Exception ex) { var outer = new Exception("[Assembler] Assembler failed to assemble.", ex); Logger.Instance.Write(new LogEntry(outer)); status = ControllerOperationStatus.Failed; } return status; }