Exemplo n.º 1
0
 static ChildWindowEvents()
 {
     EventsUtil.initFields(typeof(ChildWindowEvents), delegate(FieldInfo field, Object eventDelegate)
     {
         field.SetValue(null, eventDelegate);
     });
 }
Exemplo n.º 2
0
 static GenericViewModelEvents()
 {
     EventsUtil.initFields(typeof(GenericViewModelEvents), delegate(FieldInfo field, Object eventDelegate)
     {
         field.SetValue(null, eventDelegate);
     });
 }
Exemplo n.º 3
0
        internal CacheEventDescriptor RegisterGeneralEvents(CacheDataNotificationCallback callback, EventType eventType, EventDataFilter datafilter)
        {
            if (callback != null)
            {
                //Avoiding new ResourcePool(inside = new Hashtable) at constructor level
                if (_addEventPool == null)
                {
                    _addEventPool = new ResourcePool();
                }
                if (_removeEventPool == null)
                {
                    _removeEventPool = new ResourcePool();
                }
                if (_updateEventPool == null)
                {
                    _updateEventPool = new ResourcePool();
                }

                CacheEventDescriptor discriptor = CacheEventDescriptor.CreateCacheDiscriptor(eventType, _cacheName, callback, datafilter);

                //Registers the handl)
                bool registeredDescriptor = RegisterGeneralDiscriptor(discriptor, EventsUtil.GetEventTypeInternal(eventType));
                if (!registeredDescriptor)
                {
                    return(null);
                }

                return(discriptor);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
 static FrameworkElementEvents()
 {
     EventsUtil.initFields(typeof(FrameworkElementEvents), delegate(FieldInfo field, Object eventDelegate)
     {
         field.SetValue(null, eventDelegate);
     });
 }
Exemplo n.º 5
0
 static INotifyPropertyChangedEvents()
 {
     EventsUtil.initFields(typeof(INotifyPropertyChangedEvents), delegate(FieldInfo field, Object eventDelegate)
     {
         field.SetValue(null, eventDelegate);
     });
 }
Exemplo n.º 6
0
 static TextBoxEvents()
 {
     EventsUtil.initFields(typeof(TextBoxEvents), delegate(FieldInfo field, Object eventDelegate)
     {
         field.SetValue(null, eventDelegate);
     });
 }
Exemplo n.º 7
0
 static ContentControlEvents()
 {
     EventsUtil.initFields(typeof(ContentControlEvents), delegate(FieldInfo field, Object eventDelegate)
     {
         field.SetValue(null, eventDelegate);
     });
 }
Exemplo n.º 8
0
 public void UnRegisterCacheNotification(string key, CacheDataNotificationCallback callback, EventType EventType)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     CacheContainer.UnRegisterCacheNotification(key, callback, EventsUtil.GetEventTypeInternal(EventType));
 }
Exemplo n.º 9
0
        public void UnRegisterCacheNotification(IEnumerable <string> keys, CacheDataNotificationCallback callback, EventType EventType)
        {
            if (keys == null)
            {
                throw new ArgumentNullException("key");
            }

            string[] keysList = new List <string>(keys).ToArray();

            for (int i = 0; i < keysList.Length; i++)
            {
                if (string.IsNullOrEmpty(keysList[i]))
                {
                    throw new ArgumentNullException("key can't be null or empty");
                }
            }

            if (callback == null)
            {
                throw new ArgumentException("callback");
            }

            CacheContainer.UnRegisterCacheNotification(keysList, callback, EventsUtil.GetEventTypeInternal(EventType));
        }
Exemplo n.º 10
0
        internal EventHandle UnregisterDiscriptor(CacheEventDescriptor discriptor)
        {
            if (discriptor == null || !discriptor.IsRegistered)
            {
                return(null);
            }

            foreach (EventType type in Enum.GetValues(typeof(EventType)))
            {
                ResourcePool pool = null;

                #region Pool selection

                if ((type & discriptor.RegisteredAgainst) != 0)
                {
                    pool = GetEventPool(EventsUtil.GetEventTypeInternal(type));
                }

                if (pool == null)
                {
                    continue;
                }
                #endregion

                short           registrationSequenceId = -1;
                bool            unregisterNotification = false;
                EventDataFilter maxDataFilter          = EventDataFilter.None;

                lock (SyncLockGeneral)
                {
                    object retVal = pool.RemoveResource(discriptor);

                    if (retVal == null)
                    {
                        continue;
                    }
                    unregisterNotification = pool.Count == 0;

                    if (!unregisterNotification)
                    {
                        object[] pooledDescriptors = pool.GetAllResourceKeys();

                        if (pooledDescriptors != null)
                        {
                            for (int i = 0; i < pooledDescriptors.Length; i++)
                            {
                                CacheEventDescriptor pooledDescriptor = pooledDescriptors[i] as CacheEventDescriptor;

                                if (pooledDescriptor.DataFilter > maxDataFilter)
                                {
                                    maxDataFilter = pooledDescriptor.DataFilter;
                                }
                            }
                        }
                    }


                    discriptor.IsRegistered = false;

                    //keeps a sequence number
                    switch (type)
                    {
                    case EventType.ItemAdded:
                        //Data filter is being updated
                        if (maxDataFilter != _generalAddDataFilter)
                        {
                            _generalAddDataFilter  = maxDataFilter;
                            registrationSequenceId = ++_addEventRegistrationSequence;
                        }
                        if (unregisterNotification)
                        {
                            _generalAddDataFilter = EventDataFilter.None;
                        }
                        break;

                    case EventType.ItemRemoved:
                        if (maxDataFilter != _generalRemoveDataFilter)
                        {
                            _generalRemoveDataFilter = maxDataFilter;
                            registrationSequenceId   = ++_removeEventRegistrationSequenceId;
                        }
                        if (unregisterNotification)
                        {
                            _generalAddDataFilter = EventDataFilter.None;
                        }
                        break;

                    case EventType.ItemUpdated:
                        if (maxDataFilter != _generalUpdateDataFilter)
                        {
                            _generalUpdateDataFilter = maxDataFilter;
                            registrationSequenceId   = ++_updateEventRegisrationSequenceId;
                        }
                        if (unregisterNotification)
                        {
                            _generalAddDataFilter = EventDataFilter.None;
                        }

                        break;
                    }
                }

                if (_cache != null)
                {
                    if (unregisterNotification)
                    {
                        //client is no more interested in event, therefore unregister it from server
                        _cache.UnregiserGeneralCacheNotification(EventsUtil.GetEventTypeInternal(type));
                    }
                    else if (registrationSequenceId != -1)
                    {
                        //only caused update of data filter either upgrade or downgrade
                        _cache.RegisterCacheNotificationDataFilter(EventsUtil.GetEventTypeInternal(type), maxDataFilter, registrationSequenceId);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// TheadSafe and no locks internally
        /// </summary>
        /// <param name="key"></param>
        /// <param name="eventType">Should contain one type i.e. should not be used as a flag.
        /// Every EventType should be executed from another thread</param>
        /// <param name="item"></param>
        /// <param name="oldItem"></param>
        /// <param name="reason"></param>
        /// <param name="notifyAsync"></param>
        internal void RaiseGeneralCacheNotification(string key, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason reason, bool notifyAsync)
        {
            try
            {
                object[] registeredDiscriptors = null;

                ResourcePool eventPool = GetEventPool(EventsUtil.GetEventTypeInternal(eventType));
                if (eventPool != null)
                {
                    registeredDiscriptors = eventPool.GetAllResourceKeys();
                }

                if (registeredDiscriptors != null && registeredDiscriptors.Length > 0)
                {
                    for (int i = 0; i < registeredDiscriptors.Length; i++)
                    {
                        CacheEventDescriptor discriptor = registeredDiscriptors[i] as CacheEventDescriptor;

                        if (discriptor == null)
                        {
                            continue;
                        }

                        var bitSet = new BitSet();

                        if (_cache.SerializationFormat == Common.Enum.SerializationFormat.Json)
                        {
                            bitSet.SetBit(BitSetConstants.JsonData);
                        }

                        if (item != null)
                        {
                            item.SetValue(_cache.SafeDeserialize <object>(item.GetValue <object>(), _cache.SerializationContext, bitSet, UserObjectType.CacheItem));
                        }

                        if (oldItem != null)
                        {
                            oldItem.SetValue(_cache.SafeDeserialize <object>(oldItem.GetValue <object>(), _cache.SerializationContext, bitSet, UserObjectType.CacheItem));
                        }

                        var arg = CreateCacheEventArgument(discriptor.DataFilter, key, _cacheName, eventType, item, oldItem, reason);
                        arg.Descriptor = discriptor;

                        if (notifyAsync)
                        {
#if !NETCORE
                            discriptor.CacheDataNotificationCallback.BeginInvoke(key, arg, asyn, null);
#elif NETCORE
                            //TODO: ALACHISOFT (BeginInvoke is not supported in .Net Core thus using TaskFactory)
                            TaskFactory factory = new TaskFactory();
                            Task        task    = factory.StartNew(() => discriptor.CacheDataNotificationCallback(key, arg));
#endif
                        }
                        else
                        {
                            discriptor.CacheDataNotificationCallback.Invoke(key, arg);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (_logger != null && _logger.IsErrorEnabled)
                {
                    _logger.CriticalInfo(ex.ToString());
                }
            }
        }