Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        public override ValueSpecification clone()
        {
            InstanceValue vs = new InstanceValue(this.Type);

            vs.specValue = specValue;
            return((ValueSpecification)vs);
        }
Exemplo n.º 3
0
        public InstanceSpecification getInstanceValue()
        {
            //callbackMethod
            _update();

            ValueSpecification vSpec = null;

            if (values.Count == 1)
            {
                foreach (ValueSpecification valueSpec in values.Values)
                {
                    vSpec = valueSpec;
                }
            }

            // Check if value exist
            if (vSpec == null)
            {
                return(null);
            }

            if (vSpec.GetType().IsSubclassOf(typeof(LiteralSpecification)))
            {
                throw new Exception("Can not use this method with this kind of parameter !");
            }

            InstanceValue iValue = (InstanceValue)vSpec;

            return(iValue.SpecValue);
        }
Exemplo n.º 4
0
        public override ValueSpecification createValueFromString(string str)
        {
            Dictionary <string, InstanceSpecification> instances = getInstances(true);
            //Debug.Log (" Class :: CreateValueFromString : " + getFullName() + " / " + str +" : " + instances.Count);
            InstanceValue curInstanceValue = new InstanceValue((InstanceSpecification)(instances[str]));

            return((ValueSpecification)curInstanceValue);
        }
Exemplo n.º 5
0
        public Dictionary <string, InstanceSpecification> getInstanceValues()
        {
            //callbackMethod
            _update();

            Dictionary <string, InstanceSpecification> dict = new Dictionary <string, InstanceSpecification>();

            foreach (KeyValuePair <string, ValueSpecification> pair in values)
            {
                InstanceValue iValue = (InstanceValue)pair.Value;
                dict.Add(pair.Key, iValue.SpecValue);
            }

            return(dict);
        }
Exemplo n.º 6
0
        //default parameters sync = false
        public void start(InstanceSpecification host, Dictionary<string, InstanceSpecification> affectations, bool sync)
        {
            // StreamWriter file = MascaretApplication.Instance.logfile;
            if (action == null)
            {
               // file.WriteLine("Le noeud " + name + " n'a pas d'action associée!!!"); file.Flush();
                return;
            }

            Dictionary<string, ValueSpecification> param = new Dictionary<string, ValueSpecification>();
            if (action.Kind == "SendSignal")
            {

                if (((SendSignalAction)action).Target == null)
                {
                    foreach (ActivityEdge currentEdge in Outgoing)
                    {
                        if (currentEdge.Target.Kind == "object")
                        {
                            if (affectations.ContainsKey(currentEdge.Target.name))
                            {
                                System.Console.WriteLine("Sending signal to : " + currentEdge.Target.name);
                                SendSignalAction ssAct = (SendSignalAction)action;
                                ssAct.Target = new SendSignalTarget();
                                ssAct.Target.target = affectations[currentEdge.Target.name];
                            }

                            else
                            {
                                System.Console.WriteLine("affectation of " + currentEdge.Target.name + " not found");
                            }

                        }
                    }
                }
            }
            if (action.Kind == "CallOperation")
            {
               // file.WriteLine("Executing Call operation" + action.name + " " + ((CallOperationAction)action).Operation.getFullName()); file.Flush();

                if (((CallOperationAction)action).isDynamic())
                {
                    param = ((CallOperationAction)action).getParameters();

                }
                else
                {
                    foreach (InputPin currentPin in action.InputPins)
                    {

                        string paramName = currentPin.getIncomingObjectNode()[0].name;
                      //  file.WriteLine(" Looking for : " + paramName); file.Flush();
                        if (!affectations.ContainsKey(currentPin.getIncomingObjectNode()[0].name))
                        {
                    //        file.WriteLine(((CallOperationAction)action).Operation.getFullName() + " from " + action.Owner.name + " MISS " + currentPin.getIncomingObjectNode()[0].name); file.Flush();
                        }
                        InstanceValue val = new InstanceValue(affectations[currentPin.getIncomingObjectNode()[0].name]);
                    //    file.WriteLine("..... Trouve " + val.ToString()); file.Flush();
                        param.Add(currentPin.name, val);
                    }
                }

                if (Activity != null)
                {
                    //	action.Context(Activity.Context);
                }

            }
            currentExecution = BehaviorScheduler.Instance.executeBehavior(action, host, param, sync);
        }
Exemplo n.º 7
0
 public override ValueSpecification clone()
 {
     InstanceValue vs = new InstanceValue(this.Type);
     vs.specValue = specValue;
     return (ValueSpecification)vs;
 }
Exemplo n.º 8
0
        //default parameters sync = false
        public void start(InstanceSpecification host, Dictionary <string, InstanceSpecification> affectations, bool sync)
        {
            // StreamWriter file = MascaretApplication.Instance.logfile;
            if (action == null)
            {
                // file.WriteLine("Le noeud " + name + " n'a pas d'action associée!!!"); file.Flush();
                return;
            }

            Dictionary <string, ValueSpecification> param = new Dictionary <string, ValueSpecification>();

            if (action.Kind == "SendSignal")
            {
                if (((SendSignalAction)action).Target == null)
                {
                    foreach (ActivityEdge currentEdge in Outgoing)
                    {
                        if (currentEdge.Target.Kind == "object")
                        {
                            if (affectations.ContainsKey(currentEdge.Target.name))
                            {
                                System.Console.WriteLine("Sending signal to : " + currentEdge.Target.name);
                                SendSignalAction ssAct = (SendSignalAction)action;
                                ssAct.Target        = new SendSignalTarget();
                                ssAct.Target.target = affectations[currentEdge.Target.name];
                            }

                            else
                            {
                                System.Console.WriteLine("affectation of " + currentEdge.Target.name + " not found");
                            }
                        }
                    }
                }
            }
            if (action.Kind == "CallOperation")
            {
                // file.WriteLine("Executing Call operation" + action.name + " " + ((CallOperationAction)action).Operation.getFullName()); file.Flush();

                if (((CallOperationAction)action).isDynamic())
                {
                    param = ((CallOperationAction)action).getParameters();
                }
                else
                {
                    foreach (InputPin currentPin in action.InputPins)
                    {
                        string paramName = currentPin.getIncomingObjectNode()[0].name;
                        //  file.WriteLine(" Looking for : " + paramName); file.Flush();
                        if (!affectations.ContainsKey(currentPin.getIncomingObjectNode()[0].name))
                        {
                            //        file.WriteLine(((CallOperationAction)action).Operation.getFullName() + " from " + action.Owner.name + " MISS " + currentPin.getIncomingObjectNode()[0].name); file.Flush();
                        }
                        InstanceValue val = new InstanceValue(affectations[currentPin.getIncomingObjectNode()[0].name]);
                        //    file.WriteLine("..... Trouve " + val.ToString()); file.Flush();
                        param.Add(currentPin.name, val);
                    }
                }

                if (Activity != null)
                {
                    //	action.Context(Activity.Context);
                }
            }
            currentExecution = BehaviorScheduler.Instance.executeBehavior(action, host, param, sync);
        }
Exemplo n.º 9
0
        public override ValueSpecification createValueFromString(string str)
        {
            Dictionary<string, InstanceSpecification> instances = getInstances(true);
            //Debug.Log (" Class :: CreateValueFromString : " + getFullName() + " / " + str +" : " + instances.Count);
            InstanceValue curInstanceValue = new InstanceValue((InstanceSpecification)(instances[str]));

            return (ValueSpecification)curInstanceValue;
        }
Exemplo n.º 10
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);*/
        }