本文整理汇总了C#中EventContext.Add方法的典型用法代码示例。如果您正苦于以下问题:C# EventContext.Add方法的具体用法?C# EventContext.Add怎么用?C# EventContext.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventContext
的用法示例。
在下文中一共展示了EventContext.Add方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove
/// <summary>
/// Removes the object and key pair from the cache. The key is specified as parameter.
/// Moreover it take a removal reason and a boolean specifying if a notification should
/// be raised.
/// </summary>
/// <param name="key">key of the entry.</param>
/// <param name="removalReason">reason for the removal.</param>
/// <param name="notify">boolean specifying to raise the event.</param>
/// <param name="isUserOperation"></param>
/// <param name="lockId"></param>
/// <param name="accessType"></param>
/// <param name="operationContext"></param>
/// <returns>item value</returns>
public override CacheEntry Remove(object key, ItemRemoveReason removalReason, bool notify, bool isUserOperation, object lockId, LockAccessType accessType, OperationContext operationContext)
{
CacheEntry e = null;
CacheEntry pe = null;
{
object actualKey = key;
if (key is object[])
{
actualKey = ((object[])key)[0];
}
if (accessType != LockAccessType.IGNORE_LOCK)
{
pe = GetInternal(actualKey, false, operationContext);
if (pe != null)
{
if (pe.IsItemLocked() && !pe.CompareLock(lockId))
{
throw new LockingException("Item is locked.");
}
}
}
e = RemoveInternal(actualKey, removalReason, isUserOperation, operationContext);
EventId eventId = null;
EventContext eventContext = null;
OperationID opId = operationContext.OperatoinID;
if (e != null)
{
if (_stateTransferKeyList != null && _stateTransferKeyList.ContainsKey(key))
_stateTransferKeyList.Remove(key);
// commented by muds
try
{
if (e.ExpirationHint != null)
{
_context.ExpiryMgr.RemoveFromIndex(key);
((IDisposable)e.ExpirationHint).Dispose();
}
}
catch (Exception ex)
{
NCacheLog.Error("LocalCacheBase.Remove(object, ItemRemovedReason, bool):", ex.ToString());
}
if (IsSelfInternal)
{
// Disposed the one and only cache entry.
((IDisposable)e).Dispose();
if (removalReason == ItemRemoveReason.Expired)
{
_context.PerfStatsColl.IncrementExpiryPerSecStats();
}
else if (!_context.CacheImpl.IsEvictionAllowed && removalReason == ItemRemoveReason.Underused)
{
_context.PerfStatsColl.IncrementEvictPerSecStats();
}
_context.PerfStatsColl.IncrementCountStats((long)Count);
}
if (notify)
{
CallbackEntry cbEtnry = e.Value as CallbackEntry;// e.DeflattedValue(_context.SerializationContext);
if (cbEtnry != null && cbEtnry.ItemRemoveCallbackListener != null && cbEtnry.ItemRemoveCallbackListener.Count > 0)
{
//generate event id
if (!operationContext.Contains(OperationContextFieldName.EventContext)) //for atomic operations
{
eventId = EventId.CreateEventId(opId);
}
else //for bulk
{
eventId = ((EventContext)operationContext.GetValueByField(OperationContextFieldName.EventContext)).EventID;
}
eventId.EventType = EventType.ITEM_REMOVED_CALLBACK;
eventContext = new EventContext();
eventContext.Add(EventContextFieldName.EventID, eventId);
EventCacheEntry eventCacheEntry = CacheHelper.CreateCacheEventEntry(cbEtnry.ItemRemoveCallbackListener, e);
eventContext.Item = eventCacheEntry;
eventContext.Add(EventContextFieldName.ItemRemoveCallbackList, cbEtnry.ItemRemoveCallbackListener.Clone());
//Will always reaise the whole entry for old clients
NotifyCustomRemoveCallback(actualKey, e, removalReason, false, (OperationContext)operationContext.Clone(), eventContext);
//.........这里部分代码省略.........
示例2: Insert
//.........这里部分代码省略.........
if ((result.Result == CacheInsResult.Success || result.Result == CacheInsResult.SuccessNearEvicition) && _stateTransferKeyList != null &&
_stateTransferKeyList.ContainsKey(key))
{
result.Result = result.Result == CacheInsResult.Success ? CacheInsResult.SuccessOverwrite : CacheInsResult.SuccessOverwriteNearEviction;
}
// Not enough space, evict and try again.
if (result.Result == CacheInsResult.NeedsEviction || result.Result == CacheInsResult.SuccessNearEvicition
|| result.Result == CacheInsResult.SuccessOverwriteNearEviction)
{
Evict();
if (result.Result == CacheInsResult.SuccessNearEvicition) result.Result = CacheInsResult.Success;
if (result.Result == CacheInsResult.SuccessOverwriteNearEviction) result.Result = CacheInsResult.SuccessOverwrite;
}
// Operation completed!
if (result.Result == CacheInsResult.Success || result.Result == CacheInsResult.SuccessOverwrite)
{
// commented by muds
//remove the old hint from expiry index.
if (peExh != null)
_context.ExpiryMgr.RemoveFromIndex(key);
if (cacheEntry.ExpirationHint != null)
{
cacheEntry.ExpirationHint.CacheKey = (string)key;
if (isUserOperation)
{
try
{
_context.ExpiryMgr.ResetHint(peExh, cacheEntry.ExpirationHint);
}
catch (Exception e)
{
RemoveInternal(key, ItemRemoveReason.Removed, false, operationContext);
throw e;
}
}
else
{
cacheEntry.ExpirationHint.ReInitializeHint(Context);
}
_context.ExpiryMgr.UpdateIndex(key, cacheEntry);
}
if (IsSelfInternal)
{
_context.PerfStatsColl.IncrementCountStats((long)Count);
}
}
_stats.UpdateCount(this.Count);
switch (result.Result)
{
case CacheInsResult.Success:
break;
case CacheInsResult.SuccessOverwrite:
if (notify)
{
EventCacheEntry eventCacheEntry = CacheHelper.CreateCacheEventEntry(Runtime.Events.EventDataFilter.DataWithMetadata, cacheEntry); ;
EventCacheEntry oldEventCacheEntry = CacheHelper.CreateCacheEventEntry(Runtime.Events.EventDataFilter.DataWithMetadata, pe);
if (cbEtnry != null)
{
if (cbEtnry.ItemUpdateCallbackListener != null && cbEtnry.ItemUpdateCallbackListener.Count > 0)
{
if (!operationContext.Contains(OperationContextFieldName.EventContext)) //for atomic operations
{
eventId = EventId.CreateEventId(opId);
eventContext = new EventContext();
}
else //for bulk
{
eventId = ((EventContext)operationContext.GetValueByField(OperationContextFieldName.EventContext)).EventID;
}
eventContext = new EventContext();
eventId.EventType = EventType.ITEM_UPDATED_CALLBACK;
eventContext.Add(EventContextFieldName.EventID, eventId);
eventContext.Item = eventCacheEntry;
eventContext.OldItem = oldEventCacheEntry;
NotifyCustomUpdateCallback(key, cbEtnry.ItemUpdateCallbackListener, false, (OperationContext)operationContext.Clone(), eventContext);
}
}
}
break;
}
}
finally
{
}
if (_context.PerfStatsColl != null)
{
_context.PerfStatsColl.SetCacheSize(Size);
}
return result;
}
示例3: Add
/// <summary>
/// Adds key and value pairs to the cache. Throws an exception or returns the
/// list of keys that failed to add in the cache.
/// </summary>
/// <param name="keys">keys of the entries.</param>
/// <param name="cacheEntries">the cache entries.</param>
/// <returns>List of keys that are added or that alredy exists in the cache and their status.</returns>
public sealed override Hashtable Add(object[] keys, CacheEntry[] cacheEntries, bool notify, OperationContext operationContext)
{
Hashtable table = new Hashtable();
EventContext eventContext = null;
EventId eventId = null;
OperationID opId = operationContext.OperatoinID;
for (int i = 0; i < keys.Length; i++)
{
try
{
operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
if (notify)
{
//generate EventId
eventId = new EventId();
eventId.EventUniqueID = opId.OperationId;
eventId.OperationCounter = opId.OpCounter;
eventId.EventCounter = i;
eventContext = new EventContext();
eventContext.Add(EventContextFieldName.EventID, eventId);
operationContext.Add(OperationContextFieldName.EventContext, eventContext);
}
CacheAddResult result = Add(keys[i], cacheEntries[i], notify, operationContext);
table[keys[i]] = result;
}
catch (Exceptions.StateTransferException se)
{
table[keys[i]] = se;
}
catch (Exception inner)
{
table[keys[i]] = new OperationFailedException(inner.Message, inner);
}
finally
{
operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
}
}
if (_context.PerfStatsColl != null)
{
_context.PerfStatsColl.SetCacheSize(Size);
}
return table;
}
示例4: Get
/// <summary>
/// Retrieve the objects from the cache.
/// An array of keys is passed as parameter.
/// </summary>
/// <param name="keys">keys of the entries.</param>
/// <returns>key and entry pairs.</returns>
public sealed override Hashtable Get(object[] keys, OperationContext operationContext)
{
Hashtable entries = new Hashtable();
CacheEntry e = null;
for (int i = 0; i < keys.Length; i++)
{
try
{
if(operationContext != null)
{
operationContext.RemoveValueByField(OperationContextFieldName.EventContext);
OperationID opId = operationContext.OperatoinID;
//generate EventId
EventId eventId = EventId.CreateEventId(opId);
eventId.EventUniqueID = opId.OperationId;
eventId.OperationCounter = opId.OpCounter;
eventId.EventCounter = i;
EventContext eventContext = new EventContext();
eventContext.Add(EventContextFieldName.EventID, eventId);
operationContext.Add(OperationContextFieldName.EventContext, eventContext);
}
e = Get(keys[i], operationContext);
if (e != null)
{
entries[keys[i]] = e;
}
}
catch (StateTransferException se)
{
entries[keys[i]] = se;
}
}
return entries;
}
示例5: RaiseCustomRemoveCalbackNotifier
/// <summary>
/// Reaises the custom item remove call baack.
/// </summary>
/// <param name="key"></param>
/// <param name="cbEntry"></param>
internal void RaiseCustomRemoveCalbackNotifier(object key, CacheEntry cacheEntry, ItemRemoveReason reason, bool async, OperationContext operationContext, EventContext eventContext)
{
ArrayList destinations = null;
ArrayList nodes = null;
Hashtable intendedNotifiers = new Hashtable();
CallbackEntry cbEntry = cacheEntry.Value as CallbackEntry;
if (cbEntry != null && cbEntry.ItemRemoveCallbackListener.Count > 0)
{
if (_stats.Nodes != null)
{
nodes = _stats.Nodes.Clone() as ArrayList;
destinations = new ArrayList();
foreach (CallbackInfo cbInfo in cbEntry.ItemRemoveCallbackListener)
{
if (reason == ItemRemoveReason.Expired && cbInfo != null && !cbInfo.NotifyOnExpiration)
continue;
int index = nodes.IndexOf(new NodeInfo(Cluster.LocalAddress));
if (index != -1 && ((NodeInfo)nodes[index]).ConnectedClients.Contains(cbInfo.Client))
{
if (!destinations.Contains(Cluster.LocalAddress))
{
destinations.Add(Cluster.LocalAddress);
}
intendedNotifiers[cbInfo] = Cluster.LocalAddress;
continue;
}
else
{
foreach (NodeInfo nInfo in nodes)
{
if (nInfo.ConnectedClients != null && nInfo.ConnectedClients.Contains(cbInfo.Client))
{
if (!destinations.Contains(nInfo.Address))
{
destinations.Add(nInfo.Address);
intendedNotifiers[cbInfo] = nInfo.Address;
break;
}
}
}
}
}
}
}
if (destinations != null && destinations.Count > 0)
{
if (operationContext == null) operationContext = new OperationContext();
if (eventContext == null || !eventContext.HasEventID(EventContextOperationType.CacheOperation))
{
eventContext = CreateEventContext(operationContext, Persistence.EventType.ITEM_REMOVED_CALLBACK);
eventContext.Item = CacheHelper.CreateCacheEventEntry(cbEntry.ItemRemoveCallbackListener, cacheEntry);
eventContext.Add(EventContextFieldName.ItemRemoveCallbackList, cbEntry.ItemRemoveCallbackListener.Clone());
}
object[] packed = new object[] { key, reason, intendedNotifiers, operationContext, eventContext };
///Incase of parition, there can be same clients connected
///to multiple server. therefore the destinations list will contain more then
///one servers. so the callback will be sent to the same client through different server
///to avoid this, we will check the list for local server. if client is connected with
///local node, then there is no need to send callback to all other nodes
///if there is no local node, then we select the first node in the list.
RaiseCustomRemoveCalbackNotifier(destinations, packed, async);
}
}
示例6: RemoveSync
public override object RemoveSync(object[] keys, ItemRemoveReason reason, bool notify,
OperationContext operationContext)
{
try
{
Hashtable totalRemovedItems = new Hashtable();
CacheEntry entry = null;
IDictionaryEnumerator ide = null;
if (NCacheLog.IsInfoEnabled)
NCacheLog.Info("PartitionedCache.RemoveSync", "Keys = " + keys.Length.ToString());
for (int i = 0; i < keys.Length; i++)
{
try
{
if (keys[i] != null)
entry = Local_Remove(keys[i], reason, null, null, false, null, LockAccessType.IGNORE_LOCK, operationContext);
if (entry != null)
{
totalRemovedItems.Add(keys[i], entry);
}
}
catch (Exception ex)
{
throw;
}
}
ArrayList keysOfRemoveNotification = new ArrayList();
ArrayList entriesOfRemoveNotification = new ArrayList();
List<EventContext> eventContexts = new List<EventContext>();
int sizeThreshhold = 30*1024;
int countThreshhold = 50;
int size = 0;
ide = totalRemovedItems.GetEnumerator();
while (ide.MoveNext())
{
try
{
entry = ide.Value as CacheEntry;
if (entry != null)
{
if (entry.Value is CallbackEntry)
{
EventId eventId = null;
OperationID opId = operationContext.OperatoinID;
CallbackEntry cbEtnry = (CallbackEntry) entry.Value;
EventContext eventContext = null;
if (cbEtnry != null && cbEtnry.ItemRemoveCallbackListener != null &&
cbEtnry.ItemRemoveCallbackListener.Count > 0)
{
//generate event id
if (!operationContext.Contains(OperationContextFieldName.EventContext))
//for atomic operations
{
eventId = EventId.CreateEventId(opId);
}
else //for bulk
{
eventId =
((EventContext)
operationContext.GetValueByField(OperationContextFieldName.EventContext))
.EventID;
}
eventId.EventType = Alachisoft.NCache.Persistence.EventType.ITEM_REMOVED_CALLBACK;
eventContext = new EventContext();
eventContext.Add(EventContextFieldName.EventID, eventId);
EventCacheEntry eventCacheEntry =
CacheHelper.CreateCacheEventEntry(cbEtnry.ItemRemoveCallbackListener, entry);
eventContext.Item = eventCacheEntry;
eventContext.Add(EventContextFieldName.ItemRemoveCallbackList,
cbEtnry.ItemRemoveCallbackListener.Clone());
RaiseAsyncCustomRemoveCalbackNotifier(ide.Key, entry, reason, operationContext,
eventContext);
}
}
}
}
catch (Exception)
{
}
}
}
catch (Exception)
{
}
return null;
}