/// <summary> /// 向队列中增加统计对象 /// </summary> /// <param name="tv">主题浏览数对象</param> /// <returns>成功返回true</returns> public static bool AddQuedStats(TopicView tv) { if (tv == null) { return(false); } if (queuedAllowCount != GeneralConfigs.GetConfig().TopicQueueStatsCount || queuedStatsList == null) { SetQueueCount(); } //Check for the limit if (queuedStatsList.ViewCount >= queuedAllowCount || queuedStatsList.Count >= 5) { //aquire the lock lock (queuedStatsList.SyncRoot) { //make sure the pool queue was not cleared during a wait for the lock if (queuedStatsList.ViewCount >= queuedAllowCount || queuedStatsList.Count >= 5) { TopicView[] tva = new TopicView[queuedStatsList.Count]; queuedStatsList.CopyTo(tva, 0); #if NET1 ClearTrackTopicQueue(new TopicViewCollection(tva)); #else ClearTrackTopicQueue(new TopicViewCollection <TopicView>(tva)); #endif queuedStatsList.Clear(); queuedStatsList.ViewCount = 0; } } } bool inArray = false; foreach (TopicView curtv in queuedStatsList) { if (curtv.TopicID == tv.TopicID) { curtv.ViewCount = curtv.ViewCount + tv.ViewCount; inArray = true; break; } } if (!inArray) { queuedStatsList.Add(tv); } queuedStatsList.ViewCount = queuedStatsList.ViewCount + 1; return(true); }
//public static bool ClearQueue(bool save) //{ // lock (queuedStatsList) // { // if (save) // { // TopicView[] array = new TopicView[queuedStatsList.Count]; // queuedStatsList.CopyTo(array, 0); // ClearTrackTopicQueue(new TopicViewCollection<TopicView>(array)); // } // queuedStatsList.Clear(); // } // return true; //} static bool AddQuedStats(TopicView tv) { if (tv == null) { return(false); } if (queuedAllowCount != GeneralConfigInfo.Current.TopicQueueStatsCount || queuedStatsList == null) { SetQueueCount(); } lock (queuedStatsList) { if ((queuedStatsList.ViewCount >= queuedAllowCount || queuedStatsList.Count >= 5) && (queuedStatsList.ViewCount >= queuedAllowCount || queuedStatsList.Count >= 5)) { var array = new TopicView[queuedStatsList.Count]; queuedStatsList.CopyTo(array, 0); ClearTrackTopicQueue(new TopicViewCollection <TopicView>(array)); queuedStatsList.Clear(); queuedStatsList.ViewCount = 0; } bool flag = false; foreach (TopicView current in queuedStatsList) { if (current.TopicID == tv.TopicID) { current.ViewCount += tv.ViewCount; flag = true; break; } } if (!flag) { queuedStatsList.Add(tv); } } queuedStatsList.ViewCount = queuedStatsList.ViewCount + 1; return(true); }