当前位置: 首页>>代码示例>>C#>>正文


C# OperationContext.Clone方法代码示例

本文整理汇总了C#中OperationContext.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# OperationContext.Clone方法的具体用法?C# OperationContext.Clone怎么用?C# OperationContext.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OperationContext的用法示例。


在下文中一共展示了OperationContext.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
//.........这里部分代码省略.........
开发者ID:christrotter,项目名称:NCache,代码行数:101,代码来源:LocalCacheBase.cs

示例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;
        }
开发者ID:christrotter,项目名称:NCache,代码行数:101,代码来源:LocalCacheBase.cs


注:本文中的OperationContext.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。