public void Start() { state = ComponentState.Running; Console.WriteLine("The Conveyor Belt is up and running."); while (true) { if (state == ComponentState.Running) { EventsManager?.Invoke(this, new ProductionAreaEventArgs(ProductionAction.Ready)); } if (ToTransform.Count > 0) { Console.WriteLine("Sending job item to machine"); var e = ToTransform.Dequeue(); foreach (var machine in machinesList) { if (machine.Value.state != ComponentState.Running) { continue; } e.anythingElse = machine.Key; break; } EventsMachine?.Invoke(this, e); } } }
public void OnMachineEvent(object sender, ProductionAreaEventArgs e) { //All the calls from the Machines will land here switch (e.action) { case ProductionAction.Ready: if (ToTransform.Count != 0) { var args = ToTransform.Dequeue(); foreach (var machine in machinesList) { if (machine.Value.state != ComponentState.Running) { continue; } e.anythingElse = machine.Key; break; } EventsMachine?.Invoke(this, args); } else { EventsMachine?.Invoke(this, new ProductionAreaEventArgs(ProductionAction.None)); } break; case ProductionAction.Done: //TODO : check if another machine needs that item and proceed accordingly. //We forward the result to the Production Area Manager Console.WriteLine("**********A Machine has finished its job! Forwarding to Manager..."); EventsManager?.Invoke(this, e); break; case ProductionAction.Error: //Check the state of the Machine //If it's effectively in error, retain the task, or redirect it, and notify the ProductionAreaManager break; case ProductionAction.None: // ... not used int this context break; case ProductionAction.Prod: // ... not used int this context break; case ProductionAction.Stop: // ... not used int this context break; default: throw new ArgumentOutOfRangeException(); } }