コード例 #1
0
        private CQEventArg CreateCQEventArgument(EventDataFilter dataFilter, string key, string cacheName,
                                                 EventType eventType, EventCacheItem item, EventCacheItem oldItem)
        {
            EventCacheItem cloneItem    = null;
            EventCacheItem cloneOldItem = null;

            if (dataFilter != EventDataFilter.None && item != null)
            {
                cloneItem = item.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                {
                    cloneItem.Value = null;
                }
            }

            if (dataFilter != EventDataFilter.None && oldItem != null)
            {
                cloneOldItem = oldItem.Clone() as EventCacheItem;

                if (dataFilter == EventDataFilter.Metadata)
                {
                    cloneOldItem.Value = null;
                }
            }

            CQEventArg eventArg = new CQEventArg(cacheName, eventType, cloneItem, null);

            if (eventType == EventType.ItemUpdated)
            {
                eventArg.OldItem = cloneOldItem;
            }

            return(eventArg);
        }
コード例 #2
0
        public void OnQueryChangeNotifiation(string key, CQEventArg eventArgs)
        {
            switch (eventArgs.EventType)
            {
            case EventType.ItemAdded:
                query.OnItemAdded(key, false);
                break;

            case EventType.ItemRemoved:
                query.OnItemRemoved(key, false);
                break;

            case EventType.ItemUpdated:
                query.OnItemUpdated(key, false);
                break;
            }
        }
コード例 #3
0
        internal void FireCQEvents(string key, EventType eventType, EventCacheItem item, EventCacheItem oldItem,
                                   bool notifyAsync, string cacheName, BitSet flag, EventDataFilter datafilter)
        {
            try
            {
                CQEventArg arg = null;

                ICollection  collection = null;
                ResourcePool pool       = null;
                ResourcePool filterPool = null;
                if ((eventType & EventType.ItemAdded) != 0 && _cqAddEventPool != null)
                {
                    pool       = _cqAddEventPool;
                    collection = _cqAddEventPool.Keys;
                    filterPool = _cqAddEventDataFilter;
                }
                else if ((eventType & EventType.ItemUpdated) != 0 && _cqUpdateEventPool != null)
                {
                    pool       = _cqUpdateEventPool;
                    collection = _cqUpdateEventPool.Keys;
                    filterPool = _cqUpdateEventDataFilter;
                }
                else if ((eventType & EventType.ItemRemoved) != 0 && _cqRemoveEventPool != null)
                {
                    pool       = _cqRemoveEventPool;
                    collection = _cqRemoveEventPool.Keys;
                    filterPool = _cqRemoveEventDataFilter;
                }
                else
                {
                    return;
                }


                if (collection != null && collection.Count > 0)
                {
                    QueryDataNotificationCallback[] disc = null;
                    lock (syncLock)
                    {
                        disc = new QueryDataNotificationCallback[collection.Count];
                        collection.CopyTo(disc, 0); //to avoid locking
                    }

                    for (int i = 0; i < disc.Length; i++)
                    {
                        short  index = -1;
                        object obj   = pool.GetResource(disc[i]);
                        index = Convert.ToInt16(obj);

                        if (index > -1)
                        {
                            //Not to fire event if datafilter recieved is less than requried OR noDF present
                            EventDataFilter queryDataFilter = (EventDataFilter)filterPool.GetResource(index);

                            if ((eventType & EventType.ItemAdded) != 0)
                            {
                                arg = CreateCQEventArgument(queryDataFilter, key, cacheName, EventType.ItemAdded, item,
                                                            oldItem);
                            }
                            else if ((eventType & EventType.ItemUpdated) != 0)
                            {
                                arg = CreateCQEventArgument(queryDataFilter, key, cacheName, EventType.ItemUpdated,
                                                            item, oldItem);
                            }
                            else if ((eventType & EventType.ItemRemoved) != 0)
                            {
                                arg = CreateCQEventArgument(queryDataFilter, key, cacheName, EventType.ItemRemoved,
                                                            item, oldItem);
                            }
                            else
                            {
                                return;
                            }

                            arg.ContinuousQuery = this;

                            if (notifyAsync)
                            {
#if !NETCORE
                                disc[i].BeginInvoke(key, arg, asyn, disc[i]);
#elif NETCORE
                                TaskFactory factory = new TaskFactory();
                                int         temp    = i;
                                Task        task    = factory.StartNew(() => disc[temp](key, arg));
#endif
                            }
                            else
                            {
                                disc[i].Invoke(key, arg);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }