Example #1
0
 private void handleAssociateEvent(object[] parameters)
 {
     if (parameters.Length != 3)
     {
         throw new ParameterException("The associate_instance event needs 3 parameters.");
     }
     else
     {
         RuntimeClassBase       source       = (RuntimeClassBase)parameters [0];
         List <InstanceWrapper> to_copy_list = this.getInstances(source, this.processAssociationReference((string)parameters [1]));
         if (to_copy_list.Count != 1)
         {
             throw new AssociationReferenceException("Invalid source association reference.");
         }
         InstanceWrapper             wrapped_to_copy_instance = to_copy_list [0];
         List <Tuple <string, int> > dest_list = this.processAssociationReference((string)parameters [2]);
         if (dest_list.Count == 0)
         {
             throw new AssociationReferenceException("Invalid destination association reference.");
         }
         Tuple <string, int> last_tuple = dest_list [dest_list.Count - 1];
         if (last_tuple.Item2 != -1)
         {
             throw new AssociationReferenceException("Last association name in association reference should not be accompanied by an index.");
         }
         dest_list.RemoveAt(dest_list.Count - 1);
         foreach (InstanceWrapper i in this.getInstances(source, dest_list))
         {
             i.getAssociation(last_tuple.Item1).addInstance(wrapped_to_copy_instance);
         }
     }
 }
Example #2
0
 private void handleCreateEvent(object[] parameters)
 {
     if (parameters.Length < 2)
     {
         throw new ParameterException("The create event needs at least 2 parameters.");
     }
     else
     {
         RuntimeClassBase source           = (RuntimeClassBase)parameters [0];
         string           association_name = (string)parameters [1];
         Association      association      = this.instances_map[source].getAssociation(association_name);
         if (association.allowedToAdd())
         {
             int      constructor_parameters_length = parameters.Length - 2;
             object[] constructor_parameters        = new object[constructor_parameters_length];
             Array.Copy(parameters, 2, constructor_parameters, 0, constructor_parameters_length);
             InstanceWrapper new_instance_wrapper = this.createInstance(association.getClassName(), constructor_parameters);
             association.addInstance(new_instance_wrapper);
             source.addEvent(
                 new Event(name: "instance_created", parameters: new object[] { association_name })
                 );
         }
         else
         {
             source.addEvent(
                 new Event(name: "instance_creation_error", parameters: new object[] { association_name })
                 );
         }
     }
 }
Example #3
0
        /// <summary>
        /// Gets the instances.
        /// </summary>
        /// <returns>
        /// The instances.
        /// </returns>
        /// <param name='source'>
        /// Source.
        /// </param>
        /// <param name='traversal_list'>
        /// Traversal_list.
        /// </param>
        private List <InstanceWrapper> getInstances(RuntimeClassBase source, List <Tuple <string, int> > traversal_list)
        {
            var currents = new List <InstanceWrapper> ();

            currents.Add(this.instances_map [source]);
            foreach (Tuple <string, int> tuple in traversal_list)
            {
                var nexts = new List <InstanceWrapper> ();
                foreach (InstanceWrapper current in currents)
                {
                    Association association = current.getAssociation(tuple.Item1);
                    if (tuple.Item2 >= 0)
                    {
                        nexts.Add(association.getInstance(tuple.Item2));
                    }
                    else if (tuple.Item2 == -1)
                    {
                        nexts.AddRange(association.getAllInstances());
                    }
                    else
                    {
                        throw new AssociationReferenceException("Incorrect index in association reference.");
                    }
                }
                currents = nexts;
            }
            return(currents);
        }
Example #4
0
 public InstanceWrapper(RuntimeClassBase instance, List <Association> associations)
 {
     this.instance = instance;
     foreach (var association in associations)
     {
         this.associations[association.getName()] = association;
     }
 }
Example #5
0
 private void handleNarrowCastEvent(object[] parameters)
 {
     if (parameters.Length != 3)
     {
         throw new ParameterException("The associate_instance event needs 3 parameters.");
     }
     else
     {
         RuntimeClassBase source     = (RuntimeClassBase)parameters [0];
         Event            cast_event = (Event)parameters[2];
         foreach (InstanceWrapper i in this.getInstances(source, this.processAssociationReference((string)parameters[1])))
         {
             i.getInstance().addEvent(cast_event);
         }
     }
 }
Example #6
0
        /// <summary>
        /// Handles the start instance event.
        /// </summary>
        /// <param name='parameters'>
        /// [0] The instance the event originates from.
        /// [1] An association reference string targeting the instance to start.
        /// </param>
        private void handleStartInstanceEvent(object[] parameters)
        {
            if (parameters.Length != 2)
            {
                throw new ParameterException("The start instance event needs 2 parameters.");
            }
            else
            {
                RuntimeClassBase source = (RuntimeClassBase)parameters[0];
                var traversal_list      = this.processAssociationReference((string)parameters [1]);

                foreach (InstanceWrapper i in this.getInstances(source, traversal_list))
                {
                    i.getInstance().start();
                }
            }
        }