Exemplo n.º 1
0
 /// <summary>
 /// Invoked when an incoming request for Notify operation comes in.
 /// </summary>
 public abstract void OnNotify(IClient client, NotifyRequest packet);
Exemplo n.º 2
0
        /// <summary>
        /// Occurs when a remote client notifies the server that a property has changed.
        /// </summary>
        /// <param name="client">The remote client.</param>
        /// <param name="packet">The packet received.</param>
        private static void OnNotify(IClient client, NotifyRequest packet)
        {
            try
            {
                // Get the packet parameters
                var target = packet.Target;
                var type   = packet.Type;
                var name   = packet.Name;
                var value  = packet.Value;

                // Retrieves the target from the object lookup cache.
                Channel channel; // Also, attemps to retrieve the scope.
                var instance = ScriptMap.Get(target, out channel);
                if (instance == null)
                    return;

                try
                {
                    // Deserialize the property value
                    var instanceValue = Native.Deserialize(instance.Env, value);

                    // Make sure we have a thread static channel bound
                    Channel.Current = (instance is Scope)
                        ? (instance as Scope).Channel
                        : channel;

                    // Get the session and add a client to it, this
                    // doesn't do anything if the client already exists
                    // on this session.
                    if (Channel.Current != null)
                        Channel.Current.AddClient(client);

                    // Set the current caller
                    Channel.Current.Caller = client;
                    Channel.Current.IgnoreForCaller(target, name);

                    // In the case the instance is a scope and we have a setter
                    // defined, we need to invoke the setter too.
                    if (instance is Scope)
                    {
                        // Get the scope
                        var scope = instance as Scope;

                        // Call the setter
                        scope.CallSetter(name, instanceValue, Channel.Current);
                    }
                    else
                    {
                        // Lock the instance to avoid data races
                        lock (instance)
                        {
                            // Assign to the property without observing the assignment
                            instance.Set(name, instanceValue);
                        }
                    }

                }
                catch (Exception ex)
                {
                    // Send the exception
                    Channel.Current.SendException(ex);
                }
                finally
                {
                    // Reset the scope back to null
                    Channel.Reset();
                }
            }
            catch (Exception ex)
            {
                // Log the exception
                Service.Logger.Log(ex);
            }
        }