//defaultParamter toRun = true
        public InstanceLoader(AgentPlateform agentPlateform, Environment environment, string filename, bool toRun)
        {
            relations = new List<Relation>();
            this.toRun = toRun;
            try
            {
                if (filename != "")
                {
                    this.environment = environment;
                    this.agentPlateform = agentPlateform;
                    this.model = this.environment.Model;

                    XDocument parser;
                    this.basedir = filename;

                    //parser = XDocument.Load(filename);
                    String s = MascaretApplication.Instance.readFlow(filename);
                    parser = XDocument.Parse(s);

                    _parseInstances(parser.Root);
                    _addRelations();
                }
                relations.Clear();
            }
            catch (FileLoadException)
            {
            }
        }
        //typedef KnowledgeBase* (*BaseInitFunc)();
        //int _id=0;
        public void parseInstances(AgentPlateform agentPlateform, Environment environment, string filename, bool toRun)
        {
            this.toRun = toRun;
            this.environment = environment;
            this.agentPlateform = agentPlateform;
            this.model = this.environment.Model;
            XDocument parser = null;
            this.basedir = filename;
            parser = XDocument.Load(filename);

            _parseInstances(parser.Root);
            _addRelations();
            relations.Clear();
        }
        protected Environment parseEnvironment(string url)
        {
            Environment env = null;
            Model model = null;

            XDocument parser = null;
            string baseDir = MascaretApplication.Instance.BaseDir;
            parser = XDocument.Load(baseDir+"/"+url);
            XElement root = parser.Root;

            foreach (XElement childNode in root.Elements())
            {
                if (childNode.Name.LocalName == "Model")
                {
                    string urlModel = "";
                    XAttribute attr = (XAttribute)childNode.Attribute("url");
                    if (attr != null) urlModel = attr.Value;
                    model = parseModel(urlModel);
                }
            }
            if (model == null)
                model = this.model;

            env = new Environment(model);
            env.Url = url;
            model.addEnvironment(env);

            MascaretApplication.Instance.VRComponentFactory.Log(baseDir);

            //InstanceLoader instanceLoader = new InstanceLoader(agentPlateform, env, url + "/" + baseDir, false);
            InstanceLoader instanceLoader = new InstanceLoader(agentPlateform, env, baseDir + "/" + url, false);

            return env;
        }
Exemple #4
0
        //default parameter strIsFileName=true;
        public ModelLoader2(string str, bool strIsFileName)
        {
            _idClass = new Dictionary<String, Class>();
            //_idAsso =  new Dictionary<string, Property>();
            //_idAsso =  new MapStringProperties();
            _idOperations = new Dictionary<string, Operation>();
            _idBehaviors = new Dictionary<string, Behavior>();
            _parameters = new Dictionary<string, Parameter>();
            _partitions = new Dictionary<string, ActivityPartition>();
            _paramToType = new Dictionary<string, string>();
            _classifiers = new Dictionary<string, Classifier>();
            _callOperations = new Dictionary<CallOperationAction, string>();
            _callBehaviors = new Dictionary<CallBehaviorAction, string>();
            _callEvents = new Dictionary<CallEvent, string>();
            _signals = new Dictionary<string, Signal>();
            _events = new Dictionary<string, MascaretEvent>();
            _activityNodes = new Dictionary<string, ActivityNode>();
            _waitingNodes = new Dictionary<string, string>();
            _objectNodes = new Dictionary<string, ObjectNode>();
            _activityExpressions = new Dictionary<string, Expression>();
            _activitiesMethod = new Dictionary<string, Activity>();
            _subStateMachines = new Dictionary<string, StateMachine>();
            _subStates = new Dictionary<string, State>();
            _subStatesID = new Dictionary<string, string>();
            _primitiveTypes = new Dictionary<string, string>();
            _loader = new XDocument();

            try
            {
                String s = MascaretApplication.Instance.readFlow(str);
                _loader = XDocument.Parse(s);
                _xmi = _loader.Root;

                // MascaretApplication.Instance.logfile.WriteLine("XMI : " + _xmi.Name.LocalName.ToLower()); MascaretApplication.Instance.logfile.Flush();

                //Debug.Log (_xmi.Name);

                XElement modelNode = null;

                //   MascaretApplication.Instance.logfile.WriteLine("Parsing Model"); MascaretApplication.Instance.logfile.Flush();
                if ((_xmi.Name.LocalName.ToLower().CompareTo("uml:model") == 0) || (_xmi.Name.LocalName.ToLower().CompareTo("model") == 0))
                {
                    // MascaretApplication.Instance.logfile.WriteLine("OK"); MascaretApplication.Instance.logfile.Flush();
                    modelNode = _xmi;
                }
                else
                {
                    foreach (XElement currentNode in _xmi.Elements())
                    {
                        if (currentNode.Name.LocalName.ToLower().CompareTo("model") == 0)
                        {
                            modelNode = currentNode;
                        }
                    }
                }

                if (modelNode != null)
                {

                    XAttribute attr = (XAttribute)modelNode.Attribute("name");

                    // MascaretApplication.Instance.logfile.WriteLine("ModelName : " + attr.Value); MascaretApplication.Instance.logfile.Flush();

                    if (MascaretApplication.Instance.hasModel(attr.Value))
                    {
                        model = MascaretApplication.Instance.getModel(attr.Value);
                    }
                    else
                    {
                        model = new Model(attr.Value);
                        if (strIsFileName)
                            model.XmiUrl = str;

                        MascaretApplication.Instance.addModel(model);

                        getPrimitiveType(modelNode);
                        addStereotypes();

                        addPackage(modelNode, null);

                        _setParametersType();
                        addGeneralizations();
                        addAssociation();
                        addActivitiesAndStateMachines();
                        addCallOperations();
                        addCallBehaviors();
                        addConditions();

                        EntityClass curEntityClass = new EntityClass("undef");
                        Class classe = (Class)curEntityClass;
                        model.Package.addClasses(classe);

                        model.registerAllClasses();
                    }
                }
            }
            catch (FileLoadException)
            {
            }

            // Bouml preserved body end 0001F4E7
        }
Exemple #5
0
 public Environment(Model model)
 {
     instances = new Dictionary<string, InstanceSpecification>();
     this.model = model;
 }
        public void addModel(Model model)
        {
            if (models == null)
            {
                models = new Dictionary<string, Model>();
            }

            models.Add(model.name, model);
            if (this.model == null)
                this.model = model;
        }
        Environment parseEnvironment(string url, XElement actNode, XElement orgNode, bool loadAll)
        {
            Environment env = null;

             //   logfile.WriteLine("Parsing Environment file : " + url); logfile.Flush();

            String s = readFlow(BaseDir + "/" + url);
            XDocument parser = XDocument.Parse(s);
            XElement root = parser.Root;

            //    Model model;
            XElement modelNode = root.Element("Model");
            if (modelNode != null)
            {
                string urlModel = modelNode.Attribute("url").Value;

               /// StreamWriter file = new StreamWriter("log2.txt");
               // file.WriteLine(" URL : " + url + " : " + BaseDir + "/" + urlModel);
              //  file.Flush();
              //  file.Close();
                if (model == null) model = parseModel(BaseDir+"/"+urlModel);

               // if (model.Environments.ContainsKey(url))
              //  {
               //     env = model.Environments[url];
              //  }
              //  else
               if (loadAll) {
                    env = new Environment(model);
                    env.Url = url;
                    model.addEnvironment(env);

                    InstanceLoader instanceLoader = new InstanceLoader(agentPlateform, env, BaseDir+"/"+url, true);

                    System.Console.WriteLine("SIZE of env map " + model.Environments.Count + " of model :" + model.name);

                    if (actNode != null)
                        instanceLoader.parseInstances(agentPlateform, env, actNode.Attribute("url").Value, true);

                    if (orgNode != null)
                        instanceLoader.parseInstances(agentPlateform, env, orgNode.Attribute("url").Value, true);
                }

            }
            else
                env = null;
            return env;
        }
        public virtual void parse(XElement root, bool loadAll)
        {
            XElement appliNode = root.Element("ApplicationParameters");
            XElement actnode = root.Element("Actors");
            XElement orgNode = root.Element("Organisations");

            if (agentPlateform == null)
            {
                this.VRComponentFactory.Log("Agent Plateform");
                // Parametres par defaut de l'applie ....
                string ressourceDir = "HTTPServerBaseDir";
                agentPlateform = new AgentPlateform("localhost", 8080, ressourceDir, false);
                agent = new Agent(agentPlateform, "HTTPManager", null, "");
                agent.addBehavior("SimpleCommunicationBehavior", 0.2, true);
                agentPlateform.addAgent(agent);
            }

            XElement modelNode = root.Element("Model");
            if (modelNode != null)
            {
                // Read the url
                string urlModel = modelNode.Attribute("url").Value;
                if (model == null)
                    model = parseModel(baseDir + "/" + urlModel);
            }

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

                if (child.Name.LocalName == "Environment")
                {
                    string envUrl = child.Attribute("url").Value;
                    Environment env = parseEnvironment(envUrl, actnode, orgNode, loadAll);
                }
            }
        }