public void TestExtractorEventTransformer()
        {
            //testing on remote cache
            INamedCache cache = CacheFactory.GetCache(CacheName);

            cache.Clear();

            Hashtable ht       = new Hashtable();
            Address   address1 = new Address("Street1", "City1", "State1", "Zip1");
            Address   address2 = new Address("Street2", "City2", "State2", "Zip2");

            ht.Add("key1", address1);
            ht.Add("key2", address2);
            cache.InsertAll(ht);

            SyncListener           listener    = new SyncListener();
            IFilter                filter      = new ValueChangeEventFilter("getStreet");
            IValueExtractor        extractor   = IdentityExtractor.Instance;
            ICacheEventTransformer transformer = new ExtractorEventTransformer(null, extractor);

            cache.AddCacheListener(listener,
                                   new CacheEventTransformerFilter(filter,
                                                                   transformer),
                                   false);
            Assert.IsNull(listener.CacheEvent);

            cache["key1"] = new Address("Street1", "City1a", "State1a", "Zip1a");
            Assert.IsNull(listener.CacheEvent);

            cache["key1"] = new Address("Street1a", "City1a", "State1a", "Zip1a");
            Assert.IsNotNull(listener.CacheEvent);

            CacheFactory.Shutdown();
        }
        /// <summary>
        /// Parse the property name and initialize necessary extractor and
        /// updater.
        /// </summary>
        protected internal void Init()
        {
            // allow composite property name (not documented)
            string name   = m_name;
            int    ofLast = name.LastIndexOf('.');
            string prop   = name.Substring(ofLast + 1);

            IValueExtractor extractor = new ReflectionExtractor(prop); //(m_useIs ? "is" : "get") +
            IValueUpdater   updater   = new ReflectionUpdater(prop); //"set" +

            if (ofLast > 0)
            {
                string[] array = name.Substring(0, ofLast).Split(new char[] {'.'});
                int      count = array.Length;

                IValueExtractor[] veGet = new IValueExtractor[count + 1];
                IValueExtractor[] vePut = new IValueExtractor[count];
                for (int i = 0; i < count; i++)
                {
                    veGet[i] = vePut[i] = new ReflectionExtractor(array[i]); //"get" +
                }
                veGet[count] = extractor;

                extractor = new ChainedExtractor(veGet);
                updater   = new CompositeUpdater(count == 1 ? vePut[0] : new ChainedExtractor(vePut),
                                                 updater);

            }
            m_extractor = extractor;
            m_updater   = updater;
        }
 internal ObjectValidator(
     IValueExtractor valueExtractor,
     Dictionary<Type, ValidationUnitCollection> ruleMap)
     : base(valueExtractor)
 {
     mValueExtractor = valueExtractor;
     mRuleMap = ruleMap;
 }
Beispiel #4
0
 internal ObjectValidator(
     IValueExtractor valueExtractor,
     Dictionary <Type, ValidationUnitCollection> ruleMap)
     : base(valueExtractor)
 {
     mValueExtractor = valueExtractor;
     mRuleMap        = ruleMap;
 }
        /// <summary>
        /// Determine a hash value for the <b>ExtractorEventTransformer</b>
        /// object according to the general <b>Object.GetHashCode</b>
        /// contract.
        /// </summary>
        /// <returns>
        /// An integer hash value for this object.
        /// </returns>
        public override int GetHashCode()
        {
            IValueExtractor extractorOld = m_extractorOld;
            IValueExtractor extractorNew = m_extractorNew;

            return((extractorOld == null ? 0 : extractorOld.GetHashCode()) +
                   (extractorNew == null ? 0 : extractorNew.GetHashCode()));
        }
        public void TestWithEmptyString()
        {
            IValueExtractor ive = MockUtils.CreateExtractor(repository, "");
            var             rv  = new RequiredValidator(ive, "");

            Assert.IsFalse(rv.Validate(null), "Requried Validator does not recognize \"\" as null");
            repository.VerifyAll();
        }
        public void TestNullValueInteger()
        {
            IValueExtractor ive = MockUtils.CreateExtractor(repository, 1);
            var             rv  = new RequiredValidator(ive, 1);

            Assert.IsFalse(rv.Validate(null), "Requried Validator does not recognize default value to be null");
            repository.VerifyAll();
        }
        public void TestNullValue()
        {
            IValueExtractor ive = MockUtils.CreateExtractor(repository, null);
            var             rv  = new RequiredValidator(ive, null);

            Assert.IsFalse(rv.Validate(null), "Requried Validator does not check null");
            repository.VerifyAll();
        }
        public void TestNotNullValue()
        {
            IValueExtractor ive = MockUtils.CreateExtractor(repository, new object());
            var             rv  = new RequiredValidator(ive, null);

            Assert.IsTrue(rv.Validate(null), "Requried Validator does not check object difference from null");
            repository.VerifyAll();
        }
Beispiel #10
0
        /// <summary>
        /// Apply the test to an <see cref="ICacheEntry"/>.
        /// </summary>
        /// <param name="entry">
        /// The <b>ICacheEntry</b> to evaluate; never <c>null</c>.
        /// </param>
        /// <returns>
        /// <b>true</b> if the test passes, <b>false</b> otherwise.
        /// </returns>
        public new virtual bool EvaluateEntry(ICacheEntry entry)
        {
            IValueExtractor extractor = ValueExtractor;

            return(EvaluateExtracted(entry is IQueryCacheEntry
                    ? ((IQueryCacheEntry)entry).Extract(extractor)
                    : InvocableCacheHelper.ExtractFromEntry(extractor, entry)));
        }
Beispiel #11
0
 /// <summary>
 /// Extract value, it extract the part of the object specified by mPartName
 /// and work on the type of the object passed in the first call.
 /// </summary>
 /// <param name="objToValidate"></param>
 /// <returns></returns>
 public object ExtractValue(object objToValidate)
 {
     if (innerValueExtractor == null)
     {
         innerValueExtractor = CreateInnerExtractor(objToValidate.GetType());
     }
     return(innerValueExtractor.ExtractValue(objToValidate));
 }
        public void TestNullWithEmptyString()
        {
            IValueExtractor ive = MockUtils.CreateExtractor(repository, null);
            var             rv  = new RequiredValidator(ive, "");

            Assert.IsFalse(rv.Validate(null), "Requried Validator does not check for null when has a default value");
            repository.VerifyAll();
        }
Beispiel #13
0
        /// <summary>
        /// Construct a GroupAggregator based on a specified
        /// <see cref="IValueExtractor"/> and underlying
        /// <see cref="IEntryAggregator"/>.
        /// </summary>
        /// <param name="extractor">
        /// An <b>IValueExtractor</b> object that is used to split
        /// <see cref="IInvocableCache"/> entries into
        /// non-intersecting subsets; may not be <c>null</c>.
        /// </param>
        /// <param name="aggregator">
        /// An <b>IEntryAggregator</b> object; may not be <c>null</c>.
        /// </param>
        /// <param name="filter">
        /// An optional <see cref="IFilter"/> object used to filter out
        /// results of individual group aggregation results.
        /// </param>
        protected GroupAggregator(IValueExtractor extractor, IEntryAggregator aggregator, IFilter filter)
        {
            Debug.Assert(extractor != null && aggregator != null);

            m_extractor  = extractor;
            m_aggregator = aggregator;
            m_filter     = filter;
        }
 public SolutionEndRebuildSucceededEntry(IEntry entry, IValueExtractor valueExtractor, IDataService dataService)
 {
     this.entry          = entry;
     this.valueExtractor = valueExtractor;
     this.dataService    = dataService;
     this.entry          = entry;
     this.valueExtractor = valueExtractor;
     this.dataService    = dataService;
 }
 public RangeValueValidator(
     IValueExtractor valueExtractor,
     Double minValue,
     Double maxValue)
     : base(valueExtractor)
 {
     mMinValue = minValue;
     mMaxValue = maxValue;
 }
 public BinaryOperatorValueExtractor(
     IValueExtractor left,
     IValueExtractor right,
     MathOperation	 operation)
 {
     mLeft				= left;
     mRight			= right;
     mOperation		= operation;
 }
 /// <summary>
 /// Create a validation unit to validate recursively an object, remember that an object
 /// validation unit is not recursive.
 /// </summary>
 /// <param name="valueExtractor"></param>
 /// <param name="partName"></param>
 /// <param name="ruleMap"></param>
 /// <returns></returns>
 public static ValidationUnit CreateObjectValidationUnit(
     IValueExtractor valueExtractor,
     String partName,
     Dictionary <Type, ValidationUnitCollection> ruleMap)
 {
     return(new MultipleValidatorValidationUnit(
                false, new ErrorMessage("Field " + partName + " does not validate"),
                new ObjectValidator(valueExtractor, ruleMap)));
 }
 public RangeValueValidator(
     IValueExtractor valueExtractor,
     Double minValue,
     Double maxValue)
     : base(valueExtractor)
 {
     mMinValue = minValue;
     mMaxValue = maxValue;
 }
        public void TestBasicRangeTooLow()
        {
            var             newObject = new object();
            IValueExtractor ive       = MockUtils.CreateExtractorForBasicRange(repository, -10.0f);
            var             rv        = new RangeValueValidator(ive, 0, 100);

            Assert.IsFalse(rv.Validate(newObject), "Range incorrect validation");
            repository.VerifyAll();
        }
        public void TestBasicRangeGood()
        {
            var             newObject = new object();
            IValueExtractor ive       = MockUtils.CreateExtractor(repository, 3.5d);
            var             rv        = new RangeValueValidator(ive, 0, 100);

            Assert.IsTrue(rv.Validate(newObject), "Range incorrect validation");
            repository.VerifyAll();
        }
        public void TestValueExtractorCorrectlyCalled()
        {
            var             newObject = new object();
            IValueExtractor ive       = MockUtils.CreateExtractor(repository, null, newObject);
            var             rv        = new RequiredValidator(ive, null);

            Assert.IsFalse(rv.Validate(newObject), "Requried Validator does not check null");
            repository.VerifyAll();
        }
Beispiel #22
0
 public BinaryOperatorValueExtractor(
     IValueExtractor left,
     IValueExtractor right,
     MathOperation operation)
 {
     mLeft      = left;
     mRight     = right;
     mOperation = operation;
 }
Beispiel #23
0
        /// <summary>
        /// Add an index to the given dictionary of indexes, keyed by the given
        /// extractor. Also add the index as a listener to the given cache.
        /// </summary>
        /// <param name="extractor">
        /// The IValueExtractor object that is used to extract an indexable
        /// property value from a cache entry.
        /// </param>
        /// <param name="ordered">
        /// True if the contents of the indexed information should be ordered;
        /// false otherwise
        /// </param>
        /// <param name="comparator">
        /// The IComparer object which imposes an ordering on entries in the
        /// indexed cache or <c>null</c> if the entries' values natural
        /// ordering should be used.
        /// </param>
        /// <param name="cache">
        /// The cache that the newly created ICacheIndex will use for
        /// initialization and listen to for changes.
        /// </param>
        /// <param name="dictIndex">
        /// The dictionary of indexes that the newly created ICacheIndex will
        /// be added to.
        /// </param>
        public static void AddIndex(IValueExtractor extractor, bool ordered,
                                    IComparer comparator, IObservableCache cache, IDictionary dictIndex)
        {
            var index = (ICacheIndex)dictIndex[extractor];

            if (index == null)
            {
                for (int cAttempts = 4; ;)
                {
                    if (extractor is IIndexAwareExtractor)
                    {
                        index = ((IIndexAwareExtractor)extractor).
                                CreateIndex(ordered, comparator, dictIndex);
                        if (index == null)
                        {
                            return;
                        }
                    }
                    else
                    {
                        index = new SimpleCacheIndex(extractor, ordered, comparator);
                        dictIndex[extractor] = index;
                    }

                    ICacheListener listener = EnsureListener(index);
                    cache.AddCacheListener(listener, null, false);

                    try
                    {
                        // build the index
                        foreach (ICacheEntry entry in cache)
                        {
                            index.Insert(entry);
                        }
                        break;
                    }
                    catch (InvalidOperationException ioe) //collection was modified
                    {
                        cache.RemoveCacheListener(listener);
                        if (--cAttempts == 0)
                        {
                            RemoveIndex(extractor, cache, dictIndex);
                            CacheFactory.Log("Exception occured during index rebuild: " +
                                             ioe, CacheFactory.LogLevel.Error);
                            throw;
                        }
                    }
                }
            }
            else if (!(ordered == index.IsOrdered &&
                       Equals(comparator, index.Comparer)))
            {
                throw new InvalidOperationException("Index for " + extractor +
                                                    " already exists;" +
                                                    " remove the index and add it with the new settings");
            }
        }
Beispiel #24
0
        public void TestValueThatIsNotAString()
        {
            IValueExtractor ive = MockRepository.GenerateStub <IValueExtractor>();

            ive.Expect(o => o.ExtractValue(null)).Return(new Object());
            ive.Expect(o => o.SourceName).Return("property");
            var rv = new RangeLengthValidator(ive, 1, 10);

            Assert.Throws(typeof(ArgumentException), () => rv.Validate(null));
        }
Beispiel #25
0
        public void TestNullString()
        {
            IValueExtractor ive = MockRepository.GenerateStub <IValueExtractor>();

            ive.Expect(o => o.ExtractValue(null)).Return(null);
            ive.Expect(o => o.SourceName).Return("property");
            var rv = new RangeLengthValidator(ive, 1, 10);

            Assert.IsFalse(rv.Validate(null));
        }
Beispiel #26
0
        /// <summary>
        /// Construct a ConditionalIndex.
        /// </summary>
        /// <param name="filter">the filter that is used to evaluate the
        /// entries of the resource cache that is being indexed.
        /// </param>
        /// <param name="extractor">
        /// the <see cref="IValueExtractor"/> that is used to extract an
        /// indexed value from a resource cache entry.
        /// </param>
        /// <param name="ordered">
        /// <c>true</c> iff the contents of the indexed information should be
        /// ordered; <c>false</c> otherwise.
        /// </param>
        /// <param name="comparer">
        /// the IComparer object which imposes an ordering on entries in the
        /// index; or <tt>null</tt> if the entries' values natural ordering
        /// should be used.
        /// </param>
        /// <param name="forwardIndex">
        /// specifies whether or not this index supports a forward map
        /// </param>
        public ConditionalIndex(IFilter filter, IValueExtractor extractor,
                                bool ordered, IComparer comparer, bool forwardIndex)
            : base(extractor, ordered, comparer, false)
        {
            Filter = filter;
            IsForwardIndexSupported = forwardIndex;
            m_partial = false;

            Initialize(forwardIndex);
        }
        public void TestBasicValidationGood()
        {
            var             newObject = new object();
            IValueExtractor ive       = MockRepository.GenerateStub <IValueExtractor>();

            ive.Stub(obj => obj.ExtractValue(null)).IgnoreArguments().Return(20);
            var rv = new ActionValidation <Int32>(ive, num => num > 10);

            Assert.IsTrue(rv.Validate(newObject), "Range incorrect validation");
        }
        /// <summary>
        /// Construct the ConditionalExtractor.
        /// </summary>
        /// <param name="filter">
        /// The filter used by this extractor to create a
        /// <see cref="ConditionalIndex"/>; must not be null.
        /// </param>
        /// <param name="extractor">
        /// The extractor used by this extractor to create a
        /// <see cref="ConditionalIndex"/>; the created index will be
        /// associated with this extractor in the given index map; must
        /// not be null.
        /// </param>
        /// <param name="forwardIndex">
        /// Specifies whether or not this extractor will create a
        /// <see cref="ConditionalIndex"/> that supports a forward index.
        /// </param>
        public ConditionalExtractor(IFilter filter, IValueExtractor extractor,
                                    bool forwardIndex)
        {
            Debug.Assert(filter != null && extractor != null,
                         "Filter and extractor must not be null");

            Filter    = filter;
            Extractor = extractor;
            IsForwardIndexSupported = forwardIndex;
        }
Beispiel #29
0
        /// <summary>
        /// Create an instance of GroupAggregator based on a specified member
        /// name(s), an <see cref="IEntryAggregator"/> and a result
        /// evaluation filter.
        /// </summary>
        /// <remarks>
        /// If the specified underlying aggregator is an instance of
        /// <see cref="IParallelAwareAggregator"/>, then a parallel-aware
        /// instance of the GroupAggregator will be created. Otherwise, the
        /// resulting GroupAggregator will not be parallel-aware and could be
        /// ill-suited for aggregations run against large partitioned caches.
        /// </remarks>
        /// <param name="member">
        /// A member name or a comma-delimited sequence of names that results
        /// in a <see cref="ReflectionExtractor"/> or a
        /// <see cref="MultiExtractor"/> that will be used to split
        /// <see cref="IInvocableCache"/> entries into distinct groups.
        /// </param>
        /// <param name="aggregator">
        /// An underlying <b>IEntryAggregator</b>.
        /// </param>
        /// <param name="filter">
        /// An optional <b>IFilter</b> object that will be used to evaluate
        /// results of each individual group aggregation.
        /// </param>
        /// <returns>
        /// An instance of GroupAggregator based on a specified member
        /// name(s), an <see cref="IEntryAggregator"/> and a result
        /// evaluation filter.
        /// </returns>
        public static GroupAggregator CreateInstance(string member, IEntryAggregator aggregator, IFilter filter)
        {
            IValueExtractor extractor = member.IndexOf(',') >= 0
                                            ? new MultiExtractor(member)
                                            : member.IndexOf('.') >= 0
                                                  ? new ChainedExtractor(member)
                                                  : (IValueExtractor) new ReflectionExtractor(member);

            return(CreateInstance(extractor, aggregator, filter));
        }
Beispiel #30
0
        public void TestBasicValidationGood()
        {
            IValueExtractor ive = MockRepository.GenerateStub <IValueExtractor>();

            ive.Expect(m => m.SourceName).Return("Property");
            ive.Expect(m => m.ExtractValue(null))
            .IgnoreArguments().Return("Testregexgood");
            var rv = new RegexValidator(ive, "Test.*good");

            Assert.That((Boolean)rv.Validate(null), Is.True);
        }
Beispiel #31
0
        private static ConditionalIndex createIndex(IDictionary map, IFilter filter, IValueExtractor extractor, bool fSupportForwardMap)
        {
            var index = new ConditionalIndex(filter, extractor, false, null, fSupportForwardMap);

            foreach (DictionaryEntry de in map)
            {
                ICacheEntry entry = new CacheEntry(de.Key, de.Value);
                index.Insert(entry);
            }
            return(index);
        }
Beispiel #32
0
        public void TestNullValueExtractor()
        {
            IValueExtractor nullValueExtractor = NullImplementation.GetValueExtractor();

            Assert.IsNotNull(nullValueExtractor);
            Assert.IsInstanceOf(typeof(NullImplementation.NullValueExtractor), nullValueExtractor);
            object o  = new object();
            object o1 = nullValueExtractor.Extract(o);

            Assert.AreEqual(o, o1);
        }
Beispiel #33
0
        public void TestValidString()
        {
            IValueExtractor ive = MockRepository.GenerateStub <IValueExtractor>();

            ive.Expect(o => o.ExtractValue(null)).Return("String OK");
            ive.Expect(o => o.SourceName).Return("property");
            var rv = new RangeLengthValidator(ive, 1, 10);
            SingleValidationResult res = rv.Validate(null);

            Assert.IsTrue(res);
        }
 /// <summary>
 /// Given an array of object of validation attributes create all
 /// requested ValidationUnits.
 /// </summary>
 /// <param name="vc"></param>
 ///<param name="valueExtractor">The value extractor proposed by the caller
 /// the real value extractor can be overriden by the attribute.</param>
 /// <param name="validationfields"></param>
 private static void BuildValidationUnitFromAttributeList(
     ValidationUnitCollection vc,
     IValueExtractor valueExtractor,
     object[] validationfields)
 {
     foreach (BaseValidationAttribute va in validationfields)
     {
         if (va.IsValueExtractorOverriden)
             valueExtractor = va.CreateValueExtractor();
         vc.Add( ValidationUnit.CreateValidationUnit(
                     va.CreateErrorMessage(),
                     va.CreateValidator(valueExtractor)));
     }
 }
 public RequiredValidator(IValueExtractor valueExtractor)
     : this(valueExtractor, null)
 {
 }
 public override IValidator CreateValidator(IValueExtractor valueExtractor)
 {
     return new ConstantResultValidator(mResult);
 }
 /// <summary>
 /// this is the real routine that is overriden by derived classes
 /// </summary>
 /// <param name="valueExtractor"></param>
 /// <returns></returns>
 public abstract IValidator CreateValidator(IValueExtractor valueExtractor);
 public NotEmptyValidator(IValueExtractor valueExtractor)
     : base(valueExtractor)
 {
 }
 public override IValidator CreateValidator(IValueExtractor valueExtractor)
 {
     return new RangeValueValidator(valueExtractor, mMinValue, mMaxValue) ;
 }
 public RangeLengthValidator(IValueExtractor valueExtractor, int minLenght, int maxLength)
     : base(valueExtractor)
 {
     MinLenght = minLenght;
     MaxLength = maxLength;
 }
 public RequiredValidator(IValueExtractor valueExtractor, object nullValue)
     : base(valueExtractor)
 {
     mNullValue = nullValue;
 }
 public override IValidator CreateValidator(IValueExtractor valueExtractor)
 {
     throw new NotImplementedException();
 }
 public RangeLengthValidator(IValueExtractor valueExtractor, int maxLength)
     : this(valueExtractor, 0, maxLength)
 {
 }
 /// <summary>
 /// Create a validation unit to validate recursively an object, remember that an object
 /// validation unit is not recursive.
 /// </summary>
 /// <param name="valueExtractor"></param>
 /// <param name="partName"></param>
 /// <param name="ruleMap"></param>
 /// <returns></returns>
 public static ValidationUnit CreateObjectValidationUnit(
     IValueExtractor valueExtractor,
     String partName,
     Dictionary<Type, ValidationUnitCollection> ruleMap)
 {
     return new MultipleValidatorValidationUnit(
         false, new ErrorMessage("Field " + partName + " does not validate"),
         new ObjectValidator(valueExtractor, ruleMap));
 }
 public override IValidator CreateValidator(IValueExtractor valueExtractor)
 {
     return new RequiredValidator(valueExtractor, mNullValue);
 }
 /// <summary>
 /// Extract value, it extract the part of the object specified by mPartName 
 /// and work on the type of the object passed in the first call.
 /// </summary>
 /// <param name="objToValidate"></param>
 /// <returns></returns>
 public object ExtractValue(object objToValidate)
 {
     if (innerValueExtractor == null)
         innerValueExtractor = CreateInnerExtractor(objToValidate.GetType());
     return innerValueExtractor.ExtractValue(objToValidate);
 }
 NullableValidator(IValueExtractor valueExtractor)
     : base(valueExtractor)
 {
 }
 public RegexValidator(IValueExtractor valueExtractor, String regexExpression)
     : base(valueExtractor)
 {
     this.RegexExpression = regexExpression;
 }