Esempio 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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Callback
        /// </summary>
        /// <param name="objects"></param>
        private void SetComunicationAgent(InstructionSet objects)
        {
            // save Cast to expected object
            _comunicationAgent = objects.ObjectToProcess as ComunicationAgent;

            // throw if cast failed.
            if (_comunicationAgent == null)
            {
                throw new ArgumentException("Could not Cast Communication Agent from InstructionSet.ObjectToProcess");
            }

            // Debug Message
            DebugMessage("Successfull Registred Service at : " + _comunicationAgent.Name);
        }