Ejemplo n.º 1
0
        private void GetOrCreateComunicationAgentForType(InstructionSet objects)
        {
            // debug
            DebugMessage(" got Called by -> " + objects.SourceAgent.Name);

            // find the related Comunication Agent
            var comunicationAgent = ChildAgents.OfType <ComunicationAgent>().ToList()
                                    .FirstOrDefault(x => x.ContractType == objects.ObjectToProcess.ToString());

            // if no Comunication Agent is found, Create one
            if (comunicationAgent == null)
            {
                // Create ComunicationAgent if not existent
                comunicationAgent = new ComunicationAgent(creator: this,
                                                          name: "Comunication ->" + objects.ObjectToProcess,
                                                          debug: this.DebugThis,
                                                          contractType: objects.ObjectToProcess.ToString());

                // add Agent Reference.
                ChildAgents.Add(comunicationAgent);
            }

            // Tell the Machine the corrosponding Comunication Agent.
            CreateAndEnqueueInstuction(methodName: MachineAgent.InstuctionsMethods.SetComunicationAgent.ToString(),
                                       objectToProcess: comunicationAgent,
                                       targetAgent: objects.SourceAgent);

            // Add the Machine to Comunication Agent if Requested by Machine Agent.
            if (objects.SourceAgent.GetType() == typeof(MachineAgent))
            {
                CreateAndEnqueueInstuction(methodName: ComunicationAgent.InstuctionsMethods.AddMachineToComunicationAgent.ToString(),
                                           objectToProcess: objects.SourceAgent,
                                           targetAgent: comunicationAgent);
            }
        }
Ejemplo n.º 2
0
        internal new void Finished(InstructionSet instructionSet)
        {
            // any Not Finished do noting
            if (ChildAgents.Any(x => x.Status != Status.Finished))
            {
                return;
            }

            // Return from Production as WorkItemStatus
            var status = instructionSet.ObjectToProcess as WorkItemStatus;

            if (status != null)
            {
                var workItem = WorkItems.First(x => x.Id == status.WorkItemId);
                workItem.Status = status.Status;
            }

            // TODO Anything ?
            if (RequestItem.Article.WorkSchedules != null && WorkItems.All(x => x.Status == Status.Finished))
            {
                this.Status = Status.Finished;
                CreateAndEnqueueInstuction(methodName: StorageAgent.InstuctionsMethods.ResponseFromProduction.ToString(),
                                           objectToProcess: this,
                                           targetAgent: this.Creator); // Has been injected by Dispo and is Storage


                DebugMessage("All Workschedules have been Finished");
                return;
            }
            // else
            DebugMessage("Im Ready To get Enqued");
            Status = (Status == Status.Processed)? Status.Processed : Status.Ready;
            WorkItems.ForEach(item => item.MaterialsProvided = true);
            SetWorkItemReady();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// check Childs and Call Finish if all in State Finished.
 /// </summary>
 internal void Finished(InstructionSet objects)
 {
     if (ChildAgents.All(x => x.Status == Status.Finished) && this.Status == Status.Finished)
     {
         ChildAgents.Clear();
         Finish();
     }
 }
Ejemplo n.º 4
0
        private void StartProductionAgent()
        {
            var firstToEnqueue = false;

            // check for Children
            if (!RequestItem.Article.ArticleBoms.Any())
            {
                DebugMessage("Last leave in Bom");
                firstToEnqueue = true;
            }

            // if item hase Workschedules Request ComClient for them
            if (RequestItem.Article.WorkSchedules != null)
            {
                // Ask the Directory Agent for Service
                RequestComunicationAgentFor(workSchedules: RequestItem.Article.WorkSchedules);
                // And Create workItems
                CreateWorkItemsFromRequestItem(firstItemToBuild: firstToEnqueue);
            }

            // Create Dispo Agents for Childs.
            foreach (var articleBom in RequestItem.Article.ArticleBoms)
            {
                var item = new RequestItem
                {
                    Article  = articleBom.ArticleChild,
                    Quantity = Convert.ToInt32(articleBom.Quantity),
                    DueTime  = RequestItem.DueTime,
                    OrderId  = RequestItem.OrderId
                };

                // create Dispo Agents for to Provide Required Articles
                var dispoAgent = new DispoAgent(creator: this,
                                                system: ((StorageAgent)Creator).Creator,
                                                name: RequestItem.Article.Name + " Child of(" + this.Name + ")",
                                                debug: DebugThis,
                                                requestItem: item);
                // add to childs
                ChildAgents.Add(dispoAgent);
                //RequestMaterials.Add(item);
                // add TO Context to process them this time Period.
                Context.ProcessesRemainingThisTimePeriod.Enqueue(dispoAgent);
            }
        }
Ejemplo n.º 5
0
        internal new void Finished(InstructionSet instructionSet)
        {
            if (ChildAgents.Any(x => x.Status != Status.Finished))
            {
                return;
            }
            // else
            // Call Finish
            var intime = false;

            if (Context.TimePeriod <= requestItem.DueTime)
            {
                intime = true;
            }
            Debug.WriteLine("Order Finished at:" + Context.TimePeriod + " InTime: " + intime);
            CreateAndEnqueueInstuction(methodName: SystemAgent.InstuctionsMethods.OrderProvided.ToString(),
                                       objectToProcess: requestItem,
                                       targetAgent: this.Creator);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Startup with Creating Dispo Agent for current Item.
        /// </summary>
        /// <param name="objects"></param>
        private void StartOrder(InstructionSet objects)
        {
            var orderItem = objects.ObjectToProcess as OrderPart;

            if (orderItem == null)
            {
                throw new InvalidCastException();
            }

            // create Request Item
            requestItem = MapPropertiesToRequestItem(orderItem);

            // Create Dispo Agent
            var dispoAgent = new DispoAgent(creator: this,
                                            system: Creator,
                                            name: requestItem.Article.Name + " OrderPartId(" + orderItem.Id + ")",
                                            debug: DebugThis,
                                            requestItem: requestItem);

            ChildAgents.Add(dispoAgent);
        }