public void OnActiveQueryChanged(object key, Alachisoft.NCache.Caching.Queries.QueryChangeType changeType,
                                         List <CQCallbackInfo> activeQueries, EventContext eventContext)
        {
            try
            {
                if (_listener != null)
                {
                    foreach (CQCallbackInfo queryInfo in activeQueries)
                    {
                        EventDataFilter datafilter = EventDataFilter.None;
                        foreach (EventDataFilter df in queryInfo.DataFilters.Values)
                        {
                            datafilter = df;
                            break;
                        }

                        _listener.OnActiveQueryChanged(queryInfo.CQId,
                                                       (QueryChangeType)Convert.ToInt32(changeType), (string)key, true, null, null, null,
                                                       datafilter);
                    }
                }
            }
            catch
            {
            }
        }
Пример #2
0
 public void Deserialize(CompactReader reader)
 {
     theClient              = (string)reader.ReadObject();
     theCallback            = reader.ReadObject();
     notifyOnItemExpiration = reader.ReadBoolean();
     _dataFilter            = (EventDataFilter)reader.ReadByte();
 }
Пример #3
0
        public ActionResult Leaves(EventDataFilter vm)
        {
            Func <IQueryable <Leave>, IQueryable <Leave> > leaveFilter = q =>
            {
                q = q.Where(t => t.CreatedByUserId == WebUser.Id);

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.Start >= vm.start.Value);
                }

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.End <= vm.end.Value);
                }

                return(q);
            };

            var leaves = _leaveRepository.Search(leaveFilter);

            var payload = leaves.Select(h => new EventData
            {
                id    = h.Id,
                title = $"Leave - {h.Status}",
                start = h.Start.ToLocalDateTime().ToString("s"),
                end   = h.End.ToLocalDateTime().ToString("s")
            }).ToList();

            return(Json(payload, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public ActionResult Attendance(EventDataFilter vm)
        {
            Func <IQueryable <Attendance>, IQueryable <Attendance> > attendanceFilter = q =>
            {
                q = q.Where(t => t.EmployeeId == WebUser.Id);

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.LogDate >= vm.start.Value);
                }

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.LogDate <= vm.end.Value);
                }

                return(q);
            };

            var attendances = _attendanceRepository.Search(attendanceFilter);

            var payload = attendances.Select(h => new EventData
            {
                id     = h.Id,
                allDay = true,
                title  = $"In: {new DateTime(h.InTime.Ticks).ToLocalDateTime():t} & Out: {new DateTime(h.OutTime.Ticks).ToLocalDateTime():t}",
                start  = h.LogDate.ToString("s"),
                end    = h.LogDate.ToString("s")
            }).ToList();

            return(Json(payload, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        internal AddCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, Hashtable queryInfo, BitSet flagMap, string cacheId,EventDataFilter updateDataFilter,EventDataFilter removeDataFilter)
        {
            base.name = "AddCommand";
            base.key = key;

            _addCommand = new Alachisoft.NCache.Common.Protobuf.AddCommand();

            if (absoluteExpiration != Cache.NoAbsoluteExpiration)
                _addCommand.absExpiration = absoluteExpiration.Ticks;

            if (slidingExpiration != Cache.NoSlidingExpiration)
                _addCommand.sldExpiration = slidingExpiration.Ticks;

            Alachisoft.NCache.Caching.UserBinaryObject ubObject = Alachisoft.NCache.Caching.UserBinaryObject.CreateUserBinaryObject(value);

            _addCommand.key = key;
            _addCommand.data.AddRange(ubObject.DataList);
            _addCommand.requestId = base.RequestId;
            _addCommand.updateCallbackId = updateCallback;
            _addCommand.removeCallbackId = removeCallback;
            _addCommand.priority = (int)priority;
            _addCommand.flag = flagMap.Data;
            _addCommand.updateDataFilter = (short)updateDataFilter;
            _addCommand.removeDataFilter = (short)removeDataFilter;

            // Changes made to send Queries, Tags and NamgedTags in a single object
            ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo();

            if (queryInfo["query-info"] != null)
                objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable);

                _addCommand.objectQueryInfo = objectQueryInfo;
        }
Пример #6
0
        public ActionResult Holidays(EventDataFilter vm)
        {
            Func <IQueryable <Holiday>, IQueryable <Holiday> > holidayFilter = q =>
            {
                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.Date >= vm.start.Value);
                }

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.Date <= vm.end.Value);
                }

                return(q);
            };

            var holidays = _holidayRepository.Search(holidayFilter);

            var payload = holidays.Select(h => new EventData
            {
                id     = h.Id,
                allDay = true,
                title  = h.Title + "-" + Enum.GetName(typeof(HolidayType), h.Type) + "-Holiday",
                start  = h.Date.ToString("s"),
                end    = h.Date.ToString("s")
            }).ToList();

            return(Json(payload, JsonRequestBehavior.AllowGet));
        }
Пример #7
0
 public CallbackInfo(string client, object callback, EventDataFilter datafilter, bool notifyOnItemExpiration)
 {
     this.theClient              = client;
     this.theCallback            = callback;
     this.notifyOnItemExpiration = notifyOnItemExpiration;
     this._dataFilter            = datafilter;
 }
Пример #8
0
        internal static EventCacheItem ConvertToEventItem(EventCacheEntry entry, EventDataFilter? datafilter)
        {
            if (datafilter == EventDataFilter.None || entry == null)
                return null;

            EventCacheItem cacheItem = new EventCacheItem();

            cacheItem.priority = (int)entry.Priority;

            UserBinaryObject userBinary = entry.Value as UserBinaryObject;
            if (userBinary == null)
            {
                if (entry.Value is CallbackEntry)
                    userBinary = ((CallbackEntry)entry.Value).Value as UserBinaryObject;
            }

            if (userBinary != null)
                cacheItem.value.AddRange(userBinary.DataList);

            //Can be optimized
            if (datafilter != null)
            {
                if (datafilter == EventDataFilter.None)
                    return null;
                else if (datafilter == EventDataFilter.Metadata)
                    cacheItem.value.Clear();
            }

            return cacheItem;
        }
Пример #9
0
        public ActionResult GetAllSheets(EventDataFilter vm)
        {
            Func <IQueryable <TimeSheet>, IQueryable <TimeSheet> > timeSheetFilter = q =>
            {
                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.Date >= vm.start.Value);
                }

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.Date <= vm.end.Value);
                }

                return(q);
            };

            var timeSheets = _timeSheetRepository.Search(timeSheetFilter);

            var payload = timeSheets.ToList().Select(h => new EventData
            {
                id     = h.Id,
                allDay = true,
                title  = $"{h.Date.ToShortDateString()} - {h.TotalHours} hours - {h.State}",
                start  = h.Date.ToString("s"),
                end    = h.Date.ToString("s")
            }).ToList();

            return(Json(payload, JsonRequestBehavior.AllowGet));
        }
Пример #10
0
 public CallbackInfo(string client, object callback, EventDataFilter datafilter, bool notifyOnItemExpiration)
 {
     this.theClient = client;
     this.theCallback = callback;
     this.notifyOnItemExpiration = notifyOnItemExpiration;
     this._dataFilter = datafilter;
 }
Пример #11
0
        public ActionResult MyTasks(EventDataFilter vm)
        {
            Func <IQueryable <Task>, IQueryable <Task> > taskFilter = q =>
            {
                q = q.Where(t => t.AssigneeId == WebUser.Id);

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.DueDate >= vm.start.Value);
                }

                if (vm.end.HasValue)
                {
                    q = q.Where(t => t.DueDate <= vm.end.Value);
                }

                return(q);
            };

            var tasks = _taskRepository.Search(taskFilter);

            var payload = tasks.Select(h => new EventData
            {
                id     = h.Id,
                allDay = false,
                title  = h.Title,
                start  = h.DueDate.GetValueOrDefault().ToString("s"),
                end    = h.DueDate?.AddHours(h.ExpectedTime.GetValueOrDefault()).ToString("s") ?? ""
            }).ToList();

            return(Json(payload, JsonRequestBehavior.AllowGet));
        }
Пример #12
0
        public void OnCustomUpdateCallback(short callbackId, string key, bool notifyAsync, EventCacheItem item,
                                           EventCacheItem oldItem, BitSet flag, EventDataFilter dataFilter)
        {
            CallbackInfo cbInfo = new CallbackInfo(null, callbackId, dataFilter);

            _listener.OnCustomUpdateCallback(key, cbInfo, notifyAsync, item, oldItem, flag);
        }
Пример #13
0
        public InsertCommand(string key, byte[] value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short removeCallback, short updateCallback, Hashtable queryInfo, BitSet flagMap, object lockId, LockAccessType accessType, string cacheId, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter)
        {
            base.name = "InsertCommand";
            base.key = key;

            _insertCommand = new Alachisoft.NCache.Common.Protobuf.InsertCommand();
            _insertCommand.key = key;

            Alachisoft.NCache.Caching.UserBinaryObject ubObject = UserBinaryObject.CreateUserBinaryObject(value);
            _insertCommand.data.AddRange(ubObject.DataList);

            _insertCommand.requestId = base.RequestId;
            _insertCommand.removeCallbackId = removeCallback;
            _insertCommand.updateCallbackId = updateCallback;
            _insertCommand.updateDataFilter = (short)updateCallbackFilter;
            _insertCommand.removeDataFilter = (short)removeCallabackFilter;
            _insertCommand.priority = (int)priority;
            _insertCommand.flag = flagMap.Data;
            if(lockId != null) _insertCommand.lockId = lockId.ToString();
            _insertCommand.lockAccessType = (int)accessType;

            if (absoluteExpiration != Web.Caching.Cache.NoAbsoluteExpiration)
                _insertCommand.absExpiration = absoluteExpiration.Ticks;

            if (slidingExpiration != Web.Caching.Cache.NoSlidingExpiration)
            _insertCommand.sldExpiration = slidingExpiration.Ticks;

            ObjectQueryInfo objectQueryInfo = new ObjectQueryInfo();

            if (queryInfo["query-info"] != null)
                objectQueryInfo.queryInfo = ProtobufHelper.GetQueryInfoObj(queryInfo["query-info"] as Hashtable);

                _insertCommand.objectQueryInfo = objectQueryInfo;
        }
Пример #14
0
 public void OnCustomRemoveCallback(short callbackId, string key, object value,
                                    CacheItemRemovedReason reason, BitSet Flag, bool notifyAsync, EventCacheItem item,
                                    EventDataFilter dataFilter)
 {
     object[] val = new object[] { value, new CallbackInfo(null, callbackId, dataFilter) };
     _listener.OnCustomRemoveCallback(key, val, reason, Flag, notifyAsync, item);
 }
Пример #15
0
        internal CacheEventDescriptor RegisterGeneralEvents(CacheDataNotificationCallback callback, EventType eventType,
                                                            EventDataFilter datafilter)
        {
            if (callback != null)
            {
                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);

                if (!RegisterGeneralDiscriptor(discriptor, eventType))
                {
                    return(null);
                }

                return(discriptor);
            }
            else
            {
                return(null);
            }
        }
Пример #16
0
        /// <summary>
        /// This method registers a custom callback that is fired on change in dataset of a continous query
        /// </summary>
        /// <param name="callback">A delegate to register your custom method with</param>
        /// <param name="eventType">Describes whether the event is to be raised on Item Added, Updated or Removed</param>
        /// <param name="datafilter">This enum is to describe when registering an event, upon raise how much data is
        /// retrieved from cache when the event is raised</param>
        /// <example>
        /// /// First create an ItemCallback
        /// <code>
        /// ItemCallback(string key, CacheEventArg e)
        /// {
        ///    ...
        /// }
        /// </code>
        /// Then declare your continous query
        /// <code>
        /// ContinuousQuery cQ=new ContinuousQuery(query,Hashtable vals);
        /// </code>
        /// Then register your notification callback
        /// <code>
        /// cQ.RegisterNotification(new QueryDataNotificationCallback(ItemCallback),EventType.ItemAdded, EventDataFilter.None);
        /// </code>
        /// </example>
        public void RegisterNotification(QueryDataNotificationCallback callback, EventType eventType,
                                         EventDataFilter datafilter)
        {
            if (callback != null)
            {
                //Avoiding new ResourcePool(inside = new Hashtable) at constructor level
                if (_cqAddEventPool == null && (eventType & EventType.ItemAdded) != 0)
                {
                    _cqAddEventPool       = new ResourcePool();
                    _cqAddEventDataFilter = new ResourcePool();
                }

                if (_cqRemoveEventPool == null && (eventType & EventType.ItemRemoved) != 0)
                {
                    _cqRemoveEventPool       = new ResourcePool();
                    _cqRemoveEventDataFilter = new ResourcePool();
                }

                if (_cqUpdateEventPool == null && (eventType & EventType.ItemUpdated) != 0)
                {
                    _cqUpdateEventPool       = new ResourcePool();
                    _cqUpdateEventDataFilter = new ResourcePool();
                }

                RegisterCQ(callback, eventType, datafilter);
            }
        }
Пример #17
0
        public ActionResult Tasks(EventDataFilter vm)
        {
            Func <IQueryable <Task>, IQueryable <Task> > taskFilter = q =>
            {
                q = q.Where(t => t.ProjectId == vm.id);

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.DueDate >= vm.start.Value);
                }

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.DueDate <= vm.end.Value);
                }

                q = q.OrderByDescending(c => c.CreatedOn);

                return(q);
            };

            var payload = _taskRepository.Search(taskFilter).ToList().Select(h => new EventData
            {
                id     = h.Id,
                allDay = false,
                title  = h.Title,
                start  = h.StartDate.GetValueOrDefault().ToString("s"),
                end    = h.DueDate?.AddHours(h.ExpectedTime.GetValueOrDefault()).ToString("s") ?? ""
            }).ToList();

            return(Json(payload, JsonRequestBehavior.AllowGet));
        }
Пример #18
0
        private CacheEventArg CreateCacheEventArgument(EventDataFilter dataFilter, string key, string cacheName, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason removedReason)
        {
            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;
                }
            }

            CacheEventArg eventArg = new CacheEventArg(key, cacheName, eventType, cloneItem, null, removedReason);

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

            return(eventArg);
        }
Пример #19
0
        internal static ItemRemoveCallbackResponse GetItemRemovedCallbackResponse(EventContext eventContext, short id, string key, UserBinaryObject value, BitSet flag, ItemRemoveReason reason,EventDataFilter dataFilter)
        {
            Alachisoft.NCache.Common.Protobuf.ItemRemoveCallbackResponse itemRemovedCallback = new Alachisoft.NCache.Common.Protobuf.ItemRemoveCallbackResponse();

            itemRemovedCallback.key = key;
            itemRemovedCallback.callbackId = id;
            itemRemovedCallback.itemRemoveReason = (int)reason;
            itemRemovedCallback.flag = flag != null? (int)flag.Data : 0;
            itemRemovedCallback.dataFilter = (short)dataFilter;
            itemRemovedCallback.eventId = new Common.Protobuf.EventId();
            UserBinaryObject binaryObject = eventContext.Item != null ?(UserBinaryObject) eventContext.Item.Value : null;
            if(binaryObject != null) itemRemovedCallback.value.AddRange(binaryObject.DataList);

            if (eventContext != null)
            {
                itemRemovedCallback.eventId.eventUniqueId = eventContext.EventID.EventUniqueID;
                itemRemovedCallback.eventId.operationCounter = eventContext.EventID.OperationCounter;
                itemRemovedCallback.eventId.eventCounter = eventContext.EventID.EventCounter;
                if (eventContext.Item != null)
                    itemRemovedCallback.flag = eventContext.Item.Flags.Data;
                itemRemovedCallback.eventId.item = ConvertToEventItem(eventContext.Item, null);
                if (itemRemovedCallback.eventId.item != null && itemRemovedCallback.eventId.item.value != null)
                {
                    itemRemovedCallback.eventId.item.value.Clear();//data will be travalling in old fashion due to old callbacks
                }
            }

            return itemRemovedCallback;
        }
Пример #20
0
        public ActionResult MileStones(EventDataFilter vm)
        {
            Func <IQueryable <ProjectMileStone>, IQueryable <ProjectMileStone> > mileStoneFilter = q =>
            {
                q = q.Where(p => p.ProjectId == vm.id);

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.TargetDate >= vm.start.Value);
                }

                if (vm.start.HasValue)
                {
                    q = q.Where(t => t.TargetDate <= vm.end.Value);
                }

                q = q.OrderByDescending(c => c.CreatedOn);

                return(q);
            };

            var payload = _projectMileStoneRepository.Search(mileStoneFilter).ToList().Select(h => new EventData
            {
                id     = h.Id,
                allDay = false,
                title  = h.Title,
                start  = h.TargetDate.ToString("s"),
                end    = h.TargetDate.ToString("s")
            }).ToList();

            return(Json(payload, JsonRequestBehavior.AllowGet));
        }
Пример #21
0
        public void RegisterCacheNotification(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");
            }
            EventDataFilter datafilter = EventDataFilter.None;

            CacheContainer.RegisterCacheDataNotificationCallback(keysList, callback, eventType, datafilter, true);
        }
Пример #22
0
        public static EventCacheEntry CreateCacheEventEntry(ArrayList listeners, CacheEntry cacheEntry, CacheRuntimeContext context)
        {
            EventCacheEntry entry     = null;
            EventDataFilter maxFilter = EventDataFilter.None;


            return(CreateCacheEventEntry(maxFilter, cacheEntry, context));
        }
Пример #23
0
 internal ItemAddedEvent(string key, string cacheId, string clientid, EventContext eventContext, EventDataFilter dataFilter)
 {
     _key          = key;
     _cacheId      = cacheId;
     _clientid     = clientid;
     _eventContext = eventContext;
     _dataFilter   = dataFilter;
 }
Пример #24
0
 internal ItemUpdateCallback(short id, string key, string clientId, EventContext eventContext, EventDataFilter dataFilter)
 {
     _id           = id;
     _key          = key;
     _clientID     = clientId;
     _eventContext = eventContext;
     _dataFilter   = dataFilter;
 }
Пример #25
0
 internal ItemUpdateCallback(short id, string key, string clientId, EventContext eventContext, EventDataFilter dataFilter)
 {
     _id = id;
     _key = key;
     _clientID = clientId;
     _eventContext = eventContext;
     _dataFilter = dataFilter;
 }
Пример #26
0
 public virtual IDictionary <string, Exception> Add(string[] keys, CacheItem[] items,
                                                    short onDataSourceItemsAdded, string providerName, long[] sizes, bool encryptionEnabled,
                                                    string clientId, short updateCallbackId, short removeCallbackId,
                                                    EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter,
                                                    CallbackType callbackType = CallbackType.PushBasedNotification)
 {
     return(null);
 }
Пример #27
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    //PROTOBUF:RESPONSE
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                }
                return;
            }

            try
            {
                CallbackInfo cbUpdate = null;
                CallbackInfo cbRemove = null;


                if (cmdInfo.dataFilter != -1) //Default value in protbuf set to -1
                {
                    EventDataFilter datafilter = (EventDataFilter)cmdInfo.dataFilter;

                    cbUpdate = new CallbackInfo(clientManager.ClientID, cmdInfo.UpdateCallbackId, datafilter);
                    cbRemove = new CallbackInfo(clientManager.ClientID, cmdInfo.RemoveCallbackId, datafilter, cmdInfo.NotifyOnExpiration);
                }
                else
                {
                    cbUpdate = new CallbackInfo(clientManager.ClientID, cmdInfo.UpdateCallbackId, EventDataFilter.None);
                    cbRemove = new CallbackInfo(clientManager.ClientID, cmdInfo.RemoveCallbackId, EventDataFilter.DataWithMetadata, cmdInfo.NotifyOnExpiration);
                }


                NCache nCache = clientManager.CmdExecuter as NCache;

                nCache.Cache.RegisterKeyNotificationCallback(cmdInfo.Key, cbUpdate, cbRemove
                                                             , new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation));

                //PROTOBUF:RESPONSE
                Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.RegisterKeyNotifResponse registerKeyNotifResponse = new Alachisoft.NCache.Common.Protobuf.RegisterKeyNotifResponse();
                response.responseType             = Alachisoft.NCache.Common.Protobuf.Response.Type.REGISTER_KEY_NOTIF;
                response.registerKeyNotifResponse = registerKeyNotifResponse;
                response.requestId = command.registerKeyNotifCommand.requestId;
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                //PROTOBUF:RESPONSE
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
 public RegisterNotificationCommand(NotificationsType notifMask, EventDataFilter datafilter, short sequenceNumber)
 {
     base.name = "RegisterNotificationCommand";
     _registerNotificationCommand = new Alachisoft.NCache.Common.Protobuf.RegisterNotifCommand();
     _registerNotificationCommand.notifMask = (int)notifMask;
     _registerNotificationCommand.requestId = base.RequestId;
     _registerNotificationCommand.datafilter = (int)datafilter;
     _registerNotificationCommand.sequence = sequenceNumber;
 }
Пример #29
0
 internal CQCallbackTask(string queryId, string key, QueryChangeType changeType, string clientId, EventContext eventContext, EventDataFilter datafilter)
 {
     _queryId      = queryId;
     _key          = key;
     _changeType   = changeType;
     _clientID     = clientId;
     _eventContext = eventContext;
     _datafilter   = datafilter;
 }
Пример #30
0
 /// <summary>
 /// Add array of <see cref="CacheItem"/> to the cache.
 /// </summary>
 /// <param name="keys">The cache keys used to reference the items.</param>
 /// <param name="items">The items that are to be stored</param>
 /// <param name="group">The data group of the item</param>
 /// <param name="subGroup">Sub group of the group</param>
 /// <returns>keys that are added or that alredy exists in the cache and their status.</returns>
 /// <remarks> If CacheItem contains invalid values the related exception is thrown.
 /// See <see cref="CacheItem"/> for invalid property values and related exceptions</remarks>
 /// <example>The following example demonstrates how to add items to the cache with a sliding expiration of 5 minutes, a priority of
 /// high, and that notifies the application when the item is removed from the cache.
 ///
 /// First create a CacheItems.
 /// <code>
 /// string keys = {"ORD_23", "ORD_67"};
 /// CacheItem items = new CacheItem[2]
 /// items[0] = new CacheItem(new Order());
 /// items[0].SlidingExpiration = new TimeSpan(0,5,0);
 /// items[0].Priority = CacheItemPriority.High;
 /// items[0].ItemRemoveCallback = onRemove;
 ///
 /// items[1] = new CacheItem(new Order());
 /// items[1].SlidingExpiration = new TimeSpan(0,5,0);
 /// items[1].Priority = CacheItemPriority.Low;
 /// items[1].ItemRemoveCallback = onRemove;
 /// </code>
 ///
 /// Then add CacheItem to the cache
 /// <code>
 ///
 ///	NCache.Cache.Add(keys, items, "Customer", "Orders");
 ///
 ///	Cache.Add(keys, items, "Customer", "Orders");
 ///
 /// </code>
 /// </example>
 public virtual IDictionary Add(string[] keys, CacheItem[] items,
                                short onDataSourceItemsAdded, string providerName, long[] sizes,
                                string clientId, short updateCallbackId, short removeCallbackId,
                                EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter, bool returnVersions,
                                out IDictionary itemVersions, CallbackType callbackType = CallbackType.PushBasedNotification)
 {
     itemVersions = null;
     return(null);
 }
Пример #31
0
 public RegisterNotificationCommand(NotificationsType notifMask, EventDataFilter datafilter, short sequenceNumber)
 {
     base.name = "RegisterNotificationCommand";
     _registerNotificationCommand            = new Alachisoft.NCache.Common.Protobuf.RegisterNotifCommand();
     _registerNotificationCommand.notifMask  = (int)notifMask;
     _registerNotificationCommand.requestId  = base.RequestId;
     _registerNotificationCommand.datafilter = (int)datafilter;
     _registerNotificationCommand.sequence   = sequenceNumber;
 }
Пример #32
0
        public CallbackInfo(string client, object callback, EventDataFilter datafilter, bool notifyOnItemExpiration, CallbackType callbackType = CallbackType.PushBasedNotification)

        {
            this.theClient              = client;
            this.theCallback            = callback;
            this.notifyOnItemExpiration = notifyOnItemExpiration;
            this._dataFilter            = datafilter;
            this._callbackType          = callbackType;
        }
Пример #33
0
        public EventDataFilter GetDataFilter(string serverUID, string clientID, QueryChangeType type)
        {
            HashVector      clientDF   = null;
            EventDataFilter datafilter = EventDataFilter.None;

            if (type == QueryChangeType.Add)
            {
                if (maxAddDFAgainstCID.ContainsKey(serverUID))
                {
                    clientDF = maxAddDFAgainstCID[serverUID] as HashVector;
                    if (clientDF.ContainsKey(clientID))
                    {
                        datafilter = (EventDataFilter)clientDF[clientID];
                    }
                    return(datafilter);
                }
                else
                {
                    return(EventDataFilter.None);
                }
            }
            else if (type == QueryChangeType.Update)
            {
                if (maxUpdateDFAgainstCID.ContainsKey(serverUID))
                {
                    clientDF = maxUpdateDFAgainstCID[serverUID] as HashVector;

                    if (clientDF.ContainsKey(clientID))
                    {
                        datafilter = (EventDataFilter)clientDF[clientID];
                    }
                    return(datafilter);
                }
                else
                {
                    return(EventDataFilter.None);
                }
            }
            else
            {
                if (maxRemoveDFAgainstCID.ContainsKey(serverUID))
                {
                    clientDF = maxRemoveDFAgainstCID[serverUID] as HashVector;

                    if (clientDF.ContainsKey(clientID))
                    {
                        datafilter = (EventDataFilter)clientDF[clientID];
                    }
                    return(datafilter);
                }
                else
                {
                    return(EventDataFilter.None);
                }
            }
        }
Пример #34
0
 public virtual object Add(string key, object value, CacheDependency dependency,
                           CacheSyncDependency syncDependency, DateTime absoluteExpiration,
                           TimeSpan slidingExpiration, CacheItemPriority priority, short onRemoveCallback, short onUpdateCallback,
                           short onDsItemAddedCallback, bool isResyncExpiredItems,
                           string group, string subGroup, Hashtable queryInfo, BitSet flagMap, string providerName,
                           string resyncProviderName, EventDataFilter updateCallbackFilter,
                           EventDataFilter removeCallabackFilter, long size, string clientId)
 {
     return(null);
 }
Пример #35
0
 public ItemUpdateCallbackTask(Broker parent, string key, short callBackId, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem, BitSet flag,EventDataFilter dataFilter)
 {
     this._parent = parent;
     this._key = key;
     this._callBackId = callBackId;
     this._notifyAsync = notifyAsync;
     this._item = item;
     this._oldItem = oldItem;
     this._flag = flag;
     this._dataFilter = dataFilter;
 }
Пример #36
0
 internal ItemRemoveCallback(short id, string key, object value, ItemRemoveReason reason, string clientId, BitSet Flag, EventContext eventContext,EventDataFilter dataFilter)
 {
     _id = id;
     _key = key;
     _value = value as UserBinaryObject;
     _flag = Flag;
     _reason = reason;
     _clientID = clientId;
     _eventContext = eventContext;
     _dataFilter = dataFilter;
 }
Пример #37
0
 public ItemUpdateCallbackTask(Broker parent, string key, short callBackId, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem, BitSet flag, EventDataFilter dataFilter)
 {
     this._parent      = parent;
     this._key         = key;
     this._callBackId  = callBackId;
     this._notifyAsync = notifyAsync;
     this._item        = item;
     this._oldItem     = oldItem;
     this._flag        = flag;
     this._dataFilter  = dataFilter;
 }
Пример #38
0
 public virtual CacheItemVersion Insert(string key, object value, CacheDependency dependency,
                                        CacheSyncDependency syncDependency, DateTime absoluteExpiration,
                                        TimeSpan slidingExpiration, CacheItemPriority priority, short onRemoveCallback, short onUpdateCallback,
                                        short onDsItemUpdatedCallback, bool isResyncExpiredItems,
                                        string group, string subGroup, Hashtable queryInfo, BitSet flagMap, object lockId, CacheItemVersion version,
                                        LockAccessType accessType, string providerName,
                                        string resyncProviderName, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter,
                                        long size, string clientId, CallbackType callbackType = CallbackType.PushBasedNotification)
 {
     return(null);
 }
Пример #39
0
 internal ItemRemoveCallback(short id, string key, object value, ItemRemoveReason reason, string clientId, BitSet Flag, EventContext eventContext, EventDataFilter dataFilter)
 {
     _id           = id;
     _key          = key;
     _value        = value as UserBinaryObject;
     _flag         = Flag;
     _reason       = reason;
     _clientID     = clientId;
     _eventContext = eventContext;
     _dataFilter   = dataFilter;
 }
Пример #40
0
 public ItemRemoveCallBackTask(Broker parent, string key, short callBackId, object value, CacheItemRemovedReason reason, BitSet flag, bool notifyAsync, EventCacheItem item,EventDataFilter dataFilter)
 {
     this._parent = parent;
     this._key = key;
     this._callBackId = callBackId;
     this._value = value;
     this._reason = reason;
     this._flag = flag;
     this._notifyAsync = notifyAsync;
     this._item = item;
     this._dataFilter = dataFilter;
 }
Пример #41
0
 /// <summary>
 /// Creates a CallBackEntry.
 /// </summary>
 /// <param name="clientid"></param>
 /// <param name="reqId"></param>
 /// <param name="value">Actual data</param>
 /// <param name="onCacheItemRemovedCallback">OnCacheItemRemovedCallback</param>
 /// <param name="onCacheItemUpdateCallback">OnCacheItemUpdateCallback</param>
 /// <param name="updateDatafilter"></param>
 /// <param name="removeDatafilter"></param>
 /// <param name="callerid">Caller id i.e. Clietn application id</param>
 public CallbackEntry(string clientid, int reqId, object value, short onCacheItemRemovedCallback, short onCacheItemUpdateCallback, EventDataFilter updateDatafilter, EventDataFilter removeDatafilter)
 {
     _value = value;
     if (onCacheItemUpdateCallback != -1)
     {
         _itemUpdateListener.Add(new CallbackInfo(clientid, onCacheItemUpdateCallback, updateDatafilter));
     }
     if (onCacheItemRemovedCallback != -1)
     {
         _itemRemovedListener.Add(new CallbackInfo(clientid, onCacheItemRemovedCallback, removeDatafilter));
     }
 }
Пример #42
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>
        /// <param name="eventhandle"></param>
        internal void RaiseSelectiveCacheNotification(string key, EventType eventType, EventCacheItem item, EventCacheItem oldItem, CacheItemRemovedReason reason, bool _notifyAsync, EventHandle eventhandle,EventDataFilter dataFilter)
        {
            try
            {
                ResourcePool poolID = null;

                CacheEventArg arg = null;

                if ((eventType & EventType.ItemUpdated) != 0)
                {
                    poolID = _selectiveUpdateEventIDPool;
                }
                else if ((eventType & EventType.ItemRemoved) != 0)
                {
                    poolID = _selectiveRemoveEventIDPool;
                }

                arg = CreateCacheEventArgument(dataFilter, key, _cacheName, eventType, item, oldItem, reason);

                if (poolID == null)
                    return;

                CacheDataNotificationCallback callback = poolID.GetResource((short)eventhandle.Handle) as CacheDataNotificationCallback;

                if (callback == null) //Can occur if Unregistered concurrently
                    return;

                if (_notifyAsync)
                    System.Threading.ThreadPool.QueueUserWorkItem(waitC, new object[] { callback, key, arg}); //Faster and better
                else
                    callback.Invoke(key, arg);
            }
            catch (Exception ex)
            {
                if (_logger != null && _logger.IsErrorEnabled) _logger.CriticalInfo(ex.ToString());
            }
        }
Пример #43
0
 public void OnCustomUpdateCallback(short callbackId, string key, bool notifyAsync, EventCacheItem item, EventCacheItem oldItem, BitSet flag,EventDataFilter dataFilter)
 {
     CallbackInfo cbInfo = new CallbackInfo(null, callbackId,dataFilter);
     _listener.OnCustomUpdateCallback(key, cbInfo, notifyAsync, item, oldItem, flag);
 }
Пример #44
0
 internal virtual CacheEventDescriptor RegisterCacheNotificationInternal(string key, CacheDataNotificationCallback callback, EventType eventType, EventDataFilter datafilter, bool notifyOnItemExpiration)
 {
     if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");
     CacheEventDescriptor discriptor = null;
     try
     {
         if (key != null)
         {
             short[] callbackRefs = _eventManager.RegisterSelectiveEvent(callback, eventType, datafilter);
             _cacheImpl.RegisterKeyNotificationCallback(key, callbackRefs[0], callbackRefs[1], datafilter, notifyOnItemExpiration);
         }
     }
     catch (Exception)
     {
         if (ExceptionsEnabled) throw;
     }
     return discriptor;
 }
Пример #45
0
        /// <summary>
        /// Registers ItemUpdate or ItemRemoved events with cache
        /// </summary>
        /// <remarks>
        /// Client application can show interest in receiving events if an item is update or removed from the cache.
        /// As soon as the item is updated or removed from the cache, the client application is notified
        /// and actions can be taken accordingly.
        /// </remarks>
        /// <param name="cacheDataNotificationCallback">the CacheDataNotificationCallback that is invoked when an item is added, updated or removed from the cache.</param>
        /// <param name="eventType">Tells whether the event is to be raised on Item Added, Updated or Removed</param>
        /// <param name="datafilter">Tells whether to receive metadata, data with metadata or none when a notification is triggered</param>
        /// <example>
        /// First create an ItemCallback
        /// <code>
        /// ItemCallback(string key, CacheEventArg e)
        /// {
        ///    ...
        /// }
        /// </code>
        /// Then register the Cache Notification
        /// <code>
        /// Cache cache = NCache.InitializeCache("myCache");
        /// CacheEventDescriptor descriptor=cache.RegisterCacheNotification(new CacheDataNotificationCallback(ItemCallback), EventType.ItemAdded, EventDataFilter.None);
        /// 
        /// </code>
        /// </example>
        internal virtual CacheEventDescriptor RegisterCacheNotification(CacheDataNotificationCallback cacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)
        {
            if (cacheDataNotificationCallback == null)
                throw new ArgumentException("cacheDataNotificationCallback");

            return RegisterCacheNotificationInternal(null, cacheDataNotificationCallback, eventType, datafilter, true);
        }
Пример #46
0
        /// <summary>
        /// Function that choose the appropriate function of NCache's Cache, that need to be called
        /// according to the data provided to it.</summary>
        internal virtual void InsertOperation(string key, object value, DateTime absoluteExpiration,
            TimeSpan slidingExpiration, CacheItemPriority priority,
            LockHandle lockHandle, LockAccessType accessType, CacheDataNotificationCallback cacheItemUdpatedCallback,
            CacheDataNotificationCallback cacheItemRemovedCallaback, EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, ref long size, bool allowQueryTags)
        {
            if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");

            ValidateKeyValue(key, value);
            UsageStats stats = new UsageStats();
            stats.BeginSample();
            Hashtable queryInfo = new Hashtable();
            object lockId = (lockHandle == null) ? null : lockHandle.LockId;

            if (allowQueryTags)
            {
                queryInfo["query-info"] = GetQueryInfo(value);
            }
            short removeCallbackId = -1;
            short updateCallbackId = -1;
            short dsItemUpdateCallbackId = -1;

            BitSet flagMap = new BitSet();
            try
            {
                value = SafeSerialize(value, _serializationContext, ref flagMap, ref size);

                long objectSize = 0;
                if (DebugAPIConfiguraions.LoggingEnabled)
                    objectSize = value is byte[] ? ((byte[])value).Length : 0;
                if (_perfStatsCollector != null && value != null && value is byte[])
                    _perfStatsCollector.IncrementAvgItemSize(((byte[])value).Length);

                if (cacheItemRemovedCallaback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemRemovedCallaback, EventType.ItemRemoved, itemRemovedDataFilter);
                    removeCallbackId = callabackIds[1];
                }

                if (cacheItemUdpatedCallback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemUdpatedCallback, EventType.ItemUpdated, itemUpdateDataFilter);
                    updateCallbackId = callabackIds[0];
                }

                if (lockId != null && ((string)lockId) != string.Empty)
                    flagMap.SetBit(BitSetConstants.LockedItem);
                else
                    flagMap.UnsetBit(BitSetConstants.LockedItem);

                absoluteExpiration = ToUTC(absoluteExpiration);

                _cacheImpl.Insert(key, value, absoluteExpiration, slidingExpiration, priority, removeCallbackId, updateCallbackId, queryInfo, flagMap, lockId, accessType, itemUpdateDataFilter, itemRemovedDataFilter, size);

                if (_perfStatsCollector != null)
                {
                    stats.EndSample();
                    _perfStatsCollector.IncrementMsecPerUpdSample(stats.Current);
                    _perfStatsCollector.IncrementUpdPerSecStats();
                }
            }
            catch (Exception)
            {
                if (ExceptionsEnabled) throw;
            }
        }
Пример #47
0
        /// <summary>
        /// Function that choose the appropriate function of NCache's Cache, that need to be called
        /// according to the data provided to it.</summary>
        internal virtual object AddOperation(string key, object value, DateTime absoluteExpiration,
            TimeSpan slidingExpiration, CacheItemPriority priority, 
            
            CacheDataNotificationCallback cacheItemUdpatedCallback, CacheDataNotificationCallback cacheItemRemovedCallaback,
            EventDataFilter itemUpdateDataFilter, EventDataFilter itemRemovedDataFilter, ref long size, bool allowQueryTags)
        {
            if (_cacheImpl == null) throw new OperationFailedException("Cache is not initialized");
            ValidateKeyValue(key, value);
            UsageStats stats = new UsageStats();
            stats.BeginSample();

            Hashtable queryInfo = new Hashtable();
            if (allowQueryTags)
            {
                queryInfo["query-info"] = GetQueryInfo(value);
            }
            BitSet flagMap = new BitSet();
            try
            {
                long objectSize = 0;
                value = SafeSerialize(value, _serializationContext, ref flagMap, ref size);

                if (DebugAPIConfiguraions.LoggingEnabled)
                    objectSize = value is byte[] ? ((byte[])value).Length : 0;
                if (_perfStatsCollector != null && value != null && value is byte[])
                    _perfStatsCollector.IncrementAvgItemSize(((byte[])value).Length);
                if (DebugAPIConfiguraions.LoggingEnabled)
                {
                    LogSizeInfo(false, objectSize);
                }

                short removeCallbackID = -1;
                short updateCallbackID = -1;
                if (cacheItemRemovedCallaback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemRemovedCallaback, EventType.ItemRemoved, itemRemovedDataFilter);
                    removeCallbackID = callabackIds[1];
                }

                if (cacheItemUdpatedCallback != null)
                {
                    short[] callabackIds = _eventManager.RegisterSelectiveEvent(cacheItemUdpatedCallback, EventType.ItemUpdated, itemUpdateDataFilter);
                    updateCallbackID = callabackIds[0];
                }

                absoluteExpiration = ToUTC(absoluteExpiration);

                _cacheImpl.Add(key, value, absoluteExpiration, slidingExpiration, priority, removeCallbackID, updateCallbackID, queryInfo, flagMap, itemUpdateDataFilter, itemRemovedDataFilter, size);

                if (_perfStatsCollector != null)
                {
                    stats.EndSample();
                    _perfStatsCollector.IncrementMsecPerAddSample(stats.Current);
                    _perfStatsCollector.IncrementAddPerSecStats();
                }
                return value;
            }
            catch (Exception)
            {
                if (ExceptionsEnabled) throw;
            }
            return null;
        }
Пример #48
0
 //Creation is CacheDesriptor's responsiblity
 internal static CacheEventDescriptor CreateCacheDiscriptor(EventType eventType, string cacheName, CacheDataNotificationCallback callback, EventDataFilter datafilter)
 {
     CacheEventDescriptor descriptor = new CacheEventDescriptor();
     descriptor.RegisteredAgainst = eventType;
     descriptor.CacheName = cacheName;
     descriptor.CacheDataNotificationCallback = callback;
     descriptor.IsRegistered = true;
     descriptor.DataFilter = datafilter;
     return descriptor;
 }
Пример #49
0
        /// <summary>
        /// You can use this to notify applications when their objects are updated or removed in the cache.
        /// Callbacks can be registered against <see cref=" EventType"/> for the key the items is inserted to.
        /// To register different <see cref="EventDataFilter"/> for different <see cref="EventType"/>, you can call this function mutiple times 
        /// with a different <see cref="EventType"/>.
        /// Callback are overriden for the same <see cref="EventType"/> if called again.
        /// <see cref="EventType.ItemAdded"/> is not supported yet.
        /// </summary>
        /// <param name="callback">Callback to be raised when an item is updated or removed</param>
        /// <param name="eventType"><see cref="EventType"/> the callback is registered against</param>
        /// <param name="datafilter"><see cref="EventDataFilter"/> for every <see cref="EventType"/> registered against</param>
        public void SetCacheDataNotification(CacheDataNotificationCallback callback, EventType eventType)
        {
            EventDataFilter datafilter = EventDataFilter.None;
            if (callback == null) return;

            if ((eventType & EventType.ItemRemoved) != 0)
            {
                _cacheItemRemovedCallback = callback;
                _itemRemovedDataFilter = datafilter;
            }

            if ((eventType & EventType.ItemUpdated) != 0)
            {
                _cacheItemUpdateCallback = callback;
                _itemUpdatedDataFilter = datafilter;
            }
        }
Пример #50
0
        public override void RegisterKeyNotificationCallback(string key, short update, short remove, EventDataFilter datafilter, bool notifyOnItemExpiration)
        {
            CommandBase command = new RegisterKeyNotificationCommand(key, update, remove, datafilter, notifyOnItemExpiration);

            Request request = _broker.CreateRequest(command);
            _broker.ExecuteRequest(request);

            CommandResponse res = request.Response;
            res.ParseResponse();
        }
Пример #51
0
 public EventRegistrationInfo(EventType eventTYpe,EventDataFilter filter,short sequenceId)
 {
     _eventType = eventTYpe;
     _filter = filter;
     _registrationSequence = sequenceId;
 }
Пример #52
0
 public void OnCustomRemoveCallback(short callbackId, string key, object value, CacheItemRemovedReason reason, BitSet Flag, bool notifyAsync, EventCacheItem item,EventDataFilter dataFilter)
 {
     object[] val = new object[] { value, new CallbackInfo(null, callbackId,dataFilter) };
     _listener.OnCustomRemoveCallback(key, val, reason, Flag, notifyAsync, item);
 }
Пример #53
0
        /// <summary>
        /// Function that choose the appropriate function of NCache's Cache, that need to be called
        /// according to the data provided to it.</summary>
        public override void Insert(string key, object value,  DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short onRemoveCallback,
            short onUpdateCallback, Hashtable queryInfo, BitSet flagMap, 
            object lockId,LockAccessType accessType, EventDataFilter updateCallbackFilter, 
            EventDataFilter removeCallabackFilter, long size)
        {

            Hashtable queryInfoDic = queryInfo["query-info"] as Hashtable;
            if (queryInfoDic != null)
            {
                IDictionaryEnumerator queryInfoEnum = queryInfoDic.GetEnumerator();
                while (queryInfoEnum.MoveNext())
                {
                    ArrayList valuesEnum = (ArrayList)queryInfoEnum.Value;
                    for (int i = 0; i < valuesEnum.Count; i++)
                    {
                        if (valuesEnum[i] is DateTime)
                        {
                            valuesEnum[i] = ((DateTime)valuesEnum[i]).Ticks.ToString();
                        }
                    }
                }
            }

            object entry = MakeCompactEntry(key, value, absoluteExpiration, slidingExpiration,
                priority, onRemoveCallback, onUpdateCallback, queryInfo, flagMap, lockId, accessType, updateCallbackFilter, removeCallabackFilter);

				OperationContext operationContext = new OperationContext(OperationContextFieldName.OperationType, OperationContextOperationType.CacheOperation);
            operationContext.Add(OperationContextFieldName.ValueDataSize, size);

            _nCache.InsertEntry(entry, operationContext);
        }
Пример #54
0
 public void AddItemRemoveCallback(string clientid, object callback, EventDataFilter datafilter)
 {
     AddItemRemoveCallback(new CallbackInfo(clientid, callback, datafilter));
 }
Пример #55
0
        /// <summary>
        /// Registeres the callback sepeartely and returns short values of registeredCallbacks
        /// </summary>
        /// <param name="key"></param>
        /// <param name="callback"></param>
        /// <param name="eventType"></param>
        /// <param name="datafilter"></param>
        /// <returns>short array,<para>1st element is updated callbackRef</para><para>2st element is removed callbackRef</para></returns>
        internal short[] RegisterSelectiveEvent(CacheDataNotificationCallback callback, EventType eventType, EventDataFilter datafilter)
        {
            if (callback != null)
            {

                if (_selectiveUpdateEventPool == null)
                {
                    _selectiveUpdateEventPool = new ResourcePool();
                    _selectiveUpdateEventIDPool = new ResourcePool();
                }
                if (_selectiveRemoveEventPool == null)
                {
                    _selectiveRemoveEventPool = new ResourcePool();
                    _selectiveRemoveEventIDPool = new ResourcePool();
                }

                return RegisterSelectiveDiscriptor(callback, eventType);

            }
            else
                return null;
        }
Пример #56
0
        /// <summary>
        /// Registers the ItemUpdate or ItemRemoved events for the specified key.
        /// </summary>
        /// <param name="key">The cache key used to reference the cache item.</param>
        /// <param name="selectiveCacheDataNotificationCallback">The CacheDataNotificationCallback that is invoked when an item is added, updated or removed from the cache.</param>
        /// <param name="eventType">Tells whether the event is to be raised on Item Added, Updated or Removed</param>
        /// <param name="datafilter">Tells whether to receive metadata, data with metadata or none when a notification is triggered</param>
        /// <example>
        /// First create an ItemCallback
        /// <code>
        /// ItemCallback(string key, CacheEventArg e)
        /// {
        ///    ...
        /// }
        /// </code>
        /// Then register the Key Notification
        /// <code>
        /// Cache cache = NCache.InitializeCache("myCache");
        /// cache.RegisterCacheNotification(key, new CacheDataNotificationCallback(ItemCallback), EventType.ItemUpdated, EventDataFilter.None);
        /// 
        /// </code>
        /// </example>
        public virtual void RegisterCacheNotification(string key, CacheDataNotificationCallback selectiveCacheDataNotificationCallback, EventType eventType, EventDataFilter datafilter)
        {
            if (key == null || key.Length == 0)
                throw new ArgumentNullException("key");

            if (selectiveCacheDataNotificationCallback == null)
                throw new ArgumentException("selectiveCacheDataNotificationCallback");

            RegisterCacheNotificationInternal(key, selectiveCacheDataNotificationCallback, eventType, datafilter, true);
        }
Пример #57
0
        private CacheEventArg CreateCacheEventArgument(EventDataFilter dataFilter, string key,string cacheName,EventType eventType,EventCacheItem item,EventCacheItem oldItem,CacheItemRemovedReason removedReason)
        {
            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;
            }

            CacheEventArg eventArg = new CacheEventArg(key, cacheName, eventType, cloneItem, null, removedReason);
            if (eventType == EventType.ItemUpdated) eventArg.OldItem = cloneOldItem;

            return eventArg;
        }
Пример #58
0
        internal static ItemUpdatedCallbackResponse GetItemUpdatedCallbackResponse(EventContext eventContext, string key, short callbackid, EventDataFilter dataFilter)
        {
            Alachisoft.NCache.Common.Protobuf.ItemUpdatedCallbackResponse itemUpdatedCallback = new Alachisoft.NCache.Common.Protobuf.ItemUpdatedCallbackResponse();

            itemUpdatedCallback.key = key;
            itemUpdatedCallback.callbackId = callbackid;
            itemUpdatedCallback.dataFilter = (short)dataFilter;
            itemUpdatedCallback.eventId = new Common.Protobuf.EventId();
            if (eventContext != null)
            {
                itemUpdatedCallback.eventId.eventUniqueId = eventContext.EventID.EventUniqueID;
                itemUpdatedCallback.eventId.operationCounter = eventContext.EventID.OperationCounter;
                itemUpdatedCallback.eventId.eventCounter = eventContext.EventID.EventCounter;

                itemUpdatedCallback.eventId.item = ConvertToEventItem(eventContext.Item, dataFilter);
                itemUpdatedCallback.eventId.oldItem = ConvertToEventItem(eventContext.OldItem, dataFilter);
            }

            return itemUpdatedCallback;
        }
Пример #59
0
        /// <summary>
        /// Create a CompactEntry object
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="absoluteExpiration"></param>
        /// <param name="slidingExpiration"></param>
        /// <param name="priority"></param>
        /// <param name="onRemoveCallback"></param>
        /// <returns></returns>
        private object MakeCompactEntry(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short onRemoveCallback, short onUpdateCallback, Hashtable queryInfo, BitSet Flag, object lockId, LockAccessType accessType, EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter)
        {
            //we create a user binary object.
            if (this.SerializationEnabled)
            {
                value = UserBinaryObject.CreateUserBinaryObject((byte[])value); 
            }

            if ((short)onRemoveCallback != -1 || (short)onUpdateCallback != -1 )
                value = new CallbackEntry(ClientID, -1, value, onRemoveCallback, onUpdateCallback, Flag, updateCallbackFilter, removeCallabackFilter);
            ////muds:
            ////we can not specify both tags and groups for the same cache item.
            //WebCacheHelper.EvaluateTagsParameters(queryInfo, group);

            byte expType = WebCacheHelper.EvaluateExpirationParameters(absoluteExpiration, slidingExpiration);
            int options = 0;

            if (expType < 2)
            {
                options = expType;
            }

            int prio = Convert.ToInt32(priority);
            prio += 2;
            prio = (prio << 2);
            options = options | prio;

            long expiration = expType == 1 ? absoluteExpiration.Ticks : slidingExpiration.Ticks;

            ExpirationHint hint =  null;

            object entry = new CompactCacheEntry(key, value, hint, 
                                                 expiration, (byte)options, null, queryInfo, Flag, lockId, accessType);
            return entry;
        }
Пример #60
0
        public override void Insert(string key, object value, DateTime absoluteExpiration, TimeSpan slidingExpiration, CacheItemPriority priority, short onRemoveCallback, short onUpdateCallback, 
            Hashtable queryInfo, BitSet flagMap, object lockId, LockAccessType accessType, 
            EventDataFilter updateCallbackFilter, EventDataFilter removeCallabackFilter, long size)
        {
            InsertCommand command = new InsertCommand(key,
                (byte[])value,
                absoluteExpiration,
                slidingExpiration,
                priority,
                onRemoveCallback,
                onUpdateCallback,
                queryInfo,
                flagMap,
                lockId,
                accessType,
                CacheId, updateCallbackFilter, removeCallabackFilter);

            Request request = _broker.CreateRequest(command);
            _broker.ExecuteRequest(request);

            CommandResponse res = request.Response;
            res.ParseResponse();
        }