Ejemplo n.º 1
0
 internal void UpdateValueInBackground(TimeSpan rampUpDelay, TKey key, UpdateValueDelegate getUpdateValue)
 {
     Runner.Enqueue(async cancellationToken =>
     {
         if (Interlocked.CompareExchange(ref _isProcessingTick, 1, 0) == 0)
         {
             try
             {
                 await Task.Delay(rampUpDelay, cancellationToken);
                 await UpdateValue(key, getUpdateValue, cancellationToken);
             }
             catch (AggregateException ex)
             {
                 SetException(ex.InnerException);
             }
         }
         catch (Exception ex)
         {
             SetException(ex);
         }
         finally
         {
             Interlocked.Exchange(ref _isProcessingTick, 0);
         }
     });
Ejemplo n.º 2
0
        public virtual TValue AddOrUpdate <TItem, TValue>(TItem item, string path,
                                                          Func <TItem, object, TValue> addValueFactory,
                                                          UpdateValueDelegate <TItem, Func <TItem, object, TValue>, TValue, object> updateValueFactory,
                                                          object state = null)
        {
            Should.NotBeNull(item, "item");
            Should.NotBeNull(path, "path");
            Should.NotBeNull(addValueFactory, "addValueFactory");
            Should.NotBeNull(updateValueFactory, "updateValueFactory");
            LightDictionaryBase <string, object> dictionary = GetOrAddAttachedDictionary(item, true);

            lock (dictionary)
            {
                object value;
                if (dictionary.TryGetValue(path, out value))
                {
                    value            = updateValueFactory(item, addValueFactory, (TValue)value, state);
                    dictionary[path] = value;
                    return((TValue)value);
                }
                value = addValueFactory(item, state);
                dictionary.Add(path, value);
                return((TValue)value);
            }
        }
 static WeakListenerInternal()
 {
     Empty = new WeakEventListenerWrapper[0];
     AddSourceEventDelegate = AddSourceEvent;
     UpdateSourceEventDelegate = UpdateSourceEvent;
     HandleMethod = typeof(WeakListenerInternal).GetMethodEx("Raise", MemberFlags.Public | MemberFlags.Instance);
     EmptyListener = new WeakListenerInternal();
 }
Ejemplo n.º 4
0
 static WeakListenerInternal()
 {
     Empty = new WeakEventListenerWrapper[0];
     AddSourceEventDelegate    = AddSourceEvent;
     UpdateSourceEventDelegate = UpdateSourceEvent;
     HandleMethod  = typeof(WeakListenerInternal).GetMethodEx("Raise", MemberFlags.Public | MemberFlags.Instance);
     EmptyListener = new WeakListenerInternal();
 }
Ejemplo n.º 5
0
        public Cache(UpdateValueDelegate getUpdateValue, TimeSpan every, TimeSpan begin, TKey[] keys, TimeSpan rampUp, bool evictUnused)
        {
            var kvp = from key in keys select new KeyValuePair <TKey, Item>(key, Item.New());

            _dictionary     = new ConcurrentDictionary <TKey, Item>(kvp);
            _getUpdateValue = getUpdateValue;
            _timer          = new Timer(Tick, null, begin, every);
            _rampUpTicks    = rampUp.Ticks;
            _evictUnused    = evictUnused;
        }
        public void AddOrUpdateValueTest()
        {
            bool isInvoked = false;
            var  target    = new object();
            var  value1    = new object();
            var  value2    = new object();
            var  stateObj  = new object();
            UpdateValueDelegate <object, object, object, object> del = (item, newValue, oldValue, state) =>
            {
                item.ShouldEqual(target);
                newValue.ShouldEqual(value2);
                oldValue.ShouldEqual(value1);
                state.ShouldEqual(stateObj);
                isInvoked = true;
                return(newValue);
            };

            _provider.AddOrUpdate(target, FirstPath, value1, del, stateObj);
            isInvoked.ShouldBeFalse();
            _provider.AddOrUpdate(target, FirstPath, value2, del, stateObj);
            isInvoked.ShouldBeTrue();
        }
Ejemplo n.º 7
0
        public virtual TValue AddOrUpdate <TItem, TValue>(TItem item, string path, TValue addValue,
                                                          UpdateValueDelegate <TItem, TValue, TValue, object> updateValueFactory,
                                                          object state = null)
        {
            Should.NotBeNull(item, nameof(item));
            Should.NotBeNull(path, nameof(path));
            Should.NotBeNull(updateValueFactory, nameof(updateValueFactory));
            LightDictionaryBase <string, object> dictionary = GetOrAddAttachedDictionary(item, true);

            lock (dictionary)
            {
                object value;
                if (dictionary.TryGetValue(path, out value))
                {
                    value            = updateValueFactory(item, addValue, (TValue)value, state);
                    dictionary[path] = value;
                    return((TValue)value);
                }
                dictionary.Add(path, addValue);
                return(addValue);
            }
        }
 static WeakPropertyChangedListener()
 {
     Empty = new KeyValuePair<WeakEventListenerWrapper, string>[0];
     UpdateSourceEventDelegate = UpdateSourceEvent;
     AddSourceEventDelegate = AddSourceEvent;
 }
Ejemplo n.º 9
0
 static BindingManager()
 {
     UpdateValueFactoryDelegate  = UpdateValueFactory;
     GetBindingPredicateDelegate = GetBindingPredicate;
 }
Ejemplo n.º 10
0
 static WeakPropertyChangedListener()
 {
     Empty = new KeyValuePair <WeakEventListenerWrapper, string> [0];
     UpdateSourceEventDelegate = UpdateSourceEvent;
     AddSourceEventDelegate    = AddSourceEvent;
 }
Ejemplo n.º 11
0
 static BindingManager()
 {
     UpdateValueFactoryDelegate = UpdateValueFactory;
     GetBindingPredicateDelegate = GetBindingPredicate;
 }
Ejemplo n.º 12
0
 internal void UpdateValueInBackground(bool used, UpdateValueDelegate getUpdateValue)
 {
     _item.Used = used;
     _item.UpdateValueInBackground(_rampUp, _key, getUpdateValue);
 }