/// <summary>
        /// Begins to get the EvictionPolicy for this collection
        /// </summary>        
        /// <param name="asyncCallback">The user-defined delegate that is called when the asynchronous operation has completed.</param>
        /// <param name="asyncState">The user-defined object that qualifies or contains information about an asynchronous operation.</param>
        /// <returns>An IAsyncResult that represents the asynchronous operation.</returns>
        public IAsyncResult BeginGetEvictionPolicy(AsyncCallback asyncCallback)
        {
            var client = this.Entry.client;
            EvictionPolicyPayload payload = new EvictionPolicyPayload(PayloadAction.Get, null, this.Entry.Id, client.ClientId);

            var getResult = new SharedAsyncResult<EvictionPolicy>(asyncCallback, this);

            client.EnqueueAsyncResult(getResult, payload.PayloadId);
            client.SendPublishEvent(payload);
            return getResult;
        }
        /// <summary>
        /// Begins to get the EvictionPolicy for this collection
        /// </summary>
        /// <param name="asyncCallback">The user-defined delegate that is called when the asynchronous operation has completed.</param>
        /// <param name="asyncState">The user-defined object that qualifies or contains information about an asynchronous operation.</param>
        /// <returns>An IAsyncResult that represents the asynchronous operation.</returns>
        public IAsyncResult BeginGetEvictionPolicy(AsyncCallback asyncCallback)
        {
            var client = this.Entry.client;
            EvictionPolicyPayload payload = new EvictionPolicyPayload(PayloadAction.Get, null, this.Entry.Id, client.ClientId);

            var getResult = new SharedAsyncResult <EvictionPolicy>(asyncCallback, this);

            client.EnqueueAsyncResult(getResult, payload.PayloadId);
            client.SendPublishEvent(payload);
            return(getResult);
        }
        /// <summary>
        /// Begins to get an ObjectSecurity object that encapsulates the access control list (ACL) entries for a specified object 
        /// </summary>
        /// <param name="obj">The object whose AccessControl information you want to retrieve</param>
        /// <param name="asyncCallback">The user-defined delegate that is called when the asynchronous operation has completed.</param>
        /// <param name="asyncState">The user-defined object that qualifies or contains information about an asynchronous operation.</param>
        /// <returns>An IAsyncResult that represents the asynchronous operation.</returns>
        public IAsyncResult BeginGetAccessControl(object obj, AsyncCallback asyncCallback, object asyncState)
        {
            ISharedObjectEntry entry;
            bool isContainer = false;

            if (obj == this)
            {
                // Get the (ACL)s for the root namespace
                entry = this;
                isContainer = true;
            }
            else
            {
                if (obj is SharedCollection)
                {
                    var collection = obj as SharedCollection;
                    CollectionEntry collectionEntry;
                    if (!this.CollectionsManager.TryGetValue(collection.Name, out collectionEntry))
                    {
                        throw new ArgumentException("obj is not being tracked by this client", "obj");
                    }
                    entry = collectionEntry;
                    isContainer = true;
                }
                else
                {
                    ObjectEntry objectEntry;
                    this.ObjectsManager.TryGetValue(obj as INotifyPropertyChanged, out objectEntry);
                    entry = objectEntry;
                }
            }

            // Client has previously cached the value, return it immediately
            if (entry.ObjectSecurity != null)
            {
                var result = new AsyncResult<SharedObjectSecurity>(asyncCallback, 0);
                result.SetAsCompleted(entry.ObjectSecurity, true);
                return result;
            }

            var security = new SharedObjectSecurity(entry.Name, entry.Id, isContainer, new ETag(Guid.Empty));
            SharedObjectSecurityPayload payload = new SharedObjectSecurityPayload(PayloadAction.Get, security, this.ClientId);

            var getResult = new SharedAsyncResult<SharedObjectSecurity>(asyncCallback, payload.PayloadId);

            this.EnqueueAsyncResult(getResult, payload.PayloadId);

            this.SendPublishEvent(payload);

            return getResult;
        }
        /// <summary>
        /// Begins to get an ObjectSecurity object that encapsulates the access control list (ACL) entries for a specified object
        /// </summary>
        /// <param name="obj">The object whose AccessControl information you want to retrieve</param>
        /// <param name="asyncCallback">The user-defined delegate that is called when the asynchronous operation has completed.</param>
        /// <param name="asyncState">The user-defined object that qualifies or contains information about an asynchronous operation.</param>
        /// <returns>An IAsyncResult that represents the asynchronous operation.</returns>
        public IAsyncResult BeginGetAccessControl(object obj, AsyncCallback asyncCallback, object asyncState)
        {
            ISharedObjectEntry entry;
            bool isContainer = false;

            if (obj == this)
            {
                // Get the (ACL)s for the root namespace
                entry       = this;
                isContainer = true;
            }
            else
            {
                if (obj is SharedCollection)
                {
                    var             collection = obj as SharedCollection;
                    CollectionEntry collectionEntry;
                    if (!this.CollectionsManager.TryGetValue(collection.Name, out collectionEntry))
                    {
                        throw new ArgumentException("obj is not being tracked by this client", "obj");
                    }
                    entry       = collectionEntry;
                    isContainer = true;
                }
                else
                {
                    ObjectEntry objectEntry;
                    this.ObjectsManager.TryGetValue(obj as INotifyPropertyChanged, out objectEntry);
                    entry = objectEntry;
                }
            }

            // Client has previously cached the value, return it immediately
            if (entry.ObjectSecurity != null)
            {
                var result = new AsyncResult <SharedObjectSecurity>(asyncCallback, 0);
                result.SetAsCompleted(entry.ObjectSecurity, true);
                return(result);
            }

            var security = new SharedObjectSecurity(entry.Name, entry.Id, isContainer, new ETag(Guid.Empty));
            SharedObjectSecurityPayload payload = new SharedObjectSecurityPayload(PayloadAction.Get, security, this.ClientId);

            var getResult = new SharedAsyncResult <SharedObjectSecurity>(asyncCallback, payload.PayloadId);

            this.EnqueueAsyncResult(getResult, payload.PayloadId);

            this.SendPublishEvent(payload);

            return(getResult);
        }
        // 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);
        }
Beispiel #6
0
 private void CompleteAsyncResult <T>(SharedAsyncResult <T> result, T value, ushort payloadId)
 {
     result.SetAsCompleted(value, false);
     activeAsyncOperations.Remove(payloadId);
 }