示例#1
0
        protected void findRessources(List <string> missings)
        {
            // FileStream wFile;
            // StreamWriter file;

            // wFile = new FileStream("findRessource.txt", FileMode.Append);
            // file = new StreamWriter(wFile);
            // file.AutoFlush = true;
            bool affectAdded = false;

            List <string> always_missings = new List <string>(); // resources we always missing after a search pass

            for (int i = 0; i < missings.Count; i++)
            {
                bool missingAffected = false;
                //int it = 0;
                foreach (KeyValuePair <string, InstanceSpecification> entityp in affectations)
                // while (it < affectations.Count && !missingAffected)
                {
                    string missing = missings[i];

                    InstanceSpecification entity = entityp.Value;
                    // file.WriteLine(" LOOK FOR : " + missing + " in " + entity.name);
                    if (entity != null)
                    {
                        Slot slot = entity.getProperty(missing);
                        if (slot != null)
                        {
                            InstanceValue val = (InstanceValue)slot.getValue();
                            affectations.Add(missing, val.SpecValue);

                            missingAffected = true;
                            affectAdded     = true;
                            //  file.WriteLine(missing + " in " + entity.name + " OK ");
                            break;
                        }
                        //else Debug.Log(missing + " in " + entity.name + " NOP");
                    }
                    else
                    {
                        //cerr << "ERROR >>> " << it->first << " NOT FOUND !!" << endl;
                    }
                    // it++;
                }
                if (!missingAffected)
                {
                    always_missings.Add(missings[i]);
                }
            }

            /* If we have always missing resources but we have add some on this pass
             * we recursively search again.
             */

            //    file.Close();
            if (affectAdded)
            {
                findRessources(always_missings);
            }
        }
        //default parameters sync=false
        public GlobalActivityBehavior(GlobalActivity gActivity, InstanceSpecification host, Dictionary<string, ValueSpecification> p)
            : base(gActivity.globalActivity, host, p)
        {
            stateActivity = 0;
            this.activity = gActivity.globalActivity;
            affectations = new Dictionary<string, InstanceSpecification>();

            /* Affectation des parametres */
            MascaretApplication.Instance.VRComponentFactory.Log("BUILD AFFECTATIONS ........ " + activity.name + " : " + activity.Partitions.Count);

            foreach (ActivityPartition currentPartition in activity.Partitions)
            {
                if (currentPartition.name == "this")
                {
                    affectations.Add("this", host);
                    // MascaretApplication.Instance.VRComponentFactory.Log("Affectation de this a : " + host.name);
                }
                else
                {
                    if (p.ContainsKey(currentPartition.name))
                    {
                        InstanceValue val = (InstanceValue)p[currentPartition.name];
                        affectations.Add(currentPartition.name, val.SpecValue);
                    }
                    else
                    {
                        if (host.Slots.ContainsKey(currentPartition.name))
                            affectations.Add(currentPartition.name, host.getProperty(currentPartition.name).getValue().valueSpecificationToInstanceSpecification());
                        else
                            MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation Partition de " + currentPartition.name + " impossible ...");
                    }
                }

            }
        }
        //default parameters sync=false
        public ActivityBehaviorExecution(Activity activity, InstanceSpecification host, Dictionary<string, ValueSpecification> p, bool sync)
            : base(activity, host, p, sync)
        {
            stateActivity = 0;
            this.activity = activity;
            affectations = new Dictionary<string, InstanceSpecification>();

            /* Affectation des parametres */
            MascaretApplication.Instance.VRComponentFactory.Log("BUILD AFFECTATIONS ........ "+ activity.name + " : " + activity.Partitions.Count);

            foreach (ActivityPartition currentPartition in activity.Partitions)
            {
                if (currentPartition.name == "this")
                {
                    affectations.Add("this", host);
                   // MascaretApplication.Instance.VRComponentFactory.Log("Affectation de this a : " + host.name);
                }
                else
                {
                    if (p.ContainsKey(currentPartition.name))
                    {
                        InstanceValue val = (InstanceValue)p[currentPartition.name];
                        affectations.Add(currentPartition.name, val.SpecValue);
                    }
                    else
                    {
                        if (host.Slots.ContainsKey(currentPartition.name))
                            affectations.Add(currentPartition.name, host.getProperty(currentPartition.name).getValue().valueSpecificationToInstanceSpecification());
                        else
                            MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation Partition de " + currentPartition.name + " impossible ...");
                    }
                }

                foreach (ActivityNode currentNode in currentPartition.Node)
                {
                    if (currentNode.Kind == "object")
                    {
                        MascaretApplication.Instance.VRComponentFactory.Log(" Parameters size : "+p.Count);
                        if (p.ContainsKey(currentNode.name))
                        {
                            InstanceValue val = (InstanceValue)p[currentNode.name];
                            affectations.Add(currentNode.name, val.SpecValue);
                        }
                        else
                        {
                            MascaretApplication.Instance.VRComponentFactory.Log("Slot ? " + currentNode.name);
                            if (host.Slots.ContainsKey(currentNode.name))
                            {
                                try
                                {
                                    MascaretApplication.Instance.VRComponentFactory.Log("Find");
                                    affectations.Add(currentNode.name, ((InstanceValue)(host.getProperty(currentNode.name).getValue())).SpecValue);
                                }
                                catch (Exception)
                                {
                                   // MascaretApplication.Instance.VRComponentFactory.Log("Multiple relation found, not supported, get the last one");
                                    foreach (ValueSpecification currentValue in host.getProperty(currentNode.name).Values.Values)
                                    {
                                        affectations.Add(currentNode.name, currentValue.valueSpecificationToInstanceSpecification());

                                    }
                                }
                            }
                           // else
                              //  MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation Object de " + currentNode.name + " impossible ...");
                        }

                    }
                    else
                    {
                        if (currentNode.Kind == "action")
                        {
                            Action action = ((ActionNode)currentNode).Action;
                            if (action.Kind == "SendSignal")
                            {
                                SendSignalAction sendAct = (SendSignalAction)action;
                                MascaretApplication.Instance.VRComponentFactory.Log("SendSignal to affect");
                                if (sendAct.Target != null && sendAct.Target.targetName != "")
                                {
                                    MascaretApplication.Instance.VRComponentFactory.Log("Look for : " + sendAct.Target.targetName);

                                    if (p.ContainsKey(sendAct.Target.targetName))
                                    {
                                        InstanceValue val = (InstanceValue)p[sendAct.Target.targetName];
                                        affectations.Add(sendAct.Target.targetName, val.SpecValue);
                                    }
                                    else
                                    {
                                        if (host.Slots.ContainsKey(sendAct.Target.targetName))
                                        {
                                            InstanceSpecification instance = ((InstanceValue)(host.getProperty(sendAct.Target.targetName).getValue())).SpecValue;
                                            MascaretApplication.Instance.VRComponentFactory.Log("Affecttion : " + sendAct.Target.targetName + " a " + instance.getFullName());

                                            affectations.Add(sendAct.Target.targetName, instance);
                                            sendAct.Target.target = instance;
                                            //affectations.Add(sendAct.Target.targetName, host.getProperty(sendAct.Target.targetName).getValue().valueSpecificationToInstanceSpecification());
                                            //sendAct.Target.target = host.getProperty(sendAct.Target.targetName).getValue().valueSpecificationToInstanceSpecification();
                                        }
                                        else
                                        MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation SendAction de " + sendAct.Target.targetName + " impossible ...");
                                    }
                                }
                            }
                        }
                    }
                }

            }

            //OCLParser::Context function called
            /* OclParser::Context context;
             map<string, shared_ptr<InstanceSpecification> >::iterator it;
             for(it=_affectations.begin();it!=_affectations.end();it++)
             {
                     context[it->first]=it->second;
             }
             _activity->setContext(context);*/
        }
示例#4
0
        //default parameters sync=false
        public ActivityBehaviorExecution(Activity activity, InstanceSpecification host, Dictionary <string, ValueSpecification> p, bool sync) :
            base(activity, host, p, sync)
        {
            stateActivity = 0;
            this.activity = activity;
            affectations  = new Dictionary <string, InstanceSpecification>();


            /* Affectation des parametres */
            MascaretApplication.Instance.VRComponentFactory.Log("BUILD AFFECTATIONS ........ " + activity.name + " : " + activity.Partitions.Count);

            foreach (ActivityPartition currentPartition in activity.Partitions)
            {
                if (currentPartition.name == "this")
                {
                    affectations.Add("this", host);
                    // MascaretApplication.Instance.VRComponentFactory.Log("Affectation de this a : " + host.name);
                }
                else
                {
                    if (p.ContainsKey(currentPartition.name))
                    {
                        InstanceValue val = (InstanceValue)p[currentPartition.name];
                        affectations.Add(currentPartition.name, val.SpecValue);
                    }
                    else
                    {
                        if (host.Slots.ContainsKey(currentPartition.name))
                        {
                            affectations.Add(currentPartition.name, host.getProperty(currentPartition.name).getValue().valueSpecificationToInstanceSpecification());
                        }
                        else
                        {
                            MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation Partition de " + currentPartition.name + " impossible ...");
                        }
                    }
                }

                foreach (ActivityNode currentNode in currentPartition.Node)
                {
                    if (currentNode.Kind == "object")
                    {
                        MascaretApplication.Instance.VRComponentFactory.Log(" Parameters size : " + p.Count);
                        if (p.ContainsKey(currentNode.name))
                        {
                            InstanceValue val = (InstanceValue)p[currentNode.name];
                            affectations.Add(currentNode.name, val.SpecValue);
                        }
                        else
                        {
                            MascaretApplication.Instance.VRComponentFactory.Log("Slot ? " + currentNode.name);
                            if (host.Slots.ContainsKey(currentNode.name))
                            {
                                try
                                {
                                    MascaretApplication.Instance.VRComponentFactory.Log("Find");
                                    affectations.Add(currentNode.name, ((InstanceValue)(host.getProperty(currentNode.name).getValue())).SpecValue);
                                }
                                catch (Exception)
                                {
                                    // MascaretApplication.Instance.VRComponentFactory.Log("Multiple relation found, not supported, get the last one");
                                    foreach (ValueSpecification currentValue in host.getProperty(currentNode.name).Values.Values)
                                    {
                                        affectations.Add(currentNode.name, currentValue.valueSpecificationToInstanceSpecification());
                                    }
                                }
                            }
                            // else
                            //  MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation Object de " + currentNode.name + " impossible ...");
                        }
                    }
                    else
                    {
                        if (currentNode.Kind == "action")
                        {
                            Action action = ((ActionNode)currentNode).Action;
                            if (action.Kind == "SendSignal")
                            {
                                SendSignalAction sendAct = (SendSignalAction)action;
                                MascaretApplication.Instance.VRComponentFactory.Log("SendSignal to affect");
                                if (sendAct.Target != null && sendAct.Target.targetName != "")
                                {
                                    MascaretApplication.Instance.VRComponentFactory.Log("Look for : " + sendAct.Target.targetName);

                                    if (p.ContainsKey(sendAct.Target.targetName))
                                    {
                                        InstanceValue val = (InstanceValue)p[sendAct.Target.targetName];
                                        affectations.Add(sendAct.Target.targetName, val.SpecValue);
                                    }
                                    else
                                    {
                                        if (host.Slots.ContainsKey(sendAct.Target.targetName))
                                        {
                                            InstanceSpecification instance = ((InstanceValue)(host.getProperty(sendAct.Target.targetName).getValue())).SpecValue;
                                            MascaretApplication.Instance.VRComponentFactory.Log("Affecttion : " + sendAct.Target.targetName + " a " + instance.getFullName());

                                            affectations.Add(sendAct.Target.targetName, instance);
                                            sendAct.Target.target = instance;
                                            //affectations.Add(sendAct.Target.targetName, host.getProperty(sendAct.Target.targetName).getValue().valueSpecificationToInstanceSpecification());
                                            //sendAct.Target.target = host.getProperty(sendAct.Target.targetName).getValue().valueSpecificationToInstanceSpecification();
                                        }
                                        else
                                        {
                                            MascaretApplication.Instance.VRComponentFactory.Log("[ActivityBehaviorExecution.cpp] Affectation SendAction de " + sendAct.Target.targetName + " impossible ...");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //OCLParser::Context function called

            /* OclParser::Context context;
             * map<string, shared_ptr<InstanceSpecification> >::iterator it;
             * for(it=_affectations.begin();it!=_affectations.end();it++)
             * {
             *       context[it->first]=it->second;
             * }
             * _activity->setContext(context);*/
        }