Exemplo n.º 1
0
        public void OnManagerEvent(object sender, ProductionAreaEventArgs e)
        {
            //All the calls from the Manager will land here
            switch (e.action)
            {
            case ProductionAction.Prod:
                state = ComponentState.Running;
                Console.WriteLine("**********The Conveyor has received and queued a work item");
                ToTransform.Enqueue(e);
                break;

            case ProductionAction.Error:
                break;

            case ProductionAction.None:
                state = ComponentState.Idle;
                break;

            case ProductionAction.Done:
                break;

            case ProductionAction.Ready:
                break;

            case ProductionAction.Stop:
                Stop();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        public void OnProductionAreaServerEvent(object sender, ProductionAreaEventArgs e)
        {
            //We receive the deliveries via e.anythingelse, which here is a DeliveryOrder. The server did that . Should it? idk.
            switch (e.action)
            {
            case ProductionAction.None
                :                         //Means we are receiving a WorkOrder fetched from the WorkOrderManager by the server
                                          //TODO: For efficiency's sake, one might suggest to fetch the WO from here instead the server. Anyways.
                var completeWorkOrder = (WorkOrder)e.anythingElse;
                if (!ActiveWorkOrders.ContainsKey(completeWorkOrder.idWorkOrder))
                {
                    //We only take the first of its kind, because the WorkOrderManager doesn't necessarily
                    //know about everything that goes on in the ProductionArea

                    ActiveWorkOrders[completeWorkOrder.idWorkOrder] = completeWorkOrder;
                    Console.WriteLine("Succesfully added WorkOrder #{0} to the working set.", completeWorkOrder.idWorkOrder);
                    //Now that we are assured the WorkOrder exists, we can notify the Server that we're ready for some action.
                    var toServer = new ProductionAreaEventArgs
                    {
                        action      = ProductionAction.Ready,
                        idWorkOrder = completeWorkOrder.idWorkOrder
                    };
                    EventsServer?.Invoke(this, toServer);
                }

                break;

            case ProductionAction.Prod:

                //Determine the typeProd from e
                if (e.items.Contains("Y") && e.items.Contains("Z"))
                {
                    e.typeProd = "A";
                    if (e.items.Contains("X"))
                    {
                        e.typeProd = "B";
                        if (e.items.Contains("W"))
                        {
                            e.typeProd = "C";
                        }
                    }
                }

                Console.WriteLine("A new Task has been queued!");
                ToProcess.Enqueue(e);
                EventsServer?.Invoke(this, new ProductionAreaEventArgs(ProductionAction.Ready));
                break;
            }
        }
Exemplo n.º 4
0
        public void OnSubscribedEventMachine(object sender, ProductionAreaEventArgs e)
        {
            switch (e.action)
            {
            case ProductionAction.Prod:
            {
                state = ComponentState.Running;
                if (e.typeProd == FinishedProductType && (string)e.anythingElse == ID)
                {
                    Console.WriteLine("Machine #{0} of type {1} has received a job.", ID, FinishedProductType);
                    ProcessTranformationRequest(e);
                }

                break;
            }

            case ProductionAction.Stop:
                if (state == ComponentState.Busy)
                {
                    //If we're busy, save progress, then stop.
                    //TODO: save progress
                }

                //Else, just stop.
                Stop();
                break;

            case ProductionAction.Error:
                break;

            case ProductionAction.None:
                state = ComponentState.Idle;
                break;

            case ProductionAction.Done:
                break;

            case ProductionAction.Ready:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 5
0
        private void ProcessTranformationRequest(ProductionAreaEventArgs e)
        {
            state = ComponentState.Busy;
            //Execute the transformation, using all the items from e.items and producing the final product from it
            foreach (var i in e.items)
            {
                if (BOMsNeeded.ContainsKey(i))
                {
                    WorkingMemory[i] += 1;
                }
            }
            //else, if it's not in our recipe, scrap it and optionnally tell the conveyor belt to get its **** together.
            //In other words, this incident will be reflected the "waste" section of the yearly statistics report.

            //If every key in the Working memory has a value superior to 0, then we can go and do the thing
            //else, if at least one key has a value of 0, save progress, go in Error state and notify the ConveyorBelt
            //Because we do not have all the ingredients needed to start the operation.
            if (!WorkingMemoryOK())
            {
                state = ComponentState.Error;
                //save progress
                Events?.Invoke(this, new ProductionAreaEventArgs(ProductionAction.Error));
            }

            //DO The Thing...
            var result = Transform();

            //Prepare the finishing message
            var args = new ProductionAreaEventArgs(
                ProductionAction.Done,
                e.idWorkOrder,
                new[] { result });

            //Fire a Done Event containing the items produced
            Events?.Invoke(this, args);
            state = ComponentState.Running;
            //Then a Ready event
            Events?.Invoke(this, new ProductionAreaEventArgs(ProductionAction.Ready));
        }
Exemplo n.º 6
0
        public void OnConveyorBeltEvent(object sender, ProductionAreaEventArgs e)
        {
            //Do something when the conveyor calls us
            switch (e.action)
            {
            case ProductionAction.Ready:
                //if there is something to send, send it.
                //else, dont send anything, it can take care of itself during that time.
                if (ToProcess.Count != 0)
                {
                    var pae = ToProcess.Dequeue();                             //pull the task from the storage unit
                    Console.WriteLine("A Task has been dequeued by the Conveyor belt!");
                    EventsConveyor?.Invoke(this, pae);                         //send it to the conveyor
                }
                else
                {
                    Console.WriteLine("The Conveyor is ready, but nothing is coming...");
                    EventsConveyor?.Invoke(this, new ProductionAreaEventArgs(ProductionAction.None));
                }

                break;

            case ProductionAction.Done:
                //The conveyor belt has done one piece of job (might contain more than one item)!
                Console.WriteLine("The conveyor belt has finished a task on WO #{0}!", e.idWorkOrder);
                var toUpdate             = ActiveWorkOrders[e.idWorkOrder];
                var dictFinishedProducts = toUpdate.FinishedProducts;
                //Register the progression in the WorkOrder dictionary
                foreach (var item in e.items)
                {
                    if (!toUpdate.FinishedProducts.ContainsKey(item))
                    {
                        dictFinishedProducts[item] = 1;
                    }
                    else
                    {
                        dictFinishedProducts[item] += 1;
                    }
                }
                toUpdate.FinishedProducts =
                    dictFinishedProducts;                             //Just to make sure in case these weren't references.
                if (!toUpdate.ReadyToClose())
                {
                    ActiveWorkOrders[e.idWorkOrder] =
                        toUpdate;                                 //Just to make sure in case these weren't references.
                }
                else
                {
                    ActiveWorkOrders.Remove(e.idWorkOrder);
                }

                //Send the products to the final Warehouse via the Carrier.
                var toServer = new ProductionAreaEventArgs
                {
                    action      = ProductionAction.Done,
                    idWorkOrder = e.idWorkOrder,
                    items       = e.items
                };
                Console.WriteLine("Sending the items producted to the Prod. Area Server");
                EventsServer?.Invoke(this, toServer);
                break;
            }
        }