/// <summary>
        /// Handles the AttributeInComponentChanged-Event of an Entity. Invokes or stops a motion depending on the new values for velocity
        /// </summary>
        /// <param name="sender">The entity that fired the event</param>
        /// <param name="e">The EventArgs</param>
        private void HandleOnAttributeChanged(Object sender, ChangedAttributeEventArgs e)
        {
            Entity entity = (Entity)sender;

            CheckForEntityMoving(entity);
            CheckForEntitySpinning(entity);
        }
Exemple #2
0
 private void HandleChangedComponentAttribute(object sender, ChangedAttributeEventArgs e)
 {
     if (ChangedAttribute != null)
     {
         ChangedAttribute(this, e);
     }
 }
Exemple #3
0
 private void HandleOnAttributeInComponentChanged(object sender, ChangedAttributeEventArgs e)
 {
     if (e.Component.Name == "scripting")
     {
         InitEntityContext((Entity)sender);
     }
 }
Exemple #4
0
        /// <summary>
        /// Creates the update info from event arguments.
        /// </summary>
        /// <returns>The update info from event arguments.</returns>
        /// <param name="entityGuid">GUID of the entity triggering the AttributeChanged event</param>
        /// <param name="e">Event arguments</param>
        private UpdateInfo CreateUpdateInfoFromEventArgs(Entity entity, ChangedAttributeEventArgs e)
        {
            UpdateInfo newUpdateInfo = new UpdateInfo();

            newUpdateInfo.entityGuid    = entity.Guid.ToString();
            newUpdateInfo.componentName = e.Component.Name;
            newUpdateInfo.attributeName = e.AttributeName;
            newUpdateInfo.value         = e.NewValue;
            return(newUpdateInfo);
        }
 void HandleChangedAvatarComponent(object sender, ChangedAttributeEventArgs e)
 {
     if (e.AttributeName == "userLogin")
     {
         if (e.OldValue != null && avatarEntities.ContainsKey((string)e.OldValue))
         {
             avatarEntities.Remove((string)e.OldValue);
         }
         avatarEntities[(string)e.NewValue] = e.Entity;
     }
 }
Exemple #6
0
        private void updateCompleteGraph(object sender, ChangedAttributeEventArgs e)
        {
            string attributeUri = e.Component[e.AttributeName].GetDatapoint().Route;

            completeGraph.RDFGraph.Retract(new Triple(
                                               completeGraph.RDFGraph.CreateUriNode(new Uri(attributeUri)),
                                               completeGraph.RDFGraph.CreateUriNode("rdf:value"),
                                               completeGraph.RDFGraph.CreateLiteralNode(e.OldValue.ToString(), new Uri("xsd:attributeValue"))));
            completeGraph.RDFGraph.Assert(new Triple(
                                              completeGraph.RDFGraph.CreateUriNode(new Uri(attributeUri)),
                                              completeGraph.RDFGraph.CreateUriNode("rdf:value"),
                                              completeGraph.RDFGraph.CreateLiteralNode(e.NewValue.ToString(), new Uri("xsd:attributeValue"))));
        }
Exemple #7
0
        /// <summary>
        /// Handler for the event ChangedAttribute event in the Entity. Update local sync info for the attribute and
        /// invokes changedAttributes method on the connected sync nodes to notify them about the change.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        private void HandleLocalChangedAttribute(object sender, ChangedAttributeEventArgs e)
        {
            var componentName = e.Component.Name;
            var attributeName = e.AttributeName;

            // Ignore this change if it was caused by the scalability plugin itself.
            lock (remoteAttributeChanges)
            {
                foreach (RemoteAttributeChange change in remoteAttributeChanges)
                {
                    if (change.Entity == e.Entity && change.ComponentName == componentName &&
                        change.AttributeName == attributeName && change.Value == e.NewValue)
                    {
                        remoteAttributeChanges.Remove(change);
                        return;
                    }
                }
            }

            var newAttributeSyncInfo = new AttributeSyncInfo(LocalSyncID, e.NewValue);

            lock (localSyncInfo)
            {
                if (!localSyncInfo.ContainsKey(e.Entity.Guid))
                {
                    logger.Warn("Local attribute changed in an entity which has no sync info.");
                    return;
                }

                EntitySyncInfo entitySyncInfo = localSyncInfo[e.Entity.Guid];
                entitySyncInfo[componentName][attributeName] = newAttributeSyncInfo;
            }

            // TODO: Optimization: we can send batch updates to improve performance. Received code is written to
            // process batches already, but sending is trickier as we don't have network load feedback from KIARA yet.
            var changedAttributes = new EntitySyncInfo();

            changedAttributes[componentName][attributeName] = newAttributeSyncInfo;

            lock (remoteSyncNodes)
            {
                foreach (Connection connection in remoteSyncNodes)
                {
                    connection["changeAttributes"](e.Entity.Guid, changedAttributes);
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// Adds update information about an entity to the update queue after having received an attributeChanged event
        /// </summary>
        /// <param name="sender">Entity that invoked the attribute change event</param>
        /// <param name="e">Event Arguments</param>
        private void AddEntityUpdateToQueue(Object sender, ChangedAttributeEventArgs e)
        {
            bool gotLock = false;

            try
            {
                QueueLock.Enter(ref gotLock);
                UpdateQueue.Add(CreateUpdateInfoFromEventArgs((Entity)sender, e));
            }
            finally
            {
                if (gotLock)
                {
                    QueueLock.Exit();
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// Handler for the event ChangedAttribute event in the Entity. Update local sync info for the attribute and
        /// invokes changedAttributes method on the connected sync nodes to notify them about the change.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event arguments.</param>
        internal void HandleLocalChangedAttribute(object sender, ChangedAttributeEventArgs e)
        {
            var componentName = e.Component.Name;
            var attributeName = e.AttributeName;

            // Ignore this change if it was caused by the scalability plugin itself.
            lock (ignoredAttributeChanges)
            {
                var attributeUpdate = new AttributeUpdate(e.Entity.Guid, componentName, attributeName, e.NewValue);
                if (ignoredAttributeChanges.Remove(attributeUpdate))
                {
                    return;
                }
            }

            var newAttributeSyncInfo =
                new AttributeSyncInfo(ServerSync.LocalServer.SyncID.ToString(), e.NewValue);

            lock (syncInfo)
            {
                if (!syncInfo.ContainsKey(e.Entity.Guid))
                {
                    logger.Warn("Local attribute changed in an entity which has no sync info.");
                    return;
                }

                EntitySyncInfo entitySyncInfo = syncInfo[e.Entity.Guid];
                entitySyncInfo[componentName][attributeName] = newAttributeSyncInfo;
            }

            var changedAttributes = new EntitySyncInfo();

            changedAttributes[componentName][attributeName] = newAttributeSyncInfo;
            foreach (IRemoteServer server in ServerSync.RemoteServers)
            {
                if (server.DoI.IsInterestedInAttributeChange(e.Entity, e.Component.Name, e.AttributeName))
                {
                    server.Connection["serverSync.changeAttributes"](e.Entity.Guid.ToString(), changedAttributes);
                }
            }
        }
        /// <summary>
        /// Event Handler for AttributeInComponentChanged on Entity. When fired, the value update is queued to be persisted on the next persistence
        /// save to the database
        /// </summary>
        /// <param name="sender">Sender of the event (the Entity)</param>
        /// <param name="e">Event arguments</param>
        internal void OnAttributeChanged(Object sender, ChangedAttributeEventArgs e)
        {
            Guid changedAttributeGuid = e.Component.Definition[e.AttributeName].Guid;

            AddAttributeToPersisted(e.Component.Guid, e.AttributeName, e.NewValue);
        }