本文整理汇总了C#中OperationContext.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# OperationContext.Contains方法的具体用法?C# OperationContext.Contains怎么用?C# OperationContext.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationContext
的用法示例。
在下文中一共展示了OperationContext.Contains方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
/// <summary>
/// Adds a pair of key and value to the cache. If the specified key already exists
/// in the cache; it is updated, otherwise a new item is added to the cache.
/// </summary>
/// <param name="key">key of the entry.</param>
/// <param name="cacheEntry">the cache entry.</param>
/// <returns>returns the result of operation.</returns>
public sealed override CacheInsResultWithEntry Insert(object key, CacheEntry cacheEntry, bool notify, bool isUserOperation, object lockId, LockAccessType access, OperationContext operationContext)
{
CacheInsResultWithEntry result = new CacheInsResultWithEntry();
try
{
CacheEntry pe = null;
CallbackEntry cbEtnry = null;
OperationID opId = operationContext.OperatoinID;
EventId eventId = null;
EventContext eventContext = null;
pe = GetInternal(key, false, operationContext);
result.Entry = pe;
if (pe != null && access != LockAccessType.IGNORE_LOCK)
{
{
if (access == LockAccessType.RELEASE || access == LockAccessType.DONT_RELEASE)
{
if (pe.IsItemLocked() && !pe.CompareLock(lockId))
{
result.Result = CacheInsResult.ItemLocked;
result.Entry = null;
return result;
}
}
if (access == LockAccessType.DONT_RELEASE)
{
cacheEntry.CopyLock(pe.LockId, pe.LockDate, pe.LockExpiration);
}
else
{
cacheEntry.ReleaseLock();
}
}
}
ExpirationHint peExh = pe == null ? null : pe.ExpirationHint;
if (pe != null && pe.Value is CallbackEntry)
{
cbEtnry = pe.Value as CallbackEntry;
cacheEntry = CacheHelper.MergeEntries(pe, cacheEntry);
}
result.Result = InsertInternal(key, cacheEntry, isUserOperation, pe, operationContext);
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);
}
//.........这里部分代码省略.........
示例3: CreateEventContext
protected EventContext CreateEventContext(OperationContext operationContext, Alachisoft.NCache.Persistence.EventType eventType)
{
EventContext eventContext = new EventContext();
OperationID opId = operationContext != null ? operationContext.OperatoinID : null;
//generate event id
if (operationContext == null || !operationContext.Contains(OperationContextFieldName.EventContext)) //for atomic operations
{
eventContext.EventID = EventId.CreateEventId(opId);
}
else //for bulk
{
eventContext.EventID = ((EventContext)operationContext.GetValueByField(OperationContextFieldName.EventContext)).EventID;
}
eventContext.EventID.EventType = eventType;
return eventContext;
}
示例4: GetInternal
internal override CacheEntry GetInternal(object key, bool isUserOperation, OperationContext operationContext)
{
CacheEntry entry = base.GetInternal(key, isUserOperation, operationContext);
if (entry != null)
{
if (operationContext != null)
{
if (operationContext.Contains(OperationContextFieldName.GenerateQueryInfo))
{
if (entry.ObjectType != null)
{
CacheEntry clone = (CacheEntry)entry.Clone();
clone.QueryInfo = _queryIndexManager.GetQueryInfo(key, entry);
return clone;
}
}
}
}
return entry;
}
示例5: 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;
}