コード例 #1
0
        /// <summary>
        /// This method is called before the result of a mutating operation
        /// represented by the specified entry object is committed into the
        /// underlying cache.
        /// </summary>
        /// <remarks>
        /// An implementation of this method can evaluate the change by
        /// analyzing the original and the new value, and can perform any of
        /// the following:
        /// <list type="bullet">
        /// <item>
        /// override the requested change by setting
        /// <see cref="IInvocableCacheEntry.Value"/> to a different value;
        /// </item>
        /// <item>
        /// undo the pending change by resetting the entry value to the
        /// original value obtained from
        /// <see cref="ICacheTriggerEntry.OriginalValue"/>
        /// </item>
        /// <item>
        /// remove the entry from the underlying cache by calling
        /// <see cref="IInvocableCacheEntry.Remove"/>
        /// </item>
        /// <item>
        /// reject the pending change by throwing an <see cref="Exception"/>,
        /// which will prevent any changes from being committed, and will
        /// result in the exception being thrown from the operation that
        /// attempted to modify the cache; or
        /// </item>
        /// <item>
        /// do nothing, thus allowing the pending change to be committed to
        /// the underlying cache.
        /// </item>
        /// </list>
        /// </remarks>
        /// <param name="entry">
        /// An <see cref="ICacheTriggerEntry"/> object that represents the
        /// pending change to be committed to the cache, as well as the
        /// original state of the entry.
        /// </param>
        public virtual void Process(ICacheTriggerEntry entry)
        {
            if (entry.IsPresent && !InvocableCacheHelper.EvaluateEntry(m_filter, entry))
            {
                switch (m_action)
                {
                case ActionCode.Rollback:
                default:
                    throw new ArgumentException("Rejecting " + entry +
                                                " by trigger " + this);

                case ActionCode.Ignore:
                    object value = entry.OriginalValue;
                    if (value != null || entry.IsOriginalPresent)
                    {
                        entry.SetValue(value, true);
                    }
                    else
                    {
                        entry.Remove(true);
                    }
                    break;

                case ActionCode.Remove:
                    entry.Remove(true);
                    break;
                }
            }
        }
コード例 #2
0
            public void Process(ICacheTriggerEntry entry)
            {
                SimplePerson person  = (SimplePerson)entry.Extract(IdentityExtractor.Instance);
                String       sName   = person.LastName;
                String       sNameUC = sName.ToUpper();

                if (!sNameUC.Equals(sName))
                {
                    person.LastName = sNameUC;
                    entry.SetValue(person, false);
                }
            }