public static CounterCache GetCounterCache(Cache cache, SessionManager manager) { try { if (s_CounterCache.Expired) { lock (s_CounterCache) { if (s_CounterCache.Expired) { s_CounterCache.Flush(manager); } } } } catch(Exception ex) { manager.BlogService.EventLogWriteEntry(string.Format("GetCounterCache failed to flush the cache. {0}", ex.Message), EventLogEntryType.Error); s_CounterCache = new CounterCache(); } return s_CounterCache; }
protected void Page_Load(object sender, EventArgs e) { try { images.OnGetDataSource += new EventHandler(images_OnGetDataSource); comments.OnGetDataSource += new EventHandler(comments_OnGetDataSource); if (!IsPostBack) { PreferredOnly = PreferredOnlyFromQueryString; if (!HasAccess) { Response.Redirect(string.Format("./Login.aspx?r={0}&cookie={1}&access=denied", Renderer.UrlEncode(UrlPathAndQuery), SessionManager.sDBlogPostCookieName)); } if (SessionManager.CountersEnabled) { CounterCache.IncrementPostCounter(Post.Id, Cache, SessionManager); } GetData(sender, e); spanAdmin.Visible = SessionManager.IsAdministrator; linkEdit.NavigateUrl = string.Format("EditPost.aspx?id={0}", Post.Id); } } catch (Exception ex) { ReportException(ex); } }
protected override void OnLoad(EventArgs e) { Response.AddCacheItemDependency("Pages"); if (!Index && Header != null) { HtmlMeta noindex = new HtmlMeta(); noindex.Name = "robots"; noindex.Content = "noindex"; Header.Controls.Add(noindex); } if (!IsPostBack) { if (AutomaticTitle) { Page.Title = string.Format("{0} - {1}", SessionManager.GetSetting( "title", "Blog"), Page.Title); } if (SessionManager.CountersEnabled) { CounterCache.Increment(Request, Cache, SessionManager); } } base.OnLoad(e); }
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { string url = (string)Request.QueryString["Url"]; linkRedirect.NavigateUrl = url; if (SessionManager.CountersEnabled) { switch ((string)Request.QueryString["ObjectType"]) { case "Post": CounterCache.IncrementPostCounter(int.Parse(Request.QueryString["ObjectId"]), Cache, SessionManager); break; } } Response.Redirect(url, true); } } catch (Exception ex) { panelRedirect.Visible = false; ReportException(new Exception(string.Format( "This permalink may not exist. The following error was returned." + "<br>{0}", ex.Message))); } }
public static CounterCache GetCounterCache(Cache cache, SessionManager manager) { try { if (s_CounterCache.Expired) { lock (s_CounterCache) { if (s_CounterCache.Expired) { s_CounterCache.Flush(manager); } } } } catch (Exception ex) { manager.BlogService.EventLogWriteEntry(string.Format("GetCounterCache failed to flush the cache. {0}", ex.Message), EventLogEntryType.Error); s_CounterCache = new CounterCache(); } return(s_CounterCache); }
public Crawler(Web3Manager web3Manager, MongoClient mongoClient) { this.web3Manager = web3Manager; this.mongoClient = mongoClient; contractNeedModel = new ContractNeedCache(mongoClient.GetDatabase(Settings.Ins.mongodbDatabase)); logModel = new LogCache(mongoClient.GetDatabase(Settings.Ins.mongodbDatabase)); eventInfoModel = new EventInfoCache(mongoClient.GetDatabase(Settings.Ins.mongodbDatabase)); counterCache = new CounterCache(mongoClient.GetDatabase(Settings.Ins.mongodbDatabase)); }
public void IncrementCounter() { object ic = Request.QueryString["IncrementCounter"]; if (!IsPostBack && !ShowThumbnail && (ic == null || bool.Parse(ic.ToString()) == true)) { CounterCache.IncrementImageCounter(RequestId, Cache, SessionManager); } }
protected ReckonUnitBase() { CurrencyType = -1; CaptitalTradingRule = -1; HoldingTradingRule = -1; this.counterCacher = GetCounterCache(); externalMessageQueue.QueueItemProcessEvent += ExternalMessageQueue_QueueItemProcessEvent; }
public void Test() { const int capacity = 10; var random = new Random(31); var numbers = Enumerable.Range(-8, 16).ToArray(); var cache = new CounterCache <int, string>(capacity); var dic = numbers.ToDictionary(m => m, k => 0); for (var i = 0; i < numbers.Length * capacity; i++) { var num = numbers.Random(random); ++dic[num]; var keys = cache.GetAllKeys(); var removeFlag = cache.IsFull() && !keys.Contains(num); cache.GetOrAdd(num, k => k.ToString()); var newKeys = cache.GetAllKeys(); Assert.True(cache.Count <= capacity); var expectedCachedItem = dic.Where(m => m.Value != 0).ToArray(); if (removeFlag) { Assert.True(cache.Count == capacity); Assert.True(expectedCachedItem.Length == capacity + 1); var expectedRemoveItem = expectedCachedItem.Where(m => m.Key != num) .MinBy(m => m.Value).OrderBy(m => m.Key).First(); var removedKeys = keys.Except(newKeys).ToArray(); Assert.Single(removedKeys); Assert.Equal(expectedRemoveItem.Key, removedKeys[0]); var addedKeys = newKeys.Except(keys).ToArray(); Assert.Single(addedKeys); Assert.Equal(num, addedKeys[0]); dic[expectedRemoveItem.Key] = 0; } else { var actualKeys = newKeys.OrderBy(m => m).ToArray(); var expectKeys = expectedCachedItem.Select(m => m.Key).OrderBy(m => m).ToArray(); Assert.True(expectKeys.SequenceEqual(actualKeys)); } } }
/// <summary> /// Tries to find a counter that is supposed to be written at the specified address, /// returning the related event. /// </summary> /// <param name="counterCache">GPU counter cache to search on</param> /// <param name="gpuVa">GPU virtual address where the counter is supposed to be written</param> /// <returns>The counter event, or null if not present</returns> private static ICounterEvent FindEvent(CounterCache counterCache, ulong gpuVa) { return(counterCache.FindEvent(gpuVa)); }
/// <summary> /// 初始化委托缓存信息 /// </summary> /// <param name="orderNo"></param> /// <param name="strMessage"></param> /// <returns></returns> protected bool InitializeOrderCache(string orderNo, ref string strMessage) { //从缓存取撮合中心委托单与柜台委托单映射关系 if (OrderInfo == null) { if (this.counterCacher == null) { this.counterCacher = GetCounterCache(); } OrderInfo = this.counterCacher.GetOrderMappingInfo(orderNo); } if (OrderInfo == null) { strMessage = "GT-2500:柜台撮合中心委托映射关系丢失"; return(false); } TradeID = OrderInfo.TraderId; //买卖方向 BuySellType = OrderInfo.BuySellType; if (string.IsNullOrEmpty(CapitalAccount)) { //资金帐户 CapitalAccount = OrderInfo.CapitalAccount; } if (String.IsNullOrEmpty(HoldingAccount)) { //持仓帐户 HoldingAccount = OrderInfo.HoldingAccount; } if (String.IsNullOrEmpty(EntrustNumber)) { //柜台委托单号 EntrustNumber = OrderInfo.CounterOrderNo; if (!String.IsNullOrEmpty(EntrustNumber)) { //当发生故障恢复,加载已清算的id列表 if (TradeAmount == 0 && !HasLoadReckonedID) { LoadReckonedIDList(); } } } if (string.IsNullOrEmpty(Code)) { Code = OrderInfo.Code; } if (EntrustAmount == 0) { EntrustAmount = OrderInfo.EntrustAmount; } //初始化是否为盘前检查强行平仓和强行平仓类型 IsCheckForcedCloseOrder = OrderInfo.IsOpenMarketCheckOrder; QHForcedCloseType = OrderInfo.QHForcedCloseType; GetCurrencyType(); if (CurrencyType == -1) { strMessage = "GT-2591:[清算初始化]无法获取交易币种"; return(false); } //获取账户ID GetAccountID(); if (CapitalAccountId == -1) { strMessage = "GT-2592:[清算初始化]无法获取资金帐号ID"; return(false); } return(true); }
public AcceptLogic() { this.counterCacher = GetCounterCache(); }