Exemplo n.º 1
0
        // Send method for operations with callbacks. Store the callback in a queue for retrieval upon completion of server operation.
        private void SendPayload <T>(InterlockedPropertyInfo propInfo, AtomicOperators operation, Action <T> callback, params T[] parameters)
        {
            AtomicPayload payload =
                new AtomicPayload
                (
                    this.Client.ClientId,
                    propInfo.ObjectId,
                    propInfo.Property.Index,
                    propInfo.PropertyType.AssemblyQualifiedName,
                    operation,
                    parameters.Select(p => Json.WriteObject(p)).ToArray()
                );

            // For operations with callbacks, we need to create an async result and queue it up for retrieval when the server operation completes
            if (callback != null)
            {
                var getResult = new SharedAsyncResult <T>(EndSendAtomicPayload <T>, payload.PayloadId, callback);
                this.Client.EnqueueAsyncResult(getResult, payload.PayloadId);
            }

            this.Client.SendPublishEvent(payload);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Received the atomic update information for an object, set it internally
        /// </summary>
        /// <param name="payload"></param>
        private void ReceivedAtomicValue(AtomicPayload payload)
        {
            // Check if the data payload is a response to a request we have pending in our Async queue
            ISharedAsyncResult ar;

            if (!activeAsyncOperations.TryGetValue(payload.PayloadId, out ar))
            {
                return;
            }

            Type targetType = Type.GetType(payload.PropertyType);

            // Since target types always match to action types, we simply need to catch this and set the result properly
            if (targetType == typeof(int) || targetType == typeof(long))
            {
                var result = (SharedAsyncResult <long>)ar;
                this.CompleteAsyncResult(result, (long)Json.ReadObject(typeof(long), payload.Parameters[0]), payload.PayloadId);
            }
            else if (targetType == typeof(string))
            {
                var result = (SharedAsyncResult <string>)ar;
                this.CompleteAsyncResult(result, (string)Json.ReadObject(typeof(string), payload.Parameters[0]), payload.PayloadId);
            }
        }