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); } }
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); } }
/// <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); }