protected void buildAffectationsObject(ref List <string> missing, ActivityNode node)
        {
            string pname = node.name;

            //  MascaretApplication.Instance.logfile.WriteLine("TRY TO AFFECT OBJECT : " + pname); MascaretApplication.Instance.logfile.Flush();
            RessourceAssignement ra = organisation.findRessourceAssignement(pname);

            if (ra != null && ra.Entity != null)
            {
                affectations.Add(pname, ra.Entity);
                // MascaretApplication.Instance.logfile.WriteLine("SUCCESS TO AFFECT OBJECT : " + pname); MascaretApplication.Instance.logfile.Flush();
            }
            else
            {
                //Parameters::iterator it = _activityParams.find(pname);
                if (activityParams.ContainsKey(pname))
                {
                    affectations.Add(pname, ((InstanceValue)(activityParams[pname])).SpecValue);
                }
                else
                {
                    //    MascaretApplication.Instance.logfile.WriteLine("FAIL TO AFFECT OBJECT : " + pname); MascaretApplication.Instance.logfile.Flush();
                    missing.Add(pname);
                }
            }
        }
        protected void buildAffectationsAction(ref List <string> missing, ActivityNode node)
        {
            Action action = ((ActionNode)(node)).Action;

            if (action != null)
            {
                if (action.Kind == "SendSignal")
                {
                    SendSignalAction sendAct = (SendSignalAction)(action);
                    string           pname   = sendAct.Target.targetName;
                    if (pname != "")
                    {
                        RessourceAssignement ra = organisation.findRessourceAssignement(pname);

                        if (ra != null && ra.Entity != null)
                        {
                            affectations.Add(pname, ra.Entity);
                            sendAct.Target.target = ra.Entity;
                        }
                        else
                        {
                            missing.Add(pname);
                        }
                    }
                }
                else if (action.Kind == "CallOperation")
                {
                    CallOperationAction            callAct = (CallOperationAction)(action);
                    InstanceSpecification          host    = (InstanceSpecification)(agent);
                    Dictionary <string, Operation> opers   = host.Classifier.Operations;
                    if (opers.ContainsKey(callAct.Operation.name))
                    {
                        callAct.Operation = opers[callAct.Operation.name];
                    }
                }
                else if (action.Kind == "CallBehavior")
                {
                    /*
                     * shared_ptr<CallBehaviorAction> callBeh = shared_dynamic_cast<CallBehaviorAction>(action);
                     * map<string, shared_ptr<Operation> > opers = getHost()->getClassifier()->getOperations();
                     * map<string, shared_ptr<Operation> >::iterator it = opers.find(callBeh->getOperation()->getName());
                     * if (it != opers.end())
                     * {
                     *  callBeh->setBehavior(it->second);
                     * }
                     */
                }
                else
                {
                }
            }
        }
Beispiel #3
0
        protected OrganisationalEntity _createOrganisation(XElement node)
        {
            //StreamWriter file = new StreamWriter("Organisation.txt");

            string name = "";
            OrganisationalEntity organisation = null;
            XAttribute attr = (XAttribute)node.Attribute("name");
            if (attr != null) name = attr.Value;

            foreach (XElement struc in node.Elements())
            {
                if (struc.Name.LocalName == "Structure")
                {
                    string structName = struc.Value;

                    OrganisationalStructure structOrg = null;

                    foreach (OrganisationalStructure currentOrg in agentPlateform.Structures)
                    {
                        if (currentOrg.name == structName)
                        {
                            structOrg = currentOrg;
                            break;
                        }
                    }
                    if (structOrg == null)
                    {  }
                    else
                    {
                      //  MascaretApplication.Instance.logfile.WriteLine("Structure found"); MascaretApplication.Instance.logfile.Flush();
                        organisation = new OrganisationalEntity(name);
                        organisation.Structure = structOrg;

                        structOrg.Entities.Add(organisation);

                        foreach (XElement affects in node.Elements())
                        {
                            if (affects.Name.LocalName == "Affect")
                            {
                                attr = (XAttribute)affects.Attribute("type");

                                if (attr != null && attr.Value == "Role")
                                {

                                //    file.WriteLine("Affect Role"); file.Flush();
                                    XElement roleNode = null, agentNode = null, aidNode = null;

                                    foreach (XElement currentNode in affects.Elements())
                                    {
                                        if (currentNode.Name.LocalName == "Role")
                                            roleNode = currentNode;
                                        else if (currentNode.Name.LocalName == "Agent")
                                            agentNode = currentNode;
                                        else if (currentNode.Name.LocalName == "AID")
                                            aidNode = currentNode;
                                    }

                                    string agentName = "";
                                    string plateformeName = "localhost";
                                    int plateformePort = agentPlateform.PortNumber;
                                    if (aidNode != null)
                                    {
                                        foreach (XElement currentNode in aidNode.Elements())
                                        {
                                            if (currentNode.Name.LocalName == "Name")
                                            {
                                                agentName = currentNode.Value;
                                            }
                                            else if (currentNode.Name.LocalName == "Plateform")
                                            {
                                                plateformeName = currentNode.Value;
                                            }
                                            else if (currentNode.Name.LocalName == "Port")
                                            {
                                                string ports = currentNode.Value;
                                                plateformePort = int.Parse(ports);
                                            }
                                        }

                                    }
                                    else
                                    {
                                        agentName = agentNode.Value;
                                    }

                                    string roleName = roleNode.Value;

                                    if (plateformeName == "localhost") plateformeName = agentPlateform.name;

                                    AID aid = new AID(agentName, plateformeName, plateformePort);

                                    Role role = null;

                                //    file.WriteLine("Nb Roles : " + structOrg.Roles.Count); file.Flush();

                                    foreach (Role currentRole in structOrg.Roles)
                                    {
                                     //   file.WriteLine(currentRole.name + " == " + roleName); file.Flush();
                                        if (currentRole.name == roleName)
                                        {
                                            role = currentRole;
                                            break;
                                        }
                                    }
                                    if (role == null)
                                    {  }
                                    else
                                    {
                                     //   file.WriteLine("Assign"); file.Flush();
                                        RoleAssignement assignement = new RoleAssignement(organisation);
                                        assignement.Agent = aid;
                                        assignement.Role = role;
                                        organisation.RoleAssignement.Add(assignement);
                                    }

                                }
                                else if (attr != null && attr.Value == "Ressource")
                                {
                                    XElement ressourceNode = null, entityNode = null;
                                    string ressourceName = "";
                                    string entityName = "";

                                    foreach (XElement currentNode in affects.Elements())
                                    {
                                        if (currentNode.Name.LocalName == "Ressource")
                                            ressourceNode = currentNode;

                                        else if (currentNode.Name.LocalName == "Entity")
                                            entityNode = currentNode;
                                    }

                                    ressourceName = ressourceNode.Value;
                                    entityName = entityNode.Value;

                                    //Debug.Log( " Affectation Ressource : " + ressourceName + " = " + entityName );
                                    // Recherche de l'entite .....
                                  //  MascaretApplication.Instance.logfile.WriteLine("Ressource affect looking entity : " + entityName);
                                  //  MascaretApplication.Instance.logfile.Flush();
                                    InstanceSpecification entite = environment.getInstance(entityName);
                                    if (entite == null) {
                                     //   MascaretApplication.Instance.logfile.WriteLine("Not found");
                                     //   MascaretApplication.Instance.logfile.Flush();
                                    }

                                    // Recherche de la ressource
                                    Ressource res = null;
                                    //Debug.Log( " *** " + structOrg.Ressources.Count );
                                    foreach (Ressource currentRes in structOrg.Ressources)
                                    {
                                     //   MascaretApplication.Instance.logfile.WriteLine( "Resource search: comparing " + currentRes.name + " to " + ressourceName );
                                     //   MascaretApplication.Instance.logfile.Flush();
                                        if (currentRes.name == ressourceName)
                                        {
                                          //  MascaretApplication.Instance.logfile.WriteLine("found");
                                          //  MascaretApplication.Instance.logfile.Flush();
                                            res = currentRes;
                                            break;
                                        }
                                    }

                                    // Creation de l'assignement
                                    RessourceAssignement ra = new RessourceAssignement();
                                    ra.Entity = ((Entity)entite);
                                    ra.Ressource = res;

                                    organisation.RessourcesAssignement.Add(ra);

                                }
                            }
                        }
                    }
                }
            }

            return organisation;
        }