//TODO public void addActivityGroup(XElement node, Activity activity) { string type = ""; if (node.Attribute("{http://schema.omg.org/spec/XMI/2.1}type") != null) type = node.Attribute("{http://schema.omg.org/spec/XMI/2.1}type").Value; else type = node.Attribute("{http://www.omg.org/spec/XMI/20131001}type").Value; if (type == "uml:ActivityPartition") { string name = node.Attribute("name").Value; ActivityPartition partition = new ActivityPartition(name); //Debug.Log(" ---> Partition : " + name); string id = ""; if (node.Attribute("{http://schema.omg.org/spec/XMI/2.1}id") != null) id = node.Attribute("{http://schema.omg.org/spec/XMI/2.1}id").Value; else id = node.Attribute("{http://www.omg.org/spec/XMI/20131001}id").Value; _partitions.Add(id, partition); activity.addPartition(partition); } else if (type == "uml:LoopNode") { LoopNode loopNode = new LoopNode(node.Attribute("name").Value, "Loop"); loopNode.Description = getComment(node); activity.addNode(loopNode); string idPartition = node.Attribute("inPartition").Value; if (_partitions.ContainsKey(idPartition)) { loopNode.Partitions.Add(_partitions[idPartition]); _partitions[idPartition].Node.Add(loopNode); } /* string isTestedFirst = node.Attribute("isTestedFirst").Value; if (isTestedFirst == "true") { loopNode.setTestedFirst(true); } else { loopNode->setTestedFirst(false); }*/ _activityNodes.Add(node.Attribute("{http://schema.omg.org/spec/XMI/2.1}id").Value, loopNode); //string testId = node.Attribute("test").Value; /* map<string, shared_ptr<Expression> >::iterator it = _activityExpressions.find(testId); if (it != _activityExpressions.end()) { loopNode->setCondition(it->second); } else cerr << "Test for LoopNode : " << loopNode->getName() << " not found" << endl; */ foreach (XElement child in node.Elements()) { if (child.Name.LocalName == "node") { string inPart = node.Attribute("inPartition").Value; //child.->setProperty(string("inPartition"), inPart); //cerr << "././././././././././. transferring property: " << inPart << endl; addActivityNode(child, loopNode, activity); } } foreach (XElement child in node.Elements()) { if (child.Name.LocalName == "edge") addActivityEdge(child, loopNode); } } }
public static void executeOperationInActivity(Agent agent, string operation, Dictionary <string, string> spec, int index, CallProcedureBehaviorExecution pbe) { if (pbe != null) { ActivityPartition agentPartition = new ActivityPartition(agent.name); CallOperationAction act = new CallOperationAction(); act.Operation = MascaretUtils.getOperation(operation, agent); ActionNode an = new ActionNode(operation + "_" + index, "action"); an.Action = act; foreach (KeyValuePair <string, string> kvp in spec) { act.Arguments.Add(kvp.Key, kvp.Value); } an.Partitions = new List <ActivityPartition>(); an.Partitions.Add(agentPartition); AgentBehaviorExecution pbehavior = agent.getBehaviorExecutingByName("ProceduralBehavior"); if (pbehavior != null) { ProceduralBehavior procBehave = (ProceduralBehavior)(pbehavior); PrintSingleton.Instance.log(procBehave.RunningProcedures.Count); OrganisationalEntity askedOrg = MascaretApplication.Instance.AgentPlateform.Organisations.Find(x => x.name == pbe.action.OrganisationalEntity); Procedure askedProc = askedOrg.Structure.Procedures.Find(x => x.name == pbe.action.Procedure); Role askedRole = askedOrg.RoleAssignement.Find(x => x.Role.name == agent.name).Role; if (procBehave.RunningProcedures.Count == 0) //No runningProcedure for this agent, need to create one { Dictionary <string, ValueSpecification> procParams = new Dictionary <string, ValueSpecification>(); PrintSingleton.Instance.log("Launch procedure for " + agent.name); askedProc.Activity.Partitions.Add(agentPartition); procBehave.pushProcedureToDo(askedProc, askedOrg, askedRole, procParams); } //The new partition needs to be added to all agents.. Dictionary <string, Agent> allAgents = VRApplication.Instance.AgentPlateform.Agents; foreach (KeyValuePair <string, Agent> kvp in allAgents) { ProceduralBehavior pb = (ProceduralBehavior)kvp.Value.getBehaviorExecutingByName("ProceduralBehavior"); if (pb != null) { for (int iP = 0; iP < pb.runningProcedures.Count; iP++) { if (!pb.runningProcedures[iP].getAgentToPartition().ContainsKey(agent.Aid.toString())) { pb.runningProcedures[iP].getAgentToPartition().Add(agent.Aid.toString(), askedProc.Activity.Partitions.Find(x => x.name == agent.name)); } } } } executeOperation(an, agent); } else { PrintSingleton.Instance.log("Agent " + agent.name + " does not have a proceduralBehavior!"); } } else { PrintSingleton.Instance.log("No procedure launched!"); } }
public void addPartition(ActivityPartition val) { val.Activity = this; partitions.Add(val); }