Esempio n. 1
0
        public override double execute(double dt)
        {
            MascaretApplication appli = MascaretApplication.Instance;

            //bool found = false;
            OrganisationalEntity askedOrg  = null;
            Procedure            askedProc = null;
            Role askedRole = null;

            List <OrganisationalEntity> orgs = appli.AgentPlateform.Organisations;

            appli.VRComponentFactory.Log("CallProcedure");

            for (int iOrg = 0; iOrg < orgs.Count; iOrg++)
            {
                appli.VRComponentFactory.Log(" Org " + orgs[iOrg].name + " ?");
                if (orgs[iOrg].name == action.OrganisationalEntity)
                {
                    appli.VRComponentFactory.Log("Org : " + orgs[iOrg].name + " found");
                    OrganisationalStructure os    = orgs[iOrg].Structure;
                    List <Procedure>        procs = os.Procedures;
                    askedOrg = orgs[iOrg];

                    for (int iP = 0; iP < procs.Count; iP++)
                    {
                        if (procs[iP].name == action.Procedure)
                        {
                            appli.VRComponentFactory.Log("Procedure " + procs[iP].name + " found");
                            askedProc = procs[iP];
                            List <RoleAssignement> assigns = orgs[iOrg].RoleAssignement;

                            appli.VRComponentFactory.Log("Assigns : " + assigns.Count);
                            for (int iAss = 0; iAss < assigns.Count; iAss++)
                            {
                                Agent agt = appli.AgentPlateform.Agents[assigns[iAss].Agent.toString()];
                                askedRole = assigns[iAss].Role;

                                appli.VRComponentFactory.Log("Role : " + assigns[iAss].Role.name + " == " + agt.name);

                                AgentBehaviorExecution pbehavior = agt.getBehaviorExecutingByName("ProceduralBehavior");

                                if (pbehavior != null)
                                {
                                    appli.VRComponentFactory.Log("Procedure launched for " + agt.name);
                                    ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior);

                                    Dictionary <string, ValueSpecification> procParams = new Dictionary <string, ValueSpecification>();

                                    procBehave.pushProcedureToDo(askedProc, askedOrg, askedRole, procParams);
                                }
                            }
                        }
                    }
                }
            }

            return(0);
        }
        public override void manageRequest(HttpRequest req)
        {
            string orgName = req.parameters["alias"];

            req.response.write("<html>");
            req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            req.response.write("<body>");

            OrganisationalEntity        org  = null;
            List <OrganisationalEntity> orgs = MascaretApplication.Instance.AgentPlateform.Organisations;
            bool found = false;
            int  i     = 0;

            while (!found && i < orgs.Count)
            {
                if (orgs[i].name == orgName)
                {
                    found = true;
                }
                else
                {
                    i++;
                }
            }
            if (found)
            {
                org = orgs[i];
            }

            OrganisationalStructure struc = org.Structure;

            req.response.write("<H2>Description</H2>");
            req.response.write(org.name);

            req.response.write("<H2>Affectations</H2>");
            List <RoleAssignement> assignements = org.RoleAssignement;

            req.response.write("<ul>");
            for (int iA = 0; iA < assignements.Count; iA++)
            {
                string agentAid = assignements[iA].Agent.toString();
                Role   role     = assignements[iA].Role;
                req.response.write("<li>");
                req.response.write(agentAid);
                req.response.write(" / ");
                req.response.write(role.name);
                req.response.write(" : <a href=\"RoleClass?alias=");
                req.response.write(struc.name);
                req.response.write("&role=");
                req.response.write(role.name);
                req.response.write("\" target = \"Body\">");
                req.response.write(role.RoleClass.name);
                req.response.write("</a></li>");
            }
            req.response.write("</ul>");

            req.response.write("<H2>Procedures</H2>");
            List <Procedure> procs = struc.Procedures;

            req.response.write("<ul>");
            for (int iP = 0; iP < procs.Count; iP++)
            {
                req.response.write("<li>");
                req.response.write("<a href=\"Procedure?alias=");
                req.response.write(procs[iP].name);
                req.response.write("&org=");
                req.response.write(org.name);
                req.response.write("\" target = \"Body\">");
                req.response.write(procs[iP].name);
                req.response.write("</a></li>");
            }
            req.response.write("</ul>");

            req.response.write("<H2>Structure</H2>");
            req.response.write("<a href=\"OrgStruct?alias=");
            req.response.write(struc.name);
            req.response.write("\" target = \"Body\">");
            req.response.write(struc.name);
            req.response.write("</a>");

            req.response.write("</body>");
            req.response.write("</html>");
        }
Esempio n. 3
0
        public void addOrganisationalStructure(XElement orgNode)
        {
            XAttribute orgName = (XAttribute)orgNode.Attribute("name");

            OrganisationalStructure organisation = new OrganisationalStructure(orgName.Value);
            organisation.Description = getComment(orgNode);
            organisation.Summary = getSummary(orgNode);
            organisation.Tags = getTags(orgNode);

            //Debug.Log(MascaretApplication.Instance.Model.name);

            MascaretApplication.Instance.AgentPlateform.Structures.Add(organisation);

            foreach (XElement child in orgNode.Elements())
            {
                if (child.Name.LocalName.CompareTo("ownedAttribute") == 0)
                {

                    string childType = "", roleName = "";
                    Classifier classe = null;

                    XAttribute attr = (XAttribute)child.Attribute("type");

                    if (attr != null)
                    {
                        childType = attr.Value;
                        classe = this._classifiers[childType];
                    }

                    attr = (XAttribute)child.Attribute("name");
                    if (attr != null) roleName = attr.Value;

                    if (classe != null)
                    {
                        try
                        {

                            Role role = new Role(roleName);
                            role.RoleClass = (RoleClass)classe;
                            organisation.addRole(role);

                        }
                        catch (InvalidCastException)
                        {

                            try
                            {
                                Ressource ressource = new Ressource(roleName);
                                ressource.EntityClass = (EntityClass)classe;
                                organisation.addResource(ressource);

                            }
                            catch (InvalidCastException)
                            {
                            }
                        }
                    }
                }
            }

            foreach (XElement child in orgNode.Elements())
            {
                if (child.Name.LocalName.CompareTo("ownedBehavior") == 0)
                {

                    string childType = "", childName = "", childId = "";

                    XAttribute attr = (XAttribute)child.Attribute("{http://schema.omg.org/spec/XMI/2.1}type");
                    if (attr == null) attr = (XAttribute)child.Attribute("{http://www.omg.org/spec/XMI/20131001}type");

                    if (attr != null) childType = attr.Value;

                    attr = (XAttribute)child.Attribute("name");
                    if (attr != null) childName = attr.Value;

                    attr = (XAttribute)child.Attribute("{http://schema.omg.org/spec/XMI/2.1}id");
                    if (attr == null) attr = (XAttribute)child.Attribute("{http://www.omg.org/spec/XMI/20131001}id");

                    if (attr != null) childId = attr.Value;

                    if (childType.CompareTo("uml:Activity") == 0)
                    {
                        Activity activity = addActivity(child);
                        Procedure procedure = null;
                        MascaretApplication.Instance.VRComponentFactory.Log(" ?????? Procedure : " + childId);
                        if (isStereotypedScenarioPedagogique(child))
                        {
                            procedure = new PedagogicalScenario(childName);

                            XAttribute attr2 = child.Attribute("{http://schema.omg.org/spec/XMI/2.1}id");
                            if (attr2 == null)
                                attr2 = child.Attribute("{http://www.omg.org/spec/XMI/20131001}id");
                            ((PedagogicalScenario)procedure).Scene = _scenarioToScene[attr2.Value];
                        }
                        else
                            procedure = new Procedure(childName);
                        procedure.Activity = activity;

                        string stereo = getStereotype(childId);
                        MascaretApplication.Instance.VRComponentFactory.Log("procedure;;;;;;;;;;;;;;;;;;;;;;;;;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + childName + " : " + childId + " " + stereo);
                        if (stereo != "")
                        {
                            procedure.Stereotype = stereo;
                        }

                        organisation.addProcedure(procedure);
                        _idBehaviors.Add(childId, activity);
                    }
                }

            }
        }
        public override double execute(double dt)
        {
            if (step == 0)
            {
                // StreamWriter file = new StreamWriter("CallBehaviorExecution.txt");
                // file.AutoFlush = true;
                // file.WriteLine("CallBehaviorExecution"); file.Flush();
                if (action.Behavior.GetType().ToString() == "Mascaret.Activity")
                {
                    string procedureName = action.Behavior.name;
                    Agent  agent         = (Agent)Host;
                    string owner         = action.Owner.name;

                    //     file.WriteLine("Agent : " + agent.name); file.Flush();
                    //     file.WriteLine("ProcedureToDo : " + procedureName); file.Flush();
                    //     file.WriteLine("From Action : " + action.name); file.Flush();
                    //     file.WriteLine("From Procedure : " + owner); file.Flush();

                    ProceduralBehavior        pbehavior         = (ProceduralBehavior)(agent.getBehaviorExecutingByName("ProceduralBehavior"));
                    List <ProcedureExecution> runningProcedures = pbehavior.runningProcedures;

                    //     file.WriteLine("NB Running procs : " + runningProcedures.Count); file.Flush();
                    for (int i = 0; i < runningProcedures.Count; i++)
                    {
                        //  file.WriteLine("Running proc : " + runningProcedures[i].procedure.name); file.Flush();
                        if (runningProcedures[i].procedure.name == owner)
                        {
                            organisation = runningProcedures[i].organisation;
                            //  file.WriteLine("Organisation : " + organisation.name); file.Flush();
                        }
                    }

                    OrganisationalStructure os    = organisation.Structure;
                    List <Procedure>        procs = os.Procedures;
                    for (int iP = 0; iP < procs.Count; iP++)
                    {
                        if (procs[iP].name == procedureName)
                        {
                            procedure = procs[iP];
                        }
                    }

                    List <RoleAssignement> assigns = organisation.RoleAssignement;
                    //        file.WriteLine("Assigns : " + assigns.Count); file.Flush();
                    for (int iAss = 0; iAss < assigns.Count; iAss++)
                    {
                        Agent agt = MascaretApplication.Instance.AgentPlateform.Agents[assigns[iAss].Agent.toString()];
                        AgentBehaviorExecution pbehavior2 = agt.getBehaviorExecutingByName("ProceduralBehavior");

                        if (pbehavior2 != null)
                        {
                            //   file.WriteLine("Procedure launched for " + agt.name); file.Flush();
                            ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior2);

                            Dictionary <string, ValueSpecification> procParams = new Dictionary <string, ValueSpecification>();

                            procBehave.pushProcedureToDo(procedure, organisation, assigns[iAss].Role, procParams);
                        }
                    }
                }
                //   file.Close();
                step++;
            }
            else
            {
                OrganisationalStructure os      = organisation.Structure;
                List <RoleAssignement>  assigns = organisation.RoleAssignement;
                for (int iAss = 0; iAss < assigns.Count; iAss++)
                {
                    Agent agt = MascaretApplication.Instance.AgentPlateform.Agents[assigns[iAss].Agent.toString()];
                    AgentBehaviorExecution pbehavior = agt.getBehaviorExecutingByName("ProceduralBehavior");

                    if (pbehavior != null)
                    {
                        ProceduralBehavior        procBehave        = (ProceduralBehavior)(pbehavior);
                        List <ProcedureExecution> runningProcedures = procBehave.runningProcedures;
                        bool foundP = false;
                        for (int iP = 0; iP < runningProcedures.Count; iP++)
                        {
                            if (runningProcedures[iP].procedure.name == procedure.name)
                            {
                                foundP = true;
                            }
                        }
                        if (!foundP)
                        {
                            return(0);
                        }
                    }
                }
            }
            return(0.1);
        }
        public override void manageRequest(HttpRequest req)
        {
            string procName = req.parameters["alias"];
            string orgName  = req.parameters["org"];

            req.response.write("<html>");
            req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            req.response.write("<body>");

            OrganisationalEntity        org  = null;
            List <OrganisationalEntity> orgs = MascaretApplication.Instance.AgentPlateform.Organisations;
            bool found = false;
            int  i     = 0;

            while (!found && i < orgs.Count)
            {
                if (orgs[i].name == orgName)
                {
                    found = true;
                }
                else
                {
                    i++;
                }
            }
            if (found)
            {
                org = orgs[i];
            }

            OrganisationalStructure struc = org.Structure;

            List <Procedure> procs = struc.Procedures;
            Procedure        proc  = null;

            found = false;
            i     = 0;
            while (!found && i < procs.Count)
            {
                if (procs[i].name == procName)
                {
                    found = true;
                }
                else
                {
                    i++;
                }
            }
            if (found)
            {
                proc = procs[i];
            }

            Environment env = MascaretApplication.Instance.getEnvironment();

            List <Parameter>    parameters = new List <Parameter>();
            List <ActivityNode> nodes      = proc.Activity.Nodes;

            for (int iNode = 0; iNode < nodes.Count; iNode++)
            {
                if (nodes[iNode].Kind == "parameter")
                {
                    parameters.Add(((ActivityParameterNode)(nodes[iNode])).Parameter);
                }
            }

            req.response.write("<HR>");
            req.response.write("<H2>Parametres</H2>");
            req.response.write("<FORM METHOD=GET action=\"launchProcedure\">");
            req.response.write("<INPUT type=\"hidden\" name=\"org\" value=\"");
            req.response.write(orgName);
            req.response.write("\"/>");
            req.response.write("<INPUT type=\"hidden\" name=\"alias\" value=\"");
            req.response.write(procName);
            req.response.write("\"/>");
            req.response.write("<ul>");
            for (int iParam = 0; iParam < parameters.Count; iParam++)
            {
                Parameter param = parameters[iParam];
                req.response.write("<li>");
                Classifier type = param.Type;
                req.response.write(type.name);
                req.response.write("\t");
                req.response.write(param.name);
                if (_isBaseType2(type))
                {
                    req.response.write(" = ");
                    req.response.write(" <INPUT name=_");
                    req.response.write(param.name);
                    req.response.write(">");
                    req.response.write("</li>");
                }
                else
                {
                    req.response.write(" <select name=\"_");
                    req.response.write(param.name);
                    req.response.write("\">");

                    foreach (KeyValuePair <string, InstanceSpecification> instance in env.InstanceSpecifications)
                    {
                        if (instance.Value.Classifier != null)
                        {
                            if (instance.Value.Classifier.isA(type))
                            {
                                req.response.write(" = <option value=\"");
                                req.response.write(instance.Key);
                                req.response.write("\">");
                                req.response.write(instance.Key);
                                req.response.write("</option>");
                            }
                        }
                    }
                    req.response.write("</select>");
                }
            }
            req.response.write("</ul>");
            req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Lancer\">");
            req.response.write("</FORM>");

            req.response.write("</body>");
            req.response.write("</html>");
        }
        public override void manageRequest(HttpRequest req)
        {
            string structName = req.parameters["alias"];

            req.response.write("<html>");
            req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            req.response.write("<body>");

            OrganisationalStructure        struc   = null;
            List <OrganisationalStructure> structs = MascaretApplication.Instance.AgentPlateform.Structures;
            bool found = false;
            int  iO    = 0;

            while (!found && iO < structs.Count)
            {
                if (structs[iO].name == structName)
                {
                    found = true;
                }
                else
                {
                    iO++;
                }
            }
            if (found)
            {
                struc = structs[iO];
            }

            req.response.write("<H2>Description</H2>");
            req.response.write(struc.name);

            req.response.write("<H2>Role</H2>");
            List <Role> roles = struc.Roles;

            req.response.write("<ul>");
            for (int i = 0; i < roles.Count; i++)
            {
                req.response.write("<li>");
                req.response.write(roles[i].name);
                req.response.write(" : <a href=\"RoleClass?alias=");
                req.response.write(struc.name);
                req.response.write("&role=");
                req.response.write(roles[i].name);
                req.response.write("\" target = \"Body\">");
                req.response.write(roles[i].RoleClass.name);
                req.response.write("</a></li>");
            }
            req.response.write("</ul>");

            /*
             *  req->getResponse()->write("<H2>Entites</H2>");
             *  vector< shared_ptr<OrganisationalEntity> > entites = struc->getEntities();
             *  req->getResponse()->write("<ul>");
             *  for (size_t i = 0; i < entites.size(); i++)
             *  {
             *      req->getResponse()->write("<li>");
             *      req->getResponse()->write("<a href=\"OrgEntity?alias=");
             *      req->getResponse()->write(entites[i]->getName());
             *      req->getResponse()->write("\" target = \"Body\">");
             *      req->getResponse()->write(entites[i]->getName());
             *      req->getResponse()->write("</a></li>");
             *  }
             *  req->getResponse()->write("</ul>");
             */

            req.response.write("</body>");
            req.response.write("</html>");
        }
        protected void manageRequestAction(ACLMessage msg)
        {
            Agent agt = (Agent)(this.Host);

            string content = msg.Content;

            FIPASLParserResult result = parseFipaSLExpression(content);

            if (result.success)
            {
                if (result.isAction)
                {
                    bool done = false;

                    AgentBehavior behavior = agt.getBehaviorByBame(result.action.actionName);

                    if (behavior != null)
                    {
                        Dictionary <string, ValueSpecification> parameters = new Dictionary <string, ValueSpecification>();

                        if (result.action.paramName.Count > 0)
                        {
                            for (int i = 0; i < result.action.paramName.Count; i++)
                            {
                                LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                parameters.Add(result.action.paramName[i], (ValueSpecification)(stringValue));
                            }
                        }
                        else
                        {
                            for (int i = 0; i < result.action.paramName.Count; i++)
                            {
                                LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                parameters.Add("param" + i + '0', (ValueSpecification)(stringValue));
                            }
                        }

                        BehaviorScheduler.Instance.executeBehavior(behavior, agt, parameters, false);
                        ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                        reponse.Content = msg.Content;
                        reponse.Receivers.Add(msg.Sender);
                        agt.send(reponse);
                        done = true;
                    }

                    Class     classifier = agt.Classifier;
                    Operation operation  = null;
                    if (classifier != null && classifier.Operations.ContainsKey(result.action.actionName))
                    {
                        operation = classifier.Operations[result.action.actionName];
                        //System.Console.WriteLine("Operation:" + operation.getFullName());
                    }
                    if (operation != null)
                    {
                        Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();
                        List <Parameter> parameters = operation.Parameters;
                        List <string>    paramValue = result.action.paramValue;
                        List <string>    paramName  = result.action.paramName;

                        if (parameters.Count == paramValue.Count)
                        {
                            for (int i = 0; i < parameters.Count; i++)
                            {
                                // Pour tous les parametres issus de l'operation
                                string parameterName = parameters[i].name;

                                // Cherche l'indice de ce parameter dans paramsName
                                int indice = 0; bool found = false;
                                while (!found && indice < paramName.Count)
                                {
                                    if (paramName[indice] == parameterName)
                                    {
                                        found = true;
                                    }
                                    else
                                    {
                                        indice++;
                                    }
                                }

                                if (found)
                                {
                                    string strVal = paramValue[indice];

                                    System.Console.Write("Type : " + parameters[i].Type.getFullName());
                                    System.Console.Write(" - Name: " + parameters[i].name);
                                    System.Console.WriteLine(" - Value: " + strVal);

                                    string typeName = parameters[i].Type.getFullName();
                                    if (typeName == "boolean" || typeName == "integer" || typeName == "real" || typeName == "string")
                                    {
                                        param.Add(parameters[i].name, parameters[i].Type.createValueFromString(strVal.ToLower()));
                                    }
                                    else
                                    {
                                        try
                                        {
                                            InstanceSpecification inst = MascaretApplication.Instance.getEnvironment().getInstance(strVal.ToLower());
                                            param.Add(parameters[i].name, new InstanceValue(inst));
                                        }
                                        catch (NullReferenceException e)
                                        {
                                        }
                                    }
                                }
                            }

                            //BehaviorScheduler.Instance.executeBehavior(operation.Method, agt, param, false);

                            /*
                             *  List<ActionNode> possibleTranslation = _translateOperationToActions(operation);
                             *
                             *  shared_ptr<AgentBehaviorExecution> abe = agt->getBehaviorExecutionByName("ProceduralBehavior"); //hasslich... ja...
                             *  shared_ptr<ProceduralBehavior> pbe  = shared_dynamic_cast<ProceduralBehavior> (abe);
                             *
                             *  if (possibleTranslation.size() && pbe)
                             *  {
                             *      //add actionNode in ProceduralBehavior
                             *
                             *      pbe->pushActionToDo(possibleTranslation[0]);
                             *  }
                             *  else
                             *  {
                             *      //call method
                             */
                            BehaviorExecution be = BehaviorScheduler.Instance.executeBehavior(operation.Method, agt, param, false);

                            /*
                             * if (be != null)
                             * {
                             *  be.addCallbackOnBehaviorStop(bind(&SimpleCommunicationBehavior::_onBehaviorStop,this,_1));
                             *
                             *  _requestedAction[be->getSpecification()->getName()].push_back(msg->getSender());
                             * }*/
                            // }



                            ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                            reponse.Content = msg.Content;

                            System.Console.WriteLine("Content-Sent: " + reponse.Content);
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);
                        }
                        else
                        {
                            ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                            string     contentRep = "";
                            contentRep     += content;
                            reponse.Content = contentRep;
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);
                        }
                    }
                    else
                    {
                        string procName = result.action.actionName;
                        bool   found    = false;
                        OrganisationalEntity askedOrg  = null;
                        Procedure            askedProc = null;
                        Role askedRole = null;
                        List <OrganisationalEntity> orgs = agt.Plateform.Organisations;

                        for (int iOrg = 0; iOrg < orgs.Count; iOrg++)
                        {
                            List <RoleAssignement> assigns = orgs[iOrg].RoleAssignement;

                            for (int iAss = 0; iAss < assigns.Count; iAss++)
                            {
                                if (assigns[iAss].Agent.toString() == agt.Aid.toString())
                                {
                                    OrganisationalStructure os    = orgs[iOrg].Structure;
                                    List <Procedure>        procs = os.Procedures;

                                    for (int iP = 0; iP < procs.Count; iP++)
                                    {
                                        System.Console.WriteLine(procName + " / " + procs[iP].name);
                                        if (procs[iP].name == procName)
                                        {
                                            askedProc = procs[iP];
                                            askedOrg  = orgs[iOrg];
                                            askedRole = assigns[iAss].Role;
                                            found     = true;
                                        }
                                    }
                                }
                            }
                        }

                        if (found)
                        {
                            ACLMessage reponse = new ACLMessage(ACLPerformative.AGREE);
                            reponse.Content = msg.Content;
                            reponse.Receivers.Add(msg.Sender);
                            agt.send(reponse);

                            // Recherche du comportement procedural
                            // UGGLY
                            //System.Console.WriteLine("1");
                            AgentBehaviorExecution pbehavior = agt.getBehaviorExecutingByName("ProceduralBehavior");

                            //AgentBehaviorExecution> behavior2 = agt->getBehaviorExecutionByName("ActionListenerBehavior");
                            //System.Console.WriteLine("2");
                            if (pbehavior != null)
                            {
                                ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior);

                                Dictionary <string, ValueSpecification> procParams = new Dictionary <string, ValueSpecification>();
                                for (int i = 0; i < result.action.paramName.Count; i++)
                                {
                                    LiteralString stringValue = new LiteralString(result.action.paramValue[i]);
                                    procParams.Add(result.action.paramName[i], stringValue);
                                }

                                //System.Console.WriteLine("3");
                                Activity act = askedProc.Activity;
                                //List<ActivityNode>  nodes  = act.Nodes;

                                procBehave.pushProcedureToDo(askedProc, askedOrg, askedRole, procParams);
                                //procBehave.restart();

                                ACLMessage reponse2 = new ACLMessage(ACLPerformative.AGREE);
                                reponse2.Content = msg.Content;
                                reponse2.Receivers.Add(msg.Sender);
                                agt.send(reponse2);
                            }

                            /*
                             * else if (behavior2)
                             * {
                             *  shared_ptr<ActionListenerBehavior> procBehave  = shared_dynamic_cast<ActionListenerBehavior> (behavior2);
                             *
                             *  procBehave->pushProcedureToDo(askedProc, askedOrg, askedRole, Parameters());
                             *  procBehave->restart();
                             *
                             *  shared_ptr<ACLMessage> reponse = make_shared<ACLMessage>(AGREE);
                             *  reponse->setContent(msg->getContent());
                             *  reponse->addReceiver(msg->getSender());
                             *  agt->send(reponse);
                             * }*/
                            else
                            {
                                if (!done)
                                {
                                    ACLMessage reponse3   = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                                    string     contentRep = "";
                                    contentRep      += result.action.actionName;
                                    reponse3.Content = contentRep;
                                    reponse3.Receivers.Add(msg.Sender);
                                    agt.send(reponse3);
                                }
                            }
                        }
                        else
                        {
                            if (!done)
                            {
                                ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                                string     contentRep = "";
                                contentRep     += result.action.actionName;
                                reponse.Content = contentRep;
                                reponse.Receivers.Add(msg.Sender);
                                agt.send(reponse);
                            }
                        }
                    }
                }
                else
                {
                    // Proposition Non encore traite....
                }
            }
            else
            {
                System.Console.WriteLine("[SimpleCommunicationBehavior Warning] Parsing error. Message content parsing error: " + content);

                ACLMessage reponse    = new ACLMessage(ACLPerformative.NOT_UNDERSTOOD);
                string     contentRep = "";
                contentRep += content;

                reponse.Content = contentRep;
                reponse.Receivers.Add(msg.Sender);
                agt.send(reponse);
            }
        }
Esempio n. 8
0
        public override void manageRequest(HttpRequest req)
        {
            string procName = req.parameters["alias"];
            string orgName  = req.parameters["org"];

            req.response.write("<html>");
            req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            req.response.write("<body>");

            OrganisationalEntity        org  = null;
            List <OrganisationalEntity> orgs = MascaretApplication.Instance.AgentPlateform.Organisations;
            bool found = false;
            int  i     = 0;

            while (!found && i < orgs.Count)
            {
                if (orgs[i].name == orgName)
                {
                    found = true;
                }
                else
                {
                    i++;
                }
            }
            if (found)
            {
                org = orgs[i];
            }

            OrganisationalStructure struc = org.Structure;

            List <Procedure> procs = struc.Procedures;
            Procedure        proc  = null;

            found = false;
            i     = 0;
            while (!found && i < procs.Count)
            {
                if (procs[i].name == procName)
                {
                    found = true;
                }
                else
                {
                    i++;
                }
            }
            if (found)
            {
                proc = procs[i];
            }

            Environment env = MascaretApplication.Instance.getEnvironment();

            List <Parameter>    parameters = new List <Parameter>();
            List <ActivityNode> nodes      = proc.Activity.Nodes;

            for (int iNode = 0; iNode < nodes.Count; iNode++)
            {
                if (nodes[iNode].Kind == "parameter")
                {
                    parameters.Add(((ActivityParameterNode)(nodes[iNode])).Parameter);
                }
            }

            string paramString = "";
            Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();

            for (int iParam = 0; iParam < parameters.Count; iParam++)
            {
                string strVal = req.parameters[parameters[iParam].name];
                strVal.Replace("+", " ");

                //Debug.Log (strVal);
                param.Add(parameters[iParam].name, parameters[iParam].Type.createValueFromString(strVal));
                paramString += " :" + parameters[iParam].name + " " + strVal;
            }

            List <RoleAssignement> assignements = org.RoleAssignement;

            for (int iA = 0; iA < assignements.Count; iA++)
            {
                ACLMessage procMsg = new ACLMessage(ACLPerformative.REQUEST);
                procMsg.Receivers.Add(assignements[iA].Agent);

                AID agentAID = MascaretApplication.Instance.Agent.Aid;
                procMsg.Sender = agentAID;
                string content = "((action ";
                content        += assignements[iA].Agent.name;
                content        += " ";
                content        += "(" + proc.name;
                content        += paramString;
                content        += ")))";
                procMsg.Content = content;
                MascaretApplication.Instance.AgentPlateform.sendMessage(procMsg);

                if (agentAID.name == assignements[iA].Agent.name)
                {
                    req.response.write("<H2>Vous jouez le role ");
                    req.response.write(assignements[iA].Role.name);
                    req.response.write("</H2>");
                    req.response.write("<H3>Vous pouvez faire les actions suivantes : </H3>");

                    req.response.write("<ul>");
                    Activity act = proc.Activity;
                    List <ActivityPartition> partitions = act.Partitions;
                    for (int iPart = 0; iPart < partitions.Count; iPart++)
                    {
                        if (partitions[iPart].name == assignements[iA].Role.name)
                        {
                            nodes = partitions[iPart].Node;
                            for (int iNode = 0; iNode < nodes.Count; iNode++)
                            {
                                if (nodes[iNode].Kind == "action")
                                {
                                    req.response.write("<li>");
                                    req.response.write("<a href=\"Actions?alias=");
                                    req.response.write(nodes[iNode].name);
                                    req.response.write("&org=");
                                    req.response.write(org.name);
                                    req.response.write("&role=");
                                    req.response.write(assignements[iA].Role.name);
                                    req.response.write("&proc=");
                                    req.response.write(proc.name);
                                    req.response.write("\" target = \"Body\">");
                                    req.response.write(nodes[iNode].name);
                                    req.response.write("</a></li>");
                                }
                            }
                        }
                    }
                    req.response.write("</ul>");
                }
            }

            req.response.write("</body>");
            req.response.write("</html>");
        }