示例#1
0
        /// <summary>
        /// Received the SharedObjectSecurity information for an object, set it internally
        /// </summary>
        /// <param name="payload"></param>
        private void GotEvictionPolicy(EvictionPolicyPayload payload)
        {
            var data = payload.Policy;

            // 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))
            {
                Debug.Assert(false, "No matching asyncresult operation for the GetEvictionPolicy call");
                return;
            }

            // We know that the async results for GotEvictionPolicy will be a SharedObjectSecurity object
            var result = (SharedAsyncResult <EvictionPolicy>)ar;

            ISharedObjectEntry sharedObjectEntry = GetSharedEntry(true, payload.EntryId);

            if (sharedObjectEntry == null)
            {
                // Object/Collection does not exist, cannot set the AccessControl for it
                var error = new ObjectErrorPayload(SharedObjects.Error.ObjectNotFound, payload.EntryId, "", "EvictionPolicy was retrieved for object that is no longer in scope on the client", payload.ClientId, payload.PayloadId);
                this.CompleteAsyncResult(result, payload.PayloadId);
                RaiseError(error);
                return;
            }

            this.CompleteAsyncResult <EvictionPolicy>(result, payload.Policy, payload.PayloadId);
        }
        /// <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);
        }
        public void SetEvictionPolicy(EvictionPolicy value)
        {
            if (value is ObjectExpirationPolicy)
            {
                PropertyInfo propertyInfo = this.Type.GetProperty(((ObjectExpirationPolicy)value).TimestampPropertyName);
                if (propertyInfo == null)
                {
                    throw new ArgumentException("Object expiration policy refers to a nonexistent timestamp property");
                }
                if (propertyInfo.PropertyType != typeof(DateTime))
                {
                    throw new ArgumentException("Object expiration policy refers to an invalid timestamp property");
                }
                if (propertyInfo.IsIgnored())
                {
                    throw new ArgumentException("Object expiration policy refers to an ignored timestamp property");
                }
            }

            var client = this.Entry.client;
            var payload = new EvictionPolicyPayload(PayloadAction.Set, value, this.Entry.Id, client.ClientId);
            client.SendPublishEvent(payload);
        }
        public void SetEvictionPolicy(EvictionPolicy value)
        {
            if (value is ObjectExpirationPolicy)
            {
                PropertyInfo propertyInfo = this.Type.GetProperty(((ObjectExpirationPolicy)value).TimestampPropertyName);
                if (propertyInfo == null)
                {
                    throw new ArgumentException("Object expiration policy refers to a nonexistent timestamp property");
                }
                if (propertyInfo.PropertyType != typeof(DateTime))
                {
                    throw new ArgumentException("Object expiration policy refers to an invalid timestamp property");
                }
                if (propertyInfo.IsIgnored())
                {
                    throw new ArgumentException("Object expiration policy refers to an ignored timestamp property");
                }
            }

            var client  = this.Entry.client;
            var payload = new EvictionPolicyPayload(PayloadAction.Set, value, this.Entry.Id, client.ClientId);

            client.SendPublishEvent(payload);
        }