Beispiel #1
0
        public void addMachineRegion(XElement node, StateMachine machine, Region region, Dictionary<string, Vertex> vertices)
        {
            //   StreamWriter file = new StreamWriter("region.txt");

            foreach (XElement child in node.Elements())
            {

                if (child.Name.LocalName == "subvertex")
                {
                    string type = "";
                    if (child.Attribute("{http://schema.omg.org/spec/XMI/2.1}type") != null)
                        type = child.Attribute("{http://schema.omg.org/spec/XMI/2.1}type").Value;
                    else if (child.Attribute("{http://www.omg.org/spec/XMI/20131001}type") != null)
                        type = child.Attribute("{http://www.omg.org/spec/XMI/20131001}type").Value;

                    string name = child.Attribute("name").Value;

                    string childId = "";
                    if (child.Attribute("{http://schema.omg.org/spec/XMI/2.1}id") != null)
                        childId = child.Attribute("{http://schema.omg.org/spec/XMI/2.1}id").Value;
                    else if (child.Attribute("{http://www.omg.org/spec/XMI/20131001}id") != null)
                        childId = child.Attribute("{http://www.omg.org/spec/XMI/20131001}id").Value;

                    // MascaretApplication.Instance.logfile.WriteLine("Type : " + type); MascaretApplication.Instance.logfile.Flush();
                    if (type == "uml:State")
                    {
                        //   file.WriteLine("State : " + name); file.Flush();
                        //cerr << "State : " << name << endl;
                        // MascaretApplication.Instance.logfile.WriteLine("Name : " + name); MascaretApplication.Instance.logfile.Flush();

                        State state = new State(name, "State");
                        state.Description = getComment(child);
                        state.Summary = getSummary(child);
                        state.Tags = getTags(child);
                        region.Vertices.Add(state);

                        vertices[childId] = state;

                        foreach (XElement vertexChild in child.Elements())
                        {

                            if (vertexChild.Name.LocalName == "region")
                            {
                                Region subregion = new Region();
                                state.Regions.Add(subregion);
                                addMachineRegion(vertexChild, machine, subregion, vertices);
                                //cerr << "HAS SUBREGION....." << endl;
                            }
                            else if (vertexChild.Name.LocalName == "Entry")
                            {
                                string opEntryName = "";
                                foreach (XElement childV in vertexChild.Elements())
                                    if (childV.Name.LocalName == "body") opEntryName = childV.Value; //InnerTExt
                                Class cl = (Class)machine.Owner;
                                if (cl.hasOperation(opEntryName))
                                {
                                    Operation op = cl.Operations[opEntryName];
                                    state.EntryBehavior = op;
                                }
                                else
                                {
                                    //Debug.Log ("can't found " + opEntryName + " for entry behavior of state " + name );
                                }
                            }
                            else if (vertexChild.Name.LocalName == "Exit")
                            {
                                string opExitName = "";
                                foreach (XElement childV in vertexChild.Elements())
                                    if (childV.Name == "body") opExitName = childV.Value;
                                Class cl = (Class)machine.Owner;
                                if (cl.hasOperation(opExitName))
                                {
                                    Operation op = cl.Operations[opExitName];
                                    state.ExitBehavior = op;
                                }
                                else
                                {
                                    //Debug.Log ("can't found " + opExitName + " for entry behavior of state " + name );
                                }
                            }
                            else if (vertexChild.Name.LocalName == "Do" || vertexChild.Name.LocalName == "doBehavior" || vertexChild.Name.LocalName == "doActivity")
                            {
                                //   file.WriteLine(" ... has Do Activity");

                                string opDoName;
                                XElement bodyVertexChild = null;
                                foreach (XElement childV in vertexChild.Elements())
                                {

                                    //Debug.Log(childV.Name.LocalName);
                                    if (childV.Name.LocalName == "body") bodyVertexChild = childV;
                                    else if (childV.Name.LocalName == "method") { bodyVertexChild = childV; }
                                }

                                Class cl = (Class)machine.Owner;
                                if (bodyVertexChild != null)
                                {
                                    /*
                                    opDoName = bodyVertexChild.Value;
                                    if(cl.hasOperation(opDoName))
                                    {
                                        Operation op = cl.Operations[opDoName];
                                        state.DoBehavior = op;
                                        //Debug.Log ("Do behavior : " + op.getFullName());
                                    } else
                                    {
                                        //Debug.Log ("can't found " + opDoName + " for do behavior of state " + name);
                                    }
                                    */
                                    opDoName = bodyVertexChild.Attribute("{http://schema.omg.org/spec/XMI/2.1}idref").Value;
                                    if (_idOperations.ContainsKey(opDoName))
                                    {
                                        Operation op = _idOperations[opDoName];
                                        state.DoBehavior = op;
                                        //   file.WriteLine("Do : " + op.getFullName()); file.Flush();
                                    }

                                }
                                else
                                {
                                    string opID = vertexChild.Attribute("specification").Value;

                                    if (_idOperations.ContainsKey(opID))
                                    {
                                        Operation op = _idOperations[opID];
                                        state.DoBehavior = op;
                                        // MascaretApplication.Instance.logfile.WriteLine(op.getFullName()); MascaretApplication.Instance.logfile.Flush();
                                        //Debug.Log ("Do behavior : " + op.getFullName());
                                    }
                                    //else
                                    //Debug.Log ("can't found " + opID + " for do behavior of state " + name);
                                }

                            }
                        }

                    }
                    else if (type == "uml:Pseudostate")
                    {

                        PseudoState ps = new PseudoState(name);
                        ps.Description = getComment(child);
                        ps.Summary = getSummary(child);
                        ps.Tags = getTags(child);

                        region.Vertices.Add(ps);
                        machine.ConnectionPoint.Add(ps);

                        vertices[childId] = ps;
                        string kind;
                        if (child.Attribute("kind") == null)
                            kind = child.Attribute("name").Value;
                        else
                            kind = child.Attribute("kind").Value;

                        // MascaretApplication.Instance.logfile.WriteLine("PseudoState : " + name + " Kind : " + kind); MascaretApplication.Instance.logfile.Flush();

                        if (kind == "initial" || kind == "Initial" || kind == "Initial State")
                            ps.kind = PseudoStateKind.INITIAL;
                        else if (kind == "join")
                            ps.kind = PseudoStateKind.JOIN;
                        else if (kind == "fork")
                            ps.kind = PseudoStateKind.FORK;
                        else if (kind == "deepHistory")
                            ps.kind = PseudoStateKind.DEEPHISTORY;
                        else if (kind == "shallowHistory")
                            ps.kind = PseudoStateKind.SHALLOWHISTORY;
                        else if (kind == "choice")
                            ps.kind = PseudoStateKind.CHOICE;
                        else if (kind == "junction")
                            ps.kind = PseudoStateKind.JUNCTION;
                        else if (kind == "terminate")
                            ps.kind = PseudoStateKind.TERMINATE;
                        else if (kind == "exitPoint")
                            ps.kind = PseudoStateKind.EXITPOINT;
                        else if (kind == "entryPoint")
                            ps.kind = PseudoStateKind.ENTRYPOINT;

                    }
                    else if (type == "uml:Finalstate" || type == "uml:FinalState")
                    {
                        FinalState fs = new FinalState(name);
                        fs.Description = getComment(child);
                        fs.Summary = getSummary(child);
                        fs.Tags = getTags(child);
                        region.Vertices.Add(fs);
                        //machine->addConnectionPoint(fs);

                        vertices[childId] = fs;
                    }
                }
            }

            foreach (XElement child in node.Elements())
            {
                if (child.Name == "transition")
                    addMachineTransition(child, machine, vertices);
            }

            //  file.Close();
        }
Beispiel #2
0
        public void addStateMachineToClass(XElement smNode, Class classe)
        {
            //StreamWriter file = MascaretApplication.Instance.logfile;

            //Debug.Log ("********* [ModelLoader2 Info] addStateMachineToClass (SM: ");

            string name = smNode.Attribute("name").Value;

            //Debug.Log("RQ : " + name + " Class: " + classe.getFullName());
            // file.WriteLine("StateMachine : " + name); file.Flush();
            StateMachine machine = new StateMachine(name);

            machine.Description = getComment(smNode);
            machine.Summary = getSummary(smNode);
            machine.Tags = getTags(smNode);

            // SubMachine ?
            //if (smNode->hasProperty("submachineState")) {
            //	string subMachineRef = smNode->getProperty("id");
            //	_subStateMachines[subMachineRef] = machine;
            //cerr << "SUB STATE MACHINE" << endl;
            //} else {
            classe.addOwnedBehavior(machine);
            machine.Owner = classe;
            //}

            Dictionary<string, Vertex> vertices = new Dictionary<string, Vertex>();

            foreach (XElement child in smNode.Elements())
            {
                if (child.Name.LocalName.CompareTo("packagedElement") == 0 || child.Name.LocalName.CompareTo("ownedMember") == 0)
                {
                    string childType = "";
                    //  file.WriteLine("Child : " + child.Name.LocalName);
                    //  file.Flush();

                    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;

                    if (childType == "uml:Trigger")
                    {
                        string id = "";
                        //   file.WriteLine("Trigger");
                        XAttribute attr3 = (XAttribute)child.Attribute("{http://schema.omg.org/spec/XMI/2.1}id");
                        if (attr3 == null) attr3 = (XAttribute)child.Attribute("{http://www.omg.org/spec/XMI/20131001}id");

                        if (attr3 != null) id = attr3.Value;

                        foreach (XElement child2 in child.Elements())
                        {
                            if (child2.Name.LocalName.CompareTo("event") == 0)
                            {
                                XAttribute attr2 = (XAttribute)child2.Attribute("{http://schema.omg.org/spec/XMI/2.1}type");
                                if (attr2 == null) attr2 = (XAttribute)child.Attribute("{http://www.omg.org/spec/XMI/20131001}type");

                                if (attr2 != null) childType = attr2.Value;
                                if (childType.CompareTo("uml:SignalEvent") == 0)
                                {
                                    XElement cSignal = child2.Element("signal");
                                    XAttribute idSignal = (XAttribute)cSignal.Attribute("{http://schema.omg.org/spec/XMI/2.1}idref");
                                    if (idSignal == null) idSignal = (XAttribute)cSignal.Attribute("{http://www.omg.org/spec/XMI/20131001}idref");

                                    string idref = idSignal.Value;
                                    Signal signal = _signals[idref];
                                    //   file.WriteLine("Signal name : " + signal.name); file.Flush();
                                    SignalEvent signalEvent = new SignalEvent(signal.name);
                                    signalEvent.SignalClass = signal;

                                    _events.Add(id, signalEvent);
                                }
                            }
                        }
                    }
                }
            }

            foreach (XElement child in smNode.Elements())
            {
                if (child.Name.LocalName == "region")
                {
                    //Debug.Log(" ####### add region .....");
                    Region region = new Region();
                    machine.Region.Add(region);
                    addMachineRegion(child, machine, region, vertices);
                }
                else if (child.Name.LocalName == "transition")
                {
                    //Debug.Log(" ####### add transition.....");
                    addMachineTransition(child, machine, vertices);
                }

            }
            //    file.Close();
        }
        public override void manageRequest(HttpRequest req)
        {
            string id = req.parameters["alias"];

            Environment env = MascaretApplication.Instance.getEnvironment();

            if (!env.InstanceSpecifications.ContainsKey(id))
            {
                req.response.write("<html>");
                req.response.write("<body>");
                req.response.write("Can't find entity: " + id);
                req.response.write("</body>");
                req.response.write("</html>");
                return;
            }
            InstanceSpecification entity = env.InstanceSpecifications[id];

            VirtualHuman human = null;

            try
            {
                human = (VirtualHuman)(entity);
            }
            catch (InvalidCastException e)
            {
                req.response.write("<html>");
                req.response.write("<body>");
                req.response.write("Entity: " + id + " is not an agent");
                req.response.write("</body>");
                req.response.write("</html>");
                return;
            }

            req.response.write("<html>");
            req.response.write("<body>");
            req.response.write("<META HTTP-EQUIV=\"Refresh\" CONTENT=\"30\">");
            req.response.write("<META HTTP-EQUIV=\"Content-Type\" content=\"text/html; charset=UTF-8\">");
            req.response.write("<link href=\"doxygen.css\" rel=\"stylesheet\" type=\"text/css\">");
            req.response.write("<link href=\"tabs.css\" rel=\"stylesheet\" type=\"text/css\">");

            req.response.write("<H2>Description</H2>");
            req.response.write("<ul>");
            req.response.write("<li>");
            req.response.write(human.name);
            req.response.write("</li>");
            req.response.write("<li>");
            req.response.write(human.getFullName());
            req.response.write("</li>");
            req.response.write("<li>");
            req.response.write(human.Description);
            req.response.write("</li>");
            req.response.write("<li>");
            req.response.write(" <a href=\"Class?alias=");
            req.response.write(human.Classifier.name);
            req.response.write("\" target = \"Body\">");
            req.response.write("</a>");
            req.response.write("</li>");
            req.response.write("</ul>");

            string setControlled = req.parameters["setControlled"];

            if (setControlled == "true")
            {
                human.ControlledByHuman = true;
            }
            else if (setControlled == "false")
            {
                human.ControlledByHuman = false;
            }


            req.response.write("<HR>");
            req.response.write("<H2>Toggle controlled by human</H2>");

            req.response.write("<FORM METHOD=POST action=\"Agent?alias=" + id + "\">");
            req.response.write("<input type=\"hidden\" name=\"alias\" value=\"" + id + "\" />");
            if (human.ControlledByHuman)
            {
                req.response.write("<font color=\"darkred\">This agent is currently controlled. (will not follow procedure automatically)</font><br />");
                req.response.write("<input type=\"hidden\" name=\"setControlled\" value=\"false\" />");
                req.response.write("<input type=\"submit\" name=\"control\" value=\"Release control of this agent\" />");
            }
            else
            {
                req.response.write("<font color=\"darkgreen\">This agent is currently automatic. (will automatically follow procedures)</font><br />");
                req.response.write("<input type=\"hidden\" name=\"setControlled\" value=\"true\" />");
                req.response.write("<input type=\"submit\" name=\"control\" value=\"Take control of this agent\" />");
            }
            req.response.write("</FORM>");

            req.response.write("<HR>");
            req.response.write("<H2>Knowledge base</H2>");
            KnowledgeBase kb = human.KnowledgeBase;

            if (kb != null)
            {
                req.response.write(" <a href=\"KnowledgeBase?alias=");
                req.response.write(human.name);
                req.response.write("\" target = \"_blank\">");
                req.response.write(kb.name);
                req.response.write("</a>");
            }

            req.response.write("<HR>");
            req.response.write("<H2>Parler</H2>");
            req.response.write("<FORM METHOD=GET action=\"speak\">");
            req.response.write("<input type=\"hidden\" name=\"alias\" value=\"");
            req.response.write(id);
            req.response.write("\" />");
            req.response.write("Texte : \t <INPUT name=\"text\">");
            req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Dire\">");
            req.response.write("</FORM>");

            req.response.write("<HR>");
            req.response.write("<H2>Attributs</H2>");
            req.response.write("<FORM METHOD=GET action=\"changeAttributes\">");
            req.response.write("<input type=\"hidden\" name=\"alias\" value=\"");
            req.response.write(id);
            req.response.write("\" />");
            req.response.write("<ul>");

            Dictionary <string, Slot> attributes = human.Slots;

            foreach (KeyValuePair <string, Slot> attr in attributes)
            {
                req.response.write("<li>");
                req.response.write(attr.Key);
                req.response.write(" = ");
                //string value = it->second->getValue().getStringFromValue();
                string value = "";
                foreach (KeyValuePair <string, ValueSpecification> val in attr.Value.Values)
                {
                    value += "'" + val.Value.getStringFromValue() + "' ";
                }
                req.response.write(value);
                req.response.write("</li>");
            }
            req.response.write("</ul>");
            req.response.write("<INPUT TYPE=\"submit\" VALUE=\"Modifier\">");
            req.response.write("</FORM>");
            //req.response.flushBuffer();

            req.response.write("<HR>");
            req.response.write("<H2>Operations</H2>");
            req.response.write("<ul>");
            Class classifier = human.Classifier;
            Dictionary <string, Operation> operations = classifier.Operations;

            foreach (KeyValuePair <string, Operation> operation in operations)
            {
                req.response.write("<li>");
                req.response.write(" <a href=\"Operation?alias=");
                req.response.write(human.name);
                req.response.write("&oper=");
                req.response.write(operation.Key);
                req.response.write("\" target = \"Body\">");
                req.response.write(operation.Key);
                req.response.write("</a>");
                req.response.write("</li>");
            }
            req.response.write("</ul>");
            //req.response.flushBuffer();



            req.response.write("<HR>");
            req.response.write("<H2>Signaux</H2>");
            req.response.write("<ul>");
            Dictionary <string, Behavior> behaviors = classifier.OwnedBehavior;

            foreach (KeyValuePair <string, Behavior> behavior in behaviors)
            {
                StateMachine stateMachine = (StateMachine)(behavior.Value);
                Region       region       = stateMachine.Region[0];
                if (region != null)
                {
                    List <Transition> transitions = region.Transitions;
                    for (int iTrans = 0; iTrans < transitions.Count; iTrans++)
                    {
                        List <Trigger> triggers = transitions[iTrans].Trigger;
                        for (int iTrig = 0; iTrig < triggers.Count; iTrig++)
                        {
                            MascaretEvent evt = triggers[iTrig].MEvent;
                            if (evt != null)
                            {
                                if (evt.Type == "SignalEvent")
                                {
                                    SignalEvent signalEvent = (SignalEvent)(evt);

                                    req.response.write("<li>");
                                    req.response.write(" <a href=\"Signal?alias=");
                                    req.response.write(human.name);
                                    req.response.write("&signal=");
                                    req.response.write(((SignalEvent)(evt)).SignalClass.name);
                                    req.response.write("\" target = \"Body\">");
                                    req.response.write(((SignalEvent)(evt)).SignalClass.name);
                                    req.response.write("</a>");
                                    req.response.write("</li>");
                                }
                            }
                        }
                    }
                }
            }
            req.response.write("</ul>");

            req.response.write("</ul>");
            req.response.write("<HR>");
            req.response.write("<H2>Messages</H2>");
            req.response.write(" AID : ");
            req.response.write(human.Aid.toString());
            req.response.write("<H3>");
            req.response.write(" <a href=\"createMessage?alias=");
            req.response.write(human.name);
            req.response.write("\" target = \"Body\">");
            req.response.write("Envoyer un message");
            req.response.write("</a>");
            req.response.write("</H3>");
            req.response.write("<H3>Non lus</H3>");
            List <ACLMessage> nl = human.Mailbox.MessagesQueue;

            req.response.write("<TABLE BORDER=1>");
            req.response.write("<TR>");
            req.response.write("<TD>De </TD>");
            req.response.write("<TD>Performative </TD>");
            req.response.write("<TD>Contenu </TD>");
            req.response.write("</TR>");
            for (int inl = 0; inl < nl.Count; inl++)
            {
                ACLMessage msg = nl[inl];
                //nl.erase(nl.begin());
                req.response.write("<TR>");
                req.response.write("<TD>");
                req.response.write(msg.Sender.toString());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.getPerformativeText());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.Content);
                req.response.write("</TD>");
                req.response.write("</TR>");
            }
            req.response.write("</TABLE>");

            req.response.write("<H3>Lus</H3>");
            List <ACLMessage> l = human.Mailbox.MessagesChecked;

            req.response.write("<TABLE BORDER=1>");
            req.response.write("<TR>");
            req.response.write("<TD>De </TD>");
            req.response.write("<TD>Performative </TD>");
            req.response.write("<TD>Contenu </TD>");
            req.response.write("</TR>");
            for (int il = 0; il < l.Count; il++)
            {
                ACLMessage msg = l[il];
                req.response.write("<TR>");
                req.response.write("<TD>");
                req.response.write(msg.Sender.toString());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.getPerformativeText());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.Content);
                req.response.write("</TD>");
                req.response.write("</TR>");
            }
            req.response.write("</TABLE>");

            req.response.write("<H3>Envoyes</H3>");
            List <ACLMessage> me = human.Mailbox.MessagesSent;

            req.response.write("<TABLE BORDER=1>");
            req.response.write("<TR>");
            req.response.write("<TD>A </TD>");
            req.response.write("<TD>Performative </TD>");
            req.response.write("<TD>Contenu </TD>");
            req.response.write("</TR>");
            for (int ie = 0; ie < me.Count; ie++)
            {
                ACLMessage msg = me[ie];
                req.response.write("<TR>");
                req.response.write("<TD>");
                List <AID> receivers = msg.Receivers;
                for (int ir = 0; ir < receivers.Count; ir++)
                {
                    req.response.write(receivers[ir].toString());
                }
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.getPerformativeText());
                req.response.write("</TD>");
                req.response.write("<TD>");
                req.response.write(msg.Content);
                req.response.write("</TD>");
                req.response.write("</TR>");
            }
        }